OSDN Git Service

Address MinGW-Issue #39658; declare rand_s() function.
authorKeith Marshall <keith@users.osdn.me>
Tue, 21 Jan 2020 22:03:45 +0000 (22:03 +0000)
committerKeith Marshall <keith@users.osdn.me>
Tue, 21 Jan 2020 22:03:45 +0000 (22:03 +0000)
mingwrt/ChangeLog
mingwrt/include/stdlib.h

index 40cc39a..70d3932 100644 (file)
@@ -1,3 +1,14 @@
+2020-01-21  Keith Marshall  <keith@users.osdn.me>
+
+       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  <keith@users.osdn.me>
 
        Support GCC-9.x gratuitous dependency on ftruncate64() function.
index bf7d72d..9eb4801 100644 (file)
@@ -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;