aboutsummaryrefslogtreecommitdiffstats
path: root/src/librandom/random_devurandom.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2022-04-09 02:28:05 +0000
committerLaurent Bercot <ska@appnovation.com>2022-04-09 02:28:05 +0000
commit4e75b40d8a96c5d51490ddea43566fe8e6d4168c (patch)
tree06358f285c713a7f05297cb7d2826319d6561683 /src/librandom/random_devurandom.c
parent1fedaae65b56b8548cdf2d8c26e2becece5fec07 (diff)
downloadskalibs-4e75b40d8a96c5d51490ddea43566fe8e6d4168c.tar.gz
Prepare for 2.12.0.0. librandom revamp.
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/librandom/random_devurandom.c')
-rw-r--r--src/librandom/random_devurandom.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/librandom/random_devurandom.c b/src/librandom/random_devurandom.c
new file mode 100644
index 0000000..0ad752b
--- /dev/null
+++ b/src/librandom/random_devurandom.c
@@ -0,0 +1,22 @@
+/* ISC license. */
+
+#include <stddef.h>
+
+#include <skalibs/allreadwrite.h>
+#include <skalibs/strerr2.h>
+#include <skalibs/djbunix.h>
+#include <skalibs/random.h>
+
+void random_devurandom (char *s, size_t n)
+{
+ static int random_fd = -1 ;
+ size_t r ;
+ if (random_fd < 0)
+ {
+ random_fd = openbc_read("/dev/urandom") ;
+ if (random_fd < 0)
+ strerr_diefu2sys(111, "open ", "/dev/urandom") ;
+ }
+ r = allread(random_fd, s, n) ;
+ if (r < n) strerr_diefu2sys(111, "read from ", "/dev/urandom") ;
+}