1# getrandom.m4 serial 6 2dnl Copyright 2020 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 Mac OS X. */ 22 #include <sys/types.h> 23 #include <stdlib.h> 24 #include <sys/random.h> 25 ssize_t getrandom (void *, size_t, unsigned int); 26 ]], 27 [[]]) 28 ], 29 [gl_cv_func_getrandom_ok=yes], 30 [gl_cv_func_getrandom_ok=no]) 31 ]) 32 if test $gl_cv_func_getrandom_ok = no; then 33 REPLACE_GETRANDOM=1 34 fi 35 fi 36 37 case "$host_os" in 38 mingw*) 39 AC_CHECK_HEADERS([bcrypt.h]) 40 AC_CACHE_CHECK([whether the bcrypt library is guaranteed to be present], 41 [gl_cv_lib_assume_bcrypt], 42 [AC_COMPILE_IFELSE( 43 [AC_LANG_PROGRAM( 44 [[#include <windows.h>]], 45 [[#if !(_WIN32_WINNT >= _WIN32_WINNT_WIN7) 46 cannot assume it 47 #endif 48 ]]) 49 ], 50 [gl_cv_lib_assume_bcrypt=yes], 51 [gl_cv_lib_assume_bcrypt=no]) 52 ]) 53 if test $gl_cv_lib_assume_bcrypt = yes; then 54 AC_DEFINE([HAVE_LIB_BCRYPT], [1], 55 [Define to 1 if the bcrypt library is guaranteed to be present.]) 56 LIB_GETRANDOM='-lbcrypt' 57 else 58 LIB_GETRANDOM='-ladvapi32' 59 fi 60 ;; 61 *) 62 LIB_GETRANDOM= ;; 63 esac 64 AC_SUBST([LIB_GETRANDOM]) 65]) 66