From e1671236671afbf7719b3ef29039ec4ac5102347 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 26 Oct 2021 19:18:56 +0100 Subject: [PATCH] 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 42d8b2b16728d75159af5dfad345cf91bb2e39b2. Resolves: #833 Signed-off-by: Simon McVittie --- src/pipewire/impl-core.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/pipewire/impl-core.c b/src/pipewire/impl-core.c index 0ad8d482f..3a8c5aa4a 100644 --- a/src/pipewire/impl-core.c +++ b/src/pipewire/impl-core.c @@ -34,6 +34,19 @@ #include #endif +#ifndef HAVE_GETRANDOM +#include + +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 #include