std: Use getdents on all the BSDs

* Use the correct versioned libc calls to avoid nasty surprises
This commit is contained in:
LemonBoy 2020-03-23 18:54:14 +01:00
parent 336ed03f0f
commit 761602e3e8
3 changed files with 17 additions and 9 deletions

View File

@ -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,

View File

@ -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

View File

@ -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,