authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-03-08 16:04:02+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-03-23 18:47:40+01:00
log27344464edea0b6acf4dfc78d71700d67a3f3968
treecc6c77072ce3625dc4f1d0c7848e7d10f17149af
parent2f21c8f5ba2e73c1a674b481fd2a8ce87726c14c

std: Add missing C defines for NetBSD


4 files changed, 64 insertions(+), 6 deletions(-)

lib/std/c/netbsd.zig+9
...@@ -1,4 +1,6 @@...@@ -1,4 +1,6 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;
3
2usingnamespace std.c;4usingnamespace std.c;
35
4extern "c" fn __errno() *c_int;6extern "c" fn __errno() *c_int;
...@@ -7,6 +9,13 @@ pub const _errno = __errno;...@@ -7,6 +9,13 @@ pub const _errno = __errno;
7pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;9pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
8pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;10pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
911
12pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
13pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
14
15pub extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int;
16pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int;
17pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int;
18
10pub const pthread_mutex_t = extern struct {19pub const pthread_mutex_t = extern struct {
11 ptm_magic: c_uint = 0x33330003,20 ptm_magic: c_uint = 0x33330003,
12 ptm_errorcheck: padded_spin_t = 0,21 ptm_errorcheck: padded_spin_t = 0,
lib/std/debug.zig+2
...@@ -654,6 +654,8 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {...@@ -654,6 +654,8 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {
654 switch (builtin.os.tag) {654 switch (builtin.os.tag) {
655 .linux,655 .linux,
656 .freebsd,656 .freebsd,
657 .netbsd,
658 .dragonfly,
657 .macosx,659 .macosx,
658 .windows,660 .windows,
659 => return DebugInfo.init(allocator),661 => return DebugInfo.init(allocator),
lib/std/os.zig+30
...@@ -2542,6 +2542,17 @@ pub fn fstat(fd: fd_t) FStatError!Stat {...@@ -2542,6 +2542,17 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
2542 }2542 }
2543 }2543 }
25442544
2545 if (std.Target.current.os.tag == .netbsd) {
2546 switch (errno(system.__fstat50(fd, &stat))) {
2547 0 => return stat,
2548 EINVAL => unreachable,
2549 EBADF => unreachable, // Always a race condition.
2550 ENOMEM => return error.SystemResources,
2551 EACCES => return error.AccessDenied,
2552 else => |err| return unexpectedErrno(err),
2553 }
2554 }
2555
2545 switch (errno(system.fstat(fd, &stat))) {2556 switch (errno(system.fstat(fd, &stat))) {
2546 0 => return stat,2557 0 => return stat,
2547 EINVAL => unreachable,2558 EINVAL => unreachable,
...@@ -3401,6 +3412,16 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {...@@ -3401,6 +3412,16 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
3401 }3412 }
3402 return;3413 return;
3403 }3414 }
3415
3416 if (std.Target.current.os.tag == .netbsd) {
3417 switch (errno(system.__clock_gettime50(clk_id, tp))) {
3418 0 => return,
3419 EFAULT => unreachable,
3420 EINVAL => return error.UnsupportedClock,
3421 else => |err| return unexpectedErrno(err),
3422 }
3423 }
3424
3404 switch (errno(system.clock_gettime(clk_id, tp))) {3425 switch (errno(system.clock_gettime(clk_id, tp))) {
3405 0 => return,3426 0 => return,
3406 EFAULT => unreachable,3427 EFAULT => unreachable,
...@@ -3423,6 +3444,15 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {...@@ -3423,6 +3444,15 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
3423 return;3444 return;
3424 }3445 }
34253446
3447 if (std.Target.current.os.tag == .netbsd) {
3448 switch (errno(system.__clock_getres50(clk_id, res))) {
3449 0 => return,
3450 EFAULT => unreachable,
3451 EINVAL => return error.UnsupportedClock,
3452 else => |err| return unexpectedErrno(err),
3453 }
3454 }
3455
3426 switch (errno(system.clock_getres(clk_id, res))) {3456 switch (errno(system.clock_getres(clk_id, res))) {
3427 0 => return,3457 0 => return,
3428 EFAULT => unreachable,3458 EFAULT => unreachable,
lib/std/os/bits/netbsd.zig+23-6
...@@ -1,9 +1,12 @@...@@ -1,9 +1,12 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2const maxInt = std.math.maxInt;2const maxInt = std.math.maxInt;
33
4pub const fd_t = c_int;4pub const fd_t = i32;
5pub const pid_t = c_int;5pub const pid_t = i32;
6pub const mode_t = c_uint;6pub const mode_t = u32;
7pub const ino_t = u64;
8pub const off_t = i64;
9pub const socklen_t = u32;
710
8/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.11/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
9pub const Kevent = extern struct {12pub const Kevent = extern struct {
...@@ -68,9 +71,6 @@ pub const msghdr_const = extern struct {...@@ -68,9 +71,6 @@ pub const msghdr_const = extern struct {
68 msg_flags: i32,71 msg_flags: i32,
69};72};
7073
71pub const off_t = i64;
72pub const ino_t = u64;
73
74/// Renamed to Stat to not conflict with the stat function.74/// Renamed to Stat to not conflict with the stat function.
75/// atime, mtime, and ctime have functions to return `timespec`,75/// atime, mtime, and ctime have functions to return `timespec`,
76/// because although this is a POSIX API, the layout and names of76/// because although this is a POSIX API, the layout and names of
...@@ -816,6 +816,23 @@ pub fn S_IWHT(m: u32) bool {...@@ -816,6 +816,23 @@ pub fn S_IWHT(m: u32) bool {
816 return m & S_IFMT == S_IFWHT;816 return m & S_IFMT == S_IFWHT;
817}817}
818818
819/// Magic value that specify the use of the current working directory
820/// to determine the target of relative file paths in the openat() and
821/// similar syscalls.
822pub const AT_FDCWD = -100;
823
824/// Check access using effective user and group ID
825pub const AT_EACCESS = 0x0100;
826
827/// Do not follow symbolic links
828pub const AT_SYMLINK_NOFOLLOW = 0x0200;
829
830/// Follow symbolic link
831pub const AT_SYMLINK_FOLLOW = 0x0400;
832
833/// Remove directory instead of file
834pub const AT_REMOVEDIR = 0x0800;
835
819pub const HOST_NAME_MAX = 255;836pub const HOST_NAME_MAX = 255;
820837
821/// dummy for IP838/// dummy for IP