+2020-05-30 Bruno Haible <bruno@clisp.org>
+
+ sys_random: New module.
+ * lib/sys_random.in.h: Use the common idioms for overridable header
+ files.
+ * m4/sys_random_h.m4: New file.
+ * m4/getrandom.m4 (gl_FUNC_GETRANDOM): Require gl_SYS_RANDOM_H_DEFAULTS.
+ * modules/sys_random: New file.
+ * modules/getrandom (Files): Remove lib/sys_random.in.h.
+ (Depends-on): Add sys_random.
+ (configure.ac): Use gl_SYS_RANDOM_MODULE_INDICATOR, not
+ gl_UNISTD_MODULE_INDICATOR.
+ (Makefile.am): Don't generate sys/random.h here.
+ * doc/glibc-headers/sys_random.texi: New file.
+ * doc/gnulib.texi: Include it.
+
2020-05-30 Bruno Haible <bruno@clisp.org>
unistd: Remove conflicting declaration of getrandom().
--- /dev/null
+@node sys/random.h
+@section @file{sys/random.h}
+
+Declares the function @code{getrandom} and the flags for it.
+
+Documentation:
+@itemize
+@item
+@ifinfo
+@ref{Unpredictable Bytes,,Generating Unpredictable Bytes,libc},
+@end ifinfo
+@ifnotinfo
+@url{https://www.gnu.org/software/libc/manual/html_node/Unpredictable-Bytes.html},
+@end ifnotinfo
+@item
+@uref{https://www.kernel.org/doc/man-pages/online/pages/man2/getrandom.2.html,,man getrandom}.
+@end itemize
+
+Gnulib module: sys_random
+
+Portability problems fixed by Gnulib:
+@itemize
+@item
+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 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
+
+Portability problems not fixed by Gnulib:
+@itemize
+@end itemize
* resolv.h::
* shadow.h::
* sys/ioctl.h::
+* sys/random.h::
* sysexits.h::
* ttyent.h::
@end menu
@include glibc-headers/resolv.texi
@include glibc-headers/shadow.texi
@include glibc-headers/sys_ioctl.texi
+@include glibc-headers/sys_random.texi
@include glibc-headers/sysexits.texi
@include glibc-headers/ttyent.texi
-#ifndef _SYS_RANDOM_H
-#define _SYS_RANDOM_H 1
+/* Substitute for <sys/random.h>.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <https://www.gnu.org/licenses/>. */
+
+# if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+# endif
+@PRAGMA_COLUMNS@
+
+#ifndef _@GUARD_PREFIX@_SYS_RANDOM_H
+
+#if @HAVE_SYS_RANDOM_H@
+
+/* The include_next requires a split double-inclusion guard. */
+# @INCLUDE_NEXT@ @NEXT_SYS_RANDOM_H@
+
+#endif
+
+#ifndef _@GUARD_PREFIX@_SYS_RANDOM_H
+#define _@GUARD_PREFIX@_SYS_RANDOM_H
#include <sys/types.h>
-#define GRND_NONBLOCK 1
-#define GRND_RANDOM 2
-ssize_t getrandom (void *, size_t, unsigned int);
+/* Define the GRND_* constants. */
+#ifndef GRND_NONBLOCK
+# define GRND_NONBLOCK 1
+# define GRND_RANDOM 2
#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+
+/* The definition of _GL_ARG_NONNULL is copied here. */
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+
+
+/* Declare overridden functions. */
+
+
+#if @GNULIB_GETRANDOM@
+/* Fill a buffer with random bytes. */
+# if !@HAVE_GETRANDOM@
+_GL_FUNCDECL_SYS (getrandom, ssize_t,
+ (void *buffer, size_t length, unsigned int flags)
+ _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (getrandom, ssize_t,
+ (void *buffer, size_t length, unsigned int flags));
+_GL_CXXALIASWARN (getrandom);
+#elif defined GNULIB_POSIXCHECK
+# undef getrandom
+# if HAVE_RAW_DECL_GETRANDOM
+_GL_WARN_ON_USE (getrandom, "getrandom is unportable - "
+ "use gnulib module getrandom for portability");
+# endif
+#endif
+
+
+#endif /* _@GUARD_PREFIX@_SYS_RANDOM_H */
+#endif /* _@GUARD_PREFIX@_SYS_RANDOM_H */
-# getrandom.m4
+# getrandom.m4 serial 2
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,
AC_DEFUN([gl_FUNC_GETRANDOM],
[
+ AC_REQUIRE([gl_SYS_RANDOM_H_DEFAULTS])
AC_CHECK_FUNCS_ONCE([getrandom])
if test "$ac_cv_func_getrandom" != yes; then
HAVE_GETRANDOM=0
--- /dev/null
+# sys_random_h.m4 serial 1
+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,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_HEADER_SYS_RANDOM],
+[
+ AC_REQUIRE([gl_SYS_RANDOM_H_DEFAULTS])
+ dnl <sys/random.h> is always overridden, because of GNULIB_POSIXCHECK.
+ gl_CHECK_NEXT_HEADERS([sys/random.h])
+ if test $ac_cv_header_sys_random_h = yes; then
+ HAVE_SYS_RANDOM_H=1
+ else
+ HAVE_SYS_RANDOM_H=0
+ fi
+ AC_SUBST([HAVE_SYS_RANDOM_H])
+
+ 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([[
+#if HAVE_SYS_RANDOM_H
+# include <sys/random.h>
+#endif
+ ]],
+ [getrandom])
+])
+
+AC_DEFUN([gl_SYS_RANDOM_MODULE_INDICATOR],
+[
+ dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+ AC_REQUIRE([gl_SYS_RANDOM_H_DEFAULTS])
+ gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+ dnl Define it also as a C macro, for the benefit of the unit tests.
+ gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_SYS_RANDOM_H_DEFAULTS],
+[
+ GNULIB_GETRANDOM=0; AC_SUBST([GNULIB_GETRANDOM])
+ dnl Assume proper GNU behavior unless another module says otherwise.
+ HAVE_GETRANDOM=1; AC_SUBST([HAVE_GETRANDOM])
+])
Files:
lib/getrandom.c
-lib/sys_random.in.h
m4/getrandom.m4
Depends-on:
+sys_random
crypto/gc-random [test $HAVE_GETRANDOM = 0]
fcntl-h [test $HAVE_GETRANDOM = 0]
minmax [test $HAVE_GETRANDOM = 0]
if test $HAVE_GETRANDOM = 0; then
AC_LIBOBJ([getrandom])
fi
-gl_UNISTD_MODULE_INDICATOR([getrandom])
+gl_SYS_RANDOM_MODULE_INDICATOR([getrandom])
Makefile.am:
-BUILT_SOURCES += sys/random.h
-
-# We need the following in order to create <sys/random.h> when the system
-# doesn't have one that works with the given compiler.
-sys/random.h: sys_random.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H)
- $(AM_V_at)$(MKDIR_P) sys
- $(AM_V_GEN)rm -f $@-t $@ && \
- { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
- cat $(srcdir)/sys_random.in.h; \
- } > $@-t && \
- mv -f $@-t $@
-MOSTLYCLEANFILES += sys/random.h sys/random.h-t
-MOSTLYCLEANDIRS += sys
Include:
<sys/random.h>
--- /dev/null
+Description:
+A GNU-like <sys/random.h>.
+
+Files:
+lib/sys_random.in.h
+m4/sys_random_h.m4
+
+Depends-on:
+include_next
+snippet/arg-nonnull
+snippet/c++defs
+snippet/warn-on-use
+
+configure.ac:
+gl_HEADER_SYS_RANDOM
+AC_PROG_MKDIR_P
+
+Makefile.am:
+BUILT_SOURCES += sys/random.h
+
+# We need the following in order to create <sys/random.h> when the system
+# doesn't have one.
+sys/random.h: sys_random.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+ $(AM_V_at)$(MKDIR_P) sys
+ $(AM_V_GEN)rm -f $@-t $@ && \
+ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+ sed -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
+ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+ -e 's|@''NEXT_SYS_RANDOM_H''@|$(NEXT_SYS_RANDOM_H)|g' \
+ -e 's|@''HAVE_SYS_RANDOM_H''@|$(HAVE_SYS_RANDOM_H)|g' \
+ -e 's/@''GNULIB_GETRANDOM''@/$(GNULIB_GETRANDOM)/g' \
+ -e 's/@''HAVE_GETRANDOM''@/$(HAVE_GETRANDOM)/g' \
+ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+ < $(srcdir)/sys_random.in.h; \
+ } > $@-t && \
+ mv -f $@-t $@
+MOSTLYCLEANFILES += sys/random.h sys/random.h-t
+MOSTLYCLEANDIRS += sys
+
+Include:
+<sys/random.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all