diff options
author | Rob Landley <rob@landley.net> | 2018-07-04 18:49:03 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2018-07-04 18:49:03 -0500 |
commit | ff2d528a0a6943bd4247f3c122c145a5b19f0387 (patch) | |
tree | e79c2baaa076a33deea48e65cf158b62ec6490da /lib/portability.c | |
parent | 4d673c9ad4c65c329a85ebb19c2812ae93183099 (diff) | |
download | toybox-ff2d528a0a6943bd4247f3c122c145a5b19f0387.tar.gz |
Add xgetrandom() with probe for new system call (else open/read /dev/{,u}random)
Diffstat (limited to 'lib/portability.c')
-rw-r--r-- | lib/portability.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/portability.c b/lib/portability.c index 38cf5cb9..c42a052e 100644 --- a/lib/portability.c +++ b/lib/portability.c @@ -30,6 +30,17 @@ pid_t xfork(void) } #endif +void xgetrandom(void *buf, unsigned buflen, unsigned flags) +{ +#if CFG_TOYBOX_GETRANDOM + if (buflen != getrandom(buf, buflen, flags)) perror_exit("getrandom"); +#else + int fd = xopen(flags ? "/dev/random" : "/dev/urandom", O_RDONLY); + xreadall(fd, buf, buflen); + close(fd); +#endif +} + #if defined(__APPLE__) ssize_t getdelim(char **linep, size_t *np, int delim, FILE *stream) { |