]> Savannah Git Hosting - gnulib.git/commitdiff
getentropy: Work around a macOS and Solaris problem.
authorBruno Haible <bruno@clisp.org>
Sun, 31 May 2020 18:12:04 +0000 (20:12 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 31 May 2020 18:18:25 +0000 (20:18 +0200)
* lib/unistd.in.h: Include <sys/random.h>, when needed for the
'getentropy' module.
* m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize
UNISTD_H_HAVE_SYS_RANDOM_H.
* m4/sys_random_h.m4 (gl_HEADER_SYS_RANDOM): Set
UNISTD_H_HAVE_SYS_RANDOM_H.
* modules/unistd (Makefile.am): Substitute UNISTD_H_HAVE_SYS_RANDOM_H.
* doc/glibc-functions/getentropy.texi: Document the macOS and Solaris
problem. List more platforms.

ChangeLog
doc/glibc-functions/getentropy.texi
lib/unistd.in.h
m4/sys_random_h.m4
m4/unistd_h.m4
modules/unistd

index 9dea4c4f37cd16888e8418f2a23877fe5a5712fb..141ed8a330a7decf868da65545fb0be6460e0951 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2020-05-31  Bruno Haible  <bruno@clisp.org>
+
+       getentropy: Work around a macOS and Solaris problem.
+       * lib/unistd.in.h: Include <sys/random.h>, when needed for the
+       'getentropy' module.
+       * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize
+       UNISTD_H_HAVE_SYS_RANDOM_H.
+       * m4/sys_random_h.m4 (gl_HEADER_SYS_RANDOM): Set
+       UNISTD_H_HAVE_SYS_RANDOM_H.
+       * modules/unistd (Makefile.am): Substitute UNISTD_H_HAVE_SYS_RANDOM_H.
+       * doc/glibc-functions/getentropy.texi: Document the macOS and Solaris
+       problem. List more platforms.
+
 2020-05-31  Paul Eggert  <eggert@cs.ucla.edu>
 
        fnmatch: merge from glibc
index 5281dcd4ea9acd4233067eb337ac9eaf25ad1280..b7717e514b52a95826d6de2ce06b167bee1fd24d 100644 (file)
@@ -21,13 +21,13 @@ Portability problems fixed by Gnulib:
 @itemize
 @item
 This function is missing on some platforms:
-glibc 2.24, Mac OS X 10.5, FreeBSD 11.0, NetBSD 5.0, OpenBSD 3.8,
-Solaris 11.0, Android 9.0.
+glibc 2.24, Mac OS X 10.11, FreeBSD 11.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.0, Cygwin, mingw, MSVC 14, Android 9.0.
+@item
+This function is declared in @code{<sys/random.h>}, not in @code{<unistd.h>},
+on some platforms:
+Mac OS X 10.13, Solaris 11.4, Android 9.0.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, IRIX 6.5, mingw, MSVC 14.
 @end itemize
index 906f806c3ec5de025a7b0f51613c535f27eec8cd..71904fe5d926c6f155c1698449c8e8a5ff2cd16e 100644 (file)
 # include <netdb.h>
 #endif
 
+/* Mac OS X 10.13, Solaris 11.4, and Android 9.0 declare getentropy in
+   <sys/random.h>, not in <unistd.h>.  */
+/* But avoid namespace pollution on glibc systems.  */
+#if (@GNULIB_GETENTROPY@ || defined GNULIB_POSIXCHECK) \
+    && ((defined __APPLE__ && defined __MACH__) || defined __sun \
+        || defined __ANDROID__) \
+    && @UNISTD_H_HAVE_SYS_RANDOM_H@ \
+    && !defined __GLIBC__
+# include <sys/random.h>
+#endif
+
 /* Android 4.3 declares fchownat in <sys/stat.h>, not in <unistd.h>.  */
 /* But avoid namespace pollution on glibc systems.  */
 #if (@GNULIB_FCHOWNAT@ || defined GNULIB_POSIXCHECK) && defined __ANDROID__ \
index c4505b60d2609c43ef32ff5911f0df55d97d38e0..a964b157841a6cdb804c07f1cb7cae01ddfc84bd 100644 (file)
@@ -1,4 +1,4 @@
-# sys_random_h.m4 serial 3
+# sys_random_h.m4 serial 4
 dnl Copyright (C) 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,
@@ -16,6 +16,11 @@ AC_DEFUN([gl_HEADER_SYS_RANDOM],
   fi
   AC_SUBST([HAVE_SYS_RANDOM_H])
 
+  m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
+  if test $ac_cv_header_sys_random_h = yes; then
+    UNISTD_H_HAVE_SYS_RANDOM_H=1
+  fi
+
   dnl Check for declarations of anything we want to poison if the
   dnl corresponding gnulib module is not in use.
   gl_WARN_ON_USE_PREPARE([[
index a3b4633f6824528aa97d021369ac3e13590582fb..dfa38f85d60151e19884a45455afd68ff51f2e1e 100644 (file)
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 79
+# unistd_h.m4 serial 80
 dnl Copyright (C) 2006-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,
@@ -200,6 +200,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   REPLACE_UNLINKAT=0;     AC_SUBST([REPLACE_UNLINKAT])
   REPLACE_USLEEP=0;       AC_SUBST([REPLACE_USLEEP])
   REPLACE_WRITE=0;        AC_SUBST([REPLACE_WRITE])
+  UNISTD_H_HAVE_SYS_RANDOM_H=0; AC_SUBST([UNISTD_H_HAVE_SYS_RANDOM_H])
   UNISTD_H_HAVE_WINSOCK2_H=0; AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H])
   UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0;
                            AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS])
index f075b780291f1f46dbe77ba8c866aacd38cc9100..5550646943513223f1df8b9c9d19c32df2e25bad 100644 (file)
@@ -174,6 +174,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's|@''REPLACE_UNLINKAT''@|$(REPLACE_UNLINKAT)|g' \
              -e 's|@''REPLACE_USLEEP''@|$(REPLACE_USLEEP)|g' \
              -e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \
+             -e 's|@''UNISTD_H_HAVE_SYS_RANDOM_H''@|$(UNISTD_H_HAVE_SYS_RANDOM_H)|g' \
              -e 's|@''UNISTD_H_HAVE_WINSOCK2_H''@|$(UNISTD_H_HAVE_WINSOCK2_H)|g' \
              -e 's|@''UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \