mirror of
https://github.com/ziglang/zig.git
synced 2026-02-16 14:28:57 +00:00
In init_rand avoid reading from /dev/urandom on NetBSD/FreeBSD
Use the KERN_ARND sysctl instead.
This commit is contained in:
parent
14a954f350
commit
74ad315360
@ -1462,6 +1462,14 @@ static void init_rand() {
|
||||
unsigned seed;
|
||||
memcpy(&seed, ptr_random, sizeof(seed));
|
||||
srand(seed);
|
||||
#elif defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
|
||||
unsigned seed;
|
||||
size_t len = sizeof(seed);
|
||||
int mib[2] = { CTL_KERN, KERN_ARND };
|
||||
if (sysctl(mib, 2, &seed, &len, NULL, 0) != 0) {
|
||||
zig_panic("unable to query random data from sysctl");
|
||||
}
|
||||
srand(seed);
|
||||
#else
|
||||
int fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC);
|
||||
if (fd == -1) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user