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