]> Savannah Git Hosting - gnulib.git/commitdiff
getrandom: Fix compilation errors on older versions of mingw.
authorBruno Haible <bruno@clisp.org>
Sun, 28 Jun 2020 17:04:03 +0000 (19:04 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 28 Jun 2020 17:04:03 +0000 (19:04 +0200)
Reported by Eli Zaretskii <eliz@gnu.org> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-06/msg00059.html>.

* m4/getrandom.m4 (gl_FUNC_GETRANDOM): Test whether <bcrypt.h> exists.
* lib/getrandom.c: If <bcrypt.h> is not available, include <ntdef.h> and
define/declare BCRYPT_ALG_HANDLE, BCRYPT_USE_SYSTEM_PREFERRED_RNG,
BCryptGenRandom ourselves.

ChangeLog
lib/getrandom.c
m4/getrandom.m4

index 0bfeb44f219fd1411b39a0095b91e1755c81d1cb..ce8dc4cfc24b13f4a200bb16cacbabf5814118d6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-06-28  Bruno Haible  <bruno@clisp.org>
+
+       getrandom: Fix compilation errors on older versions of mingw.
+       Reported by Eli Zaretskii <eliz@gnu.org> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2020-06/msg00059.html>.
+       * m4/getrandom.m4 (gl_FUNC_GETRANDOM): Test whether <bcrypt.h> exists.
+       * lib/getrandom.c: If <bcrypt.h> is not available, include <ntdef.h> and
+       define/declare BCRYPT_ALG_HANDLE, BCRYPT_USE_SYSTEM_PREFERRED_RNG,
+       BCryptGenRandom ourselves.
+
 2020-06-28  Bruno Haible  <bruno@clisp.org>
 
        clean-temp: Fix wrong errno in error message.
index f0b3f53500708025e719188802071bbe6417a09d..030a78bb08d4ea09930449b2cb1c64c4752d281e 100644 (file)
 #if defined _WIN32 && ! defined __CYGWIN__
 # define WIN32_LEAN_AND_MEAN
 # include <windows.h>
-# include <bcrypt.h>
+# if HAVE_BCRYPT_H
+#  include <bcrypt.h>
+# else
+#  include <ntdef.h> /* NTSTATUS */
+typedef void * BCRYPT_ALG_HANDLE;
+#  define BCRYPT_USE_SYSTEM_PREFERRED_RNG 0x00000002
+#  if HAVE_LIB_BCRYPT
+extern NTSTATUS WINAPI BCryptGenRandom (BCRYPT_ALG_HANDLE, UCHAR *, ULONG, ULONG);
+#  endif
+# endif
 # if !HAVE_LIB_BCRYPT
 #  include <wincrypt.h>
 #  ifndef CRYPT_VERIFY_CONTEXT
index 37fb10023a0be821808849c038aefab77a535396..2a0034bf76c0c94eb549b6fdeadf569e248cf299 100644 (file)
@@ -1,4 +1,4 @@
-# getrandom.m4 serial 5
+# getrandom.m4 serial 6
 dnl Copyright 2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -36,6 +36,7 @@ AC_DEFUN([gl_FUNC_GETRANDOM],
 
   case "$host_os" in
     mingw*)
+      AC_CHECK_HEADERS([bcrypt.h])
       AC_CACHE_CHECK([whether the bcrypt library is guaranteed to be present],
         [gl_cv_lib_assume_bcrypt],
         [AC_COMPILE_IFELSE(