From afdf2fbbe1dee48a75065aa351e9e526330317fe Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 31 May 2020 01:02:21 +0200 Subject: [PATCH] sys_random: Work around macOS bug. * m4/sys_random_h.m4 (gl_HEADER_SYS_RANDOM): Include and before . * m4/getrandom.m4 (gl_FUNC_GETRANDOM): Likewise. * lib/sys_random.in.h: On macOS, include and first. * doc/glibc-headers/sys_random.texi: Mention the macOS problem. --- ChangeLog | 10 ++++++++++ doc/glibc-headers/sys_random.texi | 3 +++ lib/sys_random.in.h | 8 ++++++++ m4/getrandom.m4 | 6 ++++-- m4/sys_random_h.m4 | 5 ++++- 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index bf57624351..43145dc5be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2020-05-30 Bruno Haible + + sys_random: Work around macOS bug. + * m4/sys_random_h.m4 (gl_HEADER_SYS_RANDOM): Include and + before . + * m4/getrandom.m4 (gl_FUNC_GETRANDOM): Likewise. + * lib/sys_random.in.h: On macOS, include and + first. + * doc/glibc-headers/sys_random.texi: Mention the macOS problem. + 2020-05-30 Bruno Haible getrandom: Override incompatible system function on Solaris 11. diff --git a/doc/glibc-headers/sys_random.texi b/doc/glibc-headers/sys_random.texi index 1c28595c26..3f33962652 100644 --- a/doc/glibc-headers/sys_random.texi +++ b/doc/glibc-headers/sys_random.texi @@ -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 diff --git a/lib/sys_random.in.h b/lib/sys_random.in.h index 4d12db95ea..290fa3938e 100644 --- a/lib/sys_random.in.h +++ b/lib/sys_random.in.h @@ -23,6 +23,14 @@ #if @HAVE_SYS_RANDOM_H@ +/* On Mac OS X 10.5, assumes prior inclusion of . + On Max OS X 10.13, assumes prior inclusion of a file that + includes , such as or . */ +# if defined __APPLE__ && defined __MACH__ /* Mac OS X */ +# include +# include +# endif + /* The include_next requires a split double-inclusion guard. */ # @INCLUDE_NEXT@ @NEXT_SYS_RANDOM_H@ diff --git a/m4/getrandom.m4 b/m4/getrandom.m4 index 9fee059e43..779c6ad832 100644 --- a/m4/getrandom.m4 +++ b/m4/getrandom.m4 @@ -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 + [[/* Additional includes are needed before on Mac OS X. */ #include + #include + #include ssize_t getrandom (void *, size_t, unsigned int); ]], [[]]) diff --git a/m4/sys_random_h.m4 b/m4/sys_random_h.m4 index 135d241b57..c4505b60d2 100644 --- a/m4/sys_random_h.m4 +++ b/m4/sys_random_h.m4 @@ -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 on Mac OS X. */ +# include +# include # include #endif ]], -- 2.39.5