From: Keith Marshall Date: Tue, 21 Jan 2020 22:03:45 +0000 (+0000) Subject: Address MinGW-Issue #39658; declare rand_s() function. X-Git-Tag: wsl-5.3-release~8 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=3edbad03398142e3fe3d3bb55fa506b5b03acecd;p=mingw%2Fmingw-org-wsl.git Address MinGW-Issue #39658; declare rand_s() function. --- diff --git a/mingwrt/ChangeLog b/mingwrt/ChangeLog index 40cc39a..70d3932 100644 --- a/mingwrt/ChangeLog +++ b/mingwrt/ChangeLog @@ -1,3 +1,14 @@ +2020-01-21 Keith Marshall + + 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. + 2020-01-17 Keith Marshall Support GCC-9.x gratuitous dependency on ftruncate64() function. diff --git a/mingwrt/include/stdlib.h b/mingwrt/include/stdlib.h index bf7d72d..9eb4801 100644 --- a/mingwrt/include/stdlib.h +++ b/mingwrt/include/stdlib.h @@ -508,6 +508,25 @@ _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;