Skip to content
Snippets Groups Projects
Unverified Commit 1255078e authored by Jonas Jelonek's avatar Jonas Jelonek
Browse files

portability: add getrandom

parent 1c0f742a
No related branches found
No related tags found
No related merge requests found
#include <sys/random.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
ssize_t getrandom(void *buf, size_t buflen, unsigned int flags)
{
int fd;
ssize_t ret;
fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC);
if (fd < 0)
return -1;
ret = read(fd, buf, buflen);
close(fd);
return ret;
}
......@@ -3,6 +3,7 @@ cc = meson.get_compiler('c')
libportability_src = []
check_symbols = [
['getrandom', 'getrandom.c', 'NEED_GETRANDOM', 'sys/random.h'],
['memrchr', 'memrchr.c', 'NEED_MEMRCHR', 'string.h'],
['mknodat', 'mknodat.c', 'NEED_MKNODAT', 'sys/stat.h'],
['pipe2', 'pipe2.c', 'NEED_PIPE2', 'unistd.h'],
......
#include_next <sys/random.h>
#include <sys/types.h>
#ifdef NEED_GETRANDOM
ssize_t getrandom(void *buf, size_t buflen, unsigned int flags);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment