On Tue, Mar 8, 2011 at 8:39 PM, Kai Tietz <ktietz70@googlemail.com> wrote:
2011/3/8 Dock, Dion <dion_dock@mentor.com>:
>> > > From: Vincent Torri [mailto:vincent.torri@gmail.com]
>> > > Sent: Wednesday, March 02, 2011 11:08 PM
>> > > To: Dock, Dion
>> > > Cc: mingw-w64-public@lists.sourceforge.net
>> > > Subject: Re: [Mingw-w64-public] why aren't "secure" _s functions provided?
>> >
>> >
>> > On Thu, Mar 3, 2011 at 1:57 AM, Dock, Dion <dion_dock@mentor.com> wrote:
>> > > -----Original Message-----
>> > > From: Jon [mailto:10walls@gmail.com] On Behalf Of JonY
>> > > Sent: Monday, February 28, 2011 5:54 PM
>> > > To: Dock, Dion
>> > > Cc: mingw-w64-public@lists.sourceforge.net
>> > > Subject: Re: [Mingw-w64-public] why aren't "secure" _s functions provided?
>> > >
>> > > -----BEGIN PGP SIGNED MESSAGE-----
>> > > Hash: SHA1
>> > >
>> > > On 3/1/2011 08:27, Dock, Dion wrote:
>> > > > Why doesn't MinGW-64, etc. provide equivalents to Microsoft's secure
>> > > functions, for example, strcat_s, strncpy_s, etc.?  I understand they're not
>> > > part of the C standard, but the distribution includes various bits that contain
>> > > Microsoft functions, e.g. MessageBox.
>> > > >
>> > > > I'm curious as to whether this was a design decision or it just hasn't been
>> > > much of a priority.
>> > > >
>> > > > -Dion
>> > >
>> > > Its provided, see msvcr90 and msvcr100 import libraries. Remember to write
>> > > a manifest files to use the DLLs properly.
>> > >
>> > > The default msvcrt.dll import lib doesn't have them.
>> > >
>> >
>> > I've compiled bar.c with gcc and put it into libfoo.a.
>> >
>> > C:\Temp>C:\mingw_32\bin\i686-w64-mingw32-gcc.exe test.c -I libfoo.a C:\mingw_32\mingw\lib\libimagehlp.a
>> > C:\Views\dockd_mingw6\lip__mgls_nt\mgls_nt\src\mglslib\ libfoo.a(bar.o):bar.c:(.text+0x1bc0): undefined reference to `localtime_s'
>> > C:\Views\dockd_mingw6\lip__mgls_nt\mgls_nt\src\mglslib\ libfoo.a(bar.o):bar.c:(.text+0x1f89): undefined reference to `strnlen_s'
>> >
>> > I don't have experience with manifest files.  It's not clear which file gets the manifest (libfoo.a?) or how I would create it (I thought they were a Visual Studio thing).
>> >
>> > If I replace strnlen_s and localtime_s with strnlen and localtime, the build works.  This is why I concluded MinGW64 didn't support the "secure" functions.
>>
>> It's not a matter of mingw-w64 supporting them or not, it's a matter of knowing against which msvcrt dll your program is linked. These functions can have been introduced in some versions of DLL installed by Visual Studio. For example strnlen_s has been introduced in Visual Studio 2008 msvcrt (msvcr90.dll or msvcr90d.dll for the debug version).
>>
>> Afaik, mingw use msvcrt.dll, where the functions strnlen_s and localtime_s are not defined. And mingw must use msvcrt.dll as it must not depend on an installed version of Visual Studio
>>
>> hth
>>
>> Vincent Torri
>
> I'm back to my original question: can I use MinGW64 with source that has functions like strnlen_s?
>
> It sounds like the answer is: I can compile code with those functions in a DLL with a manifest for msvcr80 (or 90 or 100) or statically link the runtime into that DLL.  However, I cannot compile code with those functions using MinGW64.
>
> Or to put it another way, how would you get this to compile with MinGW64?
>        #include <stdio.h>
>        #include <string.h>
>
>        int main()
>        {
>           printf("%d\n", strnlen_s("foo", 2)); /* expect 2 */
>           return 0;
>        }
>
> Here's what I get:
> C:\Temp>C:\mingw_32\bin\i686-w64-mingw32-gcc.exe main.c
> C:\Users\dockd\AppData\Local\Temp\ccKqFt47.o:main.c:(.text+0x1e): undefined reference to `strnlen_s'
> collect2: ld returned 1 exit status
>
> -Dion
>
> ------------------------------------------------------------------------------
> What You Don't Know About Data Connectivity CAN Hurt You
> This paper provides an overview of data connectivity, details
> its effect on application quality, and explores various alternative
> solutions. http://p.sf.net/sfu/progress-d2d
> _______________________________________________
> Mingw-w64-public mailing list
> Mingw-w64-public@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>

There are two ways to accomplish this. You can install your headers
with option --enable-secure-api.
The other way (and that one working OOTB) - as we don't enable it by
default for good reasons - is to define before including any header
'#define MINGW_HAS_SECURE_API 1', or specify on command-line
-DMINGW_HAS_SECURE_API=1 on compilation.

Hey

in which file are those functions defined ? Are they defined in both 32 and 64 bits version ?

Vincent Torri