freebsd fixes

master
Andrew Kelley 2019-05-27 17:28:59 -04:00
parent af4b8eb6c0
commit 3640303ce1
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
4 changed files with 11 additions and 3 deletions

View File

@ -72,7 +72,7 @@ pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;
pub extern "c" fn rmdir(path: [*]const u8) c_int;
pub extern "c" fn getenv(name: [*]const u8) ?[*]u8;
pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;

View File

@ -2071,6 +2071,7 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
pub const SysCtlError = error{
PermissionDenied,
SystemResources,
NameTooLong,
Unexpected,
};
@ -2081,7 +2082,8 @@ pub fn sysctl(
newp: ?*c_void,
newlen: usize,
) SysCtlError!void {
switch (errno(system.sysctl(name.ptr, name.len, oldp, oldlenp, newp, newlen))) {
const name_len = math.cast(c_uint, name.len) catch return error.NameTooLong;
switch (errno(system.sysctl(name.ptr, name_len, oldp, oldlenp, newp, newlen))) {
0 => return,
EFAULT => unreachable,
EPERM => return error.PermissionDenied,

View File

@ -1,3 +1,6 @@
const std = @import("../../std.zig");
const maxInt = std.math.maxInt;
pub const fd_t = c_int;
pub const pid_t = c_int;

View File

@ -340,7 +340,10 @@ pub const Thread = struct {
var count: c_int = undefined;
var count_len: usize = @sizeOf(c_int);
const name = if (os.darwin.is_the_target) c"hw.logicalcpu" else c"hw.ncpu";
try os.sysctlbynameC(name, @ptrCast(*c_void, &count), &count_len, null, 0);
os.sysctlbynameC(name, &count, &count_len, null, 0) catch |err| switch (err) {
error.NameTooLong => unreachable,
else => |e| return e,
};
return @intCast(usize, count);
}
};