]>
code.delx.au - linux-getrandom-userspace/blob - getrandom.c
3 #include <sys/random.h>
5 ssize_t
getrandom(void *buf
, size_t buflen
, unsigned int flags
) {
6 char* filename
= flags
& GRND_RANDOM
? "/dev/random" : "/dev/urandom";
7 int nonblock
= flags
& GRND_NONBLOCK
? O_NONBLOCK
: 0;
8 int oflags
= O_CLOEXEC
| nonblock
;
10 int fd
= open(filename
, oflags
);
15 ssize_t bytes
= read(fd
, buf
, buflen
);