getrandom.m4 2.4 KB

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