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 +++++++----- lib/portability.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'lib') 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__) diff --git a/lib/portability.h b/lib/portability.h index 21d0b8a1..60d40498 100644 --- a/lib/portability.h +++ b/lib/portability.h @@ -266,7 +266,7 @@ extern CODE prioritynames[], facilitynames[]; #if CFG_TOYBOX_GETRANDOM #include #endif -void xgetrandom(void *buf, unsigned len, unsigned flags); +int xgetrandom(void *buf, unsigned len, unsigned flags); // Android's bionic libc doesn't have confstr. #ifdef __BIONIC__ -- cgit v1.2.3