Commit 1811e7e6c9

Marcio Giaxa <i@mgxm.me>
2018-12-18 05:42:54
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.
1 parent 11ced4f
Changed files (3)
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 {
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)));
 }
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