From 761602e3e84afee1a77daf9f850c67cb8e25f7ed Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 23 Mar 2020 18:54:14 +0100 Subject: [PATCH] std: Use getdents on all the BSDs * Use the correct versioned libc calls to avoid nasty surprises --- lib/std/c/netbsd.zig | 5 ++--- lib/std/fs.zig | 10 ++++------ lib/std/os.zig | 11 +++++++++++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index f9b2510f84..fd70220603 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -6,15 +6,14 @@ usingnamespace std.c; extern "c" fn __errno() *c_int; pub const _errno = __errno; -pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize; -pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; - pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int; pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int; pub extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int; pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int; pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int; +pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int; +pub extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int; pub const pthread_mutex_t = extern struct { ptm_magic: c_uint = 0x33330003, diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 333419d02b..c84f87daec 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -339,12 +339,10 @@ pub const Dir = struct { fn nextBsd(self: *Self) !?Entry { start_over: while (true) { if (self.index >= self.end_index) { - const rc = os.system.getdirentries( - self.dir.fd, - &self.buf, - self.buf.len, - &self.seek, - ); + const rc = if (builtin.os.tag == .netbsd) + os.system.__getdents30(self.dir.fd, &self.buf, self.buf.len) + else + os.system.getdents(self.dir.fd, &self.buf, self.buf.len); switch (os.errno(rc)) { 0 => {}, os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability diff --git a/lib/std/os.zig b/lib/std/os.zig index f03aa96cf9..4e25b254ea 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -3522,6 +3522,17 @@ 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), + } + } + switch (errno(system.sigaltstack(ss, old_ss))) { 0 => return, EFAULT => unreachable,