diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-28 14:16:22 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-28 14:16:22 -0400 |
| commit | e861515053bc3ec8624abb2856a1f809f13a51d9 (patch) | |
| tree | f9f964b13ca6ccd874be2ba5f95155c69d85cdcb /src/stdlib/threads.c | |
| parent | ebef00fc371123fae35f2bda91337b1d6ee6b146 (diff) | |
Make getrandom() platform-compatible
Diffstat (limited to 'src/stdlib/threads.c')
| -rw-r--r-- | src/stdlib/threads.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/stdlib/threads.c b/src/stdlib/threads.c index 9ad68c81..05f5a941 100644 --- a/src/stdlib/threads.c +++ b/src/stdlib/threads.c @@ -10,7 +10,6 @@ #include <stdlib.h> #include <pthread.h> #include <sys/param.h> -#include <sys/random.h> #include "arrays.h" #include "datatypes.h" @@ -21,6 +20,19 @@ #include "types.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 <sys/random.h> +#else + #error "Unsupported platform for secure random number generation" +#endif + static void *run_thread(Closure_t *closure) { uint8_t *random_bytes = GC_MALLOC_ATOMIC(40); |
