diff options
author | 2021-02-15 13:08:54 +0200 | |
---|---|---|
committer | 2021-02-15 13:08:54 +0200 | |
commit | 9569e629c8e73dcdc3f93b5fc6156db827d6b7b1 (patch) | |
tree | 43453709b52f3a1d3f74059c22d85a4d89a54aca /src/datagen.c | |
parent | 3f0c21826b4a4e59c937dc8435edb5be7100b078 (diff) | |
download | algos-ld1-9569e629c8e73dcdc3f93b5fc6156db827d6b7b1.tar.gz algos-ld1-9569e629c8e73dcdc3f93b5fc6156db827d6b7b1.tar.bz2 algos-ld1-9569e629c8e73dcdc3f93b5fc6156db827d6b7b1.zip |
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 <gediminas@varciai.lt>
Diffstat (limited to 'src/datagen.c')
-rw-r--r-- | src/datagen.c | 11 |
1 files changed, 5 insertions, 6 deletions
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 <unistd.h> -#include <stddef.h> #include <errno.h> -#include <stdlib.h> #include <string.h> -#include <sys/types.h> +#include <sys/random.h> #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; |