From e861515053bc3ec8624abb2856a1f809f13a51d9 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 28 Mar 2025 14:16:22 -0400 Subject: Make getrandom() platform-compatible --- src/stdlib/stdlib.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/stdlib/stdlib.c') diff --git a/src/stdlib/stdlib.c b/src/stdlib/stdlib.c index 4a1f7dd8..97c7b219 100644 --- a/src/stdlib/stdlib.c +++ b/src/stdlib/stdlib.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include "print.h" @@ -30,6 +29,19 @@ #include "text.h" #include "util.h" +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) +static ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) { + (void)flags; + arc4random_buf(buf, buflen); + return buflen; +} +#elif defined(__linux__) +// Use getrandom() +# include +#else + #error "Unsupported platform for secure random number generation" +#endif + public bool USE_COLOR; static void signal_handler(int sig, siginfo_t *, void *) -- cgit v1.2.3