aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-12-07 19:11:16 -0600
committerRob Landley <rob@landley.net>2018-12-07 19:11:16 -0600
commit66723ec39d978365f1e46840903ae20c33637c88 (patch)
tree86d2a9720caa7386205b6cb7d7135817cc62765c /lib
parent1bc733dea997a50f87b788473285e7202fa21c81 (diff)
downloadtoybox-66723ec39d978365f1e46840903ae20c33637c88.tar.gz
Forgot to check the portability.? changes. (Oops.)
Diffstat (limited to 'lib')
-rw-r--r--lib/portability.c12
-rw-r--r--lib/portability.h2
2 files changed, 8 insertions, 6 deletions
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 <sys/random.h>
#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__