]> Savannah Git Hosting - gnulib.git/commitdiff
sys_random: Work around macOS bug.
authorBruno Haible <bruno@clisp.org>
Sat, 30 May 2020 23:02:21 +0000 (01:02 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 30 May 2020 23:02:21 +0000 (01:02 +0200)
* m4/sys_random_h.m4 (gl_HEADER_SYS_RANDOM): Include <sys/types.h> and
<stdlib.h> before <sys/random.h>.
* m4/getrandom.m4 (gl_FUNC_GETRANDOM): Likewise.
* lib/sys_random.in.h: On macOS, include <sys/types.h> and <stdlib.h>
first.
* doc/glibc-headers/sys_random.texi: Mention the macOS problem.

ChangeLog
doc/glibc-headers/sys_random.texi
lib/sys_random.in.h
m4/getrandom.m4
m4/sys_random_h.m4

index bf5762435119b06e46ed1a3f6a0a3bc7eb251498..43145dc5beb200ba9dd2de44a9e14de63fadc82b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-05-30  Bruno Haible  <bruno@clisp.org>
+
+       sys_random: Work around macOS bug.
+       * m4/sys_random_h.m4 (gl_HEADER_SYS_RANDOM): Include <sys/types.h> and
+       <stdlib.h> before <sys/random.h>.
+       * m4/getrandom.m4 (gl_FUNC_GETRANDOM): Likewise.
+       * lib/sys_random.in.h: On macOS, include <sys/types.h> and <stdlib.h>
+       first.
+       * doc/glibc-headers/sys_random.texi: Mention the macOS problem.
+
 2020-05-30  Bruno Haible  <bruno@clisp.org>
 
        getrandom: Override incompatible system function on Solaris 11.
index 1c28595c265dab408d261e2312675e2c89d3223b..3f33962652a429eae721668ebc2a49f7b2d9d552 100644 (file)
@@ -24,6 +24,9 @@ Portability problems fixed by Gnulib:
 This header file is missing on some platforms:
 glibc 2.24, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.11, IRIX 6.5, Cygwin, mingw, MSVC 14.
 @item
+This header file is not self-contained on some platforms:
+Mac OS X 10.13.
+@item
 This header file does not declare the @code{getrandom} function on some platforms:
 Mac OS X 10.5, FreeBSD 11.0, HP-UX 11.31, Solaris 11.0.
 @end itemize
index 4d12db95eab4dcd0f4ddca96b38f5e667716823b..290fa3938e6803dae62e7b429f33e129bf12e60e 100644 (file)
 
 #if @HAVE_SYS_RANDOM_H@
 
+/* On Mac OS X 10.5, <sys/random.h> assumes prior inclusion of <sys/types.h>.
+   On Max OS X 10.13, <sys/random.h> assumes prior inclusion of a file that
+   includes <Availability.h>, such as <stdlib.h> or <unistd.h>.  */
+# if defined __APPLE__ && defined __MACH__                  /* Mac OS X */
+#  include <sys/types.h>
+#  include <stdlib.h>
+# endif
+
 /* The include_next requires a split double-inclusion guard.  */
 # @INCLUDE_NEXT@ @NEXT_SYS_RANDOM_H@
 
index 9fee059e43aae3d0af8f3c3520ed38ccd659cf59..779c6ad8329f8cf10d1ab384286c408c954e81ae 100644 (file)
@@ -1,4 +1,4 @@
-# getrandom.m4 serial 3
+# getrandom.m4 serial 4
 dnl Copyright 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,
@@ -18,8 +18,10 @@ AC_DEFUN([gl_FUNC_GETRANDOM],
       [gl_cv_func_getrandom_ok],
       [AC_COMPILE_IFELSE(
          [AC_LANG_PROGRAM(
-            [[#include <sys/random.h>
+            [[/* Additional includes are needed before <sys/random.h> on Mac OS X.  */
               #include <sys/types.h>
+              #include <stdlib.h>
+              #include <sys/random.h>
               ssize_t getrandom (void *, size_t, unsigned int);
             ]],
             [[]])
index 135d241b5712e752e357dac63c9500d72b7fcafa..c4505b60d2609c43ef32ff5911f0df55d97d38e0 100644 (file)
@@ -1,4 +1,4 @@
-# sys_random_h.m4 serial 2
+# sys_random_h.m4 serial 3
 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,
@@ -20,6 +20,9 @@ AC_DEFUN([gl_HEADER_SYS_RANDOM],
   dnl corresponding gnulib module is not in use.
   gl_WARN_ON_USE_PREPARE([[
 #if HAVE_SYS_RANDOM_H
+/* Additional includes are needed before <sys/random.h> on Mac OS X.  */
+# include <sys/types.h>
+# include <stdlib.h>
 # include <sys/random.h>
 #endif
     ]],