summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-05-30 17:33:46 +0200
committerBruno Haible <bruno@clisp.org>2020-05-30 17:33:46 +0200
commit67ae31b60bedc0a3f1ff4c06177054685b9dcc95 (patch)
tree40fe17f688df693195460133b8ea0968c8b81f21 /lib
parent9e7d098310117f0b17e7868124652a392b0a9854 (diff)
downloadgnulib-67ae31b60bedc0a3f1ff4c06177054685b9dcc95.tar.gz
getrandom: Override incompatible system function on Solaris 11.
* lib/sys_random.in.h (getrandom): Override if REPLACE_GETRANDOM is 1. * lib/getrandom.c (getrandom): When the system has getrandom, just invoke it. * m4/getrandom.m4 (gl_FUNC_GETRANDOM): Set REPLACE_GETRANDOM if the system's getrandom function's prototype is not the expected one. * m4/sys_random_h.m4 (gl_SYS_RANDOM_H_DEFAULTS): Initialize REPLACE_GETRANDOM. * modules/sys_random (Makefile.am): Substitute REPLACE_GETRANDOM. * modules/getrandom (modules/getrandom): Consider REPLACE_GETRANDOM. * tests/test-getrandom.c (main): Allow error EINVAL as an alternative to EAGAIN. * doc/glibc-functions/getrandom.texi: Mention the new module and the Solaris problem.
Diffstat (limited to 'lib')
-rw-r--r--lib/getrandom.c8
-rw-r--r--lib/sys_random.in.h16
2 files changed, 21 insertions, 3 deletions
diff --git a/lib/getrandom.c b/lib/getrandom.c
index 9b6ecb43be..f20ffe0112 100644
--- a/lib/getrandom.c
+++ b/lib/getrandom.c
@@ -21,16 +21,21 @@
#include <sys/random.h>
-#include "minmax.h"
#include <fcntl.h>
#include <stdbool.h>
#include <unistd.h>
+#include "minmax.h"
+
/* Set BUFFER (of size LENGTH) to random bytes under the control of FLAGS.
Return the number of bytes written, or -1 on error. */
ssize_t
getrandom (void *buffer, size_t length, unsigned int flags)
+#undef getrandom
{
+#if HAVE_GETRANDOM
+ return getrandom (buffer, length, flags);
+#else
static int randfd[2] = { -1, -1 };
bool devrandom = (flags & GRND_RANDOM) != 0;
int fd = randfd[devrandom];
@@ -49,4 +54,5 @@ getrandom (void *buffer, size_t length, unsigned int flags)
}
return read (fd, buffer, length);
+#endif
}
diff --git a/lib/sys_random.in.h b/lib/sys_random.in.h
index 3997cf4c3b..4d12db95ea 100644
--- a/lib/sys_random.in.h
+++ b/lib/sys_random.in.h
@@ -51,13 +51,25 @@
#if @GNULIB_GETRANDOM@
/* Fill a buffer with random bytes. */
-# if !@HAVE_GETRANDOM@
+# if @REPLACE_GETRANDOM@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef getrandom
+# define getrandom rpl_getrandom
+# endif
+_GL_FUNCDECL_RPL (getrandom, ssize_t,
+ (void *buffer, size_t length, unsigned int flags)
+ _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (getrandom, ssize_t,
+ (void *buffer, size_t length, unsigned int flags));
+# else
+# if !@HAVE_GETRANDOM@
_GL_FUNCDECL_SYS (getrandom, ssize_t,
(void *buffer, size_t length, unsigned int flags)
_GL_ARG_NONNULL ((1)));
-# endif
+# endif
_GL_CXXALIAS_SYS (getrandom, ssize_t,
(void *buffer, size_t length, unsigned int flags));
+# endif
_GL_CXXALIASWARN (getrandom);
#elif defined GNULIB_POSIXCHECK
# undef getrandom