]> Savannah Git Hosting - gnulib.git/commitdiff
sys_random: New module.
authorBruno Haible <bruno@clisp.org>
Sat, 30 May 2020 14:18:36 +0000 (16:18 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 30 May 2020 14:18:36 +0000 (16:18 +0200)
* 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.

ChangeLog
doc/glibc-headers/sys_random.texi [new file with mode: 0644]
doc/gnulib.texi
lib/sys_random.in.h
m4/getrandom.m4
m4/sys_random_h.m4 [new file with mode: 0644]
modules/getrandom
modules/sys_random [new file with mode: 0644]

index 2cb7edd31cfbc4e91ff07e5572b330d8de37da1b..3c4dd93b7cfb22085df54aacbfeab92f75615915 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+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().
diff --git a/doc/glibc-headers/sys_random.texi b/doc/glibc-headers/sys_random.texi
new file mode 100644 (file)
index 0000000..1c28595
--- /dev/null
@@ -0,0 +1,33 @@
+@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
index 3719978b6e701b7c1bb38dbb7a072ef347890f85..fd9d9b0e25dfa5518ea54ec56d5670e9bae55f4a 100644 (file)
@@ -3684,6 +3684,7 @@ not worked around by Gnulib.
 * resolv.h::
 * shadow.h::
 * sys/ioctl.h::
+* sys/random.h::
 * sysexits.h::
 * ttyent.h::
 @end menu
@@ -3718,6 +3719,7 @@ not worked around by Gnulib.
 @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
 
index e3f308ce48d2d726eb418aa9f678793c81464262..3997cf4c3bb34d2bcca0b02b5ebffb66fa97408b 100644 (file)
@@ -1,9 +1,72 @@
-#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 */
index ecb44aebf7680675e4d8762e2f53210e7857955f..79e5520931a9be8dcf633a8edf2f7ce86b889c5e 100644 (file)
@@ -1,4 +1,4 @@
-# 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,
@@ -8,6 +8,7 @@ dnl Written by Paul Eggert.
 
 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
diff --git a/m4/sys_random_h.m4 b/m4/sys_random_h.m4
new file mode 100644 (file)
index 0000000..d78307f
--- /dev/null
@@ -0,0 +1,43 @@
+# 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])
+])
index 2ae374f616fb7380ebac7fe0e98f2cbb8fc4fa35..f7b3ff9e29b1ccfa73b775c73c892164bf592db8 100644 (file)
@@ -3,10 +3,10 @@ Fill buffer with random bytes.
 
 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]
@@ -17,22 +17,9 @@ gl_FUNC_GETRANDOM
 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>
diff --git a/modules/sys_random b/modules/sys_random
new file mode 100644 (file)
index 0000000..1d0eb7c
--- /dev/null
@@ -0,0 +1,51 @@
+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