authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-03-23 18:54:14+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-03-23 18:54:14+01:00
log761602e3e84afee1a77daf9f850c67cb8e25f7ed
treec1e72f6ea4febdebd773eab186653edcdf600fd6
parent336ed03f0f4ffde8e60fb8b4859c0c2158511338

std: Use getdents on all the BSDs

* Use the correct versioned libc calls to avoid nasty surprises

3 files changed, 17 insertions(+), 9 deletions(-)

lib/std/c/netbsd.zig+2-3
......@@ -6,15 +6,14 @@ usingnamespace std.c;
66extern "c" fn __errno() *c_int;
77pub const _errno = __errno;
88
9pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
10pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
11
129pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
1310pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
1411
1512pub extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int;
1613pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int;
1714pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int;
15pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
16pub extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
1817
1918pub const pthread_mutex_t = extern struct {
2019 ptm_magic: c_uint = 0x33330003,
lib/std/fs.zig+4-6
......@@ -339,12 +339,10 @@ pub const Dir = struct {
339339 fn nextBsd(self: *Self) !?Entry {
340340 start_over: while (true) {
341341 if (self.index >= self.end_index) {
342 const rc = os.system.getdirentries(
343 self.dir.fd,
344 &self.buf,
345 self.buf.len,
346 &self.seek,
347 );
342 const rc = if (builtin.os.tag == .netbsd)
343 os.system.__getdents30(self.dir.fd, &self.buf, self.buf.len)
344 else
345 os.system.getdents(self.dir.fd, &self.buf, self.buf.len);
348346 switch (os.errno(rc)) {
349347 0 => {},
350348 os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability
lib/std/os.zig+11
......@@ -3522,6 +3522,17 @@ pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void {
35223522 if (builtin.os.tag == .windows or builtin.os.tag == .uefi or builtin.os.tag == .wasi)
35233523 @compileError("std.os.sigaltstack not available for this target");
35243524
3525 if (std.Target.current.os.tag == .netbsd) {
3526 switch (errno(system.__sigaltstack14(ss, old_ss))) {
3527 0 => return,
3528 EFAULT => unreachable,
3529 EINVAL => unreachable,
3530 ENOMEM => return error.SizeTooSmall,
3531 EPERM => return error.PermissionDenied,
3532 else => |err| return unexpectedErrno(err),
3533 }
3534 }
3535
35253536 switch (errno(system.sigaltstack(ss, old_ss))) {
35263537 0 => return,
35273538 EFAULT => unreachable,