provide getrandom wrapper to support glibc < 2.25

Debian stretch (currently stable) only has glibc 2.24...
This commit is contained in:
Daniel Micay 2018-08-24 18:44:49 -04:00
parent 35c9e6f16d
commit 71dde7c4f8

View File

@ -1,11 +1,21 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <sys/random.h>
#include "random.h" #include "random.h"
#include "util.h" #include "util.h"
#if __has_include(<sys/random.h>)
// glibc 2.25 and later
#include <sys/random.h>
#else
#include <unistd.h>
#include <sys/syscall.h>
static ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) {
return syscall(SYS_getrandom, buf, buflen, flags);
}
#endif
void get_random_seed(void *buf, size_t size) { void get_random_seed(void *buf, size_t size) {
while (size > 0) { while (size > 0) {
ssize_t r; ssize_t r;