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 @@
11const std = @import("../std.zig");
2const builtin = std.builtin;
3
24usingnamespace std.c;
35
46extern "c" fn __errno() *c_int;
......@@ -7,6 +9,13 @@ pub const _errno = __errno;
79pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
810pub 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
1019pub const pthread_mutex_t = extern struct {
1120 ptm_magic: c_uint = 0x33330003,
1221 ptm_errorcheck: padded_spin_t = 0,
lib/std/debug.zig+2
......@@ -654,6 +654,8 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {
654654 switch (builtin.os.tag) {
655655 .linux,
656656 .freebsd,
657 .netbsd,
658 .dragonfly,
657659 .macosx,
658660 .windows,
659661 => return DebugInfo.init(allocator),
lib/std/os.zig+30
......@@ -2542,6 +2542,17 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
25422542 }
25432543 }
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
25452556 switch (errno(system.fstat(fd, &stat))) {
25462557 0 => return stat,
25472558 EINVAL => unreachable,
......@@ -3401,6 +3412,16 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
34013412 }
34023413 return;
34033414 }
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
34043425 switch (errno(system.clock_gettime(clk_id, tp))) {
34053426 0 => return,
34063427 EFAULT => unreachable,
......@@ -3423,6 +3444,15 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
34233444 return;
34243445 }
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
34263456 switch (errno(system.clock_getres(clk_id, res))) {
34273457 0 => return,
34283458 EFAULT => unreachable,
lib/std/os/bits/netbsd.zig+23-6
......@@ -1,9 +1,12 @@
11const std = @import("../../std.zig");
22const maxInt = std.math.maxInt;
33
4pub const fd_t = c_int;
5pub const pid_t = c_int;
6pub const mode_t = c_uint;
4pub const fd_t = i32;
5pub const pid_t = i32;
6pub const mode_t = u32;
7pub const ino_t = u64;
8pub const off_t = i64;
9pub const socklen_t = u32;
710
811/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
912pub const Kevent = extern struct {
......@@ -68,9 +71,6 @@ pub const msghdr_const = extern struct {
6871 msg_flags: i32,
6972};
7073
71pub const off_t = i64;
72pub const ino_t = u64;
73
7474/// Renamed to Stat to not conflict with the stat function.
7575/// atime, mtime, and ctime have functions to return `timespec`,
7676/// because although this is a POSIX API, the layout and names of
......@@ -816,6 +816,23 @@ pub fn S_IWHT(m: u32) bool {
816816 return m & S_IFMT == S_IFWHT;
817817}
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
819836pub const HOST_NAME_MAX = 255;
820837
821838/// dummy for IP