1# getrandom.m4 serial 8 2dnl Copyright 2020-2021 Free Software Foundation, Inc. 3dnl This file is free software; the Free Software Foundation 4dnl gives unlimited permission to copy and/or distribute it, 5dnl with or without modifications, as long as this notice is preserved. 6 7dnl Written by Paul Eggert. 8 9AC_DEFUN([gl_FUNC_GETRANDOM], 10[ 11 AC_REQUIRE([gl_SYS_RANDOM_H_DEFAULTS]) 12 AC_CHECK_FUNCS_ONCE([getrandom]) 13 if test "$ac_cv_func_getrandom" != yes; then 14 HAVE_GETRANDOM=0 15 else 16 dnl On Solaris 11.4 the return type is 'int', not 'ssize_t'. 17 AC_CACHE_CHECK([whether getrandom is compatible with its GNU+BSD signature], 18 [gl_cv_func_getrandom_ok], 19 [AC_COMPILE_IFELSE( 20 [AC_LANG_PROGRAM( 21 [[/* Additional includes are needed before <sys/random.h> on uClibc 22 and Mac OS X. */ 23 #include <sys/types.h> 24 #include <stdlib.h> 25 #include <sys/random.h> 26 ssize_t getrandom (void *, size_t, unsigned int); 27 ]], 28 [[]]) 29 ], 30 [gl_cv_func_getrandom_ok=yes], 31 [gl_cv_func_getrandom_ok=no]) 32 ]) 33 if test $gl_cv_func_getrandom_ok = no; then 34 REPLACE_GETRANDOM=1 35 fi 36 fi 37 38 case "$host_os" in 39 mingw*) 40 AC_CHECK_HEADERS([bcrypt.h], [], [], 41 [[#include <windows.h> 42 ]]) 43 AC_CACHE_CHECK([whether the bcrypt library is guaranteed to be present], 44 [gl_cv_lib_assume_bcrypt], 45 [AC_COMPILE_IFELSE( 46 [AC_LANG_PROGRAM( 47 [[#include <windows.h>]], 48 [[#if !(_WIN32_WINNT >= _WIN32_WINNT_WIN7) 49 cannot assume it 50 #endif 51 ]]) 52 ], 53 [gl_cv_lib_assume_bcrypt=yes], 54 [gl_cv_lib_assume_bcrypt=no]) 55 ]) 56 if test $gl_cv_lib_assume_bcrypt = yes; then 57 AC_DEFINE([HAVE_LIB_BCRYPT], [1], 58 [Define to 1 if the bcrypt library is guaranteed to be present.]) 59 LIB_GETRANDOM='-lbcrypt' 60 else 61 LIB_GETRANDOM='-ladvapi32' 62 fi 63 ;; 64 *) 65 LIB_GETRANDOM= ;; 66 esac 67 AC_SUBST([LIB_GETRANDOM]) 68]) 69