From 9569e629c8e73dcdc3f93b5fc6156db827d6b7b1 Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Mon, 15 Feb 2021 13:08:54 +0200 Subject: cease inefficient /dev/urandom fiddling. Instead of reading /dev/urandom like a file (i.e. overhead / extra syscalls, etc.), just use getrandom(2) directly, lol. Signed-off-by: Gediminas Jakutis --- src/datagen.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/datagen.c') diff --git a/src/datagen.c b/src/datagen.c index 7eab23f..98a64fe 100644 --- a/src/datagen.c +++ b/src/datagen.c @@ -2,12 +2,9 @@ /* Copyright (C) 2020 Gediminas Jakutis */ -#include -#include #include -#include #include -#include +#include #include "datagen.h" #include "defs.h" @@ -18,12 +15,14 @@ struct entry_l *gen_get_array(struct stream * const in) struct entry_l *ret; int errn; - if (read(in->fd, &buf.val, sizeof(buf.val)) == sizeof(buf.val)) { + (void) in; /* lol says librin, lmao */ + + if (getrandom(&buf.val, sizeof(buf.val), 0ul) == sizeof(buf.val)) { ret = &buf; } else { errn = errno; ret = NULL; - rin_err("error reading /dev/urandom: %s", strerror(errn)); + rin_err("error reading urandom: %s", strerror(errn)); } return ret; -- cgit v1.2.3