| author | |
| committer | |
| log | 3e586264e5295be87f13c34904ff9b61a95ded16 |
| tree | 4f20f7fab5d7a4f754c65c6034240a5396b98a24 |
| parent | 39207fa1d46ccaf55de80e1afd89fbccca6a73e7 |
| parent | b93405c24bd3c58f68a272f32fe764a994e7aae6 |
| signature |
Add NetBSD support22 files changed, 1098 insertions(+), 66 deletions(-)
CMakeLists.txt+3| ... | @@ -448,6 +448,7 @@ set(ZIG_STD_FILES | ... | @@ -448,6 +448,7 @@ set(ZIG_STD_FILES |
| 448 | "c/freebsd.zig" | 448 | "c/freebsd.zig" |
| 449 | "c/index.zig" | 449 | "c/index.zig" |
| 450 | "c/linux.zig" | 450 | "c/linux.zig" |
| 451 | "c/netbsd.zig" | ||
| 451 | "c/windows.zig" | 452 | "c/windows.zig" |
| 452 | "coff.zig" | 453 | "coff.zig" |
| 453 | "crypto/blake2.zig" | 454 | "crypto/blake2.zig" |
| ... | @@ -588,6 +589,8 @@ set(ZIG_STD_FILES | ... | @@ -588,6 +589,8 @@ set(ZIG_STD_FILES |
| 588 | "os/linux/index.zig" | 589 | "os/linux/index.zig" |
| 589 | "os/linux/vdso.zig" | 590 | "os/linux/vdso.zig" |
| 590 | "os/linux/x86_64.zig" | 591 | "os/linux/x86_64.zig" |
| 592 | "os/netbsd/errno.zig" | ||
| 593 | "os/netbsd/index.zig" | ||
| 591 | "os/path.zig" | 594 | "os/path.zig" |
| 592 | "os/time.zig" | 595 | "os/time.zig" |
| 593 | "os/uefi.zig" | 596 | "os/uefi.zig" |
src-self-hosted/libc_installation.zig+1-1| ... | @@ -172,7 +172,7 @@ pub const LibCInstallation = struct { | ... | @@ -172,7 +172,7 @@ pub const LibCInstallation = struct { |
| 172 | try group.call(findNativeStaticLibDir, self, loop); | 172 | try group.call(findNativeStaticLibDir, self, loop); |
| 173 | try group.call(findNativeDynamicLinker, self, loop); | 173 | try group.call(findNativeDynamicLinker, self, loop); |
| 174 | }, | 174 | }, |
| 175 | builtin.Os.macosx, builtin.Os.freebsd => { | 175 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 176 | self.include_dir = try std.mem.dupe(loop.allocator, u8, "/usr/include"); | 176 | self.include_dir = try std.mem.dupe(loop.allocator, u8, "/usr/include"); |
| 177 | }, | 177 | }, |
| 178 | else => @compileError("unimplemented: find libc for this OS"), | 178 | else => @compileError("unimplemented: find libc for this OS"), |
src/analyze.cpp+7-4| ... | @@ -4732,7 +4732,8 @@ void find_libc_include_path(CodeGen *g) { | ... | @@ -4732,7 +4732,8 @@ void find_libc_include_path(CodeGen *g) { |
| 4732 | } | 4732 | } |
| 4733 | } else if (g->zig_target.os == OsLinux || | 4733 | } else if (g->zig_target.os == OsLinux || |
| 4734 | g->zig_target.os == OsMacOSX || | 4734 | g->zig_target.os == OsMacOSX || |
| 4735 | g->zig_target.os == OsFreeBSD) | 4735 | g->zig_target.os == OsFreeBSD || |
| 4736 | 	 g->zig_target.os == OsNetBSD) | ||
| 4736 | { | 4737 | { |
| 4737 | g->libc_include_dir = get_posix_libc_include_path(); | 4738 | g->libc_include_dir = get_posix_libc_include_path(); |
| 4738 | } else { | 4739 | } else { |
| ... | @@ -4781,7 +4782,7 @@ void find_libc_lib_path(CodeGen *g) { | ... | @@ -4781,7 +4782,7 @@ void find_libc_lib_path(CodeGen *g) { |
| 4781 | 4782 | ||
| 4782 | } else if (g->zig_target.os == OsLinux) { | 4783 | } else if (g->zig_target.os == OsLinux) { |
| 4783 | g->libc_lib_dir = get_linux_libc_lib_path("crt1.o"); | 4784 | g->libc_lib_dir = get_linux_libc_lib_path("crt1.o"); |
| 4784 | } else if (g->zig_target.os == OsFreeBSD) { | 4785 | } else if ((g->zig_target.os == OsFreeBSD) || (g->zig_target.os == OsNetBSD)) { |
| 4785 | g->libc_lib_dir = buf_create_from_str("/usr/lib"); | 4786 | g->libc_lib_dir = buf_create_from_str("/usr/lib"); |
| 4786 | } else { | 4787 | } else { |
| 4787 | zig_panic("Unable to determine libc lib path."); | 4788 | zig_panic("Unable to determine libc lib path."); |
| ... | @@ -4795,7 +4796,7 @@ void find_libc_lib_path(CodeGen *g) { | ... | @@ -4795,7 +4796,7 @@ void find_libc_lib_path(CodeGen *g) { |
| 4795 | return; | 4796 | return; |
| 4796 | } else if (g->zig_target.os == OsLinux) { | 4797 | } else if (g->zig_target.os == OsLinux) { |
| 4797 | g->libc_static_lib_dir = get_linux_libc_lib_path("crtbegin.o"); | 4798 | g->libc_static_lib_dir = get_linux_libc_lib_path("crtbegin.o"); |
| 4798 | } else if (g->zig_target.os == OsFreeBSD) { | 4799 | } else if ((g->zig_target.os == OsFreeBSD) || (g->zig_target.os == OsNetBSD)) { |
| 4799 | g->libc_static_lib_dir = buf_create_from_str("/usr/lib"); | 4800 | g->libc_static_lib_dir = buf_create_from_str("/usr/lib"); |
| 4800 | } else { | 4801 | } else { |
| 4801 | zig_panic("Unable to determine libc static lib path."); | 4802 | zig_panic("Unable to determine libc static lib path."); |
| ... | @@ -6710,7 +6711,9 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) { | ... | @@ -6710,7 +6711,9 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) { |
| 6710 | if (is_libc && g->libc_link_lib != nullptr) | 6711 | if (is_libc && g->libc_link_lib != nullptr) |
| 6711 | return g->libc_link_lib; | 6712 | return g->libc_link_lib; |
| 6712 | 6713 | ||
| 6713 | if (g->enable_cache && is_libc && g->zig_target.os != OsMacOSX && g->zig_target.os != OsIOS && g->zig_target.os != OsFreeBSD) { | 6714 | if (g->enable_cache && is_libc && g->zig_target.os != OsMacOSX && |
| 6715 | g->zig_target.os != OsIOS && g->zig_target.os != OsFreeBSD && | ||
| 6716 | 	g->zig_target.os != OsNetBSD) { | ||
| 6714 | fprintf(stderr, "TODO linking against libc is currently incompatible with `--cache on`.\n" | 6717 | fprintf(stderr, "TODO linking against libc is currently incompatible with `--cache on`.\n" |
| 6715 | "Zig is not yet capable of determining whether the libc installation has changed on subsequent builds.\n"); | 6718 | "Zig is not yet capable of determining whether the libc installation has changed on subsequent builds.\n"); |
| 6716 | exit(1); | 6719 | exit(1); |
src/codegen.cpp+2-1| ... | @@ -184,7 +184,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out | ... | @@ -184,7 +184,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out |
| 184 | // On Darwin/MacOS/iOS, we always link libSystem which contains libc. | 184 | // On Darwin/MacOS/iOS, we always link libSystem which contains libc. |
| 185 | if (g->zig_target.os == OsMacOSX || | 185 | if (g->zig_target.os == OsMacOSX || |
| 186 | g->zig_target.os == OsIOS || | 186 | g->zig_target.os == OsIOS || |
| 187 | 	g->zig_target.os == OsFreeBSD) | 187 | 	g->zig_target.os == OsFreeBSD || |
| 188 | 	g->zig_target.os == OsNetBSD) | ||
| 188 | { | 189 | { |
| 189 | g->libc_link_lib = create_link_lib(buf_create_from_str("c")); | 190 | g->libc_link_lib = create_link_lib(buf_create_from_str("c")); |
| 190 | g->link_libs_list.append(g->libc_link_lib); | 191 | g->link_libs_list.append(g->libc_link_lib); |
src/link.cpp+8-2| ... | @@ -198,6 +198,9 @@ static Buf *get_dynamic_linker_path(CodeGen *g) { | ... | @@ -198,6 +198,9 @@ static Buf *get_dynamic_linker_path(CodeGen *g) { |
| 198 | if (g->zig_target.os == OsFreeBSD) { | 198 | if (g->zig_target.os == OsFreeBSD) { |
| 199 | return buf_create_from_str("/libexec/ld-elf.so.1"); | 199 | return buf_create_from_str("/libexec/ld-elf.so.1"); |
| 200 | } | 200 | } |
| 201 | if (g->zig_target.os == OsNetBSD) { | ||
| 202 | return buf_create_from_str("/libexec/ld.elf_so"); | ||
| 203 | } | ||
| 201 | if (g->is_native_target && g->zig_target.arch.arch == ZigLLVM_x86_64) { | 204 | if (g->is_native_target && g->zig_target.arch.arch == ZigLLVM_x86_64) { |
| 202 | static const char *ld_names[] = { | 205 | static const char *ld_names[] = { |
| 203 | "ld-linux-x86-64.so.2", | 206 | "ld-linux-x86-64.so.2", |
| ... | @@ -263,10 +266,13 @@ static void construct_linker_job_elf(LinkJob *lj) { | ... | @@ -263,10 +266,13 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 263 | if (lj->link_in_crt) { | 266 | if (lj->link_in_crt) { |
| 264 | const char *crt1o; | 267 | const char *crt1o; |
| 265 | const char *crtbegino; | 268 | const char *crtbegino; |
| 266 | if (g->is_static) { | 269 | if (g->zig_target.os == OsNetBSD) { |
| 270 | 	 crt1o = "crt0.o"; | ||
| 271 | 	 crtbegino = "crtbegin.o"; | ||
| 272 | 	} else if (g->is_static) { | ||
| 267 | crt1o = "crt1.o"; | 273 | crt1o = "crt1.o"; |
| 268 | crtbegino = "crtbeginT.o"; | 274 | crtbegino = "crtbeginT.o"; |
| 269 | } else { | 275 | 	} else { |
| 270 | crt1o = "Scrt1.o"; | 276 | crt1o = "Scrt1.o"; |
| 271 | crtbegino = "crtbegin.o"; | 277 | crtbegino = "crtbegin.o"; |
| 272 | } | 278 | } |
src/os.cpp+14-5| ... | @@ -50,11 +50,11 @@ typedef SSIZE_T ssize_t; | ... | @@ -50,11 +50,11 @@ typedef SSIZE_T ssize_t; |
| 50 | 50 | ||
| 51 | #endif | 51 | #endif |
| 52 | 52 | ||
| 53 | #if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) | 53 | #if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) |
| 54 | #include <link.h> | 54 | #include <link.h> |
| 55 | #endif | 55 | #endif |
| 56 | 56 | ||
| 57 | #if defined(ZIG_OS_FREEBSD) | 57 | #if defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) |
| 58 | #include <sys/sysctl.h> | 58 | #include <sys/sysctl.h> |
| 59 | #endif | 59 | #endif |
| 60 | 60 | ||
| ... | @@ -78,7 +78,7 @@ static clock_serv_t cclock; | ... | @@ -78,7 +78,7 @@ static clock_serv_t cclock; |
| 78 | #if defined(__APPLE__) && !defined(environ) | 78 | #if defined(__APPLE__) && !defined(environ) |
| 79 | #include <crt_externs.h> | 79 | #include <crt_externs.h> |
| 80 | #define environ (*_NSGetEnviron()) | 80 | #define environ (*_NSGetEnviron()) |
| 81 | #elif defined(ZIG_OS_FREEBSD) | 81 | #elif defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) |
| 82 | extern char **environ; | 82 | extern char **environ; |
| 83 | #endif | 83 | #endif |
| 84 | 84 | ||
| ... | @@ -1458,6 +1458,15 @@ Error os_self_exe_path(Buf *out_path) { | ... | @@ -1458,6 +1458,15 @@ Error os_self_exe_path(Buf *out_path) { |
| 1458 | } | 1458 | } |
| 1459 | buf_resize(out_path, cb - 1); | 1459 | buf_resize(out_path, cb - 1); |
| 1460 | return ErrorNone; | 1460 | return ErrorNone; |
| 1461 | #elif defined(ZIG_OS_NETBSD) | ||
| 1462 | buf_resize(out_path, PATH_MAX); | ||
| 1463 | int mib[4] = { CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME }; | ||
| 1464 | size_t cb = PATH_MAX; | ||
| 1465 | if (sysctl(mib, 4, buf_ptr(out_path), &cb, nullptr, 0) != 0) { | ||
| 1466 | return ErrorUnexpected; | ||
| 1467 | } | ||
| 1468 | buf_resize(out_path, cb - 1); | ||
| 1469 | return ErrorNone; | ||
| 1461 | #endif | 1470 | #endif |
| 1462 | return ErrorFileNotFound; | 1471 | return ErrorFileNotFound; |
| 1463 | } | 1472 | } |
| ... | @@ -1776,7 +1785,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) { | ... | @@ -1776,7 +1785,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) { |
| 1776 | } | 1785 | } |
| 1777 | 1786 | ||
| 1778 | 1787 | ||
| 1779 | #if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) | 1788 | #if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) |
| 1780 | static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) { | 1789 | static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) { |
| 1781 | ZigList<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(data); | 1790 | ZigList<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(data); |
| 1782 | if (info->dlpi_name[0] == '/') { | 1791 | if (info->dlpi_name[0] == '/') { |
| ... | @@ -1787,7 +1796,7 @@ static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, | ... | @@ -1787,7 +1796,7 @@ static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, |
| 1787 | #endif | 1796 | #endif |
| 1788 | 1797 | ||
| 1789 | Error os_self_exe_shared_libs(ZigList<Buf *> &paths) { | 1798 | Error os_self_exe_shared_libs(ZigList<Buf *> &paths) { |
| 1790 | #if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) | 1799 | #if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) |
| 1791 | paths.resize(0); | 1800 | paths.resize(0); |
| 1792 | dl_iterate_phdr(self_exe_shared_libs_callback, &paths); | 1801 | dl_iterate_phdr(self_exe_shared_libs_callback, &paths); |
| 1793 | return ErrorNone; | 1802 | return ErrorNone; |
src/os.hpp+2| ... | @@ -25,6 +25,8 @@ | ... | @@ -25,6 +25,8 @@ |
| 25 | #define ZIG_OS_LINUX | 25 | #define ZIG_OS_LINUX |
| 26 | #elif defined(__FreeBSD__) | 26 | #elif defined(__FreeBSD__) |
| 27 | #define ZIG_OS_FREEBSD | 27 | #define ZIG_OS_FREEBSD |
| 28 | #elif defined(__NetBSD__) | ||
| 29 | #define ZIG_OS_NETBSD | ||
| 28 | #else | 30 | #else |
| 29 | #define ZIG_OS_UNKNOWN | 31 | #define ZIG_OS_UNKNOWN |
| 30 | #endif | 32 | #endif |
src/target.cpp+1-1| ... | @@ -743,6 +743,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { | ... | @@ -743,6 +743,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 743 | case OsMacOSX: | 743 | case OsMacOSX: |
| 744 | case OsZen: | 744 | case OsZen: |
| 745 | case OsFreeBSD: | 745 | case OsFreeBSD: |
| 746 | 	case OsNetBSD: | ||
| 746 | case OsOpenBSD: | 747 | case OsOpenBSD: |
| 747 | switch (id) { | 748 | switch (id) { |
| 748 | case CIntTypeShort: | 749 | case CIntTypeShort: |
| ... | @@ -783,7 +784,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { | ... | @@ -783,7 +784,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 783 | case OsIOS: | 784 | case OsIOS: |
| 784 | case OsKFreeBSD: | 785 | case OsKFreeBSD: |
| 785 | case OsLv2: | 786 | case OsLv2: |
| 786 | case OsNetBSD: | ||
| 787 | case OsSolaris: | 787 | case OsSolaris: |
| 788 | case OsHaiku: | 788 | case OsHaiku: |
| 789 | case OsMinix: | 789 | case OsMinix: |
std/c/index.zig+1| ... | @@ -6,6 +6,7 @@ pub use switch (builtin.os) { | ... | @@ -6,6 +6,7 @@ pub use switch (builtin.os) { |
| 6 | Os.windows => @import("windows.zig"), | 6 | Os.windows => @import("windows.zig"), |
| 7 | Os.macosx, Os.ios => @import("darwin.zig"), | 7 | Os.macosx, Os.ios => @import("darwin.zig"), |
| 8 | Os.freebsd => @import("freebsd.zig"), | 8 | Os.freebsd => @import("freebsd.zig"), |
| 9 | Os.netbsd => @import("netbsd.zig"), | ||
| 9 | else => empty_import, | 10 | else => empty_import, |
| 10 | }; | 11 | }; |
| 11 | const empty_import = @import("../empty.zig"); | 12 | const empty_import = @import("../empty.zig"); |
std/c/netbsd.zig created+116| ... | @@ -0,0 +1,116 @@ | ||
| 1 | extern "c" fn __errno() *c_int; | ||
| 2 | pub const _errno = __errno; | ||
| 3 | |||
| 4 | pub extern "c" fn kqueue() c_int; | ||
| 5 | pub extern "c" fn kevent( | ||
| 6 | kq: c_int, | ||
| 7 | changelist: [*]const Kevent, | ||
| 8 | nchanges: c_int, | ||
| 9 | eventlist: [*]Kevent, | ||
| 10 | nevents: c_int, | ||
| 11 | timeout: ?*const timespec, | ||
| 12 | ) c_int; | ||
| 13 | pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; | ||
| 14 | pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; | ||
| 15 | pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int; | ||
| 16 | pub extern "c" fn getdirentries(fd: c_int, buf_ptr: [*]u8, nbytes: usize, basep: *i64) usize; | ||
| 17 | pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize; | ||
| 18 | pub extern "c" fn pipe2(arg0: *[2]c_int, arg1: u32) c_int; | ||
| 19 | pub extern "c" fn preadv(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize; | ||
| 20 | pub extern "c" fn pwritev(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize; | ||
| 21 | pub extern "c" fn openat(fd: c_int, path: ?[*]const u8, flags: c_int) c_int; | ||
| 22 | pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int; | ||
| 23 | pub extern "c" fn setuid(uid: c_uint) c_int; | ||
| 24 | pub extern "c" fn kill(pid: c_int, sig: c_int) c_int; | ||
| 25 | pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int; | ||
| 26 | pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int; | ||
| 27 | |||
| 28 | /// Renamed from `kevent` to `Kevent` to avoid conflict with function name. | ||
| 29 | pub const Kevent = extern struct { | ||
| 30 | ident: usize, | ||
| 31 | filter: i32, | ||
| 32 | flags: u32, | ||
| 33 | fflags: u32, | ||
| 34 | data: i64, | ||
| 35 | udata: usize, | ||
| 36 | }; | ||
| 37 | |||
| 38 | pub const pthread_attr_t = extern struct { | ||
| 39 | pta_magic: u32, | ||
| 40 | pta_flags: c_int, | ||
| 41 | pta_private: *c_void, | ||
| 42 | }; | ||
| 43 | |||
| 44 | pub const msghdr = extern struct { | ||
| 45 | msg_name: *u8, | ||
| 46 | msg_namelen: socklen_t, | ||
| 47 | msg_iov: *iovec, | ||
| 48 | msg_iovlen: i32, | ||
| 49 | __pad1: i32, | ||
| 50 | msg_control: *u8, | ||
| 51 | msg_controllen: socklen_t, | ||
| 52 | __pad2: socklen_t, | ||
| 53 | msg_flags: i32, | ||
| 54 | }; | ||
| 55 | |||
| 56 | pub const Stat = extern struct { | ||
| 57 | dev: u64, | ||
| 58 | mode: u32, | ||
| 59 | ino: u64, | ||
| 60 | nlink: usize, | ||
| 61 | |||
| 62 | uid: u32, | ||
| 63 | gid: u32, | ||
| 64 | rdev: u64, | ||
| 65 | |||
| 66 | atim: timespec, | ||
| 67 | mtim: timespec, | ||
| 68 | ctim: timespec, | ||
| 69 | birthtim: timespec, | ||
| 70 | |||
| 71 | size: i64, | ||
| 72 | blocks: i64, | ||
| 73 | blksize: isize, | ||
| 74 | flags: u32, | ||
| 75 | gen: u32, | ||
| 76 | __spare: [2]u32, | ||
| 77 | }; | ||
| 78 | |||
| 79 | pub const timespec = extern struct { | ||
| 80 | tv_sec: i64, | ||
| 81 | tv_nsec: isize, | ||
| 82 | }; | ||
| 83 | |||
| 84 | pub const dirent = extern struct { | ||
| 85 | d_fileno: u64, | ||
| 86 | d_reclen: u16, | ||
| 87 | d_namlen: u16, | ||
| 88 | d_type: u8, | ||
| 89 | d_off: i64, | ||
| 90 | d_name: [512]u8, | ||
| 91 | }; | ||
| 92 | |||
| 93 | pub const in_port_t = u16; | ||
| 94 | pub const sa_family_t = u8; | ||
| 95 | |||
| 96 | pub const sockaddr = extern union { | ||
| 97 | in: sockaddr_in, | ||
| 98 | in6: sockaddr_in6, | ||
| 99 | }; | ||
| 100 | |||
| 101 | pub const sockaddr_in = extern struct { | ||
| 102 | len: u8, | ||
| 103 | family: sa_family_t, | ||
| 104 | port: in_port_t, | ||
| 105 | addr: u32, | ||
| 106 | zero: [8]u8, | ||
| 107 | }; | ||
| 108 | |||
| 109 | pub const sockaddr_in6 = extern struct { | ||
| 110 | len: u8, | ||
| 111 | family: sa_family_t, | ||
| 112 | port: in_port_t, | ||
| 113 | flowinfo: u32, | ||
| 114 | addr: [16]u8, | ||
| 115 | scope_id: u32, | ||
| 116 | }; | ||
std/debug/index.zig+3-3| ... | @@ -240,7 +240,7 @@ pub fn writeCurrentStackTraceWindows( | ... | @@ -240,7 +240,7 @@ pub fn writeCurrentStackTraceWindows( |
| 240 | pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void { | 240 | pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void { |
| 241 | switch (builtin.os) { | 241 | switch (builtin.os) { |
| 242 | builtin.Os.macosx => return printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color), | 242 | builtin.Os.macosx => return printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color), |
| 243 | builtin.Os.linux, builtin.Os.freebsd => return printSourceAtAddressLinux(debug_info, out_stream, address, tty_color), | 243 | builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => return printSourceAtAddressLinux(debug_info, out_stream, address, tty_color), |
| 244 | builtin.Os.windows => return printSourceAtAddressWindows(debug_info, out_stream, address, tty_color), | 244 | builtin.Os.windows => return printSourceAtAddressWindows(debug_info, out_stream, address, tty_color), |
| 245 | else => return error.UnsupportedOperatingSystem, | 245 | else => return error.UnsupportedOperatingSystem, |
| 246 | } | 246 | } |
| ... | @@ -717,7 +717,7 @@ pub const OpenSelfDebugInfoError = error{ | ... | @@ -717,7 +717,7 @@ pub const OpenSelfDebugInfoError = error{ |
| 717 | 717 | ||
| 718 | pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo { | 718 | pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo { |
| 719 | switch (builtin.os) { | 719 | switch (builtin.os) { |
| 720 | builtin.Os.linux, builtin.Os.freebsd => return openSelfDebugInfoLinux(allocator), | 720 | builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => return openSelfDebugInfoLinux(allocator), |
| 721 | builtin.Os.macosx, builtin.Os.ios => return openSelfDebugInfoMacOs(allocator), | 721 | builtin.Os.macosx, builtin.Os.ios => return openSelfDebugInfoMacOs(allocator), |
| 722 | builtin.Os.windows => return openSelfDebugInfoWindows(allocator), | 722 | builtin.Os.windows => return openSelfDebugInfoWindows(allocator), |
| 723 | else => return error.UnsupportedOperatingSystem, | 723 | else => return error.UnsupportedOperatingSystem, |
| ... | @@ -1141,7 +1141,7 @@ pub const DebugInfo = switch (builtin.os) { | ... | @@ -1141,7 +1141,7 @@ pub const DebugInfo = switch (builtin.os) { |
| 1141 | sect_contribs: []pdb.SectionContribEntry, | 1141 | sect_contribs: []pdb.SectionContribEntry, |
| 1142 | modules: []Module, | 1142 | modules: []Module, |
| 1143 | }, | 1143 | }, |
| 1144 | builtin.Os.linux, builtin.Os.freebsd => DwarfInfo, | 1144 | builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => DwarfInfo, |
| 1145 | else => @compileError("Unsupported OS"), | 1145 | else => @compileError("Unsupported OS"), |
| 1146 | }; | 1146 | }; |
| 1147 | 1147 |
std/event/fs.zig+23-8| ... | @@ -85,6 +85,7 @@ pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, o | ... | @@ -85,6 +85,7 @@ pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, o |
| 85 | builtin.Os.macosx, | 85 | builtin.Os.macosx, |
| 86 | builtin.Os.linux, | 86 | builtin.Os.linux, |
| 87 | builtin.Os.freebsd, | 87 | builtin.Os.freebsd, |
| 88 | builtin.Os.netbsd, | ||
| 88 | => { | 89 | => { |
| 89 | const iovecs = try loop.allocator.alloc(os.posix.iovec_const, data.len); | 90 | const iovecs = try loop.allocator.alloc(os.posix.iovec_const, data.len); |
| 90 | defer loop.allocator.free(iovecs); | 91 | defer loop.allocator.free(iovecs); |
| ... | @@ -222,6 +223,7 @@ pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset: | ... | @@ -222,6 +223,7 @@ pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset: |
| 222 | builtin.Os.macosx, | 223 | builtin.Os.macosx, |
| 223 | builtin.Os.linux, | 224 | builtin.Os.linux, |
| 224 | builtin.Os.freebsd, | 225 | builtin.Os.freebsd, |
| 226 | builtin.Os.netbsd, | ||
| 225 | => { | 227 | => { |
| 226 | const iovecs = try loop.allocator.alloc(os.posix.iovec, data.len); | 228 | const iovecs = try loop.allocator.alloc(os.posix.iovec, data.len); |
| 227 | defer loop.allocator.free(iovecs); | 229 | defer loop.allocator.free(iovecs); |
| ... | @@ -402,7 +404,11 @@ pub async fn openPosix( | ... | @@ -402,7 +404,11 @@ pub async fn openPosix( |
| 402 | 404 | ||
| 403 | pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle { | 405 | pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle { |
| 404 | switch (builtin.os) { | 406 | switch (builtin.os) { |
| 405 | builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd => { | 407 | builtin.Os.macosx, |
| 408 | builtin.Os.linux, | ||
| 409 | builtin.Os.freebsd, | ||
| 410 | builtin.Os.netbsd | ||
| 411 | => { | ||
| 406 | const flags = posix.O_LARGEFILE | posix.O_RDONLY | posix.O_CLOEXEC; | 412 | const flags = posix.O_LARGEFILE | posix.O_RDONLY | posix.O_CLOEXEC; |
| 407 | return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable); | 413 | return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable); |
| 408 | }, | 414 | }, |
| ... | @@ -431,6 +437,7 @@ pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: os.File.Mode) os | ... | @@ -431,6 +437,7 @@ pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: os.File.Mode) os |
| 431 | builtin.Os.macosx, | 437 | builtin.Os.macosx, |
| 432 | builtin.Os.linux, | 438 | builtin.Os.linux, |
| 433 | builtin.Os.freebsd, | 439 | builtin.Os.freebsd, |
| 440 | builtin.Os.netbsd, | ||
| 434 | => { | 441 | => { |
| 435 | const flags = posix.O_LARGEFILE | posix.O_WRONLY | posix.O_CREAT | posix.O_CLOEXEC | posix.O_TRUNC; | 442 | const flags = posix.O_LARGEFILE | posix.O_WRONLY | posix.O_CREAT | posix.O_CLOEXEC | posix.O_TRUNC; |
| 436 | return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable); | 443 | return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable); |
| ... | @@ -453,7 +460,7 @@ pub async fn openReadWrite( | ... | @@ -453,7 +460,7 @@ pub async fn openReadWrite( |
| 453 | mode: os.File.Mode, | 460 | mode: os.File.Mode, |
| 454 | ) os.File.OpenError!os.FileHandle { | 461 | ) os.File.OpenError!os.FileHandle { |
| 455 | switch (builtin.os) { | 462 | switch (builtin.os) { |
| 456 | builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd => { | 463 | builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 457 | const flags = posix.O_LARGEFILE | posix.O_RDWR | posix.O_CREAT | posix.O_CLOEXEC; | 464 | const flags = posix.O_LARGEFILE | posix.O_RDWR | posix.O_CREAT | posix.O_CLOEXEC; |
| 458 | return await (async openPosix(loop, path, flags, mode) catch unreachable); | 465 | return await (async openPosix(loop, path, flags, mode) catch unreachable); |
| 459 | }, | 466 | }, |
| ... | @@ -481,7 +488,7 @@ pub const CloseOperation = struct { | ... | @@ -481,7 +488,7 @@ pub const CloseOperation = struct { |
| 481 | os_data: OsData, | 488 | os_data: OsData, |
| 482 | 489 | ||
| 483 | const OsData = switch (builtin.os) { | 490 | const OsData = switch (builtin.os) { |
| 484 | builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => OsDataPosix, | 491 | builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => OsDataPosix, |
| 485 | 492 | ||
| 486 | builtin.Os.windows => struct { | 493 | builtin.Os.windows => struct { |
| 487 | handle: ?os.FileHandle, | 494 | handle: ?os.FileHandle, |
| ... | @@ -500,7 +507,7 @@ pub const CloseOperation = struct { | ... | @@ -500,7 +507,7 @@ pub const CloseOperation = struct { |
| 500 | self.* = CloseOperation{ | 507 | self.* = CloseOperation{ |
| 501 | .loop = loop, | 508 | .loop = loop, |
| 502 | .os_data = switch (builtin.os) { | 509 | .os_data = switch (builtin.os) { |
| 503 | builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => initOsDataPosix(self), | 510 | builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => initOsDataPosix(self), |
| 504 | builtin.Os.windows => OsData{ .handle = null }, | 511 | builtin.Os.windows => OsData{ .handle = null }, |
| 505 | else => @compileError("Unsupported OS"), | 512 | else => @compileError("Unsupported OS"), |
| 506 | }, | 513 | }, |
| ... | @@ -530,6 +537,7 @@ pub const CloseOperation = struct { | ... | @@ -530,6 +537,7 @@ pub const CloseOperation = struct { |
| 530 | builtin.Os.linux, | 537 | builtin.Os.linux, |
| 531 | builtin.Os.macosx, | 538 | builtin.Os.macosx, |
| 532 | builtin.Os.freebsd, | 539 | builtin.Os.freebsd, |
| 540 | builtin.Os.netbsd, | ||
| 533 | => { | 541 | => { |
| 534 | if (self.os_data.have_fd) { | 542 | if (self.os_data.have_fd) { |
| 535 | self.loop.posixFsRequest(&self.os_data.close_req_node); | 543 | self.loop.posixFsRequest(&self.os_data.close_req_node); |
| ... | @@ -552,6 +560,7 @@ pub const CloseOperation = struct { | ... | @@ -552,6 +560,7 @@ pub const CloseOperation = struct { |
| 552 | builtin.Os.linux, | 560 | builtin.Os.linux, |
| 553 | builtin.Os.macosx, | 561 | builtin.Os.macosx, |
| 554 | builtin.Os.freebsd, | 562 | builtin.Os.freebsd, |
| 563 | builtin.Os.netbsd, | ||
| 555 | => { | 564 | => { |
| 556 | self.os_data.close_req_node.data.msg.Close.fd = handle; | 565 | self.os_data.close_req_node.data.msg.Close.fd = handle; |
| 557 | self.os_data.have_fd = true; | 566 | self.os_data.have_fd = true; |
| ... | @@ -569,6 +578,7 @@ pub const CloseOperation = struct { | ... | @@ -569,6 +578,7 @@ pub const CloseOperation = struct { |
| 569 | builtin.Os.linux, | 578 | builtin.Os.linux, |
| 570 | builtin.Os.macosx, | 579 | builtin.Os.macosx, |
| 571 | builtin.Os.freebsd, | 580 | builtin.Os.freebsd, |
| 581 | builtin.Os.netbsd, | ||
| 572 | => { | 582 | => { |
| 573 | self.os_data.have_fd = false; | 583 | self.os_data.have_fd = false; |
| 574 | }, | 584 | }, |
| ... | @@ -584,6 +594,7 @@ pub const CloseOperation = struct { | ... | @@ -584,6 +594,7 @@ pub const CloseOperation = struct { |
| 584 | builtin.Os.linux, | 594 | builtin.Os.linux, |
| 585 | builtin.Os.macosx, | 595 | builtin.Os.macosx, |
| 586 | builtin.Os.freebsd, | 596 | builtin.Os.freebsd, |
| 597 | builtin.Os.netbsd, | ||
| 587 | => { | 598 | => { |
| 588 | assert(self.os_data.have_fd); | 599 | assert(self.os_data.have_fd); |
| 589 | return self.os_data.close_req_node.data.msg.Close.fd; | 600 | return self.os_data.close_req_node.data.msg.Close.fd; |
| ... | @@ -608,6 +619,7 @@ pub async fn writeFileMode(loop: *Loop, path: []const u8, contents: []const u8, | ... | @@ -608,6 +619,7 @@ pub async fn writeFileMode(loop: *Loop, path: []const u8, contents: []const u8, |
| 608 | builtin.Os.linux, | 619 | builtin.Os.linux, |
| 609 | builtin.Os.macosx, | 620 | builtin.Os.macosx, |
| 610 | builtin.Os.freebsd, | 621 | builtin.Os.freebsd, |
| 622 | builtin.Os.netbsd, | ||
| 611 | => return await (async writeFileModeThread(loop, path, contents, mode) catch unreachable), | 623 | => return await (async writeFileModeThread(loop, path, contents, mode) catch unreachable), |
| 612 | builtin.Os.windows => return await (async writeFileWindows(loop, path, contents) catch unreachable), | 624 | builtin.Os.windows => return await (async writeFileWindows(loop, path, contents) catch unreachable), |
| 613 | else => @compileError("Unsupported OS"), | 625 | else => @compileError("Unsupported OS"), |
| ... | @@ -713,7 +725,7 @@ pub fn Watch(comptime V: type) type { | ... | @@ -713,7 +725,7 @@ pub fn Watch(comptime V: type) type { |
| 713 | os_data: OsData, | 725 | os_data: OsData, |
| 714 | 726 | ||
| 715 | const OsData = switch (builtin.os) { | 727 | const OsData = switch (builtin.os) { |
| 716 | builtin.Os.macosx, builtin.Os.freebsd => struct { | 728 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => struct { |
| 717 | file_table: FileTable, | 729 | file_table: FileTable, |
| 718 | table_lock: event.Lock, | 730 | table_lock: event.Lock, |
| 719 | 731 | ||
| ... | @@ -802,7 +814,7 @@ pub fn Watch(comptime V: type) type { | ... | @@ -802,7 +814,7 @@ pub fn Watch(comptime V: type) type { |
| 802 | return self; | 814 | return self; |
| 803 | }, | 815 | }, |
| 804 | 816 | ||
| 805 | builtin.Os.macosx, builtin.Os.freebsd => { | 817 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 806 | const self = try loop.allocator.create(Self); | 818 | const self = try loop.allocator.create(Self); |
| 807 | errdefer loop.allocator.destroy(self); | 819 | errdefer loop.allocator.destroy(self); |
| 808 | 820 | ||
| ... | @@ -822,7 +834,7 @@ pub fn Watch(comptime V: type) type { | ... | @@ -822,7 +834,7 @@ pub fn Watch(comptime V: type) type { |
| 822 | /// All addFile calls and removeFile calls must have completed. | 834 | /// All addFile calls and removeFile calls must have completed. |
| 823 | pub fn destroy(self: *Self) void { | 835 | pub fn destroy(self: *Self) void { |
| 824 | switch (builtin.os) { | 836 | switch (builtin.os) { |
| 825 | builtin.Os.macosx, builtin.Os.freebsd => { | 837 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 826 | // TODO we need to cancel the coroutines before destroying the lock | 838 | // TODO we need to cancel the coroutines before destroying the lock |
| 827 | self.os_data.table_lock.deinit(); | 839 | self.os_data.table_lock.deinit(); |
| 828 | var it = self.os_data.file_table.iterator(); | 840 | var it = self.os_data.file_table.iterator(); |
| ... | @@ -864,7 +876,10 @@ pub fn Watch(comptime V: type) type { | ... | @@ -864,7 +876,10 @@ pub fn Watch(comptime V: type) type { |
| 864 | 876 | ||
| 865 | pub async fn addFile(self: *Self, file_path: []const u8, value: V) !?V { | 877 | pub async fn addFile(self: *Self, file_path: []const u8, value: V) !?V { |
| 866 | switch (builtin.os) { | 878 | switch (builtin.os) { |
| 867 | builtin.Os.macosx, builtin.Os.freebsd => return await (async addFileKEvent(self, file_path, value) catch unreachable), | 879 | builtin.Os.macosx, |
| 880 | builtin.Os.freebsd, | ||
| 881 | builtin.Os.netbsd | ||
| 882 | => return await (async addFileKEvent(self, file_path, value) catch unreachable), | ||
| 868 | builtin.Os.linux => return await (async addFileLinux(self, file_path, value) catch unreachable), | 883 | builtin.Os.linux => return await (async addFileLinux(self, file_path, value) catch unreachable), |
| 869 | builtin.Os.windows => return await (async addFileWindows(self, file_path, value) catch unreachable), | 884 | builtin.Os.windows => return await (async addFileWindows(self, file_path, value) catch unreachable), |
| 870 | else => @compileError("Unsupported OS"), | 885 | else => @compileError("Unsupported OS"), |
std/event/loop.zig+11-10| ... | @@ -50,7 +50,7 @@ pub const Loop = struct { | ... | @@ -50,7 +50,7 @@ pub const Loop = struct { |
| 50 | }; | 50 | }; |
| 51 | 51 | ||
| 52 | pub const EventFd = switch (builtin.os) { | 52 | pub const EventFd = switch (builtin.os) { |
| 53 | builtin.Os.macosx, builtin.Os.freebsd => KEventFd, | 53 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => KEventFd, |
| 54 | builtin.Os.linux => struct { | 54 | builtin.Os.linux => struct { |
| 55 | base: ResumeNode, | 55 | base: ResumeNode, |
| 56 | epoll_op: u32, | 56 | epoll_op: u32, |
| ... | @@ -69,7 +69,7 @@ pub const Loop = struct { | ... | @@ -69,7 +69,7 @@ pub const Loop = struct { |
| 69 | }; | 69 | }; |
| 70 | 70 | ||
| 71 | pub const Basic = switch (builtin.os) { | 71 | pub const Basic = switch (builtin.os) { |
| 72 | builtin.Os.macosx, builtin.Os.freebsd => KEventBasic, | 72 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => KEventBasic, |
| 73 | builtin.Os.linux => struct { | 73 | builtin.Os.linux => struct { |
| 74 | base: ResumeNode, | 74 | base: ResumeNode, |
| 75 | }, | 75 | }, |
| ... | @@ -221,7 +221,7 @@ pub const Loop = struct { | ... | @@ -221,7 +221,7 @@ pub const Loop = struct { |
| 221 | self.extra_threads[extra_thread_index] = try os.spawnThread(self, workerRun); | 221 | self.extra_threads[extra_thread_index] = try os.spawnThread(self, workerRun); |
| 222 | } | 222 | } |
| 223 | }, | 223 | }, |
| 224 | builtin.Os.macosx, builtin.Os.freebsd => { | 224 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 225 | self.os_data.kqfd = try os.bsdKQueue(); | 225 | self.os_data.kqfd = try os.bsdKQueue(); |
| 226 | errdefer os.close(self.os_data.kqfd); | 226 | errdefer os.close(self.os_data.kqfd); |
| 227 | 227 | ||
| ... | @@ -386,7 +386,7 @@ pub const Loop = struct { | ... | @@ -386,7 +386,7 @@ pub const Loop = struct { |
| 386 | os.close(self.os_data.epollfd); | 386 | os.close(self.os_data.epollfd); |
| 387 | self.allocator.free(self.eventfd_resume_nodes); | 387 | self.allocator.free(self.eventfd_resume_nodes); |
| 388 | }, | 388 | }, |
| 389 | builtin.Os.macosx, builtin.Os.freebsd => { | 389 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 390 | os.close(self.os_data.kqfd); | 390 | os.close(self.os_data.kqfd); |
| 391 | os.close(self.os_data.fs_kqfd); | 391 | os.close(self.os_data.fs_kqfd); |
| 392 | }, | 392 | }, |
| ... | @@ -501,7 +501,7 @@ pub const Loop = struct { | ... | @@ -501,7 +501,7 @@ pub const Loop = struct { |
| 501 | const eventfd_node = &resume_stack_node.data; | 501 | const eventfd_node = &resume_stack_node.data; |
| 502 | eventfd_node.base.handle = next_tick_node.data; | 502 | eventfd_node.base.handle = next_tick_node.data; |
| 503 | switch (builtin.os) { | 503 | switch (builtin.os) { |
| 504 | builtin.Os.macosx, builtin.Os.freebsd => { | 504 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 505 | const kevent_array = (*[1]posix.Kevent)(&eventfd_node.kevent); | 505 | const kevent_array = (*[1]posix.Kevent)(&eventfd_node.kevent); |
| 506 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; | 506 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; |
| 507 | _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch { | 507 | _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch { |
| ... | @@ -564,6 +564,7 @@ pub const Loop = struct { | ... | @@ -564,6 +564,7 @@ pub const Loop = struct { |
| 564 | builtin.Os.linux, | 564 | builtin.Os.linux, |
| 565 | builtin.Os.macosx, | 565 | builtin.Os.macosx, |
| 566 | builtin.Os.freebsd, | 566 | builtin.Os.freebsd, |
| 567 | builtin.Os.netbsd, | ||
| 567 | => self.os_data.fs_thread.wait(), | 568 | => self.os_data.fs_thread.wait(), |
| 568 | else => {}, | 569 | else => {}, |
| 569 | } | 570 | } |
| ... | @@ -628,7 +629,7 @@ pub const Loop = struct { | ... | @@ -628,7 +629,7 @@ pub const Loop = struct { |
| 628 | os.posixWrite(self.os_data.final_eventfd, wakeup_bytes) catch unreachable; | 629 | os.posixWrite(self.os_data.final_eventfd, wakeup_bytes) catch unreachable; |
| 629 | return; | 630 | return; |
| 630 | }, | 631 | }, |
| 631 | builtin.Os.macosx, builtin.Os.freebsd => { | 632 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 632 | self.posixFsRequest(&self.os_data.fs_end_request); | 633 | self.posixFsRequest(&self.os_data.fs_end_request); |
| 633 | const final_kevent = (*[1]posix.Kevent)(&self.os_data.final_kevent); | 634 | const final_kevent = (*[1]posix.Kevent)(&self.os_data.final_kevent); |
| 634 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; | 635 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; |
| ... | @@ -686,7 +687,7 @@ pub const Loop = struct { | ... | @@ -686,7 +687,7 @@ pub const Loop = struct { |
| 686 | } | 687 | } |
| 687 | } | 688 | } |
| 688 | }, | 689 | }, |
| 689 | builtin.Os.macosx, builtin.Os.freebsd => { | 690 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 690 | var eventlist: [1]posix.Kevent = undefined; | 691 | var eventlist: [1]posix.Kevent = undefined; |
| 691 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; | 692 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; |
| 692 | const count = os.bsdKEvent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable; | 693 | const count = os.bsdKEvent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable; |
| ... | @@ -749,7 +750,7 @@ pub const Loop = struct { | ... | @@ -749,7 +750,7 @@ pub const Loop = struct { |
| 749 | self.beginOneEvent(); // finished in posixFsRun after processing the msg | 750 | self.beginOneEvent(); // finished in posixFsRun after processing the msg |
| 750 | self.os_data.fs_queue.put(request_node); | 751 | self.os_data.fs_queue.put(request_node); |
| 751 | switch (builtin.os) { | 752 | switch (builtin.os) { |
| 752 | builtin.Os.macosx, builtin.Os.freebsd => { | 753 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 753 | const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wake); | 754 | const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wake); |
| 754 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; | 755 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; |
| 755 | _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable; | 756 | _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable; |
| ... | @@ -819,7 +820,7 @@ pub const Loop = struct { | ... | @@ -819,7 +820,7 @@ pub const Loop = struct { |
| 819 | else => unreachable, | 820 | else => unreachable, |
| 820 | } | 821 | } |
| 821 | }, | 822 | }, |
| 822 | builtin.Os.macosx, builtin.Os.freebsd => { | 823 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 823 | const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wait); | 824 | const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wait); |
| 824 | var out_kevs: [1]posix.Kevent = undefined; | 825 | var out_kevs: [1]posix.Kevent = undefined; |
| 825 | _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable; | 826 | _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable; |
| ... | @@ -831,7 +832,7 @@ pub const Loop = struct { | ... | @@ -831,7 +832,7 @@ pub const Loop = struct { |
| 831 | 832 | ||
| 832 | const OsData = switch (builtin.os) { | 833 | const OsData = switch (builtin.os) { |
| 833 | builtin.Os.linux => LinuxOsData, | 834 | builtin.Os.linux => LinuxOsData, |
| 834 | builtin.Os.macosx, builtin.Os.freebsd => KEventData, | 835 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => KEventData, |
| 835 | builtin.Os.windows => struct { | 836 | builtin.Os.windows => struct { |
| 836 | io_port: windows.HANDLE, | 837 | io_port: windows.HANDLE, |
| 837 | extra_thread_count: usize, | 838 | extra_thread_count: usize, |
std/heap.zig+3-3| ... | @@ -71,7 +71,7 @@ pub const DirectAllocator = struct { | ... | @@ -71,7 +71,7 @@ pub const DirectAllocator = struct { |
| 71 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); | 71 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); |
| 72 | 72 | ||
| 73 | switch (builtin.os) { | 73 | switch (builtin.os) { |
| 74 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | 74 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { |
| 75 | const p = os.posix; | 75 | const p = os.posix; |
| 76 | const alloc_size = if (alignment <= os.page_size) n else n + alignment; | 76 | const alloc_size = if (alignment <= os.page_size) n else n + alignment; |
| 77 | const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0); | 77 | const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0); |
| ... | @@ -120,7 +120,7 @@ pub const DirectAllocator = struct { | ... | @@ -120,7 +120,7 @@ pub const DirectAllocator = struct { |
| 120 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); | 120 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); |
| 121 | 121 | ||
| 122 | switch (builtin.os) { | 122 | switch (builtin.os) { |
| 123 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | 123 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { |
| 124 | if (new_size <= old_mem.len) { | 124 | if (new_size <= old_mem.len) { |
| 125 | const base_addr = @ptrToInt(old_mem.ptr); | 125 | const base_addr = @ptrToInt(old_mem.ptr); |
| 126 | const old_addr_end = base_addr + old_mem.len; | 126 | const old_addr_end = base_addr + old_mem.len; |
| ... | @@ -164,7 +164,7 @@ pub const DirectAllocator = struct { | ... | @@ -164,7 +164,7 @@ pub const DirectAllocator = struct { |
| 164 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); | 164 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); |
| 165 | 165 | ||
| 166 | switch (builtin.os) { | 166 | switch (builtin.os) { |
| 167 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | 167 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { |
| 168 | _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len); | 168 | _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len); |
| 169 | }, | 169 | }, |
| 170 | Os.windows => { | 170 | Os.windows => { |
std/os/file.zig+3-3| ... | @@ -237,7 +237,7 @@ pub const File = struct { | ... | @@ -237,7 +237,7 @@ pub const File = struct { |
| 237 | 237 | ||
| 238 | pub fn seekForward(self: File, amount: isize) SeekError!void { | 238 | pub fn seekForward(self: File, amount: isize) SeekError!void { |
| 239 | switch (builtin.os) { | 239 | switch (builtin.os) { |
| 240 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | 240 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { |
| 241 | const result = posix.lseek(self.handle, amount, posix.SEEK_CUR); | 241 | const result = posix.lseek(self.handle, amount, posix.SEEK_CUR); |
| 242 | const err = posix.getErrno(result); | 242 | const err = posix.getErrno(result); |
| 243 | if (err > 0) { | 243 | if (err > 0) { |
| ... | @@ -268,7 +268,7 @@ pub const File = struct { | ... | @@ -268,7 +268,7 @@ pub const File = struct { |
| 268 | 268 | ||
| 269 | pub fn seekTo(self: File, pos: usize) SeekError!void { | 269 | pub fn seekTo(self: File, pos: usize) SeekError!void { |
| 270 | switch (builtin.os) { | 270 | switch (builtin.os) { |
| 271 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | 271 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { |
| 272 | const ipos = try math.cast(isize, pos); | 272 | const ipos = try math.cast(isize, pos); |
| 273 | const result = posix.lseek(self.handle, ipos, posix.SEEK_SET); | 273 | const result = posix.lseek(self.handle, ipos, posix.SEEK_SET); |
| 274 | const err = posix.getErrno(result); | 274 | const err = posix.getErrno(result); |
| ... | @@ -309,7 +309,7 @@ pub const File = struct { | ... | @@ -309,7 +309,7 @@ pub const File = struct { |
| 309 | 309 | ||
| 310 | pub fn getPos(self: File) GetSeekPosError!usize { | 310 | pub fn getPos(self: File) GetSeekPosError!usize { |
| 311 | switch (builtin.os) { | 311 | switch (builtin.os) { |
| 312 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | 312 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { |
| 313 | const result = posix.lseek(self.handle, 0, posix.SEEK_CUR); | 313 | const result = posix.lseek(self.handle, 0, posix.SEEK_CUR); |
| 314 | const err = posix.getErrno(result); | 314 | const err = posix.getErrno(result); |
| 315 | if (err > 0) { | 315 | if (err > 0) { |
std/os/get_app_data_dir.zig+1-1| ... | @@ -43,7 +43,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD | ... | @@ -43,7 +43,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD |
| 43 | }; | 43 | }; |
| 44 | return os.path.join(allocator, [][]const u8{ home_dir, "Library", "Application Support", appname }); | 44 | return os.path.join(allocator, [][]const u8{ home_dir, "Library", "Application Support", appname }); |
| 45 | }, | 45 | }, |
| 46 | builtin.Os.linux, builtin.Os.freebsd => { | 46 | builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 47 | const home_dir = os.getEnvPosix("HOME") orelse { | 47 | const home_dir = os.getEnvPosix("HOME") orelse { |
| 48 | // TODO look in /etc/passwd | 48 | // TODO look in /etc/passwd |
| 49 | return error.AppDataDirUnavailable; | 49 | return error.AppDataDirUnavailable; |
std/os/get_user_id.zig+1-1| ... | @@ -11,7 +11,7 @@ pub const UserInfo = struct { | ... | @@ -11,7 +11,7 @@ pub const UserInfo = struct { |
| 11 | /// POSIX function which gets a uid from username. | 11 | /// POSIX function which gets a uid from username. |
| 12 | pub fn getUserInfo(name: []const u8) !UserInfo { | 12 | pub fn getUserInfo(name: []const u8) !UserInfo { |
| 13 | return switch (builtin.os) { | 13 | return switch (builtin.os) { |
| 14 | Os.linux, Os.macosx, Os.ios, Os.freebsd => posixGetUserInfo(name), | 14 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => posixGetUserInfo(name), |
| 15 | else => @compileError("Unsupported OS"), | 15 | else => @compileError("Unsupported OS"), |
| 16 | }; | 16 | }; |
| 17 | } | 17 | } |
std/os/index.zig+32-16| ... | @@ -3,7 +3,7 @@ const builtin = @import("builtin"); | ... | @@ -3,7 +3,7 @@ const builtin = @import("builtin"); |
| 3 | const Os = builtin.Os; | 3 | const Os = builtin.Os; |
| 4 | const is_windows = builtin.os == Os.windows; | 4 | const is_windows = builtin.os == Os.windows; |
| 5 | const is_posix = switch (builtin.os) { | 5 | const is_posix = switch (builtin.os) { |
| 6 | builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => true, | 6 | builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => true, |
| 7 | else => false, | 7 | else => false, |
| 8 | }; | 8 | }; |
| 9 | const os = @This(); | 9 | const os = @This(); |
| ... | @@ -30,6 +30,7 @@ pub const windows = @import("windows/index.zig"); | ... | @@ -30,6 +30,7 @@ pub const windows = @import("windows/index.zig"); |
| 30 | pub const darwin = @import("darwin.zig"); | 30 | pub const darwin = @import("darwin.zig"); |
| 31 | pub const linux = @import("linux/index.zig"); | 31 | pub const linux = @import("linux/index.zig"); |
| 32 | pub const freebsd = @import("freebsd/index.zig"); | 32 | pub const freebsd = @import("freebsd/index.zig"); |
| 33 | pub const netbsd = @import("netbsd/index.zig"); | ||
| 33 | pub const zen = @import("zen.zig"); | 34 | pub const zen = @import("zen.zig"); |
| 34 | pub const uefi = @import("uefi.zig"); | 35 | pub const uefi = @import("uefi.zig"); |
| 35 | 36 | ||
| ... | @@ -37,6 +38,7 @@ pub const posix = switch (builtin.os) { | ... | @@ -37,6 +38,7 @@ pub const posix = switch (builtin.os) { |
| 37 | Os.linux => linux, | 38 | Os.linux => linux, |
| 38 | Os.macosx, Os.ios => darwin, | 39 | Os.macosx, Os.ios => darwin, |
| 39 | Os.freebsd => freebsd, | 40 | Os.freebsd => freebsd, |
| 41 | Os.netbsd => netbsd, | ||
| 40 | Os.zen => zen, | 42 | Os.zen => zen, |
| 41 | else => @compileError("Unsupported OS"), | 43 | else => @compileError("Unsupported OS"), |
| 42 | }; | 44 | }; |
| ... | @@ -50,7 +52,7 @@ pub const time = @import("time.zig"); | ... | @@ -50,7 +52,7 @@ pub const time = @import("time.zig"); |
| 50 | 52 | ||
| 51 | pub const page_size = 4 * 1024; | 53 | pub const page_size = 4 * 1024; |
| 52 | pub const MAX_PATH_BYTES = switch (builtin.os) { | 54 | pub const MAX_PATH_BYTES = switch (builtin.os) { |
| 53 | Os.linux, Os.macosx, Os.ios, Os.freebsd => posix.PATH_MAX, | 55 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => posix.PATH_MAX, |
| 54 | // Each UTF-16LE character may be expanded to 3 UTF-8 bytes. | 56 | // Each UTF-16LE character may be expanded to 3 UTF-8 bytes. |
| 55 | // If it would require 4 UTF-8 bytes, then there would be a surrogate | 57 | // If it would require 4 UTF-8 bytes, then there would be a surrogate |
| 56 | // pair in the UTF-16LE, and we (over)account 3 bytes for it that way. | 58 | // pair in the UTF-16LE, and we (over)account 3 bytes for it that way. |
| ... | @@ -125,7 +127,7 @@ pub fn getRandomBytes(buf: []u8) !void { | ... | @@ -125,7 +127,7 @@ pub fn getRandomBytes(buf: []u8) !void { |
| 125 | else => return unexpectedErrorPosix(errno), | 127 | else => return unexpectedErrorPosix(errno), |
| 126 | } | 128 | } |
| 127 | }, | 129 | }, |
| 128 | Os.macosx, Os.ios, Os.freebsd => return getRandomBytesDevURandom(buf), | 130 | Os.macosx, Os.ios, Os.freebsd, Os.netbsd => return getRandomBytesDevURandom(buf), |
| 129 | Os.windows => { | 131 | Os.windows => { |
| 130 | // Call RtlGenRandom() instead of CryptGetRandom() on Windows | 132 | // Call RtlGenRandom() instead of CryptGetRandom() on Windows |
| 131 | // https://github.com/rust-lang-nursery/rand/issues/111 | 133 | // https://github.com/rust-lang-nursery/rand/issues/111 |
| ... | @@ -185,7 +187,7 @@ pub fn abort() noreturn { | ... | @@ -185,7 +187,7 @@ pub fn abort() noreturn { |
| 185 | c.abort(); | 187 | c.abort(); |
| 186 | } | 188 | } |
| 187 | switch (builtin.os) { | 189 | switch (builtin.os) { |
| 188 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | 190 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { |
| 189 | _ = posix.raise(posix.SIGABRT); | 191 | _ = posix.raise(posix.SIGABRT); |
| 190 | _ = posix.raise(posix.SIGKILL); | 192 | _ = posix.raise(posix.SIGKILL); |
| 191 | while (true) {} | 193 | while (true) {} |
| ... | @@ -211,7 +213,7 @@ pub fn exit(status: u8) noreturn { | ... | @@ -211,7 +213,7 @@ pub fn exit(status: u8) noreturn { |
| 211 | c.exit(status); | 213 | c.exit(status); |
| 212 | } | 214 | } |
| 213 | switch (builtin.os) { | 215 | switch (builtin.os) { |
| 214 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | 216 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { |
| 215 | posix.exit(status); | 217 | posix.exit(status); |
| 216 | }, | 218 | }, |
| 217 | Os.windows => { | 219 | Os.windows => { |
| ... | @@ -327,7 +329,7 @@ pub fn posix_preadv(fd: i32, iov: [*]const posix.iovec, count: usize, offset: u6 | ... | @@ -327,7 +329,7 @@ pub fn posix_preadv(fd: i32, iov: [*]const posix.iovec, count: usize, offset: u6 |
| 327 | } | 329 | } |
| 328 | } | 330 | } |
| 329 | }, | 331 | }, |
| 330 | builtin.Os.linux, builtin.Os.freebsd => while (true) { | 332 | builtin.Os.linux, builtin.Os.freebsd, Os.netbsd => while (true) { |
| 331 | const rc = posix.preadv(fd, iov, count, offset); | 333 | const rc = posix.preadv(fd, iov, count, offset); |
| 332 | const err = posix.getErrno(rc); | 334 | const err = posix.getErrno(rc); |
| 333 | switch (err) { | 335 | switch (err) { |
| ... | @@ -434,7 +436,7 @@ pub fn posix_pwritev(fd: i32, iov: [*]const posix.iovec_const, count: usize, off | ... | @@ -434,7 +436,7 @@ pub fn posix_pwritev(fd: i32, iov: [*]const posix.iovec_const, count: usize, off |
| 434 | } | 436 | } |
| 435 | } | 437 | } |
| 436 | }, | 438 | }, |
| 437 | builtin.Os.linux, builtin.Os.freebsd => while (true) { | 439 | builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => while (true) { |
| 438 | const rc = posix.pwritev(fd, iov, count, offset); | 440 | const rc = posix.pwritev(fd, iov, count, offset); |
| 439 | const err = posix.getErrno(rc); | 441 | const err = posix.getErrno(rc); |
| 440 | switch (err) { | 442 | switch (err) { |
| ... | @@ -699,7 +701,7 @@ pub fn getBaseAddress() usize { | ... | @@ -699,7 +701,7 @@ pub fn getBaseAddress() usize { |
| 699 | const phdr = linuxGetAuxVal(std.elf.AT_PHDR); | 701 | const phdr = linuxGetAuxVal(std.elf.AT_PHDR); |
| 700 | return phdr - @sizeOf(std.elf.Ehdr); | 702 | return phdr - @sizeOf(std.elf.Ehdr); |
| 701 | }, | 703 | }, |
| 702 | builtin.Os.macosx, builtin.Os.freebsd => return @ptrToInt(&std.c._mh_execute_header), | 704 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => return @ptrToInt(&std.c._mh_execute_header), |
| 703 | builtin.Os.windows => return @ptrToInt(windows.GetModuleHandleW(null)), | 705 | builtin.Os.windows => return @ptrToInt(windows.GetModuleHandleW(null)), |
| 704 | else => @compileError("Unsupported OS"), | 706 | else => @compileError("Unsupported OS"), |
| 705 | } | 707 | } |
| ... | @@ -1339,7 +1341,7 @@ pub fn deleteDirC(dir_path: [*]const u8) DeleteDirError!void { | ... | @@ -1339,7 +1341,7 @@ pub fn deleteDirC(dir_path: [*]const u8) DeleteDirError!void { |
| 1339 | const dir_path_w = try windows_util.cStrToPrefixedFileW(dir_path); | 1341 | const dir_path_w = try windows_util.cStrToPrefixedFileW(dir_path); |
| 1340 | return deleteDirW(&dir_path_w); | 1342 | return deleteDirW(&dir_path_w); |
| 1341 | }, | 1343 | }, |
| 1342 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | 1344 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { |
| 1343 | const err = posix.getErrno(posix.rmdir(dir_path)); | 1345 | const err = posix.getErrno(posix.rmdir(dir_path)); |
| 1344 | switch (err) { | 1346 | switch (err) { |
| 1345 | 0 => return, | 1347 | 0 => return, |
| ... | @@ -1382,7 +1384,7 @@ pub fn deleteDir(dir_path: []const u8) DeleteDirError!void { | ... | @@ -1382,7 +1384,7 @@ pub fn deleteDir(dir_path: []const u8) DeleteDirError!void { |
| 1382 | const dir_path_w = try windows_util.sliceToPrefixedFileW(dir_path); | 1384 | const dir_path_w = try windows_util.sliceToPrefixedFileW(dir_path); |
| 1383 | return deleteDirW(&dir_path_w); | 1385 | return deleteDirW(&dir_path_w); |
| 1384 | }, | 1386 | }, |
| 1385 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | 1387 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { |
| 1386 | const dir_path_c = try toPosixPath(dir_path); | 1388 | const dir_path_c = try toPosixPath(dir_path); |
| 1387 | return deleteDirC(&dir_path_c); | 1389 | return deleteDirC(&dir_path_c); |
| 1388 | }, | 1390 | }, |
| ... | @@ -1501,7 +1503,7 @@ pub const Dir = struct { | ... | @@ -1501,7 +1503,7 @@ pub const Dir = struct { |
| 1501 | allocator: *Allocator, | 1503 | allocator: *Allocator, |
| 1502 | 1504 | ||
| 1503 | pub const Handle = switch (builtin.os) { | 1505 | pub const Handle = switch (builtin.os) { |
| 1504 | Os.macosx, Os.ios, Os.freebsd => struct { | 1506 | Os.macosx, Os.ios, Os.freebsd, Os.netbsd => struct { |
| 1505 | fd: i32, | 1507 | fd: i32, |
| 1506 | seek: i64, | 1508 | seek: i64, |
| 1507 | buf: []u8, | 1509 | buf: []u8, |
| ... | @@ -1578,7 +1580,7 @@ pub const Dir = struct { | ... | @@ -1578,7 +1580,7 @@ pub const Dir = struct { |
| 1578 | .name_data = undefined, | 1580 | .name_data = undefined, |
| 1579 | }; | 1581 | }; |
| 1580 | }, | 1582 | }, |
| 1581 | Os.macosx, Os.ios, Os.freebsd => Handle{ | 1583 | Os.macosx, Os.ios, Os.freebsd, Os.netbsd => Handle{ |
| 1582 | .fd = try posixOpen( | 1584 | .fd = try posixOpen( |
| 1583 | dir_path, | 1585 | dir_path, |
| 1584 | posix.O_RDONLY | posix.O_NONBLOCK | posix.O_DIRECTORY | posix.O_CLOEXEC, | 1586 | posix.O_RDONLY | posix.O_NONBLOCK | posix.O_DIRECTORY | posix.O_CLOEXEC, |
| ... | @@ -1609,7 +1611,7 @@ pub const Dir = struct { | ... | @@ -1609,7 +1611,7 @@ pub const Dir = struct { |
| 1609 | Os.windows => { | 1611 | Os.windows => { |
| 1610 | _ = windows.FindClose(self.handle.handle); | 1612 | _ = windows.FindClose(self.handle.handle); |
| 1611 | }, | 1613 | }, |
| 1612 | Os.macosx, Os.ios, Os.linux, Os.freebsd => { | 1614 | Os.macosx, Os.ios, Os.linux, Os.freebsd, Os.netbsd => { |
| 1613 | self.allocator.free(self.handle.buf); | 1615 | self.allocator.free(self.handle.buf); |
| 1614 | os.close(self.handle.fd); | 1616 | os.close(self.handle.fd); |
| 1615 | }, | 1617 | }, |
| ... | @@ -1625,6 +1627,7 @@ pub const Dir = struct { | ... | @@ -1625,6 +1627,7 @@ pub const Dir = struct { |
| 1625 | Os.macosx, Os.ios => return self.nextDarwin(), | 1627 | Os.macosx, Os.ios => return self.nextDarwin(), |
| 1626 | Os.windows => return self.nextWindows(), | 1628 | Os.windows => return self.nextWindows(), |
| 1627 | Os.freebsd => return self.nextFreebsd(), | 1629 | Os.freebsd => return self.nextFreebsd(), |
| 1630 | Os.netbsd => return self.nextFreebsd(), | ||
| 1628 | else => @compileError("unimplemented"), | 1631 | else => @compileError("unimplemented"), |
| 1629 | } | 1632 | } |
| 1630 | } | 1633 | } |
| ... | @@ -2256,7 +2259,7 @@ pub fn unexpectedErrorWindows(err: windows.DWORD) UnexpectedError { | ... | @@ -2256,7 +2259,7 @@ pub fn unexpectedErrorWindows(err: windows.DWORD) UnexpectedError { |
| 2256 | pub fn openSelfExe() !os.File { | 2259 | pub fn openSelfExe() !os.File { |
| 2257 | switch (builtin.os) { | 2260 | switch (builtin.os) { |
| 2258 | Os.linux => return os.File.openReadC(c"/proc/self/exe"), | 2261 | Os.linux => return os.File.openReadC(c"/proc/self/exe"), |
| 2259 | Os.macosx, Os.ios, Os.freebsd => { | 2262 | Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { |
| 2260 | var buf: [MAX_PATH_BYTES]u8 = undefined; | 2263 | var buf: [MAX_PATH_BYTES]u8 = undefined; |
| 2261 | const self_exe_path = try selfExePath(&buf); | 2264 | const self_exe_path = try selfExePath(&buf); |
| 2262 | buf[self_exe_path.len] = 0; | 2265 | buf[self_exe_path.len] = 0; |
| ... | @@ -2317,6 +2320,19 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | ... | @@ -2317,6 +2320,19 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { |
| 2317 | else => unexpectedErrorPosix(err), | 2320 | else => unexpectedErrorPosix(err), |
| 2318 | }; | 2321 | }; |
| 2319 | }, | 2322 | }, |
| 2323 | Os.netbsd => { | ||
| 2324 | var mib = [4]c_int{ posix.CTL_KERN, posix.KERN_PROC_ARGS, -1, posix.KERN_PROC_PATHNAME }; | ||
| 2325 | var out_len: usize = out_buffer.len; | ||
| 2326 | const err = posix.getErrno(posix.sysctl(&mib, 4, out_buffer, &out_len, null, 0)); | ||
| 2327 | |||
| 2328 | if (err == 0) return mem.toSlice(u8, out_buffer); | ||
| 2329 | |||
| 2330 | return switch (err) { | ||
| 2331 | posix.EFAULT => error.BadAdress, | ||
| 2332 | posix.EPERM => error.PermissionDenied, | ||
| 2333 | else => unexpectedErrorPosix(err), | ||
| 2334 | }; | ||
| 2335 | }, | ||
| 2320 | Os.windows => { | 2336 | Os.windows => { |
| 2321 | var utf16le_buf: [windows_util.PATH_MAX_WIDE]u16 = undefined; | 2337 | var utf16le_buf: [windows_util.PATH_MAX_WIDE]u16 = undefined; |
| 2322 | const utf16le_slice = try selfExePathW(&utf16le_buf); | 2338 | const utf16le_slice = try selfExePathW(&utf16le_buf); |
| ... | @@ -2355,7 +2371,7 @@ pub fn selfExeDirPath(out_buffer: *[MAX_PATH_BYTES]u8) ![]const u8 { | ... | @@ -2355,7 +2371,7 @@ pub fn selfExeDirPath(out_buffer: *[MAX_PATH_BYTES]u8) ![]const u8 { |
| 2355 | // will not return null. | 2371 | // will not return null. |
| 2356 | return path.dirname(full_exe_path).?; | 2372 | return path.dirname(full_exe_path).?; |
| 2357 | }, | 2373 | }, |
| 2358 | Os.windows, Os.macosx, Os.ios, Os.freebsd => { | 2374 | Os.windows, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { |
| 2359 | const self_exe_path = try selfExePath(out_buffer); | 2375 | const self_exe_path = try selfExePath(out_buffer); |
| 2360 | // Assume that the OS APIs return absolute paths, and therefore dirname | 2376 | // Assume that the OS APIs return absolute paths, and therefore dirname |
| 2361 | // will not return null. | 2377 | // will not return null. |
| ... | @@ -3227,7 +3243,7 @@ pub const CpuCountError = error{ | ... | @@ -3227,7 +3243,7 @@ pub const CpuCountError = error{ |
| 3227 | 3243 | ||
| 3228 | pub fn cpuCount(fallback_allocator: *mem.Allocator) CpuCountError!usize { | 3244 | pub fn cpuCount(fallback_allocator: *mem.Allocator) CpuCountError!usize { |
| 3229 | switch (builtin.os) { | 3245 | switch (builtin.os) { |
| 3230 | builtin.Os.macosx, builtin.Os.freebsd => { | 3246 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 3231 | var count: c_int = undefined; | 3247 | var count: c_int = undefined; |
| 3232 | var count_len: usize = @sizeOf(c_int); | 3248 | var count_len: usize = @sizeOf(c_int); |
| 3233 | const rc = posix.sysctlbyname(switch (builtin.os) { | 3249 | const rc = posix.sysctlbyname(switch (builtin.os) { |
std/os/netbsd/errno.zig created+134| ... | @@ -0,0 +1,134 @@ | ||
| 1 | pub const EPERM = 1; // Operation not permitted | ||
| 2 | pub const ENOENT = 2; // No such file or directory | ||
| 3 | pub const ESRCH = 3; // No such process | ||
| 4 | pub const EINTR = 4; // Interrupted system call | ||
| 5 | pub const EIO = 5; // Input/output error | ||
| 6 | pub const ENXIO = 6; // Device not configured | ||
| 7 | pub const E2BIG = 7; // Argument list too long | ||
| 8 | pub const ENOEXEC = 8; // Exec format error | ||
| 9 | pub const EBADF = 9; // Bad file descriptor | ||
| 10 | pub const ECHILD = 10; // No child processes | ||
| 11 | pub const EDEADLK = 11; // Resource deadlock avoided | ||
| 12 | // 11 was EAGAIN | ||
| 13 | pub const ENOMEM = 12; // Cannot allocate memory | ||
| 14 | pub const EACCES = 13; // Permission denied | ||
| 15 | pub const EFAULT = 14; // Bad address | ||
| 16 | pub const ENOTBLK = 15; // Block device required | ||
| 17 | pub const EBUSY = 16; // Device busy | ||
| 18 | pub const EEXIST = 17; // File exists | ||
| 19 | pub const EXDEV = 18; // Cross-device link | ||
| 20 | pub const ENODEV = 19; // Operation not supported by device | ||
| 21 | pub const ENOTDIR = 20; // Not a directory | ||
| 22 | pub const EISDIR = 21; // Is a directory | ||
| 23 | pub const EINVAL = 22; // Invalid argument | ||
| 24 | pub const ENFILE = 23; // Too many open files in system | ||
| 25 | pub const EMFILE = 24; // Too many open files | ||
| 26 | pub const ENOTTY = 25; // Inappropriate ioctl for device | ||
| 27 | pub const ETXTBSY = 26; // Text file busy | ||
| 28 | pub const EFBIG = 27; // File too large | ||
| 29 | pub const ENOSPC = 28; // No space left on device | ||
| 30 | pub const ESPIPE = 29; // Illegal seek | ||
| 31 | pub const EROFS = 30; // Read-only file system | ||
| 32 | pub const EMLINK = 31; // Too many links | ||
| 33 | pub const EPIPE = 32; // Broken pipe | ||
| 34 | |||
| 35 | // math software | ||
| 36 | pub const EDOM = 33; // Numerical argument out of domain | ||
| 37 | pub const ERANGE = 34; // Result too large or too small | ||
| 38 | |||
| 39 | // non-blocking and interrupt i/o | ||
| 40 | pub const EAGAIN = 35; // Resource temporarily unavailable | ||
| 41 | pub const EWOULDBLOCK = EAGAIN; // Operation would block | ||
| 42 | pub const EINPROGRESS = 36; // Operation now in progress | ||
| 43 | pub const EALREADY = 37; // Operation already in progress | ||
| 44 | |||
| 45 | // ipc/network software -- argument errors | ||
| 46 | pub const ENOTSOCK = 38; // Socket operation on non-socket | ||
| 47 | pub const EDESTADDRREQ = 39; // Destination address required | ||
| 48 | pub const EMSGSIZE = 40; // Message too long | ||
| 49 | pub const EPROTOTYPE = 41; // Protocol wrong type for socket | ||
| 50 | pub const ENOPROTOOPT = 42; // Protocol option not available | ||
| 51 | pub const EPROTONOSUPPORT = 43; // Protocol not supported | ||
| 52 | pub const ESOCKTNOSUPPORT = 44; // Socket type not supported | ||
| 53 | pub const EOPNOTSUPP = 45; // Operation not supported | ||
| 54 | pub const EPFNOSUPPORT = 46; // Protocol family not supported | ||
| 55 | pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family | ||
| 56 | pub const EADDRINUSE = 48; // Address already in use | ||
| 57 | pub const EADDRNOTAVAIL = 49; // Can't assign requested address | ||
| 58 | |||
| 59 | // ipc/network software -- operational errors | ||
| 60 | pub const ENETDOWN = 50; // Network is down | ||
| 61 | pub const ENETUNREACH = 51; // Network is unreachable | ||
| 62 | pub const ENETRESET = 52; // Network dropped connection on reset | ||
| 63 | pub const ECONNABORTED = 53; // Software caused connection abort | ||
| 64 | pub const ECONNRESET = 54; // Connection reset by peer | ||
| 65 | pub const ENOBUFS = 55; // No buffer space available | ||
| 66 | pub const EISCONN = 56; // Socket is already connected | ||
| 67 | pub const ENOTCONN = 57; // Socket is not connected | ||
| 68 | pub const ESHUTDOWN = 58; // Can't send after socket shutdown | ||
| 69 | pub const ETOOMANYREFS = 59; // Too many references: can't splice | ||
| 70 | pub const ETIMEDOUT = 60; // Operation timed out | ||
| 71 | pub const ECONNREFUSED = 61; // Connection refused | ||
| 72 | |||
| 73 | pub const ELOOP = 62; // Too many levels of symbolic links | ||
| 74 | pub const ENAMETOOLONG = 63; // File name too long | ||
| 75 | |||
| 76 | // should be rearranged | ||
| 77 | pub const EHOSTDOWN = 64; // Host is down | ||
| 78 | pub const EHOSTUNREACH = 65; // No route to host | ||
| 79 | pub const ENOTEMPTY = 66; // Directory not empty | ||
| 80 | |||
| 81 | // quotas & mush | ||
| 82 | pub const EPROCLIM = 67; // Too many processes | ||
| 83 | pub const EUSERS = 68; // Too many users | ||
| 84 | pub const EDQUOT = 69; // Disc quota exceeded | ||
| 85 | |||
| 86 | // Network File System | ||
| 87 | pub const ESTALE = 70; // Stale NFS file handle | ||
| 88 | pub const EREMOTE = 71; // Too many levels of remote in path | ||
| 89 | pub const EBADRPC = 72; // RPC struct is bad | ||
| 90 | pub const ERPCMISMATCH = 73; // RPC version wrong | ||
| 91 | pub const EPROGUNAVAIL = 74; // RPC prog. not avail | ||
| 92 | pub const EPROGMISMATCH = 75; // Program version wrong | ||
| 93 | pub const EPROCUNAVAIL = 76; // Bad procedure for program | ||
| 94 | |||
| 95 | pub const ENOLCK = 77; // No locks available | ||
| 96 | pub const ENOSYS = 78; // Function not implemented | ||
| 97 | |||
| 98 | pub const EFTYPE = 79; // Inappropriate file type or format | ||
| 99 | pub const EAUTH = 80; // Authentication error | ||
| 100 | pub const ENEEDAUTH = 81; // Need authenticator | ||
| 101 | |||
| 102 | // SystemV IPC | ||
| 103 | pub const EIDRM = 82; // Identifier removed | ||
| 104 | pub const ENOMSG = 83; // No message of desired type | ||
| 105 | pub const EOVERFLOW = 84; // Value too large to be stored in data type | ||
| 106 | |||
| 107 | // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995 | ||
| 108 | pub const EILSEQ = 85; // Illegal byte sequence | ||
| 109 | |||
| 110 | // From IEEE Std 1003.1-2001 | ||
| 111 | // Base, Realtime, Threads or Thread Priority Scheduling option errors | ||
| 112 | pub const ENOTSUP = 86; // Not supported | ||
| 113 | |||
| 114 | // Realtime option errors | ||
| 115 | pub const ECANCELED = 87; // Operation canceled | ||
| 116 | |||
| 117 | // Realtime, XSI STREAMS option errors | ||
| 118 | pub const EBADMSG = 88; // Bad or Corrupt message | ||
| 119 | |||
| 120 | // XSI STREAMS option errors | ||
| 121 | pub const ENODATA = 89; // No message available | ||
| 122 | pub const ENOSR = 90; // No STREAM resources | ||
| 123 | pub const ENOSTR = 91; // Not a STREAM | ||
| 124 | pub const ETIME = 92; // STREAM ioctl timeout | ||
| 125 | |||
| 126 | // File system extended attribute errors | ||
| 127 | pub const ENOATTR = 93; // Attribute not found | ||
| 128 | |||
| 129 | // Realtime, XSI STREAMS option errors | ||
| 130 | pub const EMULTIHOP = 94; // Multihop attempted | ||
| 131 | pub const ENOLINK = 95; // Link has been severed | ||
| 132 | pub const EPROTO = 96; // Protocol error | ||
| 133 | |||
| 134 | pub const ELAST = 96; // Must equal largest errno | ||
std/os/netbsd/index.zig created+725| ... | @@ -0,0 +1,725 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | pub use @import("errno.zig"); | ||
| 4 | |||
| 5 | const std = @import("../../index.zig"); | ||
| 6 | const c = std.c; | ||
| 7 | |||
| 8 | const assert = std.debug.assert; | ||
| 9 | const maxInt = std.math.maxInt; | ||
| 10 | pub const Kevent = c.Kevent; | ||
| 11 | |||
| 12 | pub const CTL_KERN = 1; | ||
| 13 | pub const CTL_DEBUG = 5; | ||
| 14 | |||
| 15 | pub const KERN_PROC_ARGS = 48; // struct: process argv/env | ||
| 16 | pub const KERN_PROC_PATHNAME = 5; // path to executable | ||
| 17 | |||
| 18 | pub const PATH_MAX = 1024; | ||
| 19 | |||
| 20 | pub const STDIN_FILENO = 0; | ||
| 21 | pub const STDOUT_FILENO = 1; | ||
| 22 | pub const STDERR_FILENO = 2; | ||
| 23 | |||
| 24 | pub const PROT_NONE = 0; | ||
| 25 | pub const PROT_READ = 1; | ||
| 26 | pub const PROT_WRITE = 2; | ||
| 27 | pub const PROT_EXEC = 4; | ||
| 28 | |||
| 29 | pub const CLOCK_REALTIME = 0; | ||
| 30 | pub const CLOCK_VIRTUAL = 1; | ||
| 31 | pub const CLOCK_PROF = 2; | ||
| 32 | pub const CLOCK_MONOTONIC = 3; | ||
| 33 | pub const CLOCK_THREAD_CPUTIME_ID = 0x20000000; | ||
| 34 | pub const CLOCK_PROCESS_CPUTIME_ID = 0x40000000; | ||
| 35 | |||
| 36 | pub const MAP_FAILED = maxInt(usize); | ||
| 37 | pub const MAP_SHARED = 0x0001; | ||
| 38 | pub const MAP_PRIVATE = 0x0002; | ||
| 39 | pub const MAP_REMAPDUP = 0x0004; | ||
| 40 | pub const MAP_FIXED = 0x0010; | ||
| 41 | pub const MAP_RENAME = 0x0020; | ||
| 42 | pub const MAP_NORESERVE = 0x0040; | ||
| 43 | pub const MAP_INHERIT = 0x0080; | ||
| 44 | pub const MAP_HASSEMAPHORE = 0x0200; | ||
| 45 | pub const MAP_TRYFIXED = 0x0400; | ||
| 46 | pub const MAP_WIRED = 0x0800; | ||
| 47 | |||
| 48 | pub const MAP_FILE = 0x0000; | ||
| 49 | pub const MAP_NOSYNC = 0x0800; | ||
| 50 | pub const MAP_ANON = 0x1000; | ||
| 51 | pub const MAP_ANONYMOUS = MAP_ANON; | ||
| 52 | pub const MAP_STACK = 0x2000; | ||
| 53 | |||
| 54 | pub const WNOHANG = 0x00000001; | ||
| 55 | pub const WUNTRACED = 0x00000002; | ||
| 56 | pub const WSTOPPED = WUNTRACED; | ||
| 57 | pub const WCONTINUED = 0x00000010; | ||
| 58 | pub const WNOWAIT = 0x00010000; | ||
| 59 | pub const WEXITED = 0x00000020; | ||
| 60 | pub const WTRAPPED = 0x00000040; | ||
| 61 | |||
| 62 | pub const SA_ONSTACK = 0x0001; | ||
| 63 | pub const SA_RESTART = 0x0002; | ||
| 64 | pub const SA_RESETHAND = 0x0004; | ||
| 65 | pub const SA_NOCLDSTOP = 0x0008; | ||
| 66 | pub const SA_NODEFER = 0x0010; | ||
| 67 | pub const SA_NOCLDWAIT = 0x0020; | ||
| 68 | pub const SA_SIGINFO = 0x0040; | ||
| 69 | |||
| 70 | pub const SIGHUP = 1; | ||
| 71 | pub const SIGINT = 2; | ||
| 72 | pub const SIGQUIT = 3; | ||
| 73 | pub const SIGILL = 4; | ||
| 74 | pub const SIGTRAP = 5; | ||
| 75 | pub const SIGABRT = 6; | ||
| 76 | pub const SIGIOT = SIGABRT; | ||
| 77 | pub const SIGEMT = 7; | ||
| 78 | pub const SIGFPE = 8; | ||
| 79 | pub const SIGKILL = 9; | ||
| 80 | pub const SIGBUS = 10; | ||
| 81 | pub const SIGSEGV = 11; | ||
| 82 | pub const SIGSYS = 12; | ||
| 83 | pub const SIGPIPE = 13; | ||
| 84 | pub const SIGALRM = 14; | ||
| 85 | pub const SIGTERM = 15; | ||
| 86 | pub const SIGURG = 16; | ||
| 87 | pub const SIGSTOP = 17; | ||
| 88 | pub const SIGTSTP = 18; | ||
| 89 | pub const SIGCONT = 19; | ||
| 90 | pub const SIGCHLD = 20; | ||
| 91 | pub const SIGTTIN = 21; | ||
| 92 | pub const SIGTTOU = 22; | ||
| 93 | pub const SIGIO = 23; | ||
| 94 | pub const SIGXCPU = 24; | ||
| 95 | pub const SIGXFSZ = 25; | ||
| 96 | pub const SIGVTALRM = 26; | ||
| 97 | pub const SIGPROF = 27; | ||
| 98 | pub const SIGWINCH = 28; | ||
| 99 | pub const SIGINFO = 29; | ||
| 100 | pub const SIGUSR1 = 30; | ||
| 101 | pub const SIGUSR2 = 31; | ||
| 102 | pub const SIGPWR = 32; | ||
| 103 | |||
| 104 | pub const SIGRTMIN = 33; | ||
| 105 | pub const SIGRTMAX = 63; | ||
| 106 | |||
| 107 | // access function | ||
| 108 | pub const F_OK = 0; // test for existence of file | ||
| 109 | pub const X_OK = 1; // test for execute or search permission | ||
| 110 | pub const W_OK = 2; // test for write permission | ||
| 111 | pub const R_OK = 4; // test for read permission | ||
| 112 | |||
| 113 | |||
| 114 | pub const O_RDONLY = 0x0000; | ||
| 115 | pub const O_WRONLY = 0x0001; | ||
| 116 | pub const O_RDWR = 0x0002; | ||
| 117 | pub const O_ACCMODE = 0x0003; | ||
| 118 | |||
| 119 | pub const O_CREAT = 0x0200; | ||
| 120 | pub const O_EXCL = 0x0800; | ||
| 121 | pub const O_NOCTTY = 0x8000; | ||
| 122 | pub const O_TRUNC = 0x0400; | ||
| 123 | pub const O_APPEND = 0x0008; | ||
| 124 | pub const O_NONBLOCK = 0x0004; | ||
| 125 | pub const O_DSYNC = 0x00010000; | ||
| 126 | pub const O_SYNC = 0x0080; | ||
| 127 | pub const O_RSYNC = 0x00020000; | ||
| 128 | pub const O_DIRECTORY = 0x00080000; | ||
| 129 | pub const O_NOFOLLOW = 0x00000100; | ||
| 130 | pub const O_CLOEXEC = 0x00400000; | ||
| 131 | |||
| 132 | pub const O_ASYNC = 0x0040; | ||
| 133 | pub const O_DIRECT = 0x00080000; | ||
| 134 | pub const O_LARGEFILE = 0; | ||
| 135 | pub const O_NOATIME = 0; | ||
| 136 | pub const O_PATH = 0; | ||
| 137 | pub const O_TMPFILE = 0; | ||
| 138 | pub const O_NDELAY = O_NONBLOCK; | ||
| 139 | |||
| 140 | pub const F_DUPFD = 0; | ||
| 141 | pub const F_GETFD = 1; | ||
| 142 | pub const F_SETFD = 2; | ||
| 143 | pub const F_GETFL = 3; | ||
| 144 | pub const F_SETFL = 4; | ||
| 145 | |||
| 146 | pub const F_GETOWN = 5; | ||
| 147 | pub const F_SETOWN = 6; | ||
| 148 | |||
| 149 | pub const F_GETLK = 7; | ||
| 150 | pub const F_SETLK = 8; | ||
| 151 | pub const F_SETLKW = 9; | ||
| 152 | |||
| 153 | pub const SEEK_SET = 0; | ||
| 154 | pub const SEEK_CUR = 1; | ||
| 155 | pub const SEEK_END = 2; | ||
| 156 | |||
| 157 | pub const SIG_BLOCK = 1; | ||
| 158 | pub const SIG_UNBLOCK = 2; | ||
| 159 | pub const SIG_SETMASK = 3; | ||
| 160 | |||
| 161 | pub const SOCK_STREAM = 1; | ||
| 162 | pub const SOCK_DGRAM = 2; | ||
| 163 | pub const SOCK_RAW = 3; | ||
| 164 | pub const SOCK_RDM = 4; | ||
| 165 | pub const SOCK_SEQPACKET = 5; | ||
| 166 | |||
| 167 | pub const SOCK_CLOEXEC = 0x10000000; | ||
| 168 | pub const SOCK_NONBLOCK = 0x20000000; | ||
| 169 | |||
| 170 | pub const PROTO_ip = 0; | ||
| 171 | pub const PROTO_icmp = 1; | ||
| 172 | pub const PROTO_igmp = 2; | ||
| 173 | pub const PROTO_ggp = 3; | ||
| 174 | pub const PROTO_ipencap = 4; | ||
| 175 | pub const PROTO_tcp = 6; | ||
| 176 | pub const PROTO_egp = 8; | ||
| 177 | pub const PROTO_pup = 12; | ||
| 178 | pub const PROTO_udp = 17; | ||
| 179 | pub const PROTO_xns_idp = 22; | ||
| 180 | pub const PROTO_iso_tp4 = 29; | ||
| 181 | pub const PROTO_ipv6 = 41; | ||
| 182 | pub const PROTO_ipv6_route = 43; | ||
| 183 | pub const PROTO_ipv6_frag = 44; | ||
| 184 | pub const PROTO_rsvp = 46; | ||
| 185 | pub const PROTO_gre = 47; | ||
| 186 | pub const PROTO_esp = 50; | ||
| 187 | pub const PROTO_ah = 51; | ||
| 188 | pub const PROTO_ipv6_icmp = 58; | ||
| 189 | pub const PROTO_ipv6_nonxt = 59; | ||
| 190 | pub const PROTO_ipv6_opts = 60; | ||
| 191 | pub const PROTO_encap = 98; | ||
| 192 | pub const PROTO_pim = 103; | ||
| 193 | pub const PROTO_raw = 255; | ||
| 194 | |||
| 195 | pub const PF_UNSPEC = 0; | ||
| 196 | pub const PF_LOCAL = 1; | ||
| 197 | pub const PF_UNIX = PF_LOCAL; | ||
| 198 | pub const PF_FILE = PF_LOCAL; | ||
| 199 | pub const PF_INET = 2; | ||
| 200 | pub const PF_APPLETALK = 16; | ||
| 201 | pub const PF_INET6 = 24; | ||
| 202 | pub const PF_DECnet = 12; | ||
| 203 | pub const PF_KEY = 29; | ||
| 204 | pub const PF_ROUTE = 34; | ||
| 205 | pub const PF_SNA = 11; | ||
| 206 | pub const PF_MPLS = 33; | ||
| 207 | pub const PF_CAN = 35; | ||
| 208 | pub const PF_BLUETOOTH = 31; | ||
| 209 | pub const PF_ISDN = 26; | ||
| 210 | pub const PF_MAX = 37; | ||
| 211 | |||
| 212 | pub const AF_UNSPEC = PF_UNSPEC; | ||
| 213 | pub const AF_LOCAL = PF_LOCAL; | ||
| 214 | pub const AF_UNIX = AF_LOCAL; | ||
| 215 | pub const AF_FILE = AF_LOCAL; | ||
| 216 | pub const AF_INET = PF_INET; | ||
| 217 | pub const AF_APPLETALK = PF_APPLETALK; | ||
| 218 | pub const AF_INET6 = PF_INET6; | ||
| 219 | pub const AF_KEY = PF_KEY; | ||
| 220 | pub const AF_ROUTE = PF_ROUTE; | ||
| 221 | pub const AF_SNA = PF_SNA; | ||
| 222 | pub const AF_MPLS = PF_MPLS; | ||
| 223 | pub const AF_CAN = PF_CAN; | ||
| 224 | pub const AF_BLUETOOTH = PF_BLUETOOTH; | ||
| 225 | pub const AF_ISDN = PF_ISDN; | ||
| 226 | pub const AF_MAX = PF_MAX; | ||
| 227 | |||
| 228 | pub const DT_UNKNOWN = 0; | ||
| 229 | pub const DT_FIFO = 1; | ||
| 230 | pub const DT_CHR = 2; | ||
| 231 | pub const DT_DIR = 4; | ||
| 232 | pub const DT_BLK = 6; | ||
| 233 | pub const DT_REG = 8; | ||
| 234 | pub const DT_LNK = 10; | ||
| 235 | pub const DT_SOCK = 12; | ||
| 236 | pub const DT_WHT = 14; | ||
| 237 | |||
| 238 | /// add event to kq (implies enable) | ||
| 239 | pub const EV_ADD = 0x0001; | ||
| 240 | |||
| 241 | /// delete event from kq | ||
| 242 | pub const EV_DELETE = 0x0002; | ||
| 243 | |||
| 244 | /// enable event | ||
| 245 | pub const EV_ENABLE = 0x0004; | ||
| 246 | |||
| 247 | /// disable event (not reported) | ||
| 248 | pub const EV_DISABLE = 0x0008; | ||
| 249 | |||
| 250 | /// only report one occurrence | ||
| 251 | pub const EV_ONESHOT = 0x0010; | ||
| 252 | |||
| 253 | /// clear event state after reporting | ||
| 254 | pub const EV_CLEAR = 0x0020; | ||
| 255 | |||
| 256 | /// force immediate event output | ||
| 257 | /// ... with or without EV_ERROR | ||
| 258 | /// ... use KEVENT_FLAG_ERROR_EVENTS | ||
| 259 | /// on syscalls supporting flags | ||
| 260 | pub const EV_RECEIPT = 0x0040; | ||
| 261 | |||
| 262 | /// disable event after reporting | ||
| 263 | pub const EV_DISPATCH = 0x0080; | ||
| 264 | |||
| 265 | pub const EVFILT_READ = 0; | ||
| 266 | pub const EVFILT_WRITE = 1; | ||
| 267 | |||
| 268 | /// attached to aio requests | ||
| 269 | pub const EVFILT_AIO = 2; | ||
| 270 | |||
| 271 | /// attached to vnodes | ||
| 272 | pub const EVFILT_VNODE = 3; | ||
| 273 | |||
| 274 | /// attached to struct proc | ||
| 275 | pub const EVFILT_PROC = 4; | ||
| 276 | |||
| 277 | /// attached to struct proc | ||
| 278 | pub const EVFILT_SIGNAL = 5; | ||
| 279 | |||
| 280 | /// timers | ||
| 281 | pub const EVFILT_TIMER = 6; | ||
| 282 | |||
| 283 | /// Filesystem events | ||
| 284 | pub const EVFILT_FS = 7; | ||
| 285 | |||
| 286 | /// On input, NOTE_TRIGGER causes the event to be triggered for output. | ||
| 287 | pub const NOTE_TRIGGER = 0x08000000; | ||
| 288 | |||
| 289 | /// low water mark | ||
| 290 | pub const NOTE_LOWAT = 0x00000001; | ||
| 291 | |||
| 292 | /// vnode was removed | ||
| 293 | pub const NOTE_DELETE = 0x00000001; | ||
| 294 | |||
| 295 | /// data contents changed | ||
| 296 | pub const NOTE_WRITE = 0x00000002; | ||
| 297 | |||
| 298 | /// size increased | ||
| 299 | pub const NOTE_EXTEND = 0x00000004; | ||
| 300 | |||
| 301 | /// attributes changed | ||
| 302 | pub const NOTE_ATTRIB = 0x00000008; | ||
| 303 | |||
| 304 | /// link count changed | ||
| 305 | pub const NOTE_LINK = 0x00000010; | ||
| 306 | |||
| 307 | /// vnode was renamed | ||
| 308 | pub const NOTE_RENAME = 0x00000020; | ||
| 309 | |||
| 310 | /// vnode access was revoked | ||
| 311 | pub const NOTE_REVOKE = 0x00000040; | ||
| 312 | |||
| 313 | /// process exited | ||
| 314 | pub const NOTE_EXIT = 0x80000000; | ||
| 315 | |||
| 316 | /// process forked | ||
| 317 | pub const NOTE_FORK = 0x40000000; | ||
| 318 | |||
| 319 | /// process exec'd | ||
| 320 | pub const NOTE_EXEC = 0x20000000; | ||
| 321 | |||
| 322 | /// mask for signal & exit status | ||
| 323 | pub const NOTE_PDATAMASK = 0x000fffff; | ||
| 324 | pub const NOTE_PCTRLMASK = 0xf0000000; | ||
| 325 | |||
| 326 | pub const TIOCCBRK = 0x2000747a; | ||
| 327 | pub const TIOCCDTR = 0x20007478; | ||
| 328 | pub const TIOCCONS = 0x80047462; | ||
| 329 | pub const TIOCDCDTIMESTAMP = 0x40107458; | ||
| 330 | pub const TIOCDRAIN = 0x2000745e; | ||
| 331 | pub const TIOCEXCL = 0x2000740d; | ||
| 332 | pub const TIOCEXT = 0x80047460; | ||
| 333 | pub const TIOCFLAG_CDTRCTS = 0x10; | ||
| 334 | pub const TIOCFLAG_CLOCAL = 0x2; | ||
| 335 | pub const TIOCFLAG_CRTSCTS = 0x4; | ||
| 336 | pub const TIOCFLAG_MDMBUF = 0x8; | ||
| 337 | pub const TIOCFLAG_SOFTCAR = 0x1; | ||
| 338 | pub const TIOCFLUSH = 0x80047410; | ||
| 339 | pub const TIOCGETA = 0x402c7413; | ||
| 340 | pub const TIOCGETD = 0x4004741a; | ||
| 341 | pub const TIOCGFLAGS = 0x4004745d; | ||
| 342 | pub const TIOCGLINED = 0x40207442; | ||
| 343 | pub const TIOCGPGRP = 0x40047477; | ||
| 344 | pub const TIOCGQSIZE = 0x40047481; | ||
| 345 | pub const TIOCGRANTPT = 0x20007447; | ||
| 346 | pub const TIOCGSID = 0x40047463; | ||
| 347 | pub const TIOCGSIZE = 0x40087468; | ||
| 348 | pub const TIOCGWINSZ = 0x40087468; | ||
| 349 | pub const TIOCMBIC = 0x8004746b; | ||
| 350 | pub const TIOCMBIS = 0x8004746c; | ||
| 351 | pub const TIOCMGET = 0x4004746a; | ||
| 352 | pub const TIOCMSET = 0x8004746d; | ||
| 353 | pub const TIOCM_CAR = 0x40; | ||
| 354 | pub const TIOCM_CD = 0x40; | ||
| 355 | pub const TIOCM_CTS = 0x20; | ||
| 356 | pub const TIOCM_DSR = 0x100; | ||
| 357 | pub const TIOCM_DTR = 0x2; | ||
| 358 | pub const TIOCM_LE = 0x1; | ||
| 359 | pub const TIOCM_RI = 0x80; | ||
| 360 | pub const TIOCM_RNG = 0x80; | ||
| 361 | pub const TIOCM_RTS = 0x4; | ||
| 362 | pub const TIOCM_SR = 0x10; | ||
| 363 | pub const TIOCM_ST = 0x8; | ||
| 364 | pub const TIOCNOTTY = 0x20007471; | ||
| 365 | pub const TIOCNXCL = 0x2000740e; | ||
| 366 | pub const TIOCOUTQ = 0x40047473; | ||
| 367 | pub const TIOCPKT = 0x80047470; | ||
| 368 | pub const TIOCPKT_DATA = 0x0; | ||
| 369 | pub const TIOCPKT_DOSTOP = 0x20; | ||
| 370 | pub const TIOCPKT_FLUSHREAD = 0x1; | ||
| 371 | pub const TIOCPKT_FLUSHWRITE = 0x2; | ||
| 372 | pub const TIOCPKT_IOCTL = 0x40; | ||
| 373 | pub const TIOCPKT_NOSTOP = 0x10; | ||
| 374 | pub const TIOCPKT_START = 0x8; | ||
| 375 | pub const TIOCPKT_STOP = 0x4; | ||
| 376 | pub const TIOCPTMGET = 0x40287446; | ||
| 377 | pub const TIOCPTSNAME = 0x40287448; | ||
| 378 | pub const TIOCRCVFRAME = 0x80087445; | ||
| 379 | pub const TIOCREMOTE = 0x80047469; | ||
| 380 | pub const TIOCSBRK = 0x2000747b; | ||
| 381 | pub const TIOCSCTTY = 0x20007461; | ||
| 382 | pub const TIOCSDTR = 0x20007479; | ||
| 383 | pub const TIOCSETA = 0x802c7414; | ||
| 384 | pub const TIOCSETAF = 0x802c7416; | ||
| 385 | pub const TIOCSETAW = 0x802c7415; | ||
| 386 | pub const TIOCSETD = 0x8004741b; | ||
| 387 | pub const TIOCSFLAGS = 0x8004745c; | ||
| 388 | pub const TIOCSIG = 0x2000745f; | ||
| 389 | pub const TIOCSLINED = 0x80207443; | ||
| 390 | pub const TIOCSPGRP = 0x80047476; | ||
| 391 | pub const TIOCSQSIZE = 0x80047480; | ||
| 392 | pub const TIOCSSIZE = 0x80087467; | ||
| 393 | pub const TIOCSTART = 0x2000746e; | ||
| 394 | pub const TIOCSTAT = 0x80047465; | ||
| 395 | pub const TIOCSTI = 0x80017472; | ||
| 396 | pub const TIOCSTOP = 0x2000746f; | ||
| 397 | pub const TIOCSWINSZ = 0x80087467; | ||
| 398 | pub const TIOCUCNTL = 0x80047466; | ||
| 399 | pub const TIOCXMTFRAME = 0x80087444; | ||
| 400 | |||
| 401 | pub const sockaddr = c.sockaddr; | ||
| 402 | pub const sockaddr_in = c.sockaddr_in; | ||
| 403 | pub const sockaddr_in6 = c.sockaddr_in6; | ||
| 404 | |||
| 405 | fn unsigned(s: i32) u32 { | ||
| 406 | return @bitCast(u32, s); | ||
| 407 | } | ||
| 408 | fn signed(s: u32) i32 { | ||
| 409 | return @bitCast(i32, s); | ||
| 410 | } | ||
| 411 | pub fn WEXITSTATUS(s: i32) i32 { | ||
| 412 | return signed((unsigned(s) >> 8) & 0xff); | ||
| 413 | } | ||
| 414 | pub fn WTERMSIG(s: i32) i32 { | ||
| 415 | return signed(unsigned(s) & 0x7f); | ||
| 416 | } | ||
| 417 | pub fn WSTOPSIG(s: i32) i32 { | ||
| 418 | return WEXITSTATUS(s); | ||
| 419 | } | ||
| 420 | pub fn WIFEXITED(s: i32) bool { | ||
| 421 | return WTERMSIG(s) == 0; | ||
| 422 | } | ||
| 423 | |||
| 424 | pub fn WIFCONTINUED(s: i32) bool { | ||
| 425 | return ((s & 0x7f) == 0xffff); | ||
| 426 | } | ||
| 427 | |||
| 428 | pub fn WIFSTOPPED(s: i32) bool { | ||
| 429 | return ((s & 0x7f != 0x7f) and !WIFCONTINUED(s)); | ||
| 430 | } | ||
| 431 | |||
| 432 | pub fn WIFSIGNALED(s: i32) bool { | ||
| 433 | return !WIFSTOPPED(s) and !WIFCONTINUED(s) and !WIFEXITED(s); | ||
| 434 | } | ||
| 435 | |||
| 436 | pub const winsize = extern struct { | ||
| 437 | ws_row: u16, | ||
| 438 | ws_col: u16, | ||
| 439 | ws_xpixel: u16, | ||
| 440 | ws_ypixel: u16, | ||
| 441 | }; | ||
| 442 | |||
| 443 | /// Get the errno from a syscall return value, or 0 for no error. | ||
| 444 | pub fn getErrno(r: usize) usize { | ||
| 445 | const signed_r = @bitCast(isize, r); | ||
| 446 | return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0; | ||
| 447 | } | ||
| 448 | |||
| 449 | pub fn dup2(old: i32, new: i32) usize { | ||
| 450 | return errnoWrap(c.dup2(old, new)); | ||
| 451 | } | ||
| 452 | |||
| 453 | pub fn chdir(path: [*]const u8) usize { | ||
| 454 | return errnoWrap(c.chdir(path)); | ||
| 455 | } | ||
| 456 | |||
| 457 | pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize { | ||
| 458 | return errnoWrap(c.execve(path, argv, envp)); | ||
| 459 | } | ||
| 460 | |||
| 461 | pub fn fork() usize { | ||
| 462 | return errnoWrap(c.fork()); | ||
| 463 | } | ||
| 464 | |||
| 465 | pub fn access(path: [*]const u8, mode: u32) usize { | ||
| 466 | return errnoWrap(c.access(path, mode)); | ||
| 467 | } | ||
| 468 | |||
| 469 | pub fn getcwd(buf: [*]u8, size: usize) usize { | ||
| 470 | return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0; | ||
| 471 | } | ||
| 472 | |||
| 473 | pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { | ||
| 474 | return errnoWrap(@bitCast(isize, c.getdents(fd, drip, count))); | ||
| 475 | } | ||
| 476 | |||
| 477 | pub fn getdirentries(fd: i32, buf_ptr: [*]u8, buf_len: usize, basep: *i64) usize { | ||
| 478 | return errnoWrap(@bitCast(isize, c.getdirentries(fd, buf_ptr, buf_len, basep))); | ||
| 479 | } | ||
| 480 | |||
| 481 | pub fn realpath(noalias filename: [*]const u8, noalias resolved_name: [*]u8) usize { | ||
| 482 | return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(c._errno().*)) else 0; | ||
| 483 | } | ||
| 484 | |||
| 485 | pub fn isatty(fd: i32) bool { | ||
| 486 | return c.isatty(fd) != 0; | ||
| 487 | } | ||
| 488 | |||
| 489 | pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { | ||
| 490 | return errnoWrap(c.readlink(path, buf_ptr, buf_len)); | ||
| 491 | } | ||
| 492 | |||
| 493 | pub fn mkdir(path: [*]const u8, mode: u32) usize { | ||
| 494 | return errnoWrap(c.mkdir(path, mode)); | ||
| 495 | } | ||
| 496 | |||
| 497 | pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize { | ||
| 498 | const ptr_result = c.mmap( | ||
| 499 | @ptrCast(?*c_void, address), | ||
| 500 | length, | ||
| 501 | @bitCast(c_int, @intCast(c_uint, prot)), | ||
| 502 | @bitCast(c_int, c_uint(flags)), | ||
| 503 | fd, | ||
| 504 | offset, | ||
| 505 | ); | ||
| 506 | const isize_result = @bitCast(isize, @ptrToInt(ptr_result)); | ||
| 507 | return errnoWrap(isize_result); | ||
| 508 | } | ||
| 509 | |||
| 510 | pub fn munmap(address: usize, length: usize) usize { | ||
| 511 | return errnoWrap(c.munmap(@intToPtr(*c_void, address), length)); | ||
| 512 | } | ||
| 513 | |||
| 514 | pub fn read(fd: i32, buf: [*]u8, nbyte: usize) usize { | ||
| 515 | return errnoWrap(c.read(fd, @ptrCast(*c_void, buf), nbyte)); | ||
| 516 | } | ||
| 517 | |||
| 518 | pub fn rmdir(path: [*]const u8) usize { | ||
| 519 | return errnoWrap(c.rmdir(path)); | ||
| 520 | } | ||
| 521 | |||
| 522 | pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { | ||
| 523 | return errnoWrap(c.symlink(existing, new)); | ||
| 524 | } | ||
| 525 | |||
| 526 | pub fn pread(fd: i32, buf: [*]u8, nbyte: usize, offset: u64) usize { | ||
| 527 | return errnoWrap(c.pread(fd, @ptrCast(*c_void, buf), nbyte, offset)); | ||
| 528 | } | ||
| 529 | |||
| 530 | pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: usize) usize { | ||
| 531 | return errnoWrap(c.preadv(fd, @ptrCast(*const c_void, iov), @intCast(c_int, count), offset)); | ||
| 532 | } | ||
| 533 | |||
| 534 | pub fn pipe(fd: *[2]i32) usize { | ||
| 535 | return pipe2(fd, 0); | ||
| 536 | } | ||
| 537 | |||
| 538 | pub fn pipe2(fd: *[2]i32, flags: u32) usize { | ||
| 539 | comptime assert(i32.bit_count == c_int.bit_count); | ||
| 540 | return errnoWrap(c.pipe2(@ptrCast(*[2]c_int, fd), flags)); | ||
| 541 | } | ||
| 542 | |||
| 543 | pub fn write(fd: i32, buf: [*]const u8, nbyte: usize) usize { | ||
| 544 | return errnoWrap(c.write(fd, @ptrCast(*const c_void, buf), nbyte)); | ||
| 545 | } | ||
| 546 | |||
| 547 | pub fn pwrite(fd: i32, buf: [*]const u8, nbyte: usize, offset: u64) usize { | ||
| 548 | return errnoWrap(c.pwrite(fd, @ptrCast(*const c_void, buf), nbyte, offset)); | ||
| 549 | } | ||
| 550 | |||
| 551 | pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: usize) usize { | ||
| 552 | return errnoWrap(c.pwritev(fd, @ptrCast(*const c_void, iov), @intCast(c_int, count), offset)); | ||
| 553 | } | ||
| 554 | |||
| 555 | pub fn rename(old: [*]const u8, new: [*]const u8) usize { | ||
| 556 | return errnoWrap(c.rename(old, new)); | ||
| 557 | } | ||
| 558 | |||
| 559 | pub fn open(path: [*]const u8, flags: u32, mode: usize) usize { | ||
| 560 | return errnoWrap(c.open(path, @bitCast(c_int, flags), mode)); | ||
| 561 | } | ||
| 562 | |||
| 563 | pub fn create(path: [*]const u8, perm: usize) usize { | ||
| 564 | return arch.syscall2(SYS_creat, @ptrToInt(path), perm); | ||
| 565 | } | ||
| 566 | |||
| 567 | pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize { | ||
| 568 | return errnoWrap(c.openat(@bitCast(usize, isize(dirfd)), @ptrToInt(path), flags, mode)); | ||
| 569 | } | ||
| 570 | |||
| 571 | pub fn close(fd: i32) usize { | ||
| 572 | return errnoWrap(c.close(fd)); | ||
| 573 | } | ||
| 574 | |||
| 575 | pub fn lseek(fd: i32, offset: isize, whence: c_int) usize { | ||
| 576 | return errnoWrap(c.lseek(fd, offset, whence)); | ||
| 577 | } | ||
| 578 | |||
| 579 | pub fn exit(code: i32) noreturn { | ||
| 580 | c.exit(code); | ||
| 581 | } | ||
| 582 | |||
| 583 | pub fn kill(pid: i32, sig: i32) usize { | ||
| 584 | return errnoWrap(c.kill(pid, sig)); | ||
| 585 | } | ||
| 586 | |||
| 587 | pub fn unlink(path: [*]const u8) usize { | ||
| 588 | return errnoWrap(c.unlink(path)); | ||
| 589 | } | ||
| 590 | |||
| 591 | pub fn waitpid(pid: i32, status: *i32, options: u32) usize { | ||
| 592 | comptime assert(i32.bit_count == c_int.bit_count); | ||
| 593 | return errnoWrap(c.waitpid(pid, @ptrCast(*c_int, status), @bitCast(c_int, options))); | ||
| 594 | } | ||
| 595 | |||
| 596 | pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize { | ||
| 597 | return errnoWrap(c.nanosleep(req, rem)); | ||
| 598 | } | ||
| 599 | |||
| 600 | pub fn clock_gettime(clk_id: i32, tp: *timespec) usize { | ||
| 601 | return errnoWrap(c.clock_gettime(clk_id, tp)); | ||
| 602 | } | ||
| 603 | |||
| 604 | pub fn clock_getres(clk_id: i32, tp: *timespec) usize { | ||
| 605 | return errnoWrap(c.clock_getres(clk_id, tp)); | ||
| 606 | } | ||
| 607 | |||
| 608 | pub fn setuid(uid: u32) usize { | ||
| 609 | return errnoWrap(c.setuid(uid)); | ||
| 610 | } | ||
| 611 | |||
| 612 | pub fn setgid(gid: u32) usize { | ||
| 613 | return errnoWrap(c.setgid(gid)); | ||
| 614 | } | ||
| 615 | |||
| 616 | pub fn setreuid(ruid: u32, euid: u32) usize { | ||
| 617 | return errnoWrap(c.setreuid(ruid, euid)); | ||
| 618 | } | ||
| 619 | |||
| 620 | pub fn setregid(rgid: u32, egid: u32) usize { | ||
| 621 | return errnoWrap(c.setregid(rgid, egid)); | ||
| 622 | } | ||
| 623 | |||
| 624 | const NSIG = 32; | ||
| 625 | |||
| 626 | pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize)); | ||
| 627 | pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); | ||
| 628 | pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); | ||
| 629 | |||
| 630 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | ||
| 631 | pub const Sigaction = extern struct { | ||
| 632 | /// signal handler | ||
| 633 | __sigaction_u: extern union { | ||
| 634 | __sa_handler: extern fn (i32) void, | ||
| 635 | __sa_sigaction: extern fn (i32, *__siginfo, usize) void, | ||
| 636 | }, | ||
| 637 | |||
| 638 | /// see signal options | ||
| 639 | sa_flags: u32, | ||
| 640 | |||
| 641 | /// signal mask to apply | ||
| 642 | sa_mask: sigset_t, | ||
| 643 | }; | ||
| 644 | |||
| 645 | pub const _SIG_WORDS = 4; | ||
| 646 | pub const _SIG_MAXSIG = 128; | ||
| 647 | |||
| 648 | pub inline fn _SIG_IDX(sig: usize) usize { | ||
| 649 | return sig - 1; | ||
| 650 | } | ||
| 651 | pub inline fn _SIG_WORD(sig: usize) usize { | ||
| 652 | return_SIG_IDX(sig) >> 5; | ||
| 653 | } | ||
| 654 | pub inline fn _SIG_BIT(sig: usize) usize { | ||
| 655 | return 1 << (_SIG_IDX(sig) & 31); | ||
| 656 | } | ||
| 657 | pub inline fn _SIG_VALID(sig: usize) usize { | ||
| 658 | return sig <= _SIG_MAXSIG and sig > 0; | ||
| 659 | } | ||
| 660 | |||
| 661 | pub const sigset_t = extern struct { | ||
| 662 | __bits: [_SIG_WORDS]u32, | ||
| 663 | }; | ||
| 664 | |||
| 665 | pub fn raise(sig: i32) usize { | ||
| 666 | return errnoWrap(c.raise(sig)); | ||
| 667 | } | ||
| 668 | |||
| 669 | pub const Stat = c.Stat; | ||
| 670 | pub const dirent = c.dirent; | ||
| 671 | pub const timespec = c.timespec; | ||
| 672 | |||
| 673 | pub fn fstat(fd: i32, buf: *c.Stat) usize { | ||
| 674 | return errnoWrap(c.fstat(fd, buf)); | ||
| 675 | } | ||
| 676 | pub const iovec = extern struct { | ||
| 677 | iov_base: [*]u8, | ||
| 678 | iov_len: usize, | ||
| 679 | }; | ||
| 680 | |||
| 681 | pub const iovec_const = extern struct { | ||
| 682 | iov_base: [*]const u8, | ||
| 683 | iov_len: usize, | ||
| 684 | }; | ||
| 685 | |||
| 686 | // TODO avoid libc dependency | ||
| 687 | pub fn kqueue() usize { | ||
| 688 | return errnoWrap(c.kqueue()); | ||
| 689 | } | ||
| 690 | |||
| 691 | // TODO avoid libc dependency | ||
| 692 | pub fn kevent(kq: i32, changelist: []const Kevent, eventlist: []Kevent, timeout: ?*const timespec) usize { | ||
| 693 | return errnoWrap(c.kevent( | ||
| 694 | kq, | ||
| 695 | changelist.ptr, | ||
| 696 | @intCast(c_int, changelist.len), | ||
| 697 | eventlist.ptr, | ||
| 698 | @intCast(c_int, eventlist.len), | ||
| 699 | timeout, | ||
| 700 | )); | ||
| 701 | } | ||
| 702 | |||
| 703 | // TODO avoid libc dependency | ||
| 704 | pub fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize { | ||
| 705 | return errnoWrap(c.sysctl(name, namelen, oldp, oldlenp, newp, newlen)); | ||
| 706 | } | ||
| 707 | |||
| 708 | // TODO avoid libc dependency | ||
| 709 | pub fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize { | ||
| 710 | return errnoWrap(c.sysctlbyname(name, oldp, oldlenp, newp, newlen)); | ||
| 711 | } | ||
| 712 | |||
| 713 | // TODO avoid libc dependency | ||
| 714 | pub fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) usize { | ||
| 715 | return errnoWrap(c.sysctlnametomib(name, wibp, sizep)); | ||
| 716 | } | ||
| 717 | |||
| 718 | // TODO avoid libc dependency | ||
| 719 | |||
| 720 | /// Takes the return value from a syscall and formats it back in the way | ||
| 721 | /// that the kernel represents it to libc. Errno was a mistake, let's make | ||
| 722 | /// it go away forever. | ||
| 723 | fn errnoWrap(value: isize) usize { | ||
| 724 | return @bitCast(usize, if (value == -1) -isize(c._errno().*) else value); | ||
| 725 | } | ||
std/os/path.zig+2-2| ... | @@ -1226,7 +1226,7 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro | ... | @@ -1226,7 +1226,7 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro |
| 1226 | const pathname_w = try windows_util.cStrToPrefixedFileW(pathname); | 1226 | const pathname_w = try windows_util.cStrToPrefixedFileW(pathname); |
| 1227 | return realW(out_buffer, pathname_w); | 1227 | return realW(out_buffer, pathname_w); |
| 1228 | }, | 1228 | }, |
| 1229 | Os.freebsd, Os.macosx, Os.ios => { | 1229 | Os.freebsd, Os.netbsd, Os.macosx, Os.ios => { |
| 1230 | // TODO instead of calling the libc function here, port the implementation to Zig | 1230 | // TODO instead of calling the libc function here, port the implementation to Zig |
| 1231 | const err = posix.getErrno(posix.realpath(pathname, out_buffer)); | 1231 | const err = posix.getErrno(posix.realpath(pathname, out_buffer)); |
| 1232 | switch (err) { | 1232 | switch (err) { |
| ... | @@ -1267,7 +1267,7 @@ pub fn real(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: []const u8) RealError! | ... | @@ -1267,7 +1267,7 @@ pub fn real(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: []const u8) RealError! |
| 1267 | const pathname_w = try windows_util.sliceToPrefixedFileW(pathname); | 1267 | const pathname_w = try windows_util.sliceToPrefixedFileW(pathname); |
| 1268 | return realW(out_buffer, &pathname_w); | 1268 | return realW(out_buffer, &pathname_w); |
| 1269 | }, | 1269 | }, |
| 1270 | Os.macosx, Os.ios, Os.linux, Os.freebsd => { | 1270 | Os.macosx, Os.ios, Os.linux, Os.freebsd, Os.netbsd => { |
| 1271 | const pathname_c = try os.toPosixPath(pathname); | 1271 | const pathname_c = try os.toPosixPath(pathname); |
| 1272 | return realC(out_buffer, &pathname_c); | 1272 | return realC(out_buffer, &pathname_c); |
| 1273 | }, | 1273 | }, |
std/os/time.zig+5-5| ... | @@ -14,7 +14,7 @@ pub const epoch = @import("epoch.zig"); | ... | @@ -14,7 +14,7 @@ pub const epoch = @import("epoch.zig"); |
| 14 | /// Sleep for the specified duration | 14 | /// Sleep for the specified duration |
| 15 | pub fn sleep(nanoseconds: u64) void { | 15 | pub fn sleep(nanoseconds: u64) void { |
| 16 | switch (builtin.os) { | 16 | switch (builtin.os) { |
| 17 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { | 17 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { |
| 18 | const s = nanoseconds / ns_per_s; | 18 | const s = nanoseconds / ns_per_s; |
| 19 | const ns = nanoseconds % ns_per_s; | 19 | const ns = nanoseconds % ns_per_s; |
| 20 | posixSleep(@intCast(u63, s), @intCast(u63, ns)); | 20 | posixSleep(@intCast(u63, s), @intCast(u63, ns)); |
| ... | @@ -62,7 +62,7 @@ pub fn timestamp() u64 { | ... | @@ -62,7 +62,7 @@ pub fn timestamp() u64 { |
| 62 | /// Get the posix timestamp, UTC, in milliseconds | 62 | /// Get the posix timestamp, UTC, in milliseconds |
| 63 | pub const milliTimestamp = switch (builtin.os) { | 63 | pub const milliTimestamp = switch (builtin.os) { |
| 64 | Os.windows => milliTimestampWindows, | 64 | Os.windows => milliTimestampWindows, |
| 65 | Os.linux, Os.freebsd => milliTimestampPosix, | 65 | Os.linux, Os.freebsd, Os.netbsd => milliTimestampPosix, |
| 66 | Os.macosx, Os.ios => milliTimestampDarwin, | 66 | Os.macosx, Os.ios => milliTimestampDarwin, |
| 67 | else => @compileError("Unsupported OS"), | 67 | else => @compileError("Unsupported OS"), |
| 68 | }; | 68 | }; |
| ... | @@ -178,7 +178,7 @@ pub const Timer = struct { | ... | @@ -178,7 +178,7 @@ pub const Timer = struct { |
| 178 | debug.assert(err != windows.FALSE); | 178 | debug.assert(err != windows.FALSE); |
| 179 | self.start_time = @intCast(u64, start_time); | 179 | self.start_time = @intCast(u64, start_time); |
| 180 | }, | 180 | }, |
| 181 | Os.linux, Os.freebsd => { | 181 | Os.linux, Os.freebsd, Os.netbsd => { |
| 182 | //On Linux, seccomp can do arbitrary things to our ability to call | 182 | //On Linux, seccomp can do arbitrary things to our ability to call |
| 183 | // syscalls, including return any errno value it wants and | 183 | // syscalls, including return any errno value it wants and |
| 184 | // inconsistently throwing errors. Since we can't account for | 184 | // inconsistently throwing errors. Since we can't account for |
| ... | @@ -214,7 +214,7 @@ pub const Timer = struct { | ... | @@ -214,7 +214,7 @@ pub const Timer = struct { |
| 214 | var clock = clockNative() - self.start_time; | 214 | var clock = clockNative() - self.start_time; |
| 215 | return switch (builtin.os) { | 215 | return switch (builtin.os) { |
| 216 | Os.windows => @divFloor(clock * ns_per_s, self.frequency), | 216 | Os.windows => @divFloor(clock * ns_per_s, self.frequency), |
| 217 | Os.linux, Os.freebsd => clock, | 217 | Os.linux, Os.freebsd, Os.netbsd => clock, |
| 218 | Os.macosx, Os.ios => @divFloor(clock * self.frequency.numer, self.frequency.denom), | 218 | Os.macosx, Os.ios => @divFloor(clock * self.frequency.numer, self.frequency.denom), |
| 219 | else => @compileError("Unsupported OS"), | 219 | else => @compileError("Unsupported OS"), |
| 220 | }; | 220 | }; |
| ... | @@ -235,7 +235,7 @@ pub const Timer = struct { | ... | @@ -235,7 +235,7 @@ pub const Timer = struct { |
| 235 | 235 | ||
| 236 | const clockNative = switch (builtin.os) { | 236 | const clockNative = switch (builtin.os) { |
| 237 | Os.windows => clockWindows, | 237 | Os.windows => clockWindows, |
| 238 | Os.linux, Os.freebsd => clockLinux, | 238 | Os.linux, Os.freebsd, Os.netbsd => clockLinux, |
| 239 | Os.macosx, Os.ios => clockDarwin, | 239 | Os.macosx, Os.ios => clockDarwin, |
| 240 | else => @compileError("Unsupported OS"), | 240 | else => @compileError("Unsupported OS"), |
| 241 | }; | 241 | }; |