commit 1811e7e6c96844a8381e6a69017948cae0b8b261 (tree)
parent 11ced4f99d95ec144d9dbb79ead335b571f714fe
Author: Marcio Giaxa <i@mgxm.me>
Date: Tue, 18 Dec 2018 02:42:54 -0200
freebsd: remove getrandom dependency from libc
The system call getrandom(2) just landed on FreeBSD 12, so if we want to
support some earlier version or at least FreeBSD 11, we can't depend on
the system call.
Diffstat:
3 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/std/c/freebsd.zig b/std/c/freebsd.zig
@@ -15,7 +15,6 @@ pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usi
pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
pub extern "c" fn getdirentries(fd: c_int, buf_ptr: [*]u8, nbytes: usize, basep: *i64) usize;
pub extern "c" fn pipe2(arg0: *[2]c_int, arg1: u32) c_int;
-pub extern "c" fn getrandom(buf: [*]u8, count: usize, flags: u32) c_int;
/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
pub const Kevent = extern struct {
diff --git a/std/os/freebsd/index.zig b/std/os/freebsd/index.zig
@@ -672,10 +672,6 @@ pub fn exit(code: i32) noreturn {
c.exit(code);
}
-pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
- return errnoWrap(c.getrandom(buf, count, flags));
-}
-
pub fn kill(pid: i32, sig: i32) usize {
return arch.syscall2(SYS_kill, @bitCast(usize, isize(pid)), @bitCast(usize, isize(sig)));
}
diff --git a/std/os/index.zig b/std/os/index.zig
@@ -103,7 +103,7 @@ const math = std.math;
/// library implementation.
pub fn getRandomBytes(buf: []u8) !void {
switch (builtin.os) {
- Os.linux, Os.freebsd => while (true) {
+ Os.linux => while (true) {
// TODO check libc version and potentially call c.getrandom.
// See #397
const errno = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0));
@@ -116,7 +116,7 @@ pub fn getRandomBytes(buf: []u8) !void {
else => return unexpectedErrorPosix(errno),
}
},
- Os.macosx, Os.ios => return getRandomBytesDevURandom(buf),
+ Os.macosx, Os.ios, Os.freebsd => return getRandomBytesDevURandom(buf),
Os.windows => {
// Call RtlGenRandom() instead of CryptGetRandom() on Windows
// https://github.com/rust-lang-nursery/rand/issues/111