Commit 27344464ed
Changed files (4)
lib
std
lib/std/c/netbsd.zig
@@ -1,4 +1,6 @@
const std = @import("../std.zig");
+const builtin = std.builtin;
+
usingnamespace std.c;
extern "c" fn __errno() *c_int;
@@ -7,6 +9,13 @@ 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 const pthread_mutex_t = extern struct {
ptm_magic: c_uint = 0x33330003,
ptm_errorcheck: padded_spin_t = 0,
lib/std/os/bits/netbsd.zig
@@ -1,9 +1,12 @@
const std = @import("../../std.zig");
const maxInt = std.math.maxInt;
-pub const fd_t = c_int;
-pub const pid_t = c_int;
-pub const mode_t = c_uint;
+pub const fd_t = i32;
+pub const pid_t = i32;
+pub const mode_t = u32;
+pub const ino_t = u64;
+pub const off_t = i64;
+pub const socklen_t = u32;
/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
pub const Kevent = extern struct {
@@ -68,9 +71,6 @@ pub const msghdr_const = extern struct {
msg_flags: i32,
};
-pub const off_t = i64;
-pub const ino_t = u64;
-
/// Renamed to Stat to not conflict with the stat function.
/// atime, mtime, and ctime have functions to return `timespec`,
/// because although this is a POSIX API, the layout and names of
@@ -816,6 +816,23 @@ pub fn S_IWHT(m: u32) bool {
return m & S_IFMT == S_IFWHT;
}
+/// Magic value that specify the use of the current working directory
+/// to determine the target of relative file paths in the openat() and
+/// similar syscalls.
+pub const AT_FDCWD = -100;
+
+/// Check access using effective user and group ID
+pub const AT_EACCESS = 0x0100;
+
+/// Do not follow symbolic links
+pub const AT_SYMLINK_NOFOLLOW = 0x0200;
+
+/// Follow symbolic link
+pub const AT_SYMLINK_FOLLOW = 0x0400;
+
+/// Remove directory instead of file
+pub const AT_REMOVEDIR = 0x0800;
+
pub const HOST_NAME_MAX = 255;
/// dummy for IP
lib/std/debug.zig
@@ -654,6 +654,8 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {
switch (builtin.os.tag) {
.linux,
.freebsd,
+ .netbsd,
+ .dragonfly,
.macosx,
.windows,
=> return DebugInfo.init(allocator),
lib/std/os.zig
@@ -2542,6 +2542,17 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
}
}
+ 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),
+ }
+ }
+
switch (errno(system.fstat(fd, &stat))) {
0 => return stat,
EINVAL => unreachable,
@@ -3401,6 +3412,16 @@ 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),
+ }
+ }
+
switch (errno(system.clock_gettime(clk_id, tp))) {
0 => return,
EFAULT => unreachable,
@@ -3423,6 +3444,15 @@ 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),
+ }
+ }
+
switch (errno(system.clock_getres(clk_id, res))) {
0 => return,
EFAULT => unreachable,