From 66723ec39d978365f1e46840903ae20c33637c88 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 7 Dec 2018 19:11:16 -0600 Subject: Forgot to check the portability.? changes. (Oops.) --- lib/portability.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lib/portability.c') diff --git a/lib/portability.c b/lib/portability.c index a80ca56c..5c754d7d 100644 --- a/lib/portability.c +++ b/lib/portability.c @@ -30,18 +30,20 @@ pid_t xfork(void) } #endif -void xgetrandom(void *buf, unsigned buflen, unsigned flags) +int xgetrandom(void *buf, unsigned buflen, unsigned flags) { int fd; #if CFG_TOYBOX_GETRANDOM - if (buflen == getrandom(buf, buflen, flags)) return; - if (!CFG_TOYBOX_ON_ANDROID || errno!=ENOSYS) perror_exit("getrandom"); + if (buflen == getrandom(buf, buflen, flags&~WARN_ONLY)) return 1; + if (errno!=ENOSYS && !(flags&WARN_ONLY)) perror_exit("getrandom"); #endif - - fd = xopen(flags ? "/dev/random" : "/dev/urandom", O_RDONLY); + fd = xopen(flags ? "/dev/random" : "/dev/urandom",O_RDONLY|(flags&WARN_ONLY)); + if (fd == -1) return 0; xreadall(fd, buf, buflen); close(fd); + + return 1; } #if defined(__APPLE__) -- cgit v1.2.3