[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
sys_random: Work around macOS bug
From: |
Bruno Haible |
Subject: |
sys_random: Work around macOS bug |
Date: |
Sun, 31 May 2020 01:06:02 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-177-generic; KDE/5.18.0; x86_64; ; ) |
On Mac OS X, the header file <sys/random.h> is not self-contained.
On Mac OS X 10.5:
In file included from ./sys/random.h:28,
from ../../gllib/getrandom.c:22:
/usr/include/sys/random.h:37: error: syntax error before ‘u_int’
It needs <sys/types.h> to be included first.
On Mac OS X 10.13:
In file included from ../../gllib/getrandom.c:22:
In file included from ./sys/random.h:28:
/usr/include/sys/random.h:36:17: error: expected parameter declarator
__OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0)
__WATCHOS_AVAILABLE(3.0)
^
It needs <stdlib.h> or <unistd.h> to be included first.
This patch provides a workaround.
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.
diff --git a/doc/glibc-headers/sys_random.texi
b/doc/glibc-headers/sys_random.texi
index 1c28595..3f33962 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 4d12db9..290fa39 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, <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@
diff --git a/m4/getrandom.m4 b/m4/getrandom.m4
index 9fee059..779c6ad 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 <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);
]],
[[]])
diff --git a/m4/sys_random_h.m4 b/m4/sys_random_h.m4
index 135d241..c4505b6 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 <sys/random.h> on Mac OS X. */
+# include <sys/types.h>
+# include <stdlib.h>
# include <sys/random.h>
#endif
]],
- [PATCH] getentropy, getrandom: new modules, Paul Eggert, 2020/05/25
- Re: [PATCH] getentropy, getrandom: new modules, Bruno Haible, 2020/05/30
- Re: [PATCH] getentropy, getrandom: new modules, Bruno Haible, 2020/05/30
- sys_random: Work around macOS bug,
Bruno Haible <=
Re: [PATCH] getentropy, getrandom: new modules, Bruno Haible, 2020/05/30
fix list of crypto devices for NetBSD, OpenBSD, Bruno Haible, 2020/05/30
fix list of crypto devices for Solaris, Bruno Haible, 2020/05/31
getrandom: Add support for native Windows, Bruno Haible, 2020/05/31
getrandom: doc and test tweaks, Bruno Haible, 2020/05/31
Re: [PATCH] getentropy, getrandom: new modules, Bruno Haible, 2020/05/31