diff options
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/c.zig | 1 | ||||
| -rw-r--r-- | lib/std/c/darwin.zig | 1 | ||||
| -rw-r--r-- | lib/std/os.zig | 75 |
3 files changed, 23 insertions, 54 deletions
diff --git a/lib/std/c.zig b/lib/std/c.zig index 0d8aa13dec..1abad53375 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -74,7 +74,6 @@ pub extern "c" fn exit(code: c_int) noreturn; pub extern "c" fn isatty(fd: fd_t) c_int; pub extern "c" fn close(fd: fd_t) c_int; pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int; -pub extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int; pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int; pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: c_int) off_t; pub extern "c" fn open(path: [*:0]const u8, oflag: c_uint, ...) c_int; diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index 2134e0e7a4..74922daa01 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -13,6 +13,7 @@ pub extern "c" fn _dyld_get_image_vmaddr_slide(image_index: u32) usize; pub extern "c" fn _dyld_get_image_name(image_index: u32) [*:0]const u8; pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize; +pub extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int; pub extern "c" fn mach_absolute_time() u64; pub extern "c" fn mach_timebase_info(tinfo: ?*mach_timebase_info_data) void; diff --git a/lib/std/os.zig b/lib/std/os.zig index 4e25b254ea..dc032badea 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -2531,29 +2531,15 @@ pub const FStatError = error{ pub fn fstat(fd: fd_t) FStatError!Stat { var stat: Stat = undefined; - if (comptime std.Target.current.isDarwin()) { - switch (darwin.getErrno(darwin.@"fstat$INODE64"(fd, &stat))) { - 0 => return stat, - EINVAL => unreachable, - EBADF => unreachable, // Always a race condition. - ENOMEM => return error.SystemResources, - EACCES => return error.AccessDenied, - else => |err| return unexpectedErrno(err), - } - } - if (std.Target.current.os.tag == .netbsd) { - switch (errno(system.__fstat50(fd, &stat))) { - 0 => return stat, - EINVAL => unreachable, - EBADF => unreachable, // Always a race condition. - ENOMEM => return error.SystemResources, - EACCES => return error.AccessDenied, - else => |err| return unexpectedErrno(err), - } - } + const symbol_name = if (comptime std.Target.current.isDarwin()) + "fstat$INODE64" + else if (std.Target.current.os.tag == .netbsd) + "__fstat50" + else + "fstat"; - switch (errno(system.fstat(fd, &stat))) { + switch (errno(@field(system, symbol_name)(fd, &stat))) { 0 => return stat, EINVAL => unreachable, EBADF => unreachable, // Always a race condition. @@ -3413,16 +3399,12 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void { return; } - if (std.Target.current.os.tag == .netbsd) { - switch (errno(system.__clock_gettime50(clk_id, tp))) { - 0 => return, - EFAULT => unreachable, - EINVAL => return error.UnsupportedClock, - else => |err| return unexpectedErrno(err), - } - } + const symbol_name = if (std.Target.current.os.tag == .netbsd) + "__clock_gettime50" + else + "clock_gettime"; - switch (errno(system.clock_gettime(clk_id, tp))) { + switch (errno(@field(system, symbol_name)(clk_id, tp))) { 0 => return, EFAULT => unreachable, EINVAL => return error.UnsupportedClock, @@ -3444,16 +3426,12 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void { return; } - if (std.Target.current.os.tag == .netbsd) { - switch (errno(system.__clock_getres50(clk_id, res))) { - 0 => return, - EFAULT => unreachable, - EINVAL => return error.UnsupportedClock, - else => |err| return unexpectedErrno(err), - } - } + const symbol_name = if (std.Target.current.os.tag == .netbsd) + "__clock_getres50" + else + "clock_getres"; - switch (errno(system.clock_getres(clk_id, res))) { + switch (errno(@field(system, symbol_name)(clk_id, res))) { 0 => return, EFAULT => unreachable, EINVAL => return error.UnsupportedClock, @@ -3519,21 +3497,12 @@ pub const SigaltstackError = error{ } || UnexpectedError; pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void { - if (builtin.os.tag == .windows or builtin.os.tag == .uefi or builtin.os.tag == .wasi) - @compileError("std.os.sigaltstack not available for this target"); - - if (std.Target.current.os.tag == .netbsd) { - switch (errno(system.__sigaltstack14(ss, old_ss))) { - 0 => return, - EFAULT => unreachable, - EINVAL => unreachable, - ENOMEM => return error.SizeTooSmall, - EPERM => return error.PermissionDenied, - else => |err| return unexpectedErrno(err), - } - } + const symbol_name = if (std.Target.current.os.tag == .netbsd) + "__sigaltstack14" + else + "sigaltstack"; - switch (errno(system.sigaltstack(ss, old_ss))) { + switch (errno(@field(system, symbol_name)(ss, old_ss))) { 0 => return, EFAULT => unreachable, EINVAL => unreachable, |
