From 90b3a5b610c51939aace88f3fd9ebf0d9cc74af3 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 31 May 2020 20:12:04 +0200 Subject: [PATCH] getentropy: Work around a macOS and Solaris problem. * lib/unistd.in.h: Include , 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 | 13 +++++++++++++ doc/glibc-functions/getentropy.texi | 10 +++++----- lib/unistd.in.h | 11 +++++++++++ m4/sys_random_h.m4 | 7 ++++++- m4/unistd_h.m4 | 3 ++- modules/unistd | 1 + 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9dea4c4f37..141ed8a330 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2020-05-31 Bruno Haible + + getentropy: Work around a macOS and Solaris problem. + * lib/unistd.in.h: Include , 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 fnmatch: merge from glibc diff --git a/doc/glibc-functions/getentropy.texi b/doc/glibc-functions/getentropy.texi index 5281dcd4ea..b7717e514b 100644 --- a/doc/glibc-functions/getentropy.texi +++ b/doc/glibc-functions/getentropy.texi @@ -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{}, not in @code{}, +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 diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 906f806c3e..71904fe5d9 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -118,6 +118,17 @@ # include #endif +/* Mac OS X 10.13, Solaris 11.4, and Android 9.0 declare getentropy in + , not in . */ +/* 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 +#endif + /* Android 4.3 declares fchownat in , not in . */ /* But avoid namespace pollution on glibc systems. */ #if (@GNULIB_FCHOWNAT@ || defined GNULIB_POSIXCHECK) && defined __ANDROID__ \ diff --git a/m4/sys_random_h.m4 b/m4/sys_random_h.m4 index c4505b60d2..a964b15784 100644 --- a/m4/sys_random_h.m4 +++ b/m4/sys_random_h.m4 @@ -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([[ diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index a3b4633f68..dfa38f85d6 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -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]) diff --git a/modules/unistd b/modules/unistd index f075b78029..5550646943 100644 --- a/modules/unistd +++ b/modules/unistd @@ -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)' \ -- 2.11.4.GIT