From: Bruno Haible Date: Sun, 28 Jun 2020 17:04:03 +0000 (+0200) Subject: getrandom: Fix compilation errors on older versions of mingw. X-Git-Tag: v1.0~3950 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=70872213ef6614cf52d5978a5fdf8b9e628fc786;p=gnulib.git getrandom: Fix compilation errors on older versions of mingw. Reported by Eli Zaretskii in . * m4/getrandom.m4 (gl_FUNC_GETRANDOM): Test whether exists. * lib/getrandom.c: If is not available, include and define/declare BCRYPT_ALG_HANDLE, BCRYPT_USE_SYSTEM_PREFERRED_RNG, BCryptGenRandom ourselves. --- diff --git a/ChangeLog b/ChangeLog index 0bfeb44f21..ce8dc4cfc2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2020-06-28 Bruno Haible + + getrandom: Fix compilation errors on older versions of mingw. + Reported by Eli Zaretskii in + . + * m4/getrandom.m4 (gl_FUNC_GETRANDOM): Test whether exists. + * lib/getrandom.c: If is not available, include and + define/declare BCRYPT_ALG_HANDLE, BCRYPT_USE_SYSTEM_PREFERRED_RNG, + BCryptGenRandom ourselves. + 2020-06-28 Bruno Haible clean-temp: Fix wrong errno in error message. diff --git a/lib/getrandom.c b/lib/getrandom.c index f0b3f53500..030a78bb08 100644 --- a/lib/getrandom.c +++ b/lib/getrandom.c @@ -29,7 +29,16 @@ #if defined _WIN32 && ! defined __CYGWIN__ # define WIN32_LEAN_AND_MEAN # include -# include +# if HAVE_BCRYPT_H +# include +# else +# include /* 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 # ifndef CRYPT_VERIFY_CONTEXT diff --git a/m4/getrandom.m4 b/m4/getrandom.m4 index 37fb10023a..2a0034bf76 100644 --- a/m4/getrandom.m4 +++ b/m4/getrandom.m4 @@ -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(