diff options
author | Jasper Lievisse Adriaanse <jasper@humppa.nl> | 2020-07-03 09:42:36 +0200 |
---|---|---|
committer | Jasper Lievisse Adriaanse <jasper@humppa.nl> | 2020-07-26 14:25:04 +0200 |
commit | 0f507813ad953ef6f22a239a9e4af1dc16048c6e (patch) | |
tree | 0b5359df1e73f1593e90f61f501912d3e5a60e47 /lib | |
parent | dfcefa263ebeec391331d40e5b428453d525ab59 (diff) | |
download | epiphany-0f507813ad953ef6f22a239a9e4af1dc16048c6e.tar.gz |
Use getentropy(2) on OpenBSD
Linux and FreeBSD provided getrandom(2) which doesn't exist on OpenBSD,
so adjust the code for OpenBSD to the getentropy(2) instead.
While here adjust the headers to give this a chance to build on FreeBSD
too. Untested on FreeBSD but based on the manpage unistd.h provided
getrandom(2), not sys/random.h
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ephy-sync-utils.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/ephy-sync-utils.c b/lib/ephy-sync-utils.c index 4ae56220b..13e7d96ca 100644 --- a/lib/ephy-sync-utils.c +++ b/lib/ephy-sync-utils.c @@ -30,7 +30,11 @@ #include <libsoup/soup.h> #include <stdio.h> #include <string.h> +#if defined(__linux__) #include <sys/random.h> +#elif defined(__FreeBSD__) || defined(__OpenBSD__) +#include <unistd.h> +#endif static const char hex_digits[] = "0123456789abcdef"; @@ -179,12 +183,18 @@ ephy_sync_utils_generate_random_bytes (void *random_ctx, g_assert (num_bytes > 0); g_assert (out); +#ifdef __OpenBSD__ + if (getentropy (out, num_bytes) == -1) { + g_error ("Failed to get entropy: %s", g_strerror (errno)); + } +#else do { ret = getrandom (out, num_bytes, 0); } while (ret < (gssize)num_bytes && errno == EINTR); if (ret != (gssize)num_bytes) g_error ("Failed to generate randomness: %s", g_strerror (errno)); +#endif } char * |