authorgravatar for i@mgxm.meMarcio Giaxa <i@mgxm.me> 2018-12-18 02:42:54-02:00
committergravatar for i@mgxm.meMarcio Giaxa <i@mgxm.me> 2018-12-19 18:42:00-02:00
log1811e7e6c96844a8381e6a69017948cae0b8b261
tree4ba5e387f6cc16403a7848d73197c21463601877
parent11ced4f99d95ec144d9dbb79ead335b571f714fe

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.

3 files changed, 2 insertions(+), 7 deletions(-)

std/c/freebsd.zig-1
......@@ -15,7 +15,6 @@ pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usi
1515pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
1616pub extern "c" fn getdirentries(fd: c_int, buf_ptr: [*]u8, nbytes: usize, basep: *i64) usize;
1717pub extern "c" fn pipe2(arg0: *[2]c_int, arg1: u32) c_int;
18pub extern "c" fn getrandom(buf: [*]u8, count: usize, flags: u32) c_int;
1918
2019/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
2120pub const Kevent = extern struct {
std/os/freebsd/index.zig-4
......@@ -672,10 +672,6 @@ pub fn exit(code: i32) noreturn {
672672 c.exit(code);
673673}
674674
675pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
676 return errnoWrap(c.getrandom(buf, count, flags));
677}
678
679675pub fn kill(pid: i32, sig: i32) usize {
680676 return arch.syscall2(SYS_kill, @bitCast(usize, isize(pid)), @bitCast(usize, isize(sig)));
681677}
std/os/index.zig+2-2
......@@ -103,7 +103,7 @@ const math = std.math;
103103/// library implementation.
104104pub fn getRandomBytes(buf: []u8) !void {
105105 switch (builtin.os) {
106 Os.linux, Os.freebsd => while (true) {
106 Os.linux => while (true) {
107107 // TODO check libc version and potentially call c.getrandom.
108108 // See #397
109109 const errno = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0));
......@@ -116,7 +116,7 @@ pub fn getRandomBytes(buf: []u8) !void {
116116 else => return unexpectedErrorPosix(errno),
117117 }
118118 },
119 Os.macosx, Os.ios => return getRandomBytesDevURandom(buf),
119 Os.macosx, Os.ios, Os.freebsd => return getRandomBytesDevURandom(buf),
120120 Os.windows => {
121121 // Call RtlGenRandom() instead of CryptGetRandom() on Windows
122122 // https://github.com/rust-lang-nursery/rand/issues/111