Fix #2993 - use getrandom on freebsd

master
Euan Torano 2019-08-05 17:21:12 +01:00 committed by Andrew Kelley
parent 8aa87ec441
commit 7b8c96612f
2 changed files with 14 additions and 0 deletions

View File

@ -6,3 +6,4 @@ pub const _errno = __error;
pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) c_int;

View File

@ -120,6 +120,19 @@ pub fn getrandom(buf: []u8) GetRandomError!void {
}
}
}
if (freebsd.is_the_target) {
while (true) {
const err = std.c.getErrno(std.c.getrandom(buf.ptr, buf.len, 0));
switch (err) {
0 => return,
EINVAL => unreachable,
EFAULT => unreachable,
EINTR => continue,
else => return unexpectedErrno(err),
}
}
}
if (wasi.is_the_target) {
switch (wasi.random_get(buf.ptr, buf.len)) {
0 => return,