Debian Codegraph @

m4/getrandom.m4

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