# HG changeset patch # Parent fa07f2e1d79fbae648a758b6b1fa4502aa82b53f Address MinGW-Issue #39658; declare rand_s() function. * include/stdlib.h: When the user has defined... [_CRT_RAND_S]: ...this optional feature test macro, and then... [__MSVCRT_VERSION__ >= __MSVCR80_DLL]: ...either this non-free, or... [_WIN32_WINNT>=_WIN32_WINNT_VISTA]: ...this system-standard runtime library version constraint is satisfied, then... (rand_s): ...declare function prototype. diff --git a/mingwrt/include/stdlib.h b/mingwrt/include/stdlib.h --- a/mingwrt/include/stdlib.h +++ b/mingwrt/include/stdlib.h @@ -5,11 +5,11 @@ * associated macros, and manifest constant definitions. * * $Id$ * * Written by Colin Peters - * Copyright (C) 1997-2009, 2011, 2014-2016, 2018, MinGW.org Project. + * Copyright (C) 1997-2009, 2011, 2014-2016, 2018, 2019, MinGW.org Project. * * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation @@ -479,10 +479,29 @@ wchar_t *_wfullpath (wchar_t *, const wc _CRTIMP __cdecl __MINGW_NOTHROW int mbtowc (wchar_t *, const char *, size_t); _CRTIMP __cdecl __MINGW_NOTHROW int rand (void); _CRTIMP __cdecl __MINGW_NOTHROW void srand (unsigned int); +/* rand() is devoid of entropy, and is thus a mediocre pseudo-random number + * generator. Microsoft do offer a better quality (bogusly dubbed as a more + * secure) PRNG, in the guise of rand_s(), but it + * + * 1) must be explicitly enabled, by user defined feature test macro; + */ +#ifdef _CRT_RAND_S +/* + * 2) is not supported on Win9x, nor any WinNT version prior to WinXP; + * 3) on WinXP, requires linking with non-free MSVCR80.DLL, or later; + * 4) is provided by MSVCRT.DLL, only from Vista onward. + */ +#if __MSVCRT_VERSION__ >= __MSVCR80_DLL || _WIN32_WINNT >= _WIN32_WINNT_VISTA + +_CRTIMP __cdecl __MINGW_NOTHROW int rand_s (unsigned int *); + +#endif /* Win-Vista || MSVCR80.DLL || later */ +#endif /* _CRT_RAND_S enabled */ + _CRTIMP __cdecl __MINGW_NOTHROW void abort (void) __MINGW_ATTRIB_NORETURN; _CRTIMP __cdecl __MINGW_NOTHROW void exit (int) __MINGW_ATTRIB_NORETURN; /* Note: this is in startup code, not imported directly from the runtime DLL */