mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
Merge pull request #16052 from mikdusan/bsd-getdents
fix bad return types for BSDs getdents and debitrot openbsd
This commit is contained in:
commit
96acc204b2
@ -624,7 +624,7 @@ const PosixThreadImpl = struct {
|
||||
.openbsd => {
|
||||
var count: c_int = undefined;
|
||||
var count_size: usize = @sizeOf(c_int);
|
||||
const mib = [_]c_int{ os.CTL.HW, os.system.HW_NCPUONLINE };
|
||||
const mib = [_]c_int{ os.CTL.HW, os.system.HW.NCPUONLINE };
|
||||
os.sysctl(&mib, &count, &count_size, null, 0) catch |err| switch (err) {
|
||||
error.NameTooLong, error.UnknownName => unreachable,
|
||||
else => |e| return e,
|
||||
|
||||
@ -9,7 +9,7 @@ pub fn _errno() *c_int {
|
||||
return &errno;
|
||||
}
|
||||
|
||||
pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
|
||||
pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
|
||||
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) isize;
|
||||
pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;
|
||||
|
||||
@ -75,7 +75,7 @@ pub const _errno = __error;
|
||||
|
||||
pub extern "c" var malloc_options: [*:0]const u8;
|
||||
|
||||
pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
|
||||
pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) isize;
|
||||
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) isize;
|
||||
pub extern "c" fn getentropy(buf_ptr: [*]u8, buf_len: usize) c_int;
|
||||
|
||||
@ -16,7 +16,7 @@ pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
|
||||
pub extern "c" fn getthrid() pid_t;
|
||||
pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;
|
||||
|
||||
pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
|
||||
pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
|
||||
pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
|
||||
|
||||
pub const pthread_mutex_t = extern struct {
|
||||
@ -1606,31 +1606,34 @@ pub const KERN = struct {
|
||||
pub const PROC_NENV = 4;
|
||||
};
|
||||
|
||||
pub const HW_MACHINE = 1;
|
||||
pub const HW_MODEL = 2;
|
||||
pub const HW_NCPU = 3;
|
||||
pub const HW_BYTEORDER = 4;
|
||||
pub const HW_PHYSMEM = 5;
|
||||
pub const HW_USERMEM = 6;
|
||||
pub const HW_PAGESIZE = 7;
|
||||
pub const HW_DISKNAMES = 8;
|
||||
pub const HW_DISKSTATS = 9;
|
||||
pub const HW_DISKCOUNT = 10;
|
||||
pub const HW_SENSORS = 11;
|
||||
pub const HW_CPUSPEED = 12;
|
||||
pub const HW_SETPERF = 13;
|
||||
pub const HW_VENDOR = 14;
|
||||
pub const HW_PRODUCT = 15;
|
||||
pub const HW_VERSION = 16;
|
||||
pub const HW_SERIALNO = 17;
|
||||
pub const HW_UUID = 18;
|
||||
pub const HW_PHYSMEM64 = 19;
|
||||
pub const HW_USERMEM64 = 20;
|
||||
pub const HW_NCPUFOUND = 21;
|
||||
pub const HW_ALLOWPOWERDOWN = 22;
|
||||
pub const HW_PERFPOLICY = 23;
|
||||
pub const HW_SMT = 24;
|
||||
pub const HW_NCPUONLINE = 25;
|
||||
pub const HW = struct {
|
||||
pub const MACHINE = 1;
|
||||
pub const MODEL = 2;
|
||||
pub const NCPU = 3;
|
||||
pub const BYTEORDER = 4;
|
||||
pub const PHYSMEM = 5;
|
||||
pub const USERMEM = 6;
|
||||
pub const PAGESIZE = 7;
|
||||
pub const DISKNAMES = 8;
|
||||
pub const DISKSTATS = 9;
|
||||
pub const DISKCOUNT = 10;
|
||||
pub const SENSORS = 11;
|
||||
pub const CPUSPEED = 12;
|
||||
pub const SETPERF = 13;
|
||||
pub const VENDOR = 14;
|
||||
pub const PRODUCT = 15;
|
||||
pub const VERSION = 16;
|
||||
pub const SERIALNO = 17;
|
||||
pub const UUID = 18;
|
||||
pub const PHYSMEM64 = 19;
|
||||
pub const USERMEM64 = 20;
|
||||
pub const NCPUFOUND = 21;
|
||||
pub const ALLOWPOWERDOWN = 22;
|
||||
pub const PERFPOLICY = 23;
|
||||
pub const SMT = 24;
|
||||
pub const NCPUONLINE = 25;
|
||||
pub const POWER = 26;
|
||||
};
|
||||
|
||||
/// TODO refines if necessary
|
||||
pub const PTHREAD_STACK_MIN = switch (builtin.cpu.arch) {
|
||||
|
||||
@ -478,6 +478,9 @@ pub const IterableDir = struct {
|
||||
.FAULT => unreachable,
|
||||
.NOTDIR => unreachable,
|
||||
.INVAL => unreachable,
|
||||
// Introduced in freebsd 13.2: directory unlinked but still open.
|
||||
// To be consistent, iteration ends if the directory being iterated is deleted during iteration.
|
||||
.NOENT => return null,
|
||||
else => |err| return os.unexpectedErrno(err),
|
||||
}
|
||||
if (rc == 0) return null;
|
||||
|
||||
@ -88,6 +88,10 @@ pub const F = system.F;
|
||||
pub const FD_CLOEXEC = system.FD_CLOEXEC;
|
||||
pub const Flock = system.Flock;
|
||||
pub const HOST_NAME_MAX = system.HOST_NAME_MAX;
|
||||
pub const HW = switch (builtin.os.tag) {
|
||||
.openbsd => system.HW,
|
||||
else => .{},
|
||||
};
|
||||
pub const IFNAMESIZE = system.IFNAMESIZE;
|
||||
pub const IOV_MAX = system.IOV_MAX;
|
||||
pub const IPPROTO = system.IPPROTO;
|
||||
|
||||
@ -1163,7 +1163,7 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {
|
||||
.linux => {
|
||||
return totalSystemMemoryLinux() catch return error.UnknownTotalSystemMemory;
|
||||
},
|
||||
.freebsd, .netbsd, .openbsd, .dragonfly, .macos => {
|
||||
.freebsd, .netbsd, .dragonfly, .macos => {
|
||||
var physmem: c_ulong = undefined;
|
||||
var len: usize = @sizeOf(c_ulong);
|
||||
const name = switch (builtin.os.tag) {
|
||||
@ -1177,6 +1177,23 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {
|
||||
};
|
||||
return @intCast(usize, physmem);
|
||||
},
|
||||
.openbsd => {
|
||||
const mib: [2]c_int = [_]c_int{
|
||||
std.os.CTL.HW,
|
||||
std.os.HW.PHYSMEM64,
|
||||
};
|
||||
var physmem: i64 = undefined;
|
||||
var len: usize = @sizeOf(@TypeOf(physmem));
|
||||
std.os.sysctl(&mib, &physmem, &len, null, 0) catch |err| switch (err) {
|
||||
error.NameTooLong => unreachable, // constant, known good value
|
||||
error.PermissionDenied => unreachable, // only when setting values,
|
||||
error.SystemResources => unreachable, // memory already on the stack
|
||||
error.UnknownName => unreachable, // constant, known good value
|
||||
else => return error.UnknownTotalSystemMemory,
|
||||
};
|
||||
assert(physmem >= 0);
|
||||
return @bitCast(usize, physmem);
|
||||
},
|
||||
.windows => {
|
||||
var sbi: std.os.windows.SYSTEM_BASIC_INFORMATION = undefined;
|
||||
const rc = std.os.windows.ntdll.NtQuerySystemInformation(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user