Reinstate compatibility with older Linux with no getrandom()

Commit 42d8b2b1 "Remove legacy FreeBSD compatibility code" removed
compatibility with old versions of FreeBSD, but also removed
compatibility with old versions of Linux and glibc, which was requested
in #833.

This partially reverts commit 42d8b2b167.

Resolves: #833
Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2021-10-26 19:18:56 +01:00
parent 31f387868a
commit e167123667

View file

@ -34,6 +34,19 @@
#include <sys/random.h>
#endif
#ifndef HAVE_GETRANDOM
#include <fcntl.h>
ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) {
int fd = open("/dev/random", O_CLOEXEC);
if (fd < 0)
return -1;
ssize_t bytes = read(fd, buf, buflen);
close(fd);
return bytes;
}
#endif
#include <spa/utils/string.h>
#include <spa/debug/types.h>