| author | |
| committer | |
| log | daae7e1f5aa5aac02a342c9a60d703c2a0cba579 |
| tree | f3b2bca3e6b0d1088aa2d570bb029d076c5f3abe |
| parent | 67726e36b02d26343398ed8ede460622d706c539 |
| signature |
see #238036 files changed, 5430 insertions(+), 5948 deletions(-)
CMakeLists.txt+9| ... | @@ -474,6 +474,10 @@ set(ZIG_STD_FILES | ... | @@ -474,6 +474,10 @@ set(ZIG_STD_FILES |
| 474 | "c/linux.zig" | 474 | "c/linux.zig" |
| 475 | "c/netbsd.zig" | 475 | "c/netbsd.zig" |
| 476 | "c/windows.zig" | 476 | "c/windows.zig" |
| 477 | "c/posix.zig" | ||
| 478 | "c/posix/darwin.zig" | ||
| 479 | "c/posix/freebsd.zig" | ||
| 480 | "c/posix/windows.zig" | ||
| 477 | "coff.zig" | 481 | "coff.zig" |
| 478 | "crypto.zig" | 482 | "crypto.zig" |
| 479 | "crypto/blake2.zig" | 483 | "crypto/blake2.zig" |
| ... | @@ -612,15 +616,20 @@ set(ZIG_STD_FILES | ... | @@ -612,15 +616,20 @@ set(ZIG_STD_FILES |
| 612 | "os/linux.zig" | 616 | "os/linux.zig" |
| 613 | "os/linux/arm64.zig" | 617 | "os/linux/arm64.zig" |
| 614 | "os/linux/errno.zig" | 618 | "os/linux/errno.zig" |
| 619 | "os/linux/posix.zig" | ||
| 620 | "os/linux/posix/arm64.zig" | ||
| 621 | "os/linux/posix/x86_64.zig" | ||
| 615 | "os/linux/tls.zig" | 622 | "os/linux/tls.zig" |
| 616 | "os/linux/vdso.zig" | 623 | "os/linux/vdso.zig" |
| 617 | "os/linux/x86_64.zig" | 624 | "os/linux/x86_64.zig" |
| 618 | "os/netbsd.zig" | 625 | "os/netbsd.zig" |
| 619 | "os/netbsd/errno.zig" | 626 | "os/netbsd/errno.zig" |
| 620 | "os/path.zig" | 627 | "os/path.zig" |
| 628 | "os/posix.zig" | ||
| 621 | "os/time.zig" | 629 | "os/time.zig" |
| 622 | "os/uefi.zig" | 630 | "os/uefi.zig" |
| 623 | "os/wasi.zig" | 631 | "os/wasi.zig" |
| 632 | "os/wasi/posix.zig" | ||
| 624 | "os/windows.zig" | 633 | "os/windows.zig" |
| 625 | "os/windows/advapi32.zig" | 634 | "os/windows/advapi32.zig" |
| 626 | "os/windows/errno.zig" | 635 | "os/windows/errno.zig" |
doc/langref.html.in+1| ... | @@ -9923,6 +9923,7 @@ keyword <- KEYWORD_align / KEYWORD_and / KEYWORD_allowzero / KEYWORD_anyerror | ... | @@ -9923,6 +9923,7 @@ keyword <- KEYWORD_align / KEYWORD_and / KEYWORD_allowzero / KEYWORD_anyerror |
| 9923 | <li>Avoid local maximums.</li> | 9923 | <li>Avoid local maximums.</li> |
| 9924 | <li>Reduce the amount one must remember.</li> | 9924 | <li>Reduce the amount one must remember.</li> |
| 9925 | <li>Minimize energy spent on coding style.</li> | 9925 | <li>Minimize energy spent on coding style.</li> |
| 9926 | <li>Resource deallocation must succeed.</li> | ||
| 9926 | <li>Together we serve end users.</li> | 9927 | <li>Together we serve end users.</li> |
| 9927 | </ul> | 9928 | </ul> |
| 9928 | {#header_close#} | 9929 | {#header_close#} |
std/c.zig+47-23| ... | @@ -1,9 +1,10 @@ | ... | @@ -1,9 +1,10 @@ |
| 1 | const builtin = @import("builtin"); | 1 | const builtin = @import("builtin"); |
| 2 | 2 | ||
| 3 | pub const is_the_target = builtin.link_libc; | 3 | pub const posix = @import("c/posix.zig"); |
| 4 | pub use posix; | ||
| 4 | 5 | ||
| 5 | pub use switch (builtin.os) { | 6 | pub use switch (builtin.os) { |
| 6 | .linux => @import("c/linux.zig"), | 7 | .linux => @import("os/linux/posix.zig"), |
| 7 | .windows => @import("c/windows.zig"), | 8 | .windows => @import("c/windows.zig"), |
| 8 | .macosx, .ios, .tvos, .watchos => @import("c/darwin.zig"), | 9 | .macosx, .ios, .tvos, .watchos => @import("c/darwin.zig"), |
| 9 | .freebsd => @import("c/freebsd.zig"), | 10 | .freebsd => @import("c/freebsd.zig"), |
| ... | @@ -21,7 +22,6 @@ pub fn getErrno(rc: var) u12 { | ... | @@ -21,7 +22,6 @@ pub fn getErrno(rc: var) u12 { |
| 21 | 22 | ||
| 22 | // TODO https://github.com/ziglang/zig/issues/265 on this whole file | 23 | // TODO https://github.com/ziglang/zig/issues/265 on this whole file |
| 23 | 24 | ||
| 24 | pub const FILE = @OpaqueType(); | ||
| 25 | pub extern "c" fn fopen(filename: [*]const u8, modes: [*]const u8) ?*FILE; | 25 | pub extern "c" fn fopen(filename: [*]const u8, modes: [*]const u8) ?*FILE; |
| 26 | pub extern "c" fn fclose(stream: *FILE) c_int; | 26 | pub extern "c" fn fclose(stream: *FILE) c_int; |
| 27 | pub extern "c" fn fwrite(ptr: [*]const u8, size_of_type: usize, item_count: usize, stream: *FILE) usize; | 27 | pub extern "c" fn fwrite(ptr: [*]const u8, size_of_type: usize, item_count: usize, stream: *FILE) usize; |
| ... | @@ -29,33 +29,36 @@ pub extern "c" fn fread(ptr: [*]u8, size_of_type: usize, item_count: usize, stre | ... | @@ -29,33 +29,36 @@ pub extern "c" fn fread(ptr: [*]u8, size_of_type: usize, item_count: usize, stre |
| 29 | 29 | ||
| 30 | pub extern "c" fn abort() noreturn; | 30 | pub extern "c" fn abort() noreturn; |
| 31 | pub extern "c" fn exit(code: c_int) noreturn; | 31 | pub extern "c" fn exit(code: c_int) noreturn; |
| 32 | pub extern "c" fn isatty(fd: c_int) c_int; | 32 | pub extern "c" fn isatty(fd: fd_t) c_int; |
| 33 | pub extern "c" fn close(fd: c_int) c_int; | 33 | pub extern "c" fn close(fd: fd_t) c_int; |
| 34 | pub extern "c" fn fstat(fd: c_int, buf: *Stat) c_int; | 34 | pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int; |
| 35 | pub extern "c" fn @"fstat$INODE64"(fd: c_int, buf: *Stat) c_int; | 35 | pub extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int; |
| 36 | pub extern "c" fn lseek(fd: c_int, offset: isize, whence: c_int) isize; | 36 | pub extern "c" fn lseek(fd: fd_t, offset: isize, whence: c_int) isize; |
| 37 | pub extern "c" fn open(path: [*]const u8, oflag: c_int, ...) c_int; | 37 | pub extern "c" fn open(path: [*]const u8, oflag: c_int, ...) c_int; |
| 38 | pub extern "c" fn raise(sig: c_int) c_int; | 38 | pub extern "c" fn raise(sig: c_int) c_int; |
| 39 | pub extern "c" fn read(fd: c_int, buf: *c_void, nbyte: usize) isize; | 39 | pub extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize; |
| 40 | pub extern "c" fn pread(fd: c_int, buf: *c_void, nbyte: usize, offset: u64) isize; | 40 | pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: u64) isize; |
| 41 | pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_int, offset: usize) isize; | ||
| 42 | pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec, iovcnt: c_int, offset: usize) isize; | ||
| 41 | pub extern "c" fn stat(noalias path: [*]const u8, noalias buf: *Stat) c_int; | 43 | pub extern "c" fn stat(noalias path: [*]const u8, noalias buf: *Stat) c_int; |
| 42 | pub extern "c" fn write(fd: c_int, buf: *const c_void, nbyte: usize) isize; | 44 | pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize; |
| 43 | pub extern "c" fn pwrite(fd: c_int, buf: *const c_void, nbyte: usize, offset: u64) isize; | 45 | pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: u64) isize; |
| 44 | pub extern "c" fn mmap(addr: ?*c_void, len: usize, prot: c_int, flags: c_int, fd: c_int, offset: isize) ?*c_void; | 46 | pub extern "c" fn mmap(addr: ?*c_void, len: usize, prot: c_int, flags: c_int, fd: fd_t, offset: isize) usize; |
| 45 | pub extern "c" fn munmap(addr: ?*c_void, len: usize) c_int; | 47 | pub extern "c" fn munmap(addr: ?*c_void, len: usize) c_int; |
| 46 | pub extern "c" fn unlink(path: [*]const u8) c_int; | 48 | pub extern "c" fn unlink(path: [*]const u8) c_int; |
| 47 | pub extern "c" fn getcwd(buf: [*]u8, size: usize) ?[*]u8; | 49 | pub extern "c" fn getcwd(buf: [*]u8, size: usize) ?[*]u8; |
| 48 | pub extern "c" fn waitpid(pid: c_int, stat_loc: *c_int, options: c_int) c_int; | 50 | pub extern "c" fn waitpid(pid: c_int, stat_loc: *c_int, options: c_int) c_int; |
| 49 | pub extern "c" fn fork() c_int; | 51 | pub extern "c" fn fork() c_int; |
| 50 | pub extern "c" fn access(path: [*]const u8, mode: c_uint) c_int; | 52 | pub extern "c" fn access(path: [*]const u8, mode: c_uint) c_int; |
| 51 | pub extern "c" fn pipe(fds: *[2]c_int) c_int; | 53 | pub extern "c" fn pipe(fds: *[2]fd_t) c_int; |
| 54 | pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int; | ||
| 52 | pub extern "c" fn mkdir(path: [*]const u8, mode: c_uint) c_int; | 55 | pub extern "c" fn mkdir(path: [*]const u8, mode: c_uint) c_int; |
| 53 | pub extern "c" fn symlink(existing: [*]const u8, new: [*]const u8) c_int; | 56 | pub extern "c" fn symlink(existing: [*]const u8, new: [*]const u8) c_int; |
| 54 | pub extern "c" fn rename(old: [*]const u8, new: [*]const u8) c_int; | 57 | pub extern "c" fn rename(old: [*]const u8, new: [*]const u8) c_int; |
| 55 | pub extern "c" fn chdir(path: [*]const u8) c_int; | 58 | pub extern "c" fn chdir(path: [*]const u8) c_int; |
| 56 | pub extern "c" fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) c_int; | 59 | pub extern "c" fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) c_int; |
| 57 | pub extern "c" fn dup(fd: c_int) c_int; | 60 | pub extern "c" fn dup(fd: fd_t) c_int; |
| 58 | pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int; | 61 | pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int; |
| 59 | pub extern "c" fn readlink(noalias path: [*]const u8, noalias buf: [*]u8, bufsize: usize) isize; | 62 | pub extern "c" fn readlink(noalias path: [*]const u8, noalias buf: [*]u8, bufsize: usize) isize; |
| 60 | pub extern "c" fn realpath(noalias file_name: [*]const u8, noalias resolved_name: [*]u8) ?[*]u8; | 63 | pub extern "c" fn realpath(noalias file_name: [*]const u8, noalias resolved_name: [*]u8) ?[*]u8; |
| 61 | pub extern "c" fn sigprocmask(how: c_int, noalias set: *const sigset_t, noalias oset: ?*sigset_t) c_int; | 64 | pub extern "c" fn sigprocmask(how: c_int, noalias set: *const sigset_t, noalias oset: ?*sigset_t) c_int; |
| ... | @@ -66,6 +69,19 @@ pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int; | ... | @@ -66,6 +69,19 @@ pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int; |
| 66 | pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int; | 69 | pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int; |
| 67 | pub extern "c" fn rmdir(path: [*]const u8) c_int; | 70 | pub extern "c" fn rmdir(path: [*]const u8) c_int; |
| 68 | pub extern "c" fn getenv(name: [*]const u8) ?[*]u8; | 71 | pub extern "c" fn getenv(name: [*]const u8) ?[*]u8; |
| 72 | pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; | ||
| 73 | pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; | ||
| 74 | pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int; | ||
| 75 | |||
| 76 | pub extern "c" fn bind(socket: fd_t, address: ?*const sockaddr, address_len: socklen_t) c_int; | ||
| 77 | pub extern "c" fn socket(domain: c_int, sock_type: c_int, protocol: c_int) c_int; | ||
| 78 | pub extern "c" fn kill(pid: pid_t, sig: c_int) c_int; | ||
| 79 | pub extern "c" fn getdirentries(fd: fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) usize; | ||
| 80 | pub extern "c" fn openat(fd: c_int, path: [*]const u8, flags: c_int) c_int; | ||
| 81 | pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int; | ||
| 82 | pub extern "c" fn setuid(uid: c_uint) c_int; | ||
| 83 | pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int; | ||
| 84 | pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int; | ||
| 69 | 85 | ||
| 70 | pub extern "c" fn aligned_alloc(alignment: usize, size: usize) ?*c_void; | 86 | pub extern "c" fn aligned_alloc(alignment: usize, size: usize) ?*c_void; |
| 71 | pub extern "c" fn malloc(usize) ?*c_void; | 87 | pub extern "c" fn malloc(usize) ?*c_void; |
| ... | @@ -73,11 +89,19 @@ pub extern "c" fn realloc(?*c_void, usize) ?*c_void; | ... | @@ -73,11 +89,19 @@ pub extern "c" fn realloc(?*c_void, usize) ?*c_void; |
| 73 | pub extern "c" fn free(*c_void) void; | 89 | pub extern "c" fn free(*c_void) void; |
| 74 | pub extern "c" fn posix_memalign(memptr: **c_void, alignment: usize, size: usize) c_int; | 90 | pub extern "c" fn posix_memalign(memptr: **c_void, alignment: usize, size: usize) c_int; |
| 75 | 91 | ||
| 76 | pub extern "pthread" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: extern fn (?*c_void) ?*c_void, noalias arg: ?*c_void) c_int; | 92 | pub extern "c" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: extern fn (?*c_void) ?*c_void, noalias arg: ?*c_void) c_int; |
| 77 | pub extern "pthread" fn pthread_attr_init(attr: *pthread_attr_t) c_int; | 93 | pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) c_int; |
| 78 | pub extern "pthread" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int; | 94 | pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int; |
| 79 | pub extern "pthread" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int; | 95 | pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int; |
| 80 | pub extern "pthread" fn pthread_self() pthread_t; | 96 | pub extern "c" fn pthread_self() pthread_t; |
| 81 | pub extern "pthread" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int; | 97 | pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int; |
| 82 | 98 | ||
| 83 | pub const pthread_t = *@OpaqueType(); | 99 | pub extern "c" fn kqueue() c_int; |
| 100 | pub extern "c" fn kevent( | ||
| 101 | kq: c_int, | ||
| 102 | changelist: [*]const Kevent, | ||
| 103 | nchanges: c_int, | ||
| 104 | eventlist: [*]Kevent, | ||
| 105 | nevents: c_int, | ||
| 106 | timeout: ?*const timespec, | ||
| 107 | ) c_int; |
std/c/darwin.zig+16-177| ... | @@ -1,24 +1,19 @@ | ... | @@ -1,24 +1,19 @@ |
| 1 | const macho = @import("../macho.zig"); | 1 | const std = @import("../std.zig"); |
| 2 | const assert = std.debug.assert; | ||
| 3 | const builtin = @import("builtin"); | ||
| 4 | const macho = std.macho; | ||
| 5 | |||
| 6 | use @import("posix/darwin.zig"); | ||
| 2 | 7 | ||
| 3 | extern "c" fn __error() *c_int; | 8 | extern "c" fn __error() *c_int; |
| 4 | pub extern "c" fn _NSGetExecutablePath(buf: [*]u8, bufsize: *u32) c_int; | 9 | pub extern "c" fn _NSGetExecutablePath(buf: [*]u8, bufsize: *u32) c_int; |
| 5 | pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header; | 10 | pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header; |
| 6 | 11 | ||
| 7 | pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) usize; | 12 | pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize; |
| 8 | 13 | ||
| 9 | pub extern "c" fn mach_absolute_time() u64; | 14 | pub extern "c" fn mach_absolute_time() u64; |
| 10 | pub extern "c" fn mach_timebase_info(tinfo: ?*mach_timebase_info_data) void; | 15 | pub extern "c" fn mach_timebase_info(tinfo: ?*mach_timebase_info_data) void; |
| 11 | 16 | ||
| 12 | pub extern "c" fn kqueue() c_int; | ||
| 13 | pub extern "c" fn kevent( | ||
| 14 | kq: c_int, | ||
| 15 | changelist: [*]const Kevent, | ||
| 16 | nchanges: c_int, | ||
| 17 | eventlist: [*]Kevent, | ||
| 18 | nevents: c_int, | ||
| 19 | timeout: ?*const timespec, | ||
| 20 | ) c_int; | ||
| 21 | |||
| 22 | pub extern "c" fn kevent64( | 17 | pub extern "c" fn kevent64( |
| 23 | kq: c_int, | 18 | kq: c_int, |
| 24 | changelist: [*]const kevent64_s, | 19 | changelist: [*]const kevent64_s, |
| ... | @@ -29,13 +24,6 @@ pub extern "c" fn kevent64( | ... | @@ -29,13 +24,6 @@ pub extern "c" fn kevent64( |
| 29 | timeout: ?*const timespec, | 24 | timeout: ?*const timespec, |
| 30 | ) c_int; | 25 | ) c_int; |
| 31 | 26 | ||
| 32 | pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; | ||
| 33 | pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; | ||
| 34 | pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int; | ||
| 35 | |||
| 36 | pub extern "c" fn bind(socket: c_int, address: ?*const sockaddr, address_len: socklen_t) c_int; | ||
| 37 | pub extern "c" fn socket(domain: c_int, type: c_int, protocol: c_int) c_int; | ||
| 38 | |||
| 39 | const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header; | 27 | const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header; |
| 40 | 28 | ||
| 41 | /// The value of the link editor defined symbol _MH_EXECUTE_SYM is the address | 29 | /// The value of the link editor defined symbol _MH_EXECUTE_SYM is the address |
| ... | @@ -48,170 +36,21 @@ const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header; | ... | @@ -48,170 +36,21 @@ const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header; |
| 48 | /// export a weak symbol here, to be overridden by the real one. | 36 | /// export a weak symbol here, to be overridden by the real one. |
| 49 | pub extern "c" var _mh_execute_header: mach_hdr = undefined; | 37 | pub extern "c" var _mh_execute_header: mach_hdr = undefined; |
| 50 | comptime { | 38 | comptime { |
| 51 | @export("__mh_execute_header", _mh_execute_header, @import("builtin").GlobalLinkage.Weak); | 39 | if (std.os.darwin.is_the_target) { |
| 40 | @export("__mh_execute_header", _mh_execute_header, .Weak); | ||
| 41 | } | ||
| 52 | } | 42 | } |
| 53 | 43 | ||
| 54 | pub const mach_header_64 = macho.mach_header_64; | 44 | pub const mach_header_64 = macho.mach_header_64; |
| 55 | pub const mach_header = macho.mach_header; | 45 | pub const mach_header = macho.mach_header; |
| 56 | 46 | ||
| 57 | pub use @import("../os/darwin/errno.zig"); | ||
| 58 | |||
| 59 | pub const _errno = __error; | 47 | pub const _errno = __error; |
| 60 | 48 | ||
| 61 | pub const in_port_t = u16; | 49 | pub extern "c" fn mach_host_self() mach_port_t; |
| 62 | pub const sa_family_t = u8; | 50 | pub extern "c" fn clock_get_time(clock_serv: clock_serv_t, cur_time: *mach_timespec_t) kern_return_t; |
| 63 | pub const socklen_t = u32; | 51 | pub extern "c" fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clock_serv: ?[*]clock_serv_t) kern_return_t; |
| 64 | pub const sockaddr = extern union { | 52 | pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t; |
| 65 | in: sockaddr_in, | ||
| 66 | in6: sockaddr_in6, | ||
| 67 | }; | ||
| 68 | pub const sockaddr_in = extern struct { | ||
| 69 | len: u8, | ||
| 70 | family: sa_family_t, | ||
| 71 | port: in_port_t, | ||
| 72 | addr: u32, | ||
| 73 | zero: [8]u8, | ||
| 74 | }; | ||
| 75 | pub const sockaddr_in6 = extern struct { | ||
| 76 | len: u8, | ||
| 77 | family: sa_family_t, | ||
| 78 | port: in_port_t, | ||
| 79 | flowinfo: u32, | ||
| 80 | addr: [16]u8, | ||
| 81 | scope_id: u32, | ||
| 82 | }; | ||
| 83 | |||
| 84 | pub const timeval = extern struct { | ||
| 85 | tv_sec: c_long, | ||
| 86 | tv_usec: i32, | ||
| 87 | }; | ||
| 88 | |||
| 89 | pub const timezone = extern struct { | ||
| 90 | tz_minuteswest: i32, | ||
| 91 | tz_dsttime: i32, | ||
| 92 | }; | ||
| 93 | |||
| 94 | pub const mach_timebase_info_data = extern struct { | ||
| 95 | numer: u32, | ||
| 96 | denom: u32, | ||
| 97 | }; | ||
| 98 | |||
| 99 | /// Renamed to Stat to not conflict with the stat function. | ||
| 100 | pub const Stat = extern struct { | ||
| 101 | dev: i32, | ||
| 102 | mode: u16, | ||
| 103 | nlink: u16, | ||
| 104 | ino: u64, | ||
| 105 | uid: u32, | ||
| 106 | gid: u32, | ||
| 107 | rdev: i32, | ||
| 108 | atime: usize, | ||
| 109 | atimensec: usize, | ||
| 110 | mtime: usize, | ||
| 111 | mtimensec: usize, | ||
| 112 | ctime: usize, | ||
| 113 | ctimensec: usize, | ||
| 114 | birthtime: usize, | ||
| 115 | birthtimensec: usize, | ||
| 116 | size: i64, | ||
| 117 | blocks: i64, | ||
| 118 | blksize: i32, | ||
| 119 | flags: u32, | ||
| 120 | gen: u32, | ||
| 121 | lspare: i32, | ||
| 122 | qspare: [2]i64, | ||
| 123 | }; | ||
| 124 | 53 | ||
| 125 | pub const timespec = extern struct { | 54 | pub fn sigaddset(set: *sigset_t, signo: u5) void { |
| 126 | tv_sec: isize, | 55 | set.* |= u32(1) << (signo - 1); |
| 127 | tv_nsec: isize, | ||
| 128 | }; | ||
| 129 | |||
| 130 | pub const sigset_t = u32; | ||
| 131 | |||
| 132 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name. | ||
| 133 | pub const Sigaction = extern struct { | ||
| 134 | handler: extern fn (c_int) void, | ||
| 135 | sa_mask: sigset_t, | ||
| 136 | sa_flags: c_int, | ||
| 137 | }; | ||
| 138 | |||
| 139 | pub const dirent = extern struct { | ||
| 140 | d_ino: usize, | ||
| 141 | d_seekoff: usize, | ||
| 142 | d_reclen: u16, | ||
| 143 | d_namlen: u16, | ||
| 144 | d_type: u8, | ||
| 145 | d_name: u8, // field address is address of first byte of name | ||
| 146 | }; | ||
| 147 | |||
| 148 | pub const pthread_attr_t = extern struct { | ||
| 149 | __sig: c_long, | ||
| 150 | __opaque: [56]u8, | ||
| 151 | }; | ||
| 152 | |||
| 153 | /// Renamed from `kevent` to `Kevent` to avoid conflict with function name. | ||
| 154 | pub const Kevent = extern struct { | ||
| 155 | ident: usize, | ||
| 156 | filter: i16, | ||
| 157 | flags: u16, | ||
| 158 | fflags: u32, | ||
| 159 | data: isize, | ||
| 160 | udata: usize, | ||
| 161 | }; | ||
| 162 | |||
| 163 | // sys/types.h on macos uses #pragma pack(4) so these checks are | ||
| 164 | // to make sure the struct is laid out the same. These values were | ||
| 165 | // produced from C code using the offsetof macro. | ||
| 166 | const std = @import("../std.zig"); | ||
| 167 | const assert = std.debug.assert; | ||
| 168 | |||
| 169 | comptime { | ||
| 170 | assert(@byteOffsetOf(Kevent, "ident") == 0); | ||
| 171 | assert(@byteOffsetOf(Kevent, "filter") == 8); | ||
| 172 | assert(@byteOffsetOf(Kevent, "flags") == 10); | ||
| 173 | assert(@byteOffsetOf(Kevent, "fflags") == 12); | ||
| 174 | assert(@byteOffsetOf(Kevent, "data") == 16); | ||
| 175 | assert(@byteOffsetOf(Kevent, "udata") == 24); | ||
| 176 | } | ||
| 177 | |||
| 178 | pub const kevent64_s = extern struct { | ||
| 179 | ident: u64, | ||
| 180 | filter: i16, | ||
| 181 | flags: u16, | ||
| 182 | fflags: u32, | ||
| 183 | data: i64, | ||
| 184 | udata: u64, | ||
| 185 | ext: [2]u64, | ||
| 186 | }; | ||
| 187 | |||
| 188 | pub const mach_port_t = c_uint; | ||
| 189 | pub const clock_serv_t = mach_port_t; | ||
| 190 | pub const clock_res_t = c_int; | ||
| 191 | pub const mach_port_name_t = natural_t; | ||
| 192 | pub const natural_t = c_uint; | ||
| 193 | pub const mach_timespec_t = extern struct { | ||
| 194 | tv_sec: c_uint, | ||
| 195 | tv_nsec: clock_res_t, | ||
| 196 | }; | ||
| 197 | pub const kern_return_t = c_int; | ||
| 198 | pub const host_t = mach_port_t; | ||
| 199 | pub const CALENDAR_CLOCK = 1; | ||
| 200 | |||
| 201 | pub extern fn mach_host_self() mach_port_t; | ||
| 202 | pub extern fn clock_get_time(clock_serv: clock_serv_t, cur_time: *mach_timespec_t) kern_return_t; | ||
| 203 | pub extern fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clock_serv: ?[*]clock_serv_t) kern_return_t; | ||
| 204 | pub extern fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t; | ||
| 205 | |||
| 206 | // sys/types.h on macos uses #pragma pack() so these checks are | ||
| 207 | // to make sure the struct is laid out the same. These values were | ||
| 208 | // produced from C code using the offsetof macro. | ||
| 209 | comptime { | ||
| 210 | assert(@byteOffsetOf(kevent64_s, "ident") == 0); | ||
| 211 | assert(@byteOffsetOf(kevent64_s, "filter") == 8); | ||
| 212 | assert(@byteOffsetOf(kevent64_s, "flags") == 10); | ||
| 213 | assert(@byteOffsetOf(kevent64_s, "fflags") == 12); | ||
| 214 | assert(@byteOffsetOf(kevent64_s, "data") == 16); | ||
| 215 | assert(@byteOffsetOf(kevent64_s, "udata") == 24); | ||
| 216 | assert(@byteOffsetOf(kevent64_s, "ext") == 32); | ||
| 217 | } | 56 | } |
std/c/freebsd.zig-150| ... | @@ -1,154 +1,4 @@ | ... | @@ -1,154 +1,4 @@ |
| 1 | extern "c" fn __error() *c_int; | 1 | extern "c" fn __error() *c_int; |
| 2 | pub const _errno = __error; | 2 | pub const _errno = __error; |
| 3 | 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; | 4 | 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: i16, | ||
| 32 | flags: u16, | ||
| 33 | fflags: u32, | ||
| 34 | data: i64, | ||
| 35 | udata: usize, | ||
| 36 | // TODO ext | ||
| 37 | }; | ||
| 38 | |||
| 39 | pub const pthread_attr_t = extern struct { | ||
| 40 | __size: [56]u8, | ||
| 41 | __align: c_long, | ||
| 42 | }; | ||
| 43 | |||
| 44 | pub const msghdr = extern struct { | ||
| 45 | /// optional address | ||
| 46 | msg_name: ?*sockaddr, | ||
| 47 | |||
| 48 | /// size of address | ||
| 49 | msg_namelen: socklen_t, | ||
| 50 | |||
| 51 | /// scatter/gather array | ||
| 52 | msg_iov: [*]iovec, | ||
| 53 | |||
| 54 | /// # elements in msg_iov | ||
| 55 | msg_iovlen: i32, | ||
| 56 | |||
| 57 | /// ancillary data | ||
| 58 | msg_control: ?*c_void, | ||
| 59 | |||
| 60 | /// ancillary data buffer len | ||
| 61 | msg_controllen: socklen_t, | ||
| 62 | |||
| 63 | /// flags on received message | ||
| 64 | msg_flags: i32, | ||
| 65 | }; | ||
| 66 | |||
| 67 | pub const msghdr_const = extern struct { | ||
| 68 | /// optional address | ||
| 69 | msg_name: ?*const sockaddr, | ||
| 70 | |||
| 71 | /// size of address | ||
| 72 | msg_namelen: socklen_t, | ||
| 73 | |||
| 74 | /// scatter/gather array | ||
| 75 | msg_iov: [*]iovec_const, | ||
| 76 | |||
| 77 | /// # elements in msg_iov | ||
| 78 | msg_iovlen: i32, | ||
| 79 | |||
| 80 | /// ancillary data | ||
| 81 | msg_control: ?*c_void, | ||
| 82 | |||
| 83 | /// ancillary data buffer len | ||
| 84 | msg_controllen: socklen_t, | ||
| 85 | |||
| 86 | /// flags on received message | ||
| 87 | msg_flags: i32, | ||
| 88 | }; | ||
| 89 | |||
| 90 | pub const Stat = extern struct { | ||
| 91 | dev: u64, | ||
| 92 | ino: u64, | ||
| 93 | nlink: usize, | ||
| 94 | |||
| 95 | mode: u16, | ||
| 96 | __pad0: u16, | ||
| 97 | uid: u32, | ||
| 98 | gid: u32, | ||
| 99 | __pad1: u32, | ||
| 100 | rdev: u64, | ||
| 101 | |||
| 102 | atim: timespec, | ||
| 103 | mtim: timespec, | ||
| 104 | ctim: timespec, | ||
| 105 | birthtim: timespec, | ||
| 106 | |||
| 107 | size: i64, | ||
| 108 | blocks: i64, | ||
| 109 | blksize: isize, | ||
| 110 | flags: u32, | ||
| 111 | gen: u64, | ||
| 112 | __spare: [10]u64, | ||
| 113 | }; | ||
| 114 | |||
| 115 | pub const timespec = extern struct { | ||
| 116 | tv_sec: isize, | ||
| 117 | tv_nsec: isize, | ||
| 118 | }; | ||
| 119 | |||
| 120 | pub const dirent = extern struct { | ||
| 121 | d_fileno: usize, | ||
| 122 | d_off: i64, | ||
| 123 | d_reclen: u16, | ||
| 124 | d_type: u8, | ||
| 125 | d_pad0: u8, | ||
| 126 | d_namlen: u16, | ||
| 127 | d_pad1: u16, | ||
| 128 | d_name: [256]u8, | ||
| 129 | }; | ||
| 130 | |||
| 131 | pub const in_port_t = u16; | ||
| 132 | pub const sa_family_t = u16; | ||
| 133 | |||
| 134 | pub const sockaddr = extern union { | ||
| 135 | in: sockaddr_in, | ||
| 136 | in6: sockaddr_in6, | ||
| 137 | }; | ||
| 138 | |||
| 139 | pub const sockaddr_in = extern struct { | ||
| 140 | len: u8, | ||
| 141 | family: sa_family_t, | ||
| 142 | port: in_port_t, | ||
| 143 | addr: [16]u8, | ||
| 144 | zero: [8]u8, | ||
| 145 | }; | ||
| 146 | |||
| 147 | pub const sockaddr_in6 = extern struct { | ||
| 148 | len: u8, | ||
| 149 | family: sa_family_t, | ||
| 150 | port: in_port_t, | ||
| 151 | flowinfo: u32, | ||
| 152 | addr: [16]u8, | ||
| 153 | scope_id: u32, | ||
| 154 | }; |
std/c/netbsd.zig-146| ... | @@ -1,150 +1,4 @@ | ... | @@ -1,150 +1,4 @@ |
| 1 | extern "c" fn __errno() *c_int; | 1 | extern "c" fn __errno() *c_int; |
| 2 | pub const _errno = __errno; | 2 | pub const _errno = __errno; |
| 3 | 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; | 4 | 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 | /// optional address | ||
| 46 | msg_name: ?*sockaddr, | ||
| 47 | |||
| 48 | /// size of address | ||
| 49 | msg_namelen: socklen_t, | ||
| 50 | |||
| 51 | /// scatter/gather array | ||
| 52 | msg_iov: [*]iovec, | ||
| 53 | |||
| 54 | /// # elements in msg_iov | ||
| 55 | msg_iovlen: i32, | ||
| 56 | |||
| 57 | /// ancillary data | ||
| 58 | msg_control: ?*c_void, | ||
| 59 | |||
| 60 | /// ancillary data buffer len | ||
| 61 | msg_controllen: socklen_t, | ||
| 62 | |||
| 63 | /// flags on received message | ||
| 64 | msg_flags: i32, | ||
| 65 | }; | ||
| 66 | |||
| 67 | pub const msghdr_const = extern struct { | ||
| 68 | /// optional address | ||
| 69 | msg_name: ?*const sockaddr, | ||
| 70 | |||
| 71 | /// size of address | ||
| 72 | msg_namelen: socklen_t, | ||
| 73 | |||
| 74 | /// scatter/gather array | ||
| 75 | msg_iov: [*]iovec_const, | ||
| 76 | |||
| 77 | /// # elements in msg_iov | ||
| 78 | msg_iovlen: i32, | ||
| 79 | |||
| 80 | /// ancillary data | ||
| 81 | msg_control: ?*c_void, | ||
| 82 | |||
| 83 | /// ancillary data buffer len | ||
| 84 | msg_controllen: socklen_t, | ||
| 85 | |||
| 86 | /// flags on received message | ||
| 87 | msg_flags: i32, | ||
| 88 | }; | ||
| 89 | |||
| 90 | pub const Stat = extern struct { | ||
| 91 | dev: u64, | ||
| 92 | mode: u32, | ||
| 93 | ino: u64, | ||
| 94 | nlink: usize, | ||
| 95 | |||
| 96 | uid: u32, | ||
| 97 | gid: u32, | ||
| 98 | rdev: u64, | ||
| 99 | |||
| 100 | atim: timespec, | ||
| 101 | mtim: timespec, | ||
| 102 | ctim: timespec, | ||
| 103 | birthtim: timespec, | ||
| 104 | |||
| 105 | size: i64, | ||
| 106 | blocks: i64, | ||
| 107 | blksize: isize, | ||
| 108 | flags: u32, | ||
| 109 | gen: u32, | ||
| 110 | __spare: [2]u32, | ||
| 111 | }; | ||
| 112 | |||
| 113 | pub const timespec = extern struct { | ||
| 114 | tv_sec: i64, | ||
| 115 | tv_nsec: isize, | ||
| 116 | }; | ||
| 117 | |||
| 118 | pub const dirent = extern struct { | ||
| 119 | d_fileno: u64, | ||
| 120 | d_reclen: u16, | ||
| 121 | d_namlen: u16, | ||
| 122 | d_type: u8, | ||
| 123 | d_off: i64, | ||
| 124 | d_name: [512]u8, | ||
| 125 | }; | ||
| 126 | |||
| 127 | pub const in_port_t = u16; | ||
| 128 | pub const sa_family_t = u8; | ||
| 129 | |||
| 130 | pub const sockaddr = extern union { | ||
| 131 | in: sockaddr_in, | ||
| 132 | in6: sockaddr_in6, | ||
| 133 | }; | ||
| 134 | |||
| 135 | pub const sockaddr_in = extern struct { | ||
| 136 | len: u8, | ||
| 137 | family: sa_family_t, | ||
| 138 | port: in_port_t, | ||
| 139 | addr: u32, | ||
| 140 | zero: [8]u8, | ||
| 141 | }; | ||
| 142 | |||
| 143 | pub const sockaddr_in6 = extern struct { | ||
| 144 | len: u8, | ||
| 145 | family: sa_family_t, | ||
| 146 | port: in_port_t, | ||
| 147 | flowinfo: u32, | ||
| 148 | addr: [16]u8, | ||
| 149 | scope_id: u32, | ||
| 150 | }; |
std/c/posix.zig created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | // Declarations that are intended to be imported into the POSIX namespace. | ||
| 2 | |||
| 3 | const builtin = @import("builtin"); | ||
| 4 | |||
| 5 | pub use switch (builtin.os) { | ||
| 6 | .windows => @import("posix/windows.zig"), | ||
| 7 | .macosx, .ios, .tvos, .watchos => @import("posix/darwin.zig"), | ||
| 8 | .freebsd => @import("posix/freebsd.zig"), | ||
| 9 | .netbsd => @import("posix/netbsd.zig"), | ||
| 10 | else => struct {}, | ||
| 11 | }; | ||
| 12 | |||
| 13 | pub const fd_t = c_int; | ||
| 14 | pub const pid_t = c_int; | ||
| 15 | pub const pthread_t = *@OpaqueType(); | ||
| 16 | pub const FILE = @OpaqueType(); | ||
| 17 | |||
| 18 | pub const iovec = extern struct { | ||
| 19 | iov_base: [*]u8, | ||
| 20 | iov_len: usize, | ||
| 21 | }; | ||
| 22 | |||
| 23 | pub const iovec_const = extern struct { | ||
| 24 | iov_base: [*]const u8, | ||
| 25 | iov_len: usize, | ||
| 26 | }; | ||
std/c/posix/darwin.zig created+1099| ... | @@ -0,0 +1,1099 @@ | ||
| 1 | const std = @import("../std.zig"); | ||
| 2 | const assert = std.debug.assert; | ||
| 3 | |||
| 4 | pub fn sigaction(sig: u5, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize { | ||
| 5 | assert(sig != SIGKILL); | ||
| 6 | assert(sig != SIGSTOP); | ||
| 7 | var cact = c.Sigaction{ | ||
| 8 | .handler = @ptrCast(extern fn (c_int) void, act.handler), | ||
| 9 | .sa_flags = @bitCast(c_int, act.flags), | ||
| 10 | .sa_mask = act.mask, | ||
| 11 | }; | ||
| 12 | var coact: c.Sigaction = undefined; | ||
| 13 | const result = errnoWrap(c.sigaction(sig, &cact, &coact)); | ||
| 14 | if (result != 0) { | ||
| 15 | return result; | ||
| 16 | } | ||
| 17 | if (oact) |old| { | ||
| 18 | old.* = Sigaction{ | ||
| 19 | .handler = @ptrCast(extern fn (i32) void, coact.handler), | ||
| 20 | .flags = @bitCast(u32, coact.sa_flags), | ||
| 21 | .mask = coact.sa_mask, | ||
| 22 | }; | ||
| 23 | } | ||
| 24 | return result; | ||
| 25 | } | ||
| 26 | |||
| 27 | pub const in_port_t = u16; | ||
| 28 | pub const sa_family_t = u8; | ||
| 29 | pub const socklen_t = u32; | ||
| 30 | pub const sockaddr = extern union { | ||
| 31 | in: sockaddr_in, | ||
| 32 | in6: sockaddr_in6, | ||
| 33 | }; | ||
| 34 | pub const sockaddr_in = extern struct { | ||
| 35 | len: u8, | ||
| 36 | family: sa_family_t, | ||
| 37 | port: in_port_t, | ||
| 38 | addr: u32, | ||
| 39 | zero: [8]u8, | ||
| 40 | }; | ||
| 41 | pub const sockaddr_in6 = extern struct { | ||
| 42 | len: u8, | ||
| 43 | family: sa_family_t, | ||
| 44 | port: in_port_t, | ||
| 45 | flowinfo: u32, | ||
| 46 | addr: [16]u8, | ||
| 47 | scope_id: u32, | ||
| 48 | }; | ||
| 49 | |||
| 50 | pub const timeval = extern struct { | ||
| 51 | tv_sec: c_long, | ||
| 52 | tv_usec: i32, | ||
| 53 | }; | ||
| 54 | |||
| 55 | pub const timezone = extern struct { | ||
| 56 | tz_minuteswest: i32, | ||
| 57 | tz_dsttime: i32, | ||
| 58 | }; | ||
| 59 | |||
| 60 | pub const mach_timebase_info_data = extern struct { | ||
| 61 | numer: u32, | ||
| 62 | denom: u32, | ||
| 63 | }; | ||
| 64 | |||
| 65 | /// Renamed to Stat to not conflict with the stat function. | ||
| 66 | pub const Stat = extern struct { | ||
| 67 | dev: i32, | ||
| 68 | mode: u16, | ||
| 69 | nlink: u16, | ||
| 70 | ino: u64, | ||
| 71 | uid: u32, | ||
| 72 | gid: u32, | ||
| 73 | rdev: i32, | ||
| 74 | atime: usize, | ||
| 75 | atimensec: usize, | ||
| 76 | mtime: usize, | ||
| 77 | mtimensec: usize, | ||
| 78 | ctime: usize, | ||
| 79 | ctimensec: usize, | ||
| 80 | birthtime: usize, | ||
| 81 | birthtimensec: usize, | ||
| 82 | size: i64, | ||
| 83 | blocks: i64, | ||
| 84 | blksize: i32, | ||
| 85 | flags: u32, | ||
| 86 | gen: u32, | ||
| 87 | lspare: i32, | ||
| 88 | qspare: [2]i64, | ||
| 89 | }; | ||
| 90 | |||
| 91 | pub const timespec = extern struct { | ||
| 92 | tv_sec: isize, | ||
| 93 | tv_nsec: isize, | ||
| 94 | }; | ||
| 95 | |||
| 96 | pub const sigset_t = u32; | ||
| 97 | pub const empty_sigset = sigset_t(0); | ||
| 98 | |||
| 99 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name. | ||
| 100 | pub const Sigaction = extern struct { | ||
| 101 | handler: extern fn (c_int) void, | ||
| 102 | sa_mask: sigset_t, | ||
| 103 | sa_flags: c_int, | ||
| 104 | }; | ||
| 105 | |||
| 106 | pub const dirent = extern struct { | ||
| 107 | d_ino: usize, | ||
| 108 | d_seekoff: usize, | ||
| 109 | d_reclen: u16, | ||
| 110 | d_namlen: u16, | ||
| 111 | d_type: u8, | ||
| 112 | d_name: u8, // field address is address of first byte of name | ||
| 113 | }; | ||
| 114 | |||
| 115 | pub const pthread_attr_t = extern struct { | ||
| 116 | __sig: c_long, | ||
| 117 | __opaque: [56]u8, | ||
| 118 | }; | ||
| 119 | |||
| 120 | /// Renamed from `kevent` to `Kevent` to avoid conflict with function name. | ||
| 121 | pub const Kevent = extern struct { | ||
| 122 | ident: usize, | ||
| 123 | filter: i16, | ||
| 124 | flags: u16, | ||
| 125 | fflags: u32, | ||
| 126 | data: isize, | ||
| 127 | udata: usize, | ||
| 128 | }; | ||
| 129 | |||
| 130 | // sys/types.h on macos uses #pragma pack(4) so these checks are | ||
| 131 | // to make sure the struct is laid out the same. These values were | ||
| 132 | // produced from C code using the offsetof macro. | ||
| 133 | comptime { | ||
| 134 | assert(@byteOffsetOf(Kevent, "ident") == 0); | ||
| 135 | assert(@byteOffsetOf(Kevent, "filter") == 8); | ||
| 136 | assert(@byteOffsetOf(Kevent, "flags") == 10); | ||
| 137 | assert(@byteOffsetOf(Kevent, "fflags") == 12); | ||
| 138 | assert(@byteOffsetOf(Kevent, "data") == 16); | ||
| 139 | assert(@byteOffsetOf(Kevent, "udata") == 24); | ||
| 140 | } | ||
| 141 | |||
| 142 | pub const kevent64_s = extern struct { | ||
| 143 | ident: u64, | ||
| 144 | filter: i16, | ||
| 145 | flags: u16, | ||
| 146 | fflags: u32, | ||
| 147 | data: i64, | ||
| 148 | udata: u64, | ||
| 149 | ext: [2]u64, | ||
| 150 | }; | ||
| 151 | |||
| 152 | // sys/types.h on macos uses #pragma pack() so these checks are | ||
| 153 | // to make sure the struct is laid out the same. These values were | ||
| 154 | // produced from C code using the offsetof macro. | ||
| 155 | comptime { | ||
| 156 | assert(@byteOffsetOf(kevent64_s, "ident") == 0); | ||
| 157 | assert(@byteOffsetOf(kevent64_s, "filter") == 8); | ||
| 158 | assert(@byteOffsetOf(kevent64_s, "flags") == 10); | ||
| 159 | assert(@byteOffsetOf(kevent64_s, "fflags") == 12); | ||
| 160 | assert(@byteOffsetOf(kevent64_s, "data") == 16); | ||
| 161 | assert(@byteOffsetOf(kevent64_s, "udata") == 24); | ||
| 162 | assert(@byteOffsetOf(kevent64_s, "ext") == 32); | ||
| 163 | } | ||
| 164 | |||
| 165 | pub const mach_port_t = c_uint; | ||
| 166 | pub const clock_serv_t = mach_port_t; | ||
| 167 | pub const clock_res_t = c_int; | ||
| 168 | pub const mach_port_name_t = natural_t; | ||
| 169 | pub const natural_t = c_uint; | ||
| 170 | pub const mach_timespec_t = extern struct { | ||
| 171 | tv_sec: c_uint, | ||
| 172 | tv_nsec: clock_res_t, | ||
| 173 | }; | ||
| 174 | pub const kern_return_t = c_int; | ||
| 175 | pub const host_t = mach_port_t; | ||
| 176 | pub const CALENDAR_CLOCK = 1; | ||
| 177 | |||
| 178 | pub const PATH_MAX = 1024; | ||
| 179 | |||
| 180 | pub const STDIN_FILENO = 0; | ||
| 181 | pub const STDOUT_FILENO = 1; | ||
| 182 | pub const STDERR_FILENO = 2; | ||
| 183 | |||
| 184 | /// [MC2] no permissions | ||
| 185 | pub const PROT_NONE = 0x00; | ||
| 186 | |||
| 187 | /// [MC2] pages can be read | ||
| 188 | pub const PROT_READ = 0x01; | ||
| 189 | |||
| 190 | /// [MC2] pages can be written | ||
| 191 | pub const PROT_WRITE = 0x02; | ||
| 192 | |||
| 193 | /// [MC2] pages can be executed | ||
| 194 | pub const PROT_EXEC = 0x04; | ||
| 195 | |||
| 196 | /// allocated from memory, swap space | ||
| 197 | pub const MAP_ANONYMOUS = 0x1000; | ||
| 198 | |||
| 199 | /// map from file (default) | ||
| 200 | pub const MAP_FILE = 0x0000; | ||
| 201 | |||
| 202 | /// interpret addr exactly | ||
| 203 | pub const MAP_FIXED = 0x0010; | ||
| 204 | |||
| 205 | /// region may contain semaphores | ||
| 206 | pub const MAP_HASSEMAPHORE = 0x0200; | ||
| 207 | |||
| 208 | /// changes are private | ||
| 209 | pub const MAP_PRIVATE = 0x0002; | ||
| 210 | |||
| 211 | /// share changes | ||
| 212 | pub const MAP_SHARED = 0x0001; | ||
| 213 | |||
| 214 | /// don't cache pages for this mapping | ||
| 215 | pub const MAP_NOCACHE = 0x0400; | ||
| 216 | |||
| 217 | /// don't reserve needed swap area | ||
| 218 | pub const MAP_NORESERVE = 0x0040; | ||
| 219 | pub const MAP_FAILED = maxInt(usize); | ||
| 220 | |||
| 221 | /// [XSI] no hang in wait/no child to reap | ||
| 222 | pub const WNOHANG = 0x00000001; | ||
| 223 | |||
| 224 | /// [XSI] notify on stop, untraced child | ||
| 225 | pub const WUNTRACED = 0x00000002; | ||
| 226 | |||
| 227 | /// take signal on signal stack | ||
| 228 | pub const SA_ONSTACK = 0x0001; | ||
| 229 | |||
| 230 | /// restart system on signal return | ||
| 231 | pub const SA_RESTART = 0x0002; | ||
| 232 | |||
| 233 | /// reset to SIG_DFL when taking signal | ||
| 234 | pub const SA_RESETHAND = 0x0004; | ||
| 235 | |||
| 236 | /// do not generate SIGCHLD on child stop | ||
| 237 | pub const SA_NOCLDSTOP = 0x0008; | ||
| 238 | |||
| 239 | /// don't mask the signal we're delivering | ||
| 240 | pub const SA_NODEFER = 0x0010; | ||
| 241 | |||
| 242 | /// don't keep zombies around | ||
| 243 | pub const SA_NOCLDWAIT = 0x0020; | ||
| 244 | |||
| 245 | /// signal handler with SA_SIGINFO args | ||
| 246 | pub const SA_SIGINFO = 0x0040; | ||
| 247 | |||
| 248 | /// do not bounce off kernel's sigtramp | ||
| 249 | pub const SA_USERTRAMP = 0x0100; | ||
| 250 | |||
| 251 | /// signal handler with SA_SIGINFO args with 64bit regs information | ||
| 252 | pub const SA_64REGSET = 0x0200; | ||
| 253 | |||
| 254 | pub const O_LARGEFILE = 0x0000; | ||
| 255 | pub const O_PATH = 0x0000; | ||
| 256 | |||
| 257 | pub const F_OK = 0; | ||
| 258 | pub const X_OK = 1; | ||
| 259 | pub const W_OK = 2; | ||
| 260 | pub const R_OK = 4; | ||
| 261 | |||
| 262 | /// open for reading only | ||
| 263 | pub const O_RDONLY = 0x0000; | ||
| 264 | |||
| 265 | /// open for writing only | ||
| 266 | pub const O_WRONLY = 0x0001; | ||
| 267 | |||
| 268 | /// open for reading and writing | ||
| 269 | pub const O_RDWR = 0x0002; | ||
| 270 | |||
| 271 | /// do not block on open or for data to become available | ||
| 272 | pub const O_NONBLOCK = 0x0004; | ||
| 273 | |||
| 274 | /// append on each write | ||
| 275 | pub const O_APPEND = 0x0008; | ||
| 276 | |||
| 277 | /// create file if it does not exist | ||
| 278 | pub const O_CREAT = 0x0200; | ||
| 279 | |||
| 280 | /// truncate size to 0 | ||
| 281 | pub const O_TRUNC = 0x0400; | ||
| 282 | |||
| 283 | /// error if O_CREAT and the file exists | ||
| 284 | pub const O_EXCL = 0x0800; | ||
| 285 | |||
| 286 | /// atomically obtain a shared lock | ||
| 287 | pub const O_SHLOCK = 0x0010; | ||
| 288 | |||
| 289 | /// atomically obtain an exclusive lock | ||
| 290 | pub const O_EXLOCK = 0x0020; | ||
| 291 | |||
| 292 | /// do not follow symlinks | ||
| 293 | pub const O_NOFOLLOW = 0x0100; | ||
| 294 | |||
| 295 | /// allow open of symlinks | ||
| 296 | pub const O_SYMLINK = 0x200000; | ||
| 297 | |||
| 298 | /// descriptor requested for event notifications only | ||
| 299 | pub const O_EVTONLY = 0x8000; | ||
| 300 | |||
| 301 | /// mark as close-on-exec | ||
| 302 | pub const O_CLOEXEC = 0x1000000; | ||
| 303 | |||
| 304 | pub const O_ACCMODE = 3; | ||
| 305 | pub const O_ALERT = 536870912; | ||
| 306 | pub const O_ASYNC = 64; | ||
| 307 | pub const O_DIRECTORY = 1048576; | ||
| 308 | pub const O_DP_GETRAWENCRYPTED = 1; | ||
| 309 | pub const O_DP_GETRAWUNENCRYPTED = 2; | ||
| 310 | pub const O_DSYNC = 4194304; | ||
| 311 | pub const O_FSYNC = O_SYNC; | ||
| 312 | pub const O_NOCTTY = 131072; | ||
| 313 | pub const O_POPUP = 2147483648; | ||
| 314 | pub const O_SYNC = 128; | ||
| 315 | |||
| 316 | pub const SEEK_SET = 0x0; | ||
| 317 | pub const SEEK_CUR = 0x1; | ||
| 318 | pub const SEEK_END = 0x2; | ||
| 319 | |||
| 320 | pub const DT_UNKNOWN = 0; | ||
| 321 | pub const DT_FIFO = 1; | ||
| 322 | pub const DT_CHR = 2; | ||
| 323 | pub const DT_DIR = 4; | ||
| 324 | pub const DT_BLK = 6; | ||
| 325 | pub const DT_REG = 8; | ||
| 326 | pub const DT_LNK = 10; | ||
| 327 | pub const DT_SOCK = 12; | ||
| 328 | pub const DT_WHT = 14; | ||
| 329 | |||
| 330 | /// block specified signal set | ||
| 331 | pub const SIG_BLOCK = 1; | ||
| 332 | |||
| 333 | /// unblock specified signal set | ||
| 334 | pub const SIG_UNBLOCK = 2; | ||
| 335 | |||
| 336 | /// set specified signal set | ||
| 337 | pub const SIG_SETMASK = 3; | ||
| 338 | |||
| 339 | /// hangup | ||
| 340 | pub const SIGHUP = 1; | ||
| 341 | |||
| 342 | /// interrupt | ||
| 343 | pub const SIGINT = 2; | ||
| 344 | |||
| 345 | /// quit | ||
| 346 | pub const SIGQUIT = 3; | ||
| 347 | |||
| 348 | /// illegal instruction (not reset when caught) | ||
| 349 | pub const SIGILL = 4; | ||
| 350 | |||
| 351 | /// trace trap (not reset when caught) | ||
| 352 | pub const SIGTRAP = 5; | ||
| 353 | |||
| 354 | /// abort() | ||
| 355 | pub const SIGABRT = 6; | ||
| 356 | |||
| 357 | /// pollable event ([XSR] generated, not supported) | ||
| 358 | pub const SIGPOLL = 7; | ||
| 359 | |||
| 360 | /// compatibility | ||
| 361 | pub const SIGIOT = SIGABRT; | ||
| 362 | |||
| 363 | /// EMT instruction | ||
| 364 | pub const SIGEMT = 7; | ||
| 365 | |||
| 366 | /// floating point exception | ||
| 367 | pub const SIGFPE = 8; | ||
| 368 | |||
| 369 | /// kill (cannot be caught or ignored) | ||
| 370 | pub const SIGKILL = 9; | ||
| 371 | |||
| 372 | /// bus error | ||
| 373 | pub const SIGBUS = 10; | ||
| 374 | |||
| 375 | /// segmentation violation | ||
| 376 | pub const SIGSEGV = 11; | ||
| 377 | |||
| 378 | /// bad argument to system call | ||
| 379 | pub const SIGSYS = 12; | ||
| 380 | |||
| 381 | /// write on a pipe with no one to read it | ||
| 382 | pub const SIGPIPE = 13; | ||
| 383 | |||
| 384 | /// alarm clock | ||
| 385 | pub const SIGALRM = 14; | ||
| 386 | |||
| 387 | /// software termination signal from kill | ||
| 388 | pub const SIGTERM = 15; | ||
| 389 | |||
| 390 | /// urgent condition on IO channel | ||
| 391 | pub const SIGURG = 16; | ||
| 392 | |||
| 393 | /// sendable stop signal not from tty | ||
| 394 | pub const SIGSTOP = 17; | ||
| 395 | |||
| 396 | /// stop signal from tty | ||
| 397 | pub const SIGTSTP = 18; | ||
| 398 | |||
| 399 | /// continue a stopped process | ||
| 400 | pub const SIGCONT = 19; | ||
| 401 | |||
| 402 | /// to parent on child stop or exit | ||
| 403 | pub const SIGCHLD = 20; | ||
| 404 | |||
| 405 | /// to readers pgrp upon background tty read | ||
| 406 | pub const SIGTTIN = 21; | ||
| 407 | |||
| 408 | /// like TTIN for output if (tp->t_local&LTOSTOP) | ||
| 409 | pub const SIGTTOU = 22; | ||
| 410 | |||
| 411 | /// input/output possible signal | ||
| 412 | pub const SIGIO = 23; | ||
| 413 | |||
| 414 | /// exceeded CPU time limit | ||
| 415 | pub const SIGXCPU = 24; | ||
| 416 | |||
| 417 | /// exceeded file size limit | ||
| 418 | pub const SIGXFSZ = 25; | ||
| 419 | |||
| 420 | /// virtual time alarm | ||
| 421 | pub const SIGVTALRM = 26; | ||
| 422 | |||
| 423 | /// profiling time alarm | ||
| 424 | pub const SIGPROF = 27; | ||
| 425 | |||
| 426 | /// window size changes | ||
| 427 | pub const SIGWINCH = 28; | ||
| 428 | |||
| 429 | /// information request | ||
| 430 | pub const SIGINFO = 29; | ||
| 431 | |||
| 432 | /// user defined signal 1 | ||
| 433 | pub const SIGUSR1 = 30; | ||
| 434 | |||
| 435 | /// user defined signal 2 | ||
| 436 | pub const SIGUSR2 = 31; | ||
| 437 | |||
| 438 | /// no flag value | ||
| 439 | pub const KEVENT_FLAG_NONE = 0x000; | ||
| 440 | |||
| 441 | /// immediate timeout | ||
| 442 | pub const KEVENT_FLAG_IMMEDIATE = 0x001; | ||
| 443 | |||
| 444 | /// output events only include change | ||
| 445 | pub const KEVENT_FLAG_ERROR_EVENTS = 0x002; | ||
| 446 | |||
| 447 | /// add event to kq (implies enable) | ||
| 448 | pub const EV_ADD = 0x0001; | ||
| 449 | |||
| 450 | /// delete event from kq | ||
| 451 | pub const EV_DELETE = 0x0002; | ||
| 452 | |||
| 453 | /// enable event | ||
| 454 | pub const EV_ENABLE = 0x0004; | ||
| 455 | |||
| 456 | /// disable event (not reported) | ||
| 457 | pub const EV_DISABLE = 0x0008; | ||
| 458 | |||
| 459 | /// only report one occurrence | ||
| 460 | pub const EV_ONESHOT = 0x0010; | ||
| 461 | |||
| 462 | /// clear event state after reporting | ||
| 463 | pub const EV_CLEAR = 0x0020; | ||
| 464 | |||
| 465 | /// force immediate event output | ||
| 466 | /// ... with or without EV_ERROR | ||
| 467 | /// ... use KEVENT_FLAG_ERROR_EVENTS | ||
| 468 | /// on syscalls supporting flags | ||
| 469 | pub const EV_RECEIPT = 0x0040; | ||
| 470 | |||
| 471 | /// disable event after reporting | ||
| 472 | pub const EV_DISPATCH = 0x0080; | ||
| 473 | |||
| 474 | /// unique kevent per udata value | ||
| 475 | pub const EV_UDATA_SPECIFIC = 0x0100; | ||
| 476 | |||
| 477 | /// ... in combination with EV_DELETE | ||
| 478 | /// will defer delete until udata-specific | ||
| 479 | /// event enabled. EINPROGRESS will be | ||
| 480 | /// returned to indicate the deferral | ||
| 481 | pub const EV_DISPATCH2 = EV_DISPATCH | EV_UDATA_SPECIFIC; | ||
| 482 | |||
| 483 | /// report that source has vanished | ||
| 484 | /// ... only valid with EV_DISPATCH2 | ||
| 485 | pub const EV_VANISHED = 0x0200; | ||
| 486 | |||
| 487 | /// reserved by system | ||
| 488 | pub const EV_SYSFLAGS = 0xF000; | ||
| 489 | |||
| 490 | /// filter-specific flag | ||
| 491 | pub const EV_FLAG0 = 0x1000; | ||
| 492 | |||
| 493 | /// filter-specific flag | ||
| 494 | pub const EV_FLAG1 = 0x2000; | ||
| 495 | |||
| 496 | /// EOF detected | ||
| 497 | pub const EV_EOF = 0x8000; | ||
| 498 | |||
| 499 | /// error, data contains errno | ||
| 500 | pub const EV_ERROR = 0x4000; | ||
| 501 | |||
| 502 | pub const EV_POLL = EV_FLAG0; | ||
| 503 | pub const EV_OOBAND = EV_FLAG1; | ||
| 504 | |||
| 505 | pub const EVFILT_READ = -1; | ||
| 506 | pub const EVFILT_WRITE = -2; | ||
| 507 | |||
| 508 | /// attached to aio requests | ||
| 509 | pub const EVFILT_AIO = -3; | ||
| 510 | |||
| 511 | /// attached to vnodes | ||
| 512 | pub const EVFILT_VNODE = -4; | ||
| 513 | |||
| 514 | /// attached to struct proc | ||
| 515 | pub const EVFILT_PROC = -5; | ||
| 516 | |||
| 517 | /// attached to struct proc | ||
| 518 | pub const EVFILT_SIGNAL = -6; | ||
| 519 | |||
| 520 | /// timers | ||
| 521 | pub const EVFILT_TIMER = -7; | ||
| 522 | |||
| 523 | /// Mach portsets | ||
| 524 | pub const EVFILT_MACHPORT = -8; | ||
| 525 | |||
| 526 | /// Filesystem events | ||
| 527 | pub const EVFILT_FS = -9; | ||
| 528 | |||
| 529 | /// User events | ||
| 530 | pub const EVFILT_USER = -10; | ||
| 531 | |||
| 532 | /// Virtual memory events | ||
| 533 | pub const EVFILT_VM = -12; | ||
| 534 | |||
| 535 | /// Exception events | ||
| 536 | pub const EVFILT_EXCEPT = -15; | ||
| 537 | |||
| 538 | pub const EVFILT_SYSCOUNT = 17; | ||
| 539 | |||
| 540 | /// On input, NOTE_TRIGGER causes the event to be triggered for output. | ||
| 541 | pub const NOTE_TRIGGER = 0x01000000; | ||
| 542 | |||
| 543 | /// ignore input fflags | ||
| 544 | pub const NOTE_FFNOP = 0x00000000; | ||
| 545 | |||
| 546 | /// and fflags | ||
| 547 | pub const NOTE_FFAND = 0x40000000; | ||
| 548 | |||
| 549 | /// or fflags | ||
| 550 | pub const NOTE_FFOR = 0x80000000; | ||
| 551 | |||
| 552 | /// copy fflags | ||
| 553 | pub const NOTE_FFCOPY = 0xc0000000; | ||
| 554 | |||
| 555 | /// mask for operations | ||
| 556 | pub const NOTE_FFCTRLMASK = 0xc0000000; | ||
| 557 | pub const NOTE_FFLAGSMASK = 0x00ffffff; | ||
| 558 | |||
| 559 | /// low water mark | ||
| 560 | pub const NOTE_LOWAT = 0x00000001; | ||
| 561 | |||
| 562 | /// OOB data | ||
| 563 | pub const NOTE_OOB = 0x00000002; | ||
| 564 | |||
| 565 | /// vnode was removed | ||
| 566 | pub const NOTE_DELETE = 0x00000001; | ||
| 567 | |||
| 568 | /// data contents changed | ||
| 569 | pub const NOTE_WRITE = 0x00000002; | ||
| 570 | |||
| 571 | /// size increased | ||
| 572 | pub const NOTE_EXTEND = 0x00000004; | ||
| 573 | |||
| 574 | /// attributes changed | ||
| 575 | pub const NOTE_ATTRIB = 0x00000008; | ||
| 576 | |||
| 577 | /// link count changed | ||
| 578 | pub const NOTE_LINK = 0x00000010; | ||
| 579 | |||
| 580 | /// vnode was renamed | ||
| 581 | pub const NOTE_RENAME = 0x00000020; | ||
| 582 | |||
| 583 | /// vnode access was revoked | ||
| 584 | pub const NOTE_REVOKE = 0x00000040; | ||
| 585 | |||
| 586 | /// No specific vnode event: to test for EVFILT_READ activation | ||
| 587 | pub const NOTE_NONE = 0x00000080; | ||
| 588 | |||
| 589 | /// vnode was unlocked by flock(2) | ||
| 590 | pub const NOTE_FUNLOCK = 0x00000100; | ||
| 591 | |||
| 592 | /// process exited | ||
| 593 | pub const NOTE_EXIT = 0x80000000; | ||
| 594 | |||
| 595 | /// process forked | ||
| 596 | pub const NOTE_FORK = 0x40000000; | ||
| 597 | |||
| 598 | /// process exec'd | ||
| 599 | pub const NOTE_EXEC = 0x20000000; | ||
| 600 | |||
| 601 | /// shared with EVFILT_SIGNAL | ||
| 602 | pub const NOTE_SIGNAL = 0x08000000; | ||
| 603 | |||
| 604 | /// exit status to be returned, valid for child process only | ||
| 605 | pub const NOTE_EXITSTATUS = 0x04000000; | ||
| 606 | |||
| 607 | /// provide details on reasons for exit | ||
| 608 | pub const NOTE_EXIT_DETAIL = 0x02000000; | ||
| 609 | |||
| 610 | /// mask for signal & exit status | ||
| 611 | pub const NOTE_PDATAMASK = 0x000fffff; | ||
| 612 | pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK); | ||
| 613 | |||
| 614 | pub const NOTE_EXIT_DETAIL_MASK = 0x00070000; | ||
| 615 | pub const NOTE_EXIT_DECRYPTFAIL = 0x00010000; | ||
| 616 | pub const NOTE_EXIT_MEMORY = 0x00020000; | ||
| 617 | pub const NOTE_EXIT_CSERROR = 0x00040000; | ||
| 618 | |||
| 619 | /// will react on memory pressure | ||
| 620 | pub const NOTE_VM_PRESSURE = 0x80000000; | ||
| 621 | |||
| 622 | /// will quit on memory pressure, possibly after cleaning up dirty state | ||
| 623 | pub const NOTE_VM_PRESSURE_TERMINATE = 0x40000000; | ||
| 624 | |||
| 625 | /// will quit immediately on memory pressure | ||
| 626 | pub const NOTE_VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000; | ||
| 627 | |||
| 628 | /// there was an error | ||
| 629 | pub const NOTE_VM_ERROR = 0x10000000; | ||
| 630 | |||
| 631 | /// data is seconds | ||
| 632 | pub const NOTE_SECONDS = 0x00000001; | ||
| 633 | |||
| 634 | /// data is microseconds | ||
| 635 | pub const NOTE_USECONDS = 0x00000002; | ||
| 636 | |||
| 637 | /// data is nanoseconds | ||
| 638 | pub const NOTE_NSECONDS = 0x00000004; | ||
| 639 | |||
| 640 | /// absolute timeout | ||
| 641 | pub const NOTE_ABSOLUTE = 0x00000008; | ||
| 642 | |||
| 643 | /// ext[1] holds leeway for power aware timers | ||
| 644 | pub const NOTE_LEEWAY = 0x00000010; | ||
| 645 | |||
| 646 | /// system does minimal timer coalescing | ||
| 647 | pub const NOTE_CRITICAL = 0x00000020; | ||
| 648 | |||
| 649 | /// system does maximum timer coalescing | ||
| 650 | pub const NOTE_BACKGROUND = 0x00000040; | ||
| 651 | pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080; | ||
| 652 | |||
| 653 | /// data is mach absolute time units | ||
| 654 | pub const NOTE_MACHTIME = 0x00000100; | ||
| 655 | |||
| 656 | pub const AF_UNSPEC = 0; | ||
| 657 | pub const AF_LOCAL = 1; | ||
| 658 | pub const AF_UNIX = AF_LOCAL; | ||
| 659 | pub const AF_INET = 2; | ||
| 660 | pub const AF_SYS_CONTROL = 2; | ||
| 661 | pub const AF_IMPLINK = 3; | ||
| 662 | pub const AF_PUP = 4; | ||
| 663 | pub const AF_CHAOS = 5; | ||
| 664 | pub const AF_NS = 6; | ||
| 665 | pub const AF_ISO = 7; | ||
| 666 | pub const AF_OSI = AF_ISO; | ||
| 667 | pub const AF_ECMA = 8; | ||
| 668 | pub const AF_DATAKIT = 9; | ||
| 669 | pub const AF_CCITT = 10; | ||
| 670 | pub const AF_SNA = 11; | ||
| 671 | pub const AF_DECnet = 12; | ||
| 672 | pub const AF_DLI = 13; | ||
| 673 | pub const AF_LAT = 14; | ||
| 674 | pub const AF_HYLINK = 15; | ||
| 675 | pub const AF_APPLETALK = 16; | ||
| 676 | pub const AF_ROUTE = 17; | ||
| 677 | pub const AF_LINK = 18; | ||
| 678 | pub const AF_XTP = 19; | ||
| 679 | pub const AF_COIP = 20; | ||
| 680 | pub const AF_CNT = 21; | ||
| 681 | pub const AF_RTIP = 22; | ||
| 682 | pub const AF_IPX = 23; | ||
| 683 | pub const AF_SIP = 24; | ||
| 684 | pub const AF_PIP = 25; | ||
| 685 | pub const AF_ISDN = 28; | ||
| 686 | pub const AF_E164 = AF_ISDN; | ||
| 687 | pub const AF_KEY = 29; | ||
| 688 | pub const AF_INET6 = 30; | ||
| 689 | pub const AF_NATM = 31; | ||
| 690 | pub const AF_SYSTEM = 32; | ||
| 691 | pub const AF_NETBIOS = 33; | ||
| 692 | pub const AF_PPP = 34; | ||
| 693 | pub const AF_MAX = 40; | ||
| 694 | |||
| 695 | pub const PF_UNSPEC = AF_UNSPEC; | ||
| 696 | pub const PF_LOCAL = AF_LOCAL; | ||
| 697 | pub const PF_UNIX = PF_LOCAL; | ||
| 698 | pub const PF_INET = AF_INET; | ||
| 699 | pub const PF_IMPLINK = AF_IMPLINK; | ||
| 700 | pub const PF_PUP = AF_PUP; | ||
| 701 | pub const PF_CHAOS = AF_CHAOS; | ||
| 702 | pub const PF_NS = AF_NS; | ||
| 703 | pub const PF_ISO = AF_ISO; | ||
| 704 | pub const PF_OSI = AF_ISO; | ||
| 705 | pub const PF_ECMA = AF_ECMA; | ||
| 706 | pub const PF_DATAKIT = AF_DATAKIT; | ||
| 707 | pub const PF_CCITT = AF_CCITT; | ||
| 708 | pub const PF_SNA = AF_SNA; | ||
| 709 | pub const PF_DECnet = AF_DECnet; | ||
| 710 | pub const PF_DLI = AF_DLI; | ||
| 711 | pub const PF_LAT = AF_LAT; | ||
| 712 | pub const PF_HYLINK = AF_HYLINK; | ||
| 713 | pub const PF_APPLETALK = AF_APPLETALK; | ||
| 714 | pub const PF_ROUTE = AF_ROUTE; | ||
| 715 | pub const PF_LINK = AF_LINK; | ||
| 716 | pub const PF_XTP = AF_XTP; | ||
| 717 | pub const PF_COIP = AF_COIP; | ||
| 718 | pub const PF_CNT = AF_CNT; | ||
| 719 | pub const PF_SIP = AF_SIP; | ||
| 720 | pub const PF_IPX = AF_IPX; | ||
| 721 | pub const PF_RTIP = AF_RTIP; | ||
| 722 | pub const PF_PIP = AF_PIP; | ||
| 723 | pub const PF_ISDN = AF_ISDN; | ||
| 724 | pub const PF_KEY = AF_KEY; | ||
| 725 | pub const PF_INET6 = AF_INET6; | ||
| 726 | pub const PF_NATM = AF_NATM; | ||
| 727 | pub const PF_SYSTEM = AF_SYSTEM; | ||
| 728 | pub const PF_NETBIOS = AF_NETBIOS; | ||
| 729 | pub const PF_PPP = AF_PPP; | ||
| 730 | pub const PF_MAX = AF_MAX; | ||
| 731 | |||
| 732 | pub const SYSPROTO_EVENT = 1; | ||
| 733 | pub const SYSPROTO_CONTROL = 2; | ||
| 734 | |||
| 735 | pub const SOCK_STREAM = 1; | ||
| 736 | pub const SOCK_DGRAM = 2; | ||
| 737 | pub const SOCK_RAW = 3; | ||
| 738 | pub const SOCK_RDM = 4; | ||
| 739 | pub const SOCK_SEQPACKET = 5; | ||
| 740 | pub const SOCK_MAXADDRLEN = 255; | ||
| 741 | |||
| 742 | pub const IPPROTO_ICMP = 1; | ||
| 743 | pub const IPPROTO_ICMPV6 = 58; | ||
| 744 | pub const IPPROTO_TCP = 6; | ||
| 745 | pub const IPPROTO_UDP = 17; | ||
| 746 | pub const IPPROTO_IP = 0; | ||
| 747 | pub const IPPROTO_IPV6 = 41; | ||
| 748 | |||
| 749 | fn wstatus(x: i32) i32 { | ||
| 750 | return x & 0o177; | ||
| 751 | } | ||
| 752 | const wstopped = 0o177; | ||
| 753 | pub fn WEXITSTATUS(x: i32) i32 { | ||
| 754 | return x >> 8; | ||
| 755 | } | ||
| 756 | pub fn WTERMSIG(x: i32) i32 { | ||
| 757 | return wstatus(x); | ||
| 758 | } | ||
| 759 | pub fn WSTOPSIG(x: i32) i32 { | ||
| 760 | return x >> 8; | ||
| 761 | } | ||
| 762 | pub fn WIFEXITED(x: i32) bool { | ||
| 763 | return wstatus(x) == 0; | ||
| 764 | } | ||
| 765 | pub fn WIFSTOPPED(x: i32) bool { | ||
| 766 | return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13; | ||
| 767 | } | ||
| 768 | pub fn WIFSIGNALED(x: i32) bool { | ||
| 769 | return wstatus(x) != wstopped and wstatus(x) != 0; | ||
| 770 | } | ||
| 771 | |||
| 772 | /// Operation not permitted | ||
| 773 | pub const EPERM = 1; | ||
| 774 | |||
| 775 | /// No such file or directory | ||
| 776 | pub const ENOENT = 2; | ||
| 777 | |||
| 778 | /// No such process | ||
| 779 | pub const ESRCH = 3; | ||
| 780 | |||
| 781 | /// Interrupted system call | ||
| 782 | pub const EINTR = 4; | ||
| 783 | |||
| 784 | /// Input/output error | ||
| 785 | pub const EIO = 5; | ||
| 786 | |||
| 787 | /// Device not configured | ||
| 788 | pub const ENXIO = 6; | ||
| 789 | |||
| 790 | /// Argument list too long | ||
| 791 | pub const E2BIG = 7; | ||
| 792 | |||
| 793 | /// Exec format error | ||
| 794 | pub const ENOEXEC = 8; | ||
| 795 | |||
| 796 | /// Bad file descriptor | ||
| 797 | pub const EBADF = 9; | ||
| 798 | |||
| 799 | /// No child processes | ||
| 800 | pub const ECHILD = 10; | ||
| 801 | |||
| 802 | /// Resource deadlock avoided | ||
| 803 | pub const EDEADLK = 11; | ||
| 804 | |||
| 805 | /// Cannot allocate memory | ||
| 806 | pub const ENOMEM = 12; | ||
| 807 | |||
| 808 | /// Permission denied | ||
| 809 | pub const EACCES = 13; | ||
| 810 | |||
| 811 | /// Bad address | ||
| 812 | pub const EFAULT = 14; | ||
| 813 | |||
| 814 | /// Block device required | ||
| 815 | pub const ENOTBLK = 15; | ||
| 816 | |||
| 817 | /// Device / Resource busy | ||
| 818 | pub const EBUSY = 16; | ||
| 819 | |||
| 820 | /// File exists | ||
| 821 | pub const EEXIST = 17; | ||
| 822 | |||
| 823 | /// Cross-device link | ||
| 824 | pub const EXDEV = 18; | ||
| 825 | |||
| 826 | /// Operation not supported by device | ||
| 827 | pub const ENODEV = 19; | ||
| 828 | |||
| 829 | /// Not a directory | ||
| 830 | pub const ENOTDIR = 20; | ||
| 831 | |||
| 832 | /// Is a directory | ||
| 833 | pub const EISDIR = 21; | ||
| 834 | |||
| 835 | /// Invalid argument | ||
| 836 | pub const EINVAL = 22; | ||
| 837 | |||
| 838 | /// Too many open files in system | ||
| 839 | pub const ENFILE = 23; | ||
| 840 | |||
| 841 | /// Too many open files | ||
| 842 | pub const EMFILE = 24; | ||
| 843 | |||
| 844 | /// Inappropriate ioctl for device | ||
| 845 | pub const ENOTTY = 25; | ||
| 846 | |||
| 847 | /// Text file busy | ||
| 848 | pub const ETXTBSY = 26; | ||
| 849 | |||
| 850 | /// File too large | ||
| 851 | pub const EFBIG = 27; | ||
| 852 | |||
| 853 | /// No space left on device | ||
| 854 | pub const ENOSPC = 28; | ||
| 855 | |||
| 856 | /// Illegal seek | ||
| 857 | pub const ESPIPE = 29; | ||
| 858 | |||
| 859 | /// Read-only file system | ||
| 860 | pub const EROFS = 30; | ||
| 861 | |||
| 862 | /// Too many links | ||
| 863 | pub const EMLINK = 31; | ||
| 864 | /// Broken pipe | ||
| 865 | |||
| 866 | // math software | ||
| 867 | pub const EPIPE = 32; | ||
| 868 | |||
| 869 | /// Numerical argument out of domain | ||
| 870 | pub const EDOM = 33; | ||
| 871 | /// Result too large | ||
| 872 | |||
| 873 | // non-blocking and interrupt i/o | ||
| 874 | pub const ERANGE = 34; | ||
| 875 | |||
| 876 | /// Resource temporarily unavailable | ||
| 877 | pub const EAGAIN = 35; | ||
| 878 | |||
| 879 | /// Operation would block | ||
| 880 | pub const EWOULDBLOCK = EAGAIN; | ||
| 881 | |||
| 882 | /// Operation now in progress | ||
| 883 | pub const EINPROGRESS = 36; | ||
| 884 | /// Operation already in progress | ||
| 885 | |||
| 886 | // ipc/network software -- argument errors | ||
| 887 | pub const EALREADY = 37; | ||
| 888 | |||
| 889 | /// Socket operation on non-socket | ||
| 890 | pub const ENOTSOCK = 38; | ||
| 891 | |||
| 892 | /// Destination address required | ||
| 893 | pub const EDESTADDRREQ = 39; | ||
| 894 | |||
| 895 | /// Message too long | ||
| 896 | pub const EMSGSIZE = 40; | ||
| 897 | |||
| 898 | /// Protocol wrong type for socket | ||
| 899 | pub const EPROTOTYPE = 41; | ||
| 900 | |||
| 901 | /// Protocol not available | ||
| 902 | pub const ENOPROTOOPT = 42; | ||
| 903 | |||
| 904 | /// Protocol not supported | ||
| 905 | pub const EPROTONOSUPPORT = 43; | ||
| 906 | |||
| 907 | /// Socket type not supported | ||
| 908 | pub const ESOCKTNOSUPPORT = 44; | ||
| 909 | |||
| 910 | /// Operation not supported | ||
| 911 | pub const ENOTSUP = 45; | ||
| 912 | |||
| 913 | /// Protocol family not supported | ||
| 914 | pub const EPFNOSUPPORT = 46; | ||
| 915 | |||
| 916 | /// Address family not supported by protocol family | ||
| 917 | pub const EAFNOSUPPORT = 47; | ||
| 918 | |||
| 919 | /// Address already in use | ||
| 920 | pub const EADDRINUSE = 48; | ||
| 921 | /// Can't assign requested address | ||
| 922 | |||
| 923 | // ipc/network software -- operational errors | ||
| 924 | pub const EADDRNOTAVAIL = 49; | ||
| 925 | |||
| 926 | /// Network is down | ||
| 927 | pub const ENETDOWN = 50; | ||
| 928 | |||
| 929 | /// Network is unreachable | ||
| 930 | pub const ENETUNREACH = 51; | ||
| 931 | |||
| 932 | /// Network dropped connection on reset | ||
| 933 | pub const ENETRESET = 52; | ||
| 934 | |||
| 935 | /// Software caused connection abort | ||
| 936 | pub const ECONNABORTED = 53; | ||
| 937 | |||
| 938 | /// Connection reset by peer | ||
| 939 | pub const ECONNRESET = 54; | ||
| 940 | |||
| 941 | /// No buffer space available | ||
| 942 | pub const ENOBUFS = 55; | ||
| 943 | |||
| 944 | /// Socket is already connected | ||
| 945 | pub const EISCONN = 56; | ||
| 946 | |||
| 947 | /// Socket is not connected | ||
| 948 | pub const ENOTCONN = 57; | ||
| 949 | |||
| 950 | /// Can't send after socket shutdown | ||
| 951 | pub const ESHUTDOWN = 58; | ||
| 952 | |||
| 953 | /// Too many references: can't splice | ||
| 954 | pub const ETOOMANYREFS = 59; | ||
| 955 | |||
| 956 | /// Operation timed out | ||
| 957 | pub const ETIMEDOUT = 60; | ||
| 958 | |||
| 959 | /// Connection refused | ||
| 960 | pub const ECONNREFUSED = 61; | ||
| 961 | |||
| 962 | /// Too many levels of symbolic links | ||
| 963 | pub const ELOOP = 62; | ||
| 964 | |||
| 965 | /// File name too long | ||
| 966 | pub const ENAMETOOLONG = 63; | ||
| 967 | |||
| 968 | /// Host is down | ||
| 969 | pub const EHOSTDOWN = 64; | ||
| 970 | |||
| 971 | /// No route to host | ||
| 972 | pub const EHOSTUNREACH = 65; | ||
| 973 | /// Directory not empty | ||
| 974 | |||
| 975 | // quotas & mush | ||
| 976 | pub const ENOTEMPTY = 66; | ||
| 977 | |||
| 978 | /// Too many processes | ||
| 979 | pub const EPROCLIM = 67; | ||
| 980 | |||
| 981 | /// Too many users | ||
| 982 | pub const EUSERS = 68; | ||
| 983 | /// Disc quota exceeded | ||
| 984 | |||
| 985 | // Network File System | ||
| 986 | pub const EDQUOT = 69; | ||
| 987 | |||
| 988 | /// Stale NFS file handle | ||
| 989 | pub const ESTALE = 70; | ||
| 990 | |||
| 991 | /// Too many levels of remote in path | ||
| 992 | pub const EREMOTE = 71; | ||
| 993 | |||
| 994 | /// RPC struct is bad | ||
| 995 | pub const EBADRPC = 72; | ||
| 996 | |||
| 997 | /// RPC version wrong | ||
| 998 | pub const ERPCMISMATCH = 73; | ||
| 999 | |||
| 1000 | /// RPC prog. not avail | ||
| 1001 | pub const EPROGUNAVAIL = 74; | ||
| 1002 | |||
| 1003 | /// Program version wrong | ||
| 1004 | pub const EPROGMISMATCH = 75; | ||
| 1005 | |||
| 1006 | /// Bad procedure for program | ||
| 1007 | pub const EPROCUNAVAIL = 76; | ||
| 1008 | |||
| 1009 | /// No locks available | ||
| 1010 | pub const ENOLCK = 77; | ||
| 1011 | |||
| 1012 | /// Function not implemented | ||
| 1013 | pub const ENOSYS = 78; | ||
| 1014 | |||
| 1015 | /// Inappropriate file type or format | ||
| 1016 | pub const EFTYPE = 79; | ||
| 1017 | |||
| 1018 | /// Authentication error | ||
| 1019 | pub const EAUTH = 80; | ||
| 1020 | /// Need authenticator | ||
| 1021 | |||
| 1022 | // Intelligent device errors | ||
| 1023 | pub const ENEEDAUTH = 81; | ||
| 1024 | |||
| 1025 | /// Device power is off | ||
| 1026 | pub const EPWROFF = 82; | ||
| 1027 | |||
| 1028 | /// Device error, e.g. paper out | ||
| 1029 | pub const EDEVERR = 83; | ||
| 1030 | /// Value too large to be stored in data type | ||
| 1031 | |||
| 1032 | // Program loading errors | ||
| 1033 | pub const EOVERFLOW = 84; | ||
| 1034 | |||
| 1035 | /// Bad executable | ||
| 1036 | pub const EBADEXEC = 85; | ||
| 1037 | |||
| 1038 | /// Bad CPU type in executable | ||
| 1039 | pub const EBADARCH = 86; | ||
| 1040 | |||
| 1041 | /// Shared library version mismatch | ||
| 1042 | pub const ESHLIBVERS = 87; | ||
| 1043 | |||
| 1044 | /// Malformed Macho file | ||
| 1045 | pub const EBADMACHO = 88; | ||
| 1046 | |||
| 1047 | /// Operation canceled | ||
| 1048 | pub const ECANCELED = 89; | ||
| 1049 | |||
| 1050 | /// Identifier removed | ||
| 1051 | pub const EIDRM = 90; | ||
| 1052 | |||
| 1053 | /// No message of desired type | ||
| 1054 | pub const ENOMSG = 91; | ||
| 1055 | |||
| 1056 | /// Illegal byte sequence | ||
| 1057 | pub const EILSEQ = 92; | ||
| 1058 | |||
| 1059 | /// Attribute not found | ||
| 1060 | pub const ENOATTR = 93; | ||
| 1061 | |||
| 1062 | /// Bad message | ||
| 1063 | pub const EBADMSG = 94; | ||
| 1064 | |||
| 1065 | /// Reserved | ||
| 1066 | pub const EMULTIHOP = 95; | ||
| 1067 | |||
| 1068 | /// No message available on STREAM | ||
| 1069 | pub const ENODATA = 96; | ||
| 1070 | |||
| 1071 | /// Reserved | ||
| 1072 | pub const ENOLINK = 97; | ||
| 1073 | |||
| 1074 | /// No STREAM resources | ||
| 1075 | pub const ENOSR = 98; | ||
| 1076 | |||
| 1077 | /// Not a STREAM | ||
| 1078 | pub const ENOSTR = 99; | ||
| 1079 | |||
| 1080 | /// Protocol error | ||
| 1081 | pub const EPROTO = 100; | ||
| 1082 | |||
| 1083 | /// STREAM ioctl timeout | ||
| 1084 | pub const ETIME = 101; | ||
| 1085 | |||
| 1086 | /// No such policy registered | ||
| 1087 | pub const ENOPOLICY = 103; | ||
| 1088 | |||
| 1089 | /// State not recoverable | ||
| 1090 | pub const ENOTRECOVERABLE = 104; | ||
| 1091 | |||
| 1092 | /// Previous owner died | ||
| 1093 | pub const EOWNERDEAD = 105; | ||
| 1094 | |||
| 1095 | /// Interface output queue is full | ||
| 1096 | pub const EQFULL = 106; | ||
| 1097 | |||
| 1098 | /// Must be equal largest errno | ||
| 1099 | pub const ELAST = 106; | ||
std/c/posix/freebsd.zig created+839| ... | @@ -0,0 +1,839 @@ | ||
| 1 | const std = @import("../std.zig"); | ||
| 2 | |||
| 3 | /// Renamed from `kevent` to `Kevent` to avoid conflict with function name. | ||
| 4 | pub const Kevent = extern struct { | ||
| 5 | ident: usize, | ||
| 6 | filter: i16, | ||
| 7 | flags: u16, | ||
| 8 | fflags: u32, | ||
| 9 | data: i64, | ||
| 10 | udata: usize, | ||
| 11 | // TODO ext | ||
| 12 | }; | ||
| 13 | |||
| 14 | pub const pthread_attr_t = extern struct { | ||
| 15 | __size: [56]u8, | ||
| 16 | __align: c_long, | ||
| 17 | }; | ||
| 18 | |||
| 19 | pub const msghdr = extern struct { | ||
| 20 | /// optional address | ||
| 21 | msg_name: ?*sockaddr, | ||
| 22 | |||
| 23 | /// size of address | ||
| 24 | msg_namelen: socklen_t, | ||
| 25 | |||
| 26 | /// scatter/gather array | ||
| 27 | msg_iov: [*]iovec, | ||
| 28 | |||
| 29 | /// # elements in msg_iov | ||
| 30 | msg_iovlen: i32, | ||
| 31 | |||
| 32 | /// ancillary data | ||
| 33 | msg_control: ?*c_void, | ||
| 34 | |||
| 35 | /// ancillary data buffer len | ||
| 36 | msg_controllen: socklen_t, | ||
| 37 | |||
| 38 | /// flags on received message | ||
| 39 | msg_flags: i32, | ||
| 40 | }; | ||
| 41 | |||
| 42 | pub const msghdr_const = extern struct { | ||
| 43 | /// optional address | ||
| 44 | msg_name: ?*const sockaddr, | ||
| 45 | |||
| 46 | /// size of address | ||
| 47 | msg_namelen: socklen_t, | ||
| 48 | |||
| 49 | /// scatter/gather array | ||
| 50 | msg_iov: [*]iovec_const, | ||
| 51 | |||
| 52 | /// # elements in msg_iov | ||
| 53 | msg_iovlen: i32, | ||
| 54 | |||
| 55 | /// ancillary data | ||
| 56 | msg_control: ?*c_void, | ||
| 57 | |||
| 58 | /// ancillary data buffer len | ||
| 59 | msg_controllen: socklen_t, | ||
| 60 | |||
| 61 | /// flags on received message | ||
| 62 | msg_flags: i32, | ||
| 63 | }; | ||
| 64 | |||
| 65 | pub const Stat = extern struct { | ||
| 66 | dev: u64, | ||
| 67 | ino: u64, | ||
| 68 | nlink: usize, | ||
| 69 | |||
| 70 | mode: u16, | ||
| 71 | __pad0: u16, | ||
| 72 | uid: u32, | ||
| 73 | gid: u32, | ||
| 74 | __pad1: u32, | ||
| 75 | rdev: u64, | ||
| 76 | |||
| 77 | atim: timespec, | ||
| 78 | mtim: timespec, | ||
| 79 | ctim: timespec, | ||
| 80 | birthtim: timespec, | ||
| 81 | |||
| 82 | size: i64, | ||
| 83 | blocks: i64, | ||
| 84 | blksize: isize, | ||
| 85 | flags: u32, | ||
| 86 | gen: u64, | ||
| 87 | __spare: [10]u64, | ||
| 88 | }; | ||
| 89 | |||
| 90 | pub const timespec = extern struct { | ||
| 91 | tv_sec: isize, | ||
| 92 | tv_nsec: isize, | ||
| 93 | }; | ||
| 94 | |||
| 95 | pub const dirent = extern struct { | ||
| 96 | d_fileno: usize, | ||
| 97 | d_off: i64, | ||
| 98 | d_reclen: u16, | ||
| 99 | d_type: u8, | ||
| 100 | d_pad0: u8, | ||
| 101 | d_namlen: u16, | ||
| 102 | d_pad1: u16, | ||
| 103 | d_name: [256]u8, | ||
| 104 | }; | ||
| 105 | |||
| 106 | pub const in_port_t = u16; | ||
| 107 | pub const sa_family_t = u16; | ||
| 108 | |||
| 109 | pub const sockaddr = extern union { | ||
| 110 | in: sockaddr_in, | ||
| 111 | in6: sockaddr_in6, | ||
| 112 | }; | ||
| 113 | |||
| 114 | pub const sockaddr_in = extern struct { | ||
| 115 | len: u8, | ||
| 116 | family: sa_family_t, | ||
| 117 | port: in_port_t, | ||
| 118 | addr: [16]u8, | ||
| 119 | zero: [8]u8, | ||
| 120 | }; | ||
| 121 | |||
| 122 | pub const sockaddr_in6 = extern struct { | ||
| 123 | len: u8, | ||
| 124 | family: sa_family_t, | ||
| 125 | port: in_port_t, | ||
| 126 | flowinfo: u32, | ||
| 127 | addr: [16]u8, | ||
| 128 | scope_id: u32, | ||
| 129 | }; | ||
| 130 | |||
| 131 | pub const CTL_KERN = 1; | ||
| 132 | pub const CTL_DEBUG = 5; | ||
| 133 | |||
| 134 | pub const KERN_PROC = 14; // struct: process entries | ||
| 135 | pub const KERN_PROC_PATHNAME = 12; // path to executable | ||
| 136 | |||
| 137 | pub const PATH_MAX = 1024; | ||
| 138 | |||
| 139 | pub const STDIN_FILENO = 0; | ||
| 140 | pub const STDOUT_FILENO = 1; | ||
| 141 | pub const STDERR_FILENO = 2; | ||
| 142 | |||
| 143 | pub const PROT_NONE = 0; | ||
| 144 | pub const PROT_READ = 1; | ||
| 145 | pub const PROT_WRITE = 2; | ||
| 146 | pub const PROT_EXEC = 4; | ||
| 147 | |||
| 148 | pub const CLOCK_REALTIME = 0; | ||
| 149 | pub const CLOCK_VIRTUAL = 1; | ||
| 150 | pub const CLOCK_PROF = 2; | ||
| 151 | pub const CLOCK_MONOTONIC = 4; | ||
| 152 | pub const CLOCK_UPTIME = 5; | ||
| 153 | pub const CLOCK_UPTIME_PRECISE = 7; | ||
| 154 | pub const CLOCK_UPTIME_FAST = 8; | ||
| 155 | pub const CLOCK_REALTIME_PRECISE = 9; | ||
| 156 | pub const CLOCK_REALTIME_FAST = 10; | ||
| 157 | pub const CLOCK_MONOTONIC_PRECISE = 11; | ||
| 158 | pub const CLOCK_MONOTONIC_FAST = 12; | ||
| 159 | pub const CLOCK_SECOND = 13; | ||
| 160 | pub const CLOCK_THREAD_CPUTIME_ID = 14; | ||
| 161 | pub const CLOCK_PROCESS_CPUTIME_ID = 15; | ||
| 162 | |||
| 163 | pub const MAP_FAILED = maxInt(usize); | ||
| 164 | pub const MAP_SHARED = 0x0001; | ||
| 165 | pub const MAP_PRIVATE = 0x0002; | ||
| 166 | pub const MAP_FIXED = 0x0010; | ||
| 167 | pub const MAP_STACK = 0x0400; | ||
| 168 | pub const MAP_NOSYNC = 0x0800; | ||
| 169 | pub const MAP_ANON = 0x1000; | ||
| 170 | pub const MAP_ANONYMOUS = MAP_ANON; | ||
| 171 | pub const MAP_FILE = 0; | ||
| 172 | pub const MAP_NORESERVE = 0; | ||
| 173 | |||
| 174 | pub const MAP_GUARD = 0x00002000; | ||
| 175 | pub const MAP_EXCL = 0x00004000; | ||
| 176 | pub const MAP_NOCORE = 0x00020000; | ||
| 177 | pub const MAP_PREFAULT_READ = 0x00040000; | ||
| 178 | pub const MAP_32BIT = 0x00080000; | ||
| 179 | |||
| 180 | pub const WNOHANG = 1; | ||
| 181 | pub const WUNTRACED = 2; | ||
| 182 | pub const WSTOPPED = WUNTRACED; | ||
| 183 | pub const WCONTINUED = 4; | ||
| 184 | pub const WNOWAIT = 8; | ||
| 185 | pub const WEXITED = 16; | ||
| 186 | pub const WTRAPPED = 32; | ||
| 187 | |||
| 188 | pub const SA_ONSTACK = 0x0001; | ||
| 189 | pub const SA_RESTART = 0x0002; | ||
| 190 | pub const SA_RESETHAND = 0x0004; | ||
| 191 | pub const SA_NOCLDSTOP = 0x0008; | ||
| 192 | pub const SA_NODEFER = 0x0010; | ||
| 193 | pub const SA_NOCLDWAIT = 0x0020; | ||
| 194 | pub const SA_SIGINFO = 0x0040; | ||
| 195 | |||
| 196 | pub const SIGHUP = 1; | ||
| 197 | pub const SIGINT = 2; | ||
| 198 | pub const SIGQUIT = 3; | ||
| 199 | pub const SIGILL = 4; | ||
| 200 | pub const SIGTRAP = 5; | ||
| 201 | pub const SIGABRT = 6; | ||
| 202 | pub const SIGIOT = SIGABRT; | ||
| 203 | pub const SIGEMT = 7; | ||
| 204 | pub const SIGFPE = 8; | ||
| 205 | pub const SIGKILL = 9; | ||
| 206 | pub const SIGBUS = 10; | ||
| 207 | pub const SIGSEGV = 11; | ||
| 208 | pub const SIGSYS = 12; | ||
| 209 | pub const SIGPIPE = 13; | ||
| 210 | pub const SIGALRM = 14; | ||
| 211 | pub const SIGTERM = 15; | ||
| 212 | pub const SIGURG = 16; | ||
| 213 | pub const SIGSTOP = 17; | ||
| 214 | pub const SIGTSTP = 18; | ||
| 215 | pub const SIGCONT = 19; | ||
| 216 | pub const SIGCHLD = 20; | ||
| 217 | pub const SIGTTIN = 21; | ||
| 218 | pub const SIGTTOU = 22; | ||
| 219 | pub const SIGIO = 23; | ||
| 220 | pub const SIGXCPU = 24; | ||
| 221 | pub const SIGXFSZ = 25; | ||
| 222 | pub const SIGVTALRM = 26; | ||
| 223 | pub const SIGPROF = 27; | ||
| 224 | pub const SIGWINCH = 28; | ||
| 225 | pub const SIGINFO = 29; | ||
| 226 | pub const SIGUSR1 = 30; | ||
| 227 | pub const SIGUSR2 = 31; | ||
| 228 | pub const SIGTHR = 32; | ||
| 229 | pub const SIGLWP = SIGTHR; | ||
| 230 | pub const SIGLIBRT = 33; | ||
| 231 | |||
| 232 | pub const SIGRTMIN = 65; | ||
| 233 | pub const SIGRTMAX = 126; | ||
| 234 | |||
| 235 | // access function | ||
| 236 | pub const F_OK = 0; // test for existence of file | ||
| 237 | pub const X_OK = 1; // test for execute or search permission | ||
| 238 | pub const W_OK = 2; // test for write permission | ||
| 239 | pub const R_OK = 4; // test for read permission | ||
| 240 | |||
| 241 | pub const O_RDONLY = 0x0000; | ||
| 242 | pub const O_WRONLY = 0x0001; | ||
| 243 | pub const O_RDWR = 0x0002; | ||
| 244 | pub const O_ACCMODE = 0x0003; | ||
| 245 | |||
| 246 | pub const O_CREAT = 0x0200; | ||
| 247 | pub const O_EXCL = 0x0800; | ||
| 248 | pub const O_NOCTTY = 0x8000; | ||
| 249 | pub const O_TRUNC = 0x0400; | ||
| 250 | pub const O_APPEND = 0x0008; | ||
| 251 | pub const O_NONBLOCK = 0x0004; | ||
| 252 | pub const O_DSYNC = 0o10000; | ||
| 253 | pub const O_SYNC = 0x0080; | ||
| 254 | pub const O_RSYNC = 0o4010000; | ||
| 255 | pub const O_DIRECTORY = 0o200000; | ||
| 256 | pub const O_NOFOLLOW = 0x0100; | ||
| 257 | pub const O_CLOEXEC = 0x00100000; | ||
| 258 | |||
| 259 | pub const O_ASYNC = 0x0040; | ||
| 260 | pub const O_DIRECT = 0x00010000; | ||
| 261 | pub const O_LARGEFILE = 0; | ||
| 262 | pub const O_NOATIME = 0o1000000; | ||
| 263 | pub const O_PATH = 0o10000000; | ||
| 264 | pub const O_TMPFILE = 0o20200000; | ||
| 265 | pub const O_NDELAY = O_NONBLOCK; | ||
| 266 | |||
| 267 | pub const F_DUPFD = 0; | ||
| 268 | pub const F_GETFD = 1; | ||
| 269 | pub const F_SETFD = 2; | ||
| 270 | pub const F_GETFL = 3; | ||
| 271 | pub const F_SETFL = 4; | ||
| 272 | |||
| 273 | pub const F_SETOWN = 8; | ||
| 274 | pub const F_GETOWN = 9; | ||
| 275 | pub const F_SETSIG = 10; | ||
| 276 | pub const F_GETSIG = 11; | ||
| 277 | |||
| 278 | pub const F_GETLK = 5; | ||
| 279 | pub const F_SETLK = 6; | ||
| 280 | pub const F_SETLKW = 7; | ||
| 281 | |||
| 282 | pub const F_SETOWN_EX = 15; | ||
| 283 | pub const F_GETOWN_EX = 16; | ||
| 284 | |||
| 285 | pub const F_GETOWNER_UIDS = 17; | ||
| 286 | |||
| 287 | pub const SEEK_SET = 0; | ||
| 288 | pub const SEEK_CUR = 1; | ||
| 289 | pub const SEEK_END = 2; | ||
| 290 | |||
| 291 | pub const SIG_BLOCK = 1; | ||
| 292 | pub const SIG_UNBLOCK = 2; | ||
| 293 | pub const SIG_SETMASK = 3; | ||
| 294 | |||
| 295 | pub const SOCK_STREAM = 1; | ||
| 296 | pub const SOCK_DGRAM = 2; | ||
| 297 | pub const SOCK_RAW = 3; | ||
| 298 | pub const SOCK_RDM = 4; | ||
| 299 | pub const SOCK_SEQPACKET = 5; | ||
| 300 | |||
| 301 | pub const SOCK_CLOEXEC = 0x10000000; | ||
| 302 | pub const SOCK_NONBLOCK = 0x20000000; | ||
| 303 | |||
| 304 | pub const PROTO_ip = 0o000; | ||
| 305 | pub const PROTO_icmp = 0o001; | ||
| 306 | pub const PROTO_igmp = 0o002; | ||
| 307 | pub const PROTO_ggp = 0o003; | ||
| 308 | pub const PROTO_ipencap = 0o004; | ||
| 309 | pub const PROTO_st = 0o005; | ||
| 310 | pub const PROTO_tcp = 0o006; | ||
| 311 | pub const PROTO_egp = 0o010; | ||
| 312 | pub const PROTO_pup = 0o014; | ||
| 313 | pub const PROTO_udp = 0o021; | ||
| 314 | pub const PROTO_hmp = 0o024; | ||
| 315 | pub const PROTO_xns_idp = 0o026; | ||
| 316 | pub const PROTO_rdp = 0o033; | ||
| 317 | pub const PROTO_iso_tp4 = 0o035; | ||
| 318 | pub const PROTO_xtp = 0o044; | ||
| 319 | pub const PROTO_ddp = 0o045; | ||
| 320 | pub const PROTO_idpr_cmtp = 0o046; | ||
| 321 | pub const PROTO_ipv6 = 0o051; | ||
| 322 | pub const PROTO_ipv6_route = 0o053; | ||
| 323 | pub const PROTO_ipv6_frag = 0o054; | ||
| 324 | pub const PROTO_idrp = 0o055; | ||
| 325 | pub const PROTO_rsvp = 0o056; | ||
| 326 | pub const PROTO_gre = 0o057; | ||
| 327 | pub const PROTO_esp = 0o062; | ||
| 328 | pub const PROTO_ah = 0o063; | ||
| 329 | pub const PROTO_skip = 0o071; | ||
| 330 | pub const PROTO_ipv6_icmp = 0o072; | ||
| 331 | pub const PROTO_ipv6_nonxt = 0o073; | ||
| 332 | pub const PROTO_ipv6_opts = 0o074; | ||
| 333 | pub const PROTO_rspf = 0o111; | ||
| 334 | pub const PROTO_vmtp = 0o121; | ||
| 335 | pub const PROTO_ospf = 0o131; | ||
| 336 | pub const PROTO_ipip = 0o136; | ||
| 337 | pub const PROTO_encap = 0o142; | ||
| 338 | pub const PROTO_pim = 0o147; | ||
| 339 | pub const PROTO_raw = 0o377; | ||
| 340 | |||
| 341 | pub const PF_UNSPEC = 0; | ||
| 342 | pub const PF_LOCAL = 1; | ||
| 343 | pub const PF_UNIX = PF_LOCAL; | ||
| 344 | pub const PF_FILE = PF_LOCAL; | ||
| 345 | pub const PF_INET = 2; | ||
| 346 | pub const PF_AX25 = 3; | ||
| 347 | pub const PF_IPX = 4; | ||
| 348 | pub const PF_APPLETALK = 5; | ||
| 349 | pub const PF_NETROM = 6; | ||
| 350 | pub const PF_BRIDGE = 7; | ||
| 351 | pub const PF_ATMPVC = 8; | ||
| 352 | pub const PF_X25 = 9; | ||
| 353 | pub const PF_INET6 = 10; | ||
| 354 | pub const PF_ROSE = 11; | ||
| 355 | pub const PF_DECnet = 12; | ||
| 356 | pub const PF_NETBEUI = 13; | ||
| 357 | pub const PF_SECURITY = 14; | ||
| 358 | pub const PF_KEY = 15; | ||
| 359 | pub const PF_NETLINK = 16; | ||
| 360 | pub const PF_ROUTE = PF_NETLINK; | ||
| 361 | pub const PF_PACKET = 17; | ||
| 362 | pub const PF_ASH = 18; | ||
| 363 | pub const PF_ECONET = 19; | ||
| 364 | pub const PF_ATMSVC = 20; | ||
| 365 | pub const PF_RDS = 21; | ||
| 366 | pub const PF_SNA = 22; | ||
| 367 | pub const PF_IRDA = 23; | ||
| 368 | pub const PF_PPPOX = 24; | ||
| 369 | pub const PF_WANPIPE = 25; | ||
| 370 | pub const PF_LLC = 26; | ||
| 371 | pub const PF_IB = 27; | ||
| 372 | pub const PF_MPLS = 28; | ||
| 373 | pub const PF_CAN = 29; | ||
| 374 | pub const PF_TIPC = 30; | ||
| 375 | pub const PF_BLUETOOTH = 31; | ||
| 376 | pub const PF_IUCV = 32; | ||
| 377 | pub const PF_RXRPC = 33; | ||
| 378 | pub const PF_ISDN = 34; | ||
| 379 | pub const PF_PHONET = 35; | ||
| 380 | pub const PF_IEEE802154 = 36; | ||
| 381 | pub const PF_CAIF = 37; | ||
| 382 | pub const PF_ALG = 38; | ||
| 383 | pub const PF_NFC = 39; | ||
| 384 | pub const PF_VSOCK = 40; | ||
| 385 | pub const PF_MAX = 41; | ||
| 386 | |||
| 387 | pub const AF_UNSPEC = PF_UNSPEC; | ||
| 388 | pub const AF_LOCAL = PF_LOCAL; | ||
| 389 | pub const AF_UNIX = AF_LOCAL; | ||
| 390 | pub const AF_FILE = AF_LOCAL; | ||
| 391 | pub const AF_INET = PF_INET; | ||
| 392 | pub const AF_AX25 = PF_AX25; | ||
| 393 | pub const AF_IPX = PF_IPX; | ||
| 394 | pub const AF_APPLETALK = PF_APPLETALK; | ||
| 395 | pub const AF_NETROM = PF_NETROM; | ||
| 396 | pub const AF_BRIDGE = PF_BRIDGE; | ||
| 397 | pub const AF_ATMPVC = PF_ATMPVC; | ||
| 398 | pub const AF_X25 = PF_X25; | ||
| 399 | pub const AF_INET6 = PF_INET6; | ||
| 400 | pub const AF_ROSE = PF_ROSE; | ||
| 401 | pub const AF_DECnet = PF_DECnet; | ||
| 402 | pub const AF_NETBEUI = PF_NETBEUI; | ||
| 403 | pub const AF_SECURITY = PF_SECURITY; | ||
| 404 | pub const AF_KEY = PF_KEY; | ||
| 405 | pub const AF_NETLINK = PF_NETLINK; | ||
| 406 | pub const AF_ROUTE = PF_ROUTE; | ||
| 407 | pub const AF_PACKET = PF_PACKET; | ||
| 408 | pub const AF_ASH = PF_ASH; | ||
| 409 | pub const AF_ECONET = PF_ECONET; | ||
| 410 | pub const AF_ATMSVC = PF_ATMSVC; | ||
| 411 | pub const AF_RDS = PF_RDS; | ||
| 412 | pub const AF_SNA = PF_SNA; | ||
| 413 | pub const AF_IRDA = PF_IRDA; | ||
| 414 | pub const AF_PPPOX = PF_PPPOX; | ||
| 415 | pub const AF_WANPIPE = PF_WANPIPE; | ||
| 416 | pub const AF_LLC = PF_LLC; | ||
| 417 | pub const AF_IB = PF_IB; | ||
| 418 | pub const AF_MPLS = PF_MPLS; | ||
| 419 | pub const AF_CAN = PF_CAN; | ||
| 420 | pub const AF_TIPC = PF_TIPC; | ||
| 421 | pub const AF_BLUETOOTH = PF_BLUETOOTH; | ||
| 422 | pub const AF_IUCV = PF_IUCV; | ||
| 423 | pub const AF_RXRPC = PF_RXRPC; | ||
| 424 | pub const AF_ISDN = PF_ISDN; | ||
| 425 | pub const AF_PHONET = PF_PHONET; | ||
| 426 | pub const AF_IEEE802154 = PF_IEEE802154; | ||
| 427 | pub const AF_CAIF = PF_CAIF; | ||
| 428 | pub const AF_ALG = PF_ALG; | ||
| 429 | pub const AF_NFC = PF_NFC; | ||
| 430 | pub const AF_VSOCK = PF_VSOCK; | ||
| 431 | pub const AF_MAX = PF_MAX; | ||
| 432 | |||
| 433 | pub const DT_UNKNOWN = 0; | ||
| 434 | pub const DT_FIFO = 1; | ||
| 435 | pub const DT_CHR = 2; | ||
| 436 | pub const DT_DIR = 4; | ||
| 437 | pub const DT_BLK = 6; | ||
| 438 | pub const DT_REG = 8; | ||
| 439 | pub const DT_LNK = 10; | ||
| 440 | pub const DT_SOCK = 12; | ||
| 441 | pub const DT_WHT = 14; | ||
| 442 | |||
| 443 | /// add event to kq (implies enable) | ||
| 444 | pub const EV_ADD = 0x0001; | ||
| 445 | |||
| 446 | /// delete event from kq | ||
| 447 | pub const EV_DELETE = 0x0002; | ||
| 448 | |||
| 449 | /// enable event | ||
| 450 | pub const EV_ENABLE = 0x0004; | ||
| 451 | |||
| 452 | /// disable event (not reported) | ||
| 453 | pub const EV_DISABLE = 0x0008; | ||
| 454 | |||
| 455 | /// only report one occurrence | ||
| 456 | pub const EV_ONESHOT = 0x0010; | ||
| 457 | |||
| 458 | /// clear event state after reporting | ||
| 459 | pub const EV_CLEAR = 0x0020; | ||
| 460 | |||
| 461 | /// force immediate event output | ||
| 462 | /// ... with or without EV_ERROR | ||
| 463 | /// ... use KEVENT_FLAG_ERROR_EVENTS | ||
| 464 | /// on syscalls supporting flags | ||
| 465 | pub const EV_RECEIPT = 0x0040; | ||
| 466 | |||
| 467 | /// disable event after reporting | ||
| 468 | pub const EV_DISPATCH = 0x0080; | ||
| 469 | |||
| 470 | pub const EVFILT_READ = -1; | ||
| 471 | pub const EVFILT_WRITE = -2; | ||
| 472 | |||
| 473 | /// attached to aio requests | ||
| 474 | pub const EVFILT_AIO = -3; | ||
| 475 | |||
| 476 | /// attached to vnodes | ||
| 477 | pub const EVFILT_VNODE = -4; | ||
| 478 | |||
| 479 | /// attached to struct proc | ||
| 480 | pub const EVFILT_PROC = -5; | ||
| 481 | |||
| 482 | /// attached to struct proc | ||
| 483 | pub const EVFILT_SIGNAL = -6; | ||
| 484 | |||
| 485 | /// timers | ||
| 486 | pub const EVFILT_TIMER = -7; | ||
| 487 | |||
| 488 | /// Process descriptors | ||
| 489 | pub const EVFILT_PROCDESC = -8; | ||
| 490 | |||
| 491 | /// Filesystem events | ||
| 492 | pub const EVFILT_FS = -9; | ||
| 493 | |||
| 494 | pub const EVFILT_LIO = -10; | ||
| 495 | |||
| 496 | /// User events | ||
| 497 | pub const EVFILT_USER = -11; | ||
| 498 | |||
| 499 | /// Sendfile events | ||
| 500 | pub const EVFILT_SENDFILE = -12; | ||
| 501 | |||
| 502 | pub const EVFILT_EMPTY = -13; | ||
| 503 | |||
| 504 | /// On input, NOTE_TRIGGER causes the event to be triggered for output. | ||
| 505 | pub const NOTE_TRIGGER = 0x01000000; | ||
| 506 | |||
| 507 | /// ignore input fflags | ||
| 508 | pub const NOTE_FFNOP = 0x00000000; | ||
| 509 | |||
| 510 | /// and fflags | ||
| 511 | pub const NOTE_FFAND = 0x40000000; | ||
| 512 | |||
| 513 | /// or fflags | ||
| 514 | pub const NOTE_FFOR = 0x80000000; | ||
| 515 | |||
| 516 | /// copy fflags | ||
| 517 | pub const NOTE_FFCOPY = 0xc0000000; | ||
| 518 | |||
| 519 | /// mask for operations | ||
| 520 | pub const NOTE_FFCTRLMASK = 0xc0000000; | ||
| 521 | pub const NOTE_FFLAGSMASK = 0x00ffffff; | ||
| 522 | |||
| 523 | /// low water mark | ||
| 524 | pub const NOTE_LOWAT = 0x00000001; | ||
| 525 | |||
| 526 | /// behave like poll() | ||
| 527 | pub const NOTE_FILE_POLL = 0x00000002; | ||
| 528 | |||
| 529 | /// vnode was removed | ||
| 530 | pub const NOTE_DELETE = 0x00000001; | ||
| 531 | |||
| 532 | /// data contents changed | ||
| 533 | pub const NOTE_WRITE = 0x00000002; | ||
| 534 | |||
| 535 | /// size increased | ||
| 536 | pub const NOTE_EXTEND = 0x00000004; | ||
| 537 | |||
| 538 | /// attributes changed | ||
| 539 | pub const NOTE_ATTRIB = 0x00000008; | ||
| 540 | |||
| 541 | /// link count changed | ||
| 542 | pub const NOTE_LINK = 0x00000010; | ||
| 543 | |||
| 544 | /// vnode was renamed | ||
| 545 | pub const NOTE_RENAME = 0x00000020; | ||
| 546 | |||
| 547 | /// vnode access was revoked | ||
| 548 | pub const NOTE_REVOKE = 0x00000040; | ||
| 549 | |||
| 550 | /// vnode was opened | ||
| 551 | pub const NOTE_OPEN = 0x00000080; | ||
| 552 | |||
| 553 | /// file closed, fd did not allow write | ||
| 554 | pub const NOTE_CLOSE = 0x00000100; | ||
| 555 | |||
| 556 | /// file closed, fd did allow write | ||
| 557 | pub const NOTE_CLOSE_WRITE = 0x00000200; | ||
| 558 | |||
| 559 | /// file was read | ||
| 560 | pub const NOTE_READ = 0x00000400; | ||
| 561 | |||
| 562 | /// process exited | ||
| 563 | pub const NOTE_EXIT = 0x80000000; | ||
| 564 | |||
| 565 | /// process forked | ||
| 566 | pub const NOTE_FORK = 0x40000000; | ||
| 567 | |||
| 568 | /// process exec'd | ||
| 569 | pub const NOTE_EXEC = 0x20000000; | ||
| 570 | |||
| 571 | /// mask for signal & exit status | ||
| 572 | pub const NOTE_PDATAMASK = 0x000fffff; | ||
| 573 | pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK); | ||
| 574 | |||
| 575 | /// data is seconds | ||
| 576 | pub const NOTE_SECONDS = 0x00000001; | ||
| 577 | |||
| 578 | /// data is milliseconds | ||
| 579 | pub const NOTE_MSECONDS = 0x00000002; | ||
| 580 | |||
| 581 | /// data is microseconds | ||
| 582 | pub const NOTE_USECONDS = 0x00000004; | ||
| 583 | |||
| 584 | /// data is nanoseconds | ||
| 585 | pub const NOTE_NSECONDS = 0x00000008; | ||
| 586 | |||
| 587 | /// timeout is absolute | ||
| 588 | pub const NOTE_ABSTIME = 0x00000010; | ||
| 589 | |||
| 590 | pub const TCGETS = 0x5401; | ||
| 591 | pub const TCSETS = 0x5402; | ||
| 592 | pub const TCSETSW = 0x5403; | ||
| 593 | pub const TCSETSF = 0x5404; | ||
| 594 | pub const TCGETA = 0x5405; | ||
| 595 | pub const TCSETA = 0x5406; | ||
| 596 | pub const TCSETAW = 0x5407; | ||
| 597 | pub const TCSETAF = 0x5408; | ||
| 598 | pub const TCSBRK = 0x5409; | ||
| 599 | pub const TCXONC = 0x540A; | ||
| 600 | pub const TCFLSH = 0x540B; | ||
| 601 | pub const TIOCEXCL = 0x540C; | ||
| 602 | pub const TIOCNXCL = 0x540D; | ||
| 603 | pub const TIOCSCTTY = 0x540E; | ||
| 604 | pub const TIOCGPGRP = 0x540F; | ||
| 605 | pub const TIOCSPGRP = 0x5410; | ||
| 606 | pub const TIOCOUTQ = 0x5411; | ||
| 607 | pub const TIOCSTI = 0x5412; | ||
| 608 | pub const TIOCGWINSZ = 0x5413; | ||
| 609 | pub const TIOCSWINSZ = 0x5414; | ||
| 610 | pub const TIOCMGET = 0x5415; | ||
| 611 | pub const TIOCMBIS = 0x5416; | ||
| 612 | pub const TIOCMBIC = 0x5417; | ||
| 613 | pub const TIOCMSET = 0x5418; | ||
| 614 | pub const TIOCGSOFTCAR = 0x5419; | ||
| 615 | pub const TIOCSSOFTCAR = 0x541A; | ||
| 616 | pub const FIONREAD = 0x541B; | ||
| 617 | pub const TIOCINQ = FIONREAD; | ||
| 618 | pub const TIOCLINUX = 0x541C; | ||
| 619 | pub const TIOCCONS = 0x541D; | ||
| 620 | pub const TIOCGSERIAL = 0x541E; | ||
| 621 | pub const TIOCSSERIAL = 0x541F; | ||
| 622 | pub const TIOCPKT = 0x5420; | ||
| 623 | pub const FIONBIO = 0x5421; | ||
| 624 | pub const TIOCNOTTY = 0x5422; | ||
| 625 | pub const TIOCSETD = 0x5423; | ||
| 626 | pub const TIOCGETD = 0x5424; | ||
| 627 | pub const TCSBRKP = 0x5425; | ||
| 628 | pub const TIOCSBRK = 0x5427; | ||
| 629 | pub const TIOCCBRK = 0x5428; | ||
| 630 | pub const TIOCGSID = 0x5429; | ||
| 631 | pub const TIOCGRS485 = 0x542E; | ||
| 632 | pub const TIOCSRS485 = 0x542F; | ||
| 633 | pub const TIOCGPTN = 0x80045430; | ||
| 634 | pub const TIOCSPTLCK = 0x40045431; | ||
| 635 | pub const TIOCGDEV = 0x80045432; | ||
| 636 | pub const TCGETX = 0x5432; | ||
| 637 | pub const TCSETX = 0x5433; | ||
| 638 | pub const TCSETXF = 0x5434; | ||
| 639 | pub const TCSETXW = 0x5435; | ||
| 640 | pub const TIOCSIG = 0x40045436; | ||
| 641 | pub const TIOCVHANGUP = 0x5437; | ||
| 642 | pub const TIOCGPKT = 0x80045438; | ||
| 643 | pub const TIOCGPTLCK = 0x80045439; | ||
| 644 | pub const TIOCGEXCL = 0x80045440; | ||
| 645 | |||
| 646 | fn unsigned(s: i32) u32 { | ||
| 647 | return @bitCast(u32, s); | ||
| 648 | } | ||
| 649 | fn signed(s: u32) i32 { | ||
| 650 | return @bitCast(i32, s); | ||
| 651 | } | ||
| 652 | pub fn WEXITSTATUS(s: i32) i32 { | ||
| 653 | return signed((unsigned(s) & 0xff00) >> 8); | ||
| 654 | } | ||
| 655 | pub fn WTERMSIG(s: i32) i32 { | ||
| 656 | return signed(unsigned(s) & 0x7f); | ||
| 657 | } | ||
| 658 | pub fn WSTOPSIG(s: i32) i32 { | ||
| 659 | return WEXITSTATUS(s); | ||
| 660 | } | ||
| 661 | pub fn WIFEXITED(s: i32) bool { | ||
| 662 | return WTERMSIG(s) == 0; | ||
| 663 | } | ||
| 664 | pub fn WIFSTOPPED(s: i32) bool { | ||
| 665 | return @intCast(u16, (((unsigned(s) & 0xffff) *% 0x10001) >> 8)) > 0x7f00; | ||
| 666 | } | ||
| 667 | pub fn WIFSIGNALED(s: i32) bool { | ||
| 668 | return (unsigned(s) & 0xffff) -% 1 < 0xff; | ||
| 669 | } | ||
| 670 | |||
| 671 | pub const winsize = extern struct { | ||
| 672 | ws_row: u16, | ||
| 673 | ws_col: u16, | ||
| 674 | ws_xpixel: u16, | ||
| 675 | ws_ypixel: u16, | ||
| 676 | }; | ||
| 677 | |||
| 678 | const NSIG = 32; | ||
| 679 | |||
| 680 | pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize)); | ||
| 681 | pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); | ||
| 682 | pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); | ||
| 683 | |||
| 684 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | ||
| 685 | pub const Sigaction = extern struct { | ||
| 686 | /// signal handler | ||
| 687 | __sigaction_u: extern union { | ||
| 688 | __sa_handler: extern fn (i32) void, | ||
| 689 | __sa_sigaction: extern fn (i32, *__siginfo, usize) void, | ||
| 690 | }, | ||
| 691 | |||
| 692 | /// see signal options | ||
| 693 | sa_flags: u32, | ||
| 694 | |||
| 695 | /// signal mask to apply | ||
| 696 | sa_mask: sigset_t, | ||
| 697 | }; | ||
| 698 | |||
| 699 | pub const _SIG_WORDS = 4; | ||
| 700 | pub const _SIG_MAXSIG = 128; | ||
| 701 | |||
| 702 | pub inline fn _SIG_IDX(sig: usize) usize { | ||
| 703 | return sig - 1; | ||
| 704 | } | ||
| 705 | pub inline fn _SIG_WORD(sig: usize) usize { | ||
| 706 | return_SIG_IDX(sig) >> 5; | ||
| 707 | } | ||
| 708 | pub inline fn _SIG_BIT(sig: usize) usize { | ||
| 709 | return 1 << (_SIG_IDX(sig) & 31); | ||
| 710 | } | ||
| 711 | pub inline fn _SIG_VALID(sig: usize) usize { | ||
| 712 | return sig <= _SIG_MAXSIG and sig > 0; | ||
| 713 | } | ||
| 714 | |||
| 715 | pub const sigset_t = extern struct { | ||
| 716 | __bits: [_SIG_WORDS]u32, | ||
| 717 | }; | ||
| 718 | |||
| 719 | pub const EPERM = 1; // Operation not permitted | ||
| 720 | pub const ENOENT = 2; // No such file or directory | ||
| 721 | pub const ESRCH = 3; // No such process | ||
| 722 | pub const EINTR = 4; // Interrupted system call | ||
| 723 | pub const EIO = 5; // Input/output error | ||
| 724 | pub const ENXIO = 6; // Device not configured | ||
| 725 | pub const E2BIG = 7; // Argument list too long | ||
| 726 | pub const ENOEXEC = 8; // Exec format error | ||
| 727 | pub const EBADF = 9; // Bad file descriptor | ||
| 728 | pub const ECHILD = 10; // No child processes | ||
| 729 | pub const EDEADLK = 11; // Resource deadlock avoided | ||
| 730 | // 11 was EAGAIN | ||
| 731 | pub const ENOMEM = 12; // Cannot allocate memory | ||
| 732 | pub const EACCES = 13; // Permission denied | ||
| 733 | pub const EFAULT = 14; // Bad address | ||
| 734 | pub const ENOTBLK = 15; // Block device required | ||
| 735 | pub const EBUSY = 16; // Device busy | ||
| 736 | pub const EEXIST = 17; // File exists | ||
| 737 | pub const EXDEV = 18; // Cross-device link | ||
| 738 | pub const ENODEV = 19; // Operation not supported by device | ||
| 739 | pub const ENOTDIR = 20; // Not a directory | ||
| 740 | pub const EISDIR = 21; // Is a directory | ||
| 741 | pub const EINVAL = 22; // Invalid argument | ||
| 742 | pub const ENFILE = 23; // Too many open files in system | ||
| 743 | pub const EMFILE = 24; // Too many open files | ||
| 744 | pub const ENOTTY = 25; // Inappropriate ioctl for device | ||
| 745 | pub const ETXTBSY = 26; // Text file busy | ||
| 746 | pub const EFBIG = 27; // File too large | ||
| 747 | pub const ENOSPC = 28; // No space left on device | ||
| 748 | pub const ESPIPE = 29; // Illegal seek | ||
| 749 | pub const EROFS = 30; // Read-only filesystem | ||
| 750 | pub const EMLINK = 31; // Too many links | ||
| 751 | pub const EPIPE = 32; // Broken pipe | ||
| 752 | |||
| 753 | // math software | ||
| 754 | pub const EDOM = 33; // Numerical argument out of domain | ||
| 755 | pub const ERANGE = 34; // Result too large | ||
| 756 | |||
| 757 | // non-blocking and interrupt i/o | ||
| 758 | pub const EAGAIN = 35; // Resource temporarily unavailable | ||
| 759 | pub const EWOULDBLOCK = EAGAIN; // Operation would block | ||
| 760 | pub const EINPROGRESS = 36; // Operation now in progress | ||
| 761 | pub const EALREADY = 37; // Operation already in progress | ||
| 762 | |||
| 763 | // ipc/network software -- argument errors | ||
| 764 | pub const ENOTSOCK = 38; // Socket operation on non-socket | ||
| 765 | pub const EDESTADDRREQ = 39; // Destination address required | ||
| 766 | pub const EMSGSIZE = 40; // Message too long | ||
| 767 | pub const EPROTOTYPE = 41; // Protocol wrong type for socket | ||
| 768 | pub const ENOPROTOOPT = 42; // Protocol not available | ||
| 769 | pub const EPROTONOSUPPORT = 43; // Protocol not supported | ||
| 770 | pub const ESOCKTNOSUPPORT = 44; // Socket type not supported | ||
| 771 | pub const EOPNOTSUPP = 45; // Operation not supported | ||
| 772 | pub const ENOTSUP = EOPNOTSUPP; // Operation not supported | ||
| 773 | pub const EPFNOSUPPORT = 46; // Protocol family not supported | ||
| 774 | pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family | ||
| 775 | pub const EADDRINUSE = 48; // Address already in use | ||
| 776 | pub const EADDRNOTAVAIL = 49; // Can't assign requested address | ||
| 777 | |||
| 778 | // ipc/network software -- operational errors | ||
| 779 | pub const ENETDOWN = 50; // Network is down | ||
| 780 | pub const ENETUNREACH = 51; // Network is unreachable | ||
| 781 | pub const ENETRESET = 52; // Network dropped connection on reset | ||
| 782 | pub const ECONNABORTED = 53; // Software caused connection abort | ||
| 783 | pub const ECONNRESET = 54; // Connection reset by peer | ||
| 784 | pub const ENOBUFS = 55; // No buffer space available | ||
| 785 | pub const EISCONN = 56; // Socket is already connected | ||
| 786 | pub const ENOTCONN = 57; // Socket is not connected | ||
| 787 | pub const ESHUTDOWN = 58; // Can't send after socket shutdown | ||
| 788 | pub const ETOOMANYREFS = 59; // Too many references: can't splice | ||
| 789 | pub const ETIMEDOUT = 60; // Operation timed out | ||
| 790 | pub const ECONNREFUSED = 61; // Connection refused | ||
| 791 | |||
| 792 | pub const ELOOP = 62; // Too many levels of symbolic links | ||
| 793 | pub const ENAMETOOLONG = 63; // File name too long | ||
| 794 | |||
| 795 | // should be rearranged | ||
| 796 | pub const EHOSTDOWN = 64; // Host is down | ||
| 797 | pub const EHOSTUNREACH = 65; // No route to host | ||
| 798 | pub const ENOTEMPTY = 66; // Directory not empty | ||
| 799 | |||
| 800 | // quotas & mush | ||
| 801 | pub const EPROCLIM = 67; // Too many processes | ||
| 802 | pub const EUSERS = 68; // Too many users | ||
| 803 | pub const EDQUOT = 69; // Disc quota exceeded | ||
| 804 | |||
| 805 | // Network File System | ||
| 806 | pub const ESTALE = 70; // Stale NFS file handle | ||
| 807 | pub const EREMOTE = 71; // Too many levels of remote in path | ||
| 808 | pub const EBADRPC = 72; // RPC struct is bad | ||
| 809 | pub const ERPCMISMATCH = 73; // RPC version wrong | ||
| 810 | pub const EPROGUNAVAIL = 74; // RPC prog. not avail | ||
| 811 | pub const EPROGMISMATCH = 75; // Program version wrong | ||
| 812 | pub const EPROCUNAVAIL = 76; // Bad procedure for program | ||
| 813 | |||
| 814 | pub const ENOLCK = 77; // No locks available | ||
| 815 | pub const ENOSYS = 78; // Function not implemented | ||
| 816 | |||
| 817 | pub const EFTYPE = 79; // Inappropriate file type or format | ||
| 818 | pub const EAUTH = 80; // Authentication error | ||
| 819 | pub const ENEEDAUTH = 81; // Need authenticator | ||
| 820 | pub const EIDRM = 82; // Identifier removed | ||
| 821 | pub const ENOMSG = 83; // No message of desired type | ||
| 822 | pub const EOVERFLOW = 84; // Value too large to be stored in data type | ||
| 823 | pub const ECANCELED = 85; // Operation canceled | ||
| 824 | pub const EILSEQ = 86; // Illegal byte sequence | ||
| 825 | pub const ENOATTR = 87; // Attribute not found | ||
| 826 | |||
| 827 | pub const EDOOFUS = 88; // Programming error | ||
| 828 | |||
| 829 | pub const EBADMSG = 89; // Bad message | ||
| 830 | pub const EMULTIHOP = 90; // Multihop attempted | ||
| 831 | pub const ENOLINK = 91; // Link has been severed | ||
| 832 | pub const EPROTO = 92; // Protocol error | ||
| 833 | |||
| 834 | pub const ENOTCAPABLE = 93; // Capabilities insufficient | ||
| 835 | pub const ECAPMODE = 94; // Not permitted in capability mode | ||
| 836 | pub const ENOTRECOVERABLE = 95; // State not recoverable | ||
| 837 | pub const EOWNERDEAD = 96; // Previous owner died | ||
| 838 | |||
| 839 | pub const ELAST = 96; // Must be equal largest errno | ||
std/c/posix/netbsd.zig created+728| ... | @@ -0,0 +1,728 @@ | ||
| 1 | const std = @import("../../std.zig"); | ||
| 2 | const maxInt = std.math.maxInt; | ||
| 3 | |||
| 4 | /// Renamed from `kevent` to `Kevent` to avoid conflict with function name. | ||
| 5 | pub const Kevent = extern struct { | ||
| 6 | ident: usize, | ||
| 7 | filter: i32, | ||
| 8 | flags: u32, | ||
| 9 | fflags: u32, | ||
| 10 | data: i64, | ||
| 11 | udata: usize, | ||
| 12 | }; | ||
| 13 | |||
| 14 | pub const pthread_attr_t = extern struct { | ||
| 15 | pta_magic: u32, | ||
| 16 | pta_flags: c_int, | ||
| 17 | pta_private: *c_void, | ||
| 18 | }; | ||
| 19 | |||
| 20 | pub const msghdr = extern struct { | ||
| 21 | /// optional address | ||
| 22 | msg_name: ?*sockaddr, | ||
| 23 | |||
| 24 | /// size of address | ||
| 25 | msg_namelen: socklen_t, | ||
| 26 | |||
| 27 | /// scatter/gather array | ||
| 28 | msg_iov: [*]iovec, | ||
| 29 | |||
| 30 | /// # elements in msg_iov | ||
| 31 | msg_iovlen: i32, | ||
| 32 | |||
| 33 | /// ancillary data | ||
| 34 | msg_control: ?*c_void, | ||
| 35 | |||
| 36 | /// ancillary data buffer len | ||
| 37 | msg_controllen: socklen_t, | ||
| 38 | |||
| 39 | /// flags on received message | ||
| 40 | msg_flags: i32, | ||
| 41 | }; | ||
| 42 | |||
| 43 | pub const msghdr_const = extern struct { | ||
| 44 | /// optional address | ||
| 45 | msg_name: ?*const sockaddr, | ||
| 46 | |||
| 47 | /// size of address | ||
| 48 | msg_namelen: socklen_t, | ||
| 49 | |||
| 50 | /// scatter/gather array | ||
| 51 | msg_iov: [*]iovec_const, | ||
| 52 | |||
| 53 | /// # elements in msg_iov | ||
| 54 | msg_iovlen: i32, | ||
| 55 | |||
| 56 | /// ancillary data | ||
| 57 | msg_control: ?*c_void, | ||
| 58 | |||
| 59 | /// ancillary data buffer len | ||
| 60 | msg_controllen: socklen_t, | ||
| 61 | |||
| 62 | /// flags on received message | ||
| 63 | msg_flags: i32, | ||
| 64 | }; | ||
| 65 | |||
| 66 | pub const Stat = extern struct { | ||
| 67 | dev: u64, | ||
| 68 | mode: u32, | ||
| 69 | ino: u64, | ||
| 70 | nlink: usize, | ||
| 71 | |||
| 72 | uid: u32, | ||
| 73 | gid: u32, | ||
| 74 | rdev: u64, | ||
| 75 | |||
| 76 | atim: timespec, | ||
| 77 | mtim: timespec, | ||
| 78 | ctim: timespec, | ||
| 79 | birthtim: timespec, | ||
| 80 | |||
| 81 | size: i64, | ||
| 82 | blocks: i64, | ||
| 83 | blksize: isize, | ||
| 84 | flags: u32, | ||
| 85 | gen: u32, | ||
| 86 | __spare: [2]u32, | ||
| 87 | }; | ||
| 88 | |||
| 89 | pub const timespec = extern struct { | ||
| 90 | tv_sec: i64, | ||
| 91 | tv_nsec: isize, | ||
| 92 | }; | ||
| 93 | |||
| 94 | pub const dirent = extern struct { | ||
| 95 | d_fileno: u64, | ||
| 96 | d_reclen: u16, | ||
| 97 | d_namlen: u16, | ||
| 98 | d_type: u8, | ||
| 99 | d_off: i64, | ||
| 100 | d_name: [512]u8, | ||
| 101 | }; | ||
| 102 | |||
| 103 | pub const in_port_t = u16; | ||
| 104 | pub const sa_family_t = u8; | ||
| 105 | |||
| 106 | pub const sockaddr = extern union { | ||
| 107 | in: sockaddr_in, | ||
| 108 | in6: sockaddr_in6, | ||
| 109 | }; | ||
| 110 | |||
| 111 | pub const sockaddr_in = extern struct { | ||
| 112 | len: u8, | ||
| 113 | family: sa_family_t, | ||
| 114 | port: in_port_t, | ||
| 115 | addr: u32, | ||
| 116 | zero: [8]u8, | ||
| 117 | }; | ||
| 118 | |||
| 119 | pub const sockaddr_in6 = extern struct { | ||
| 120 | len: u8, | ||
| 121 | family: sa_family_t, | ||
| 122 | port: in_port_t, | ||
| 123 | flowinfo: u32, | ||
| 124 | addr: [16]u8, | ||
| 125 | scope_id: u32, | ||
| 126 | }; | ||
| 127 | |||
| 128 | pub const CTL_KERN = 1; | ||
| 129 | pub const CTL_DEBUG = 5; | ||
| 130 | |||
| 131 | pub const KERN_PROC_ARGS = 48; // struct: process argv/env | ||
| 132 | pub const KERN_PROC_PATHNAME = 5; // path to executable | ||
| 133 | |||
| 134 | pub const PATH_MAX = 1024; | ||
| 135 | |||
| 136 | pub const STDIN_FILENO = 0; | ||
| 137 | pub const STDOUT_FILENO = 1; | ||
| 138 | pub const STDERR_FILENO = 2; | ||
| 139 | |||
| 140 | pub const PROT_NONE = 0; | ||
| 141 | pub const PROT_READ = 1; | ||
| 142 | pub const PROT_WRITE = 2; | ||
| 143 | pub const PROT_EXEC = 4; | ||
| 144 | |||
| 145 | pub const CLOCK_REALTIME = 0; | ||
| 146 | pub const CLOCK_VIRTUAL = 1; | ||
| 147 | pub const CLOCK_PROF = 2; | ||
| 148 | pub const CLOCK_MONOTONIC = 3; | ||
| 149 | pub const CLOCK_THREAD_CPUTIME_ID = 0x20000000; | ||
| 150 | pub const CLOCK_PROCESS_CPUTIME_ID = 0x40000000; | ||
| 151 | |||
| 152 | pub const MAP_FAILED = maxInt(usize); | ||
| 153 | pub const MAP_SHARED = 0x0001; | ||
| 154 | pub const MAP_PRIVATE = 0x0002; | ||
| 155 | pub const MAP_REMAPDUP = 0x0004; | ||
| 156 | pub const MAP_FIXED = 0x0010; | ||
| 157 | pub const MAP_RENAME = 0x0020; | ||
| 158 | pub const MAP_NORESERVE = 0x0040; | ||
| 159 | pub const MAP_INHERIT = 0x0080; | ||
| 160 | pub const MAP_HASSEMAPHORE = 0x0200; | ||
| 161 | pub const MAP_TRYFIXED = 0x0400; | ||
| 162 | pub const MAP_WIRED = 0x0800; | ||
| 163 | |||
| 164 | pub const MAP_FILE = 0x0000; | ||
| 165 | pub const MAP_NOSYNC = 0x0800; | ||
| 166 | pub const MAP_ANON = 0x1000; | ||
| 167 | pub const MAP_ANONYMOUS = MAP_ANON; | ||
| 168 | pub const MAP_STACK = 0x2000; | ||
| 169 | |||
| 170 | pub const WNOHANG = 0x00000001; | ||
| 171 | pub const WUNTRACED = 0x00000002; | ||
| 172 | pub const WSTOPPED = WUNTRACED; | ||
| 173 | pub const WCONTINUED = 0x00000010; | ||
| 174 | pub const WNOWAIT = 0x00010000; | ||
| 175 | pub const WEXITED = 0x00000020; | ||
| 176 | pub const WTRAPPED = 0x00000040; | ||
| 177 | |||
| 178 | pub const SA_ONSTACK = 0x0001; | ||
| 179 | pub const SA_RESTART = 0x0002; | ||
| 180 | pub const SA_RESETHAND = 0x0004; | ||
| 181 | pub const SA_NOCLDSTOP = 0x0008; | ||
| 182 | pub const SA_NODEFER = 0x0010; | ||
| 183 | pub const SA_NOCLDWAIT = 0x0020; | ||
| 184 | pub const SA_SIGINFO = 0x0040; | ||
| 185 | |||
| 186 | pub const SIGHUP = 1; | ||
| 187 | pub const SIGINT = 2; | ||
| 188 | pub const SIGQUIT = 3; | ||
| 189 | pub const SIGILL = 4; | ||
| 190 | pub const SIGTRAP = 5; | ||
| 191 | pub const SIGABRT = 6; | ||
| 192 | pub const SIGIOT = SIGABRT; | ||
| 193 | pub const SIGEMT = 7; | ||
| 194 | pub const SIGFPE = 8; | ||
| 195 | pub const SIGKILL = 9; | ||
| 196 | pub const SIGBUS = 10; | ||
| 197 | pub const SIGSEGV = 11; | ||
| 198 | pub const SIGSYS = 12; | ||
| 199 | pub const SIGPIPE = 13; | ||
| 200 | pub const SIGALRM = 14; | ||
| 201 | pub const SIGTERM = 15; | ||
| 202 | pub const SIGURG = 16; | ||
| 203 | pub const SIGSTOP = 17; | ||
| 204 | pub const SIGTSTP = 18; | ||
| 205 | pub const SIGCONT = 19; | ||
| 206 | pub const SIGCHLD = 20; | ||
| 207 | pub const SIGTTIN = 21; | ||
| 208 | pub const SIGTTOU = 22; | ||
| 209 | pub const SIGIO = 23; | ||
| 210 | pub const SIGXCPU = 24; | ||
| 211 | pub const SIGXFSZ = 25; | ||
| 212 | pub const SIGVTALRM = 26; | ||
| 213 | pub const SIGPROF = 27; | ||
| 214 | pub const SIGWINCH = 28; | ||
| 215 | pub const SIGINFO = 29; | ||
| 216 | pub const SIGUSR1 = 30; | ||
| 217 | pub const SIGUSR2 = 31; | ||
| 218 | pub const SIGPWR = 32; | ||
| 219 | |||
| 220 | pub const SIGRTMIN = 33; | ||
| 221 | pub const SIGRTMAX = 63; | ||
| 222 | |||
| 223 | // access function | ||
| 224 | pub const F_OK = 0; // test for existence of file | ||
| 225 | pub const X_OK = 1; // test for execute or search permission | ||
| 226 | pub const W_OK = 2; // test for write permission | ||
| 227 | pub const R_OK = 4; // test for read permission | ||
| 228 | |||
| 229 | pub const O_RDONLY = 0x0000; | ||
| 230 | pub const O_WRONLY = 0x0001; | ||
| 231 | pub const O_RDWR = 0x0002; | ||
| 232 | pub const O_ACCMODE = 0x0003; | ||
| 233 | |||
| 234 | pub const O_CREAT = 0x0200; | ||
| 235 | pub const O_EXCL = 0x0800; | ||
| 236 | pub const O_NOCTTY = 0x8000; | ||
| 237 | pub const O_TRUNC = 0x0400; | ||
| 238 | pub const O_APPEND = 0x0008; | ||
| 239 | pub const O_NONBLOCK = 0x0004; | ||
| 240 | pub const O_DSYNC = 0x00010000; | ||
| 241 | pub const O_SYNC = 0x0080; | ||
| 242 | pub const O_RSYNC = 0x00020000; | ||
| 243 | pub const O_DIRECTORY = 0x00080000; | ||
| 244 | pub const O_NOFOLLOW = 0x00000100; | ||
| 245 | pub const O_CLOEXEC = 0x00400000; | ||
| 246 | |||
| 247 | pub const O_ASYNC = 0x0040; | ||
| 248 | pub const O_DIRECT = 0x00080000; | ||
| 249 | pub const O_LARGEFILE = 0; | ||
| 250 | pub const O_NOATIME = 0; | ||
| 251 | pub const O_PATH = 0; | ||
| 252 | pub const O_TMPFILE = 0; | ||
| 253 | pub const O_NDELAY = O_NONBLOCK; | ||
| 254 | |||
| 255 | pub const F_DUPFD = 0; | ||
| 256 | pub const F_GETFD = 1; | ||
| 257 | pub const F_SETFD = 2; | ||
| 258 | pub const F_GETFL = 3; | ||
| 259 | pub const F_SETFL = 4; | ||
| 260 | |||
| 261 | pub const F_GETOWN = 5; | ||
| 262 | pub const F_SETOWN = 6; | ||
| 263 | |||
| 264 | pub const F_GETLK = 7; | ||
| 265 | pub const F_SETLK = 8; | ||
| 266 | pub const F_SETLKW = 9; | ||
| 267 | |||
| 268 | pub const SEEK_SET = 0; | ||
| 269 | pub const SEEK_CUR = 1; | ||
| 270 | pub const SEEK_END = 2; | ||
| 271 | |||
| 272 | pub const SIG_BLOCK = 1; | ||
| 273 | pub const SIG_UNBLOCK = 2; | ||
| 274 | pub const SIG_SETMASK = 3; | ||
| 275 | |||
| 276 | pub const SOCK_STREAM = 1; | ||
| 277 | pub const SOCK_DGRAM = 2; | ||
| 278 | pub const SOCK_RAW = 3; | ||
| 279 | pub const SOCK_RDM = 4; | ||
| 280 | pub const SOCK_SEQPACKET = 5; | ||
| 281 | |||
| 282 | pub const SOCK_CLOEXEC = 0x10000000; | ||
| 283 | pub const SOCK_NONBLOCK = 0x20000000; | ||
| 284 | |||
| 285 | pub const PROTO_ip = 0; | ||
| 286 | pub const PROTO_icmp = 1; | ||
| 287 | pub const PROTO_igmp = 2; | ||
| 288 | pub const PROTO_ggp = 3; | ||
| 289 | pub const PROTO_ipencap = 4; | ||
| 290 | pub const PROTO_tcp = 6; | ||
| 291 | pub const PROTO_egp = 8; | ||
| 292 | pub const PROTO_pup = 12; | ||
| 293 | pub const PROTO_udp = 17; | ||
| 294 | pub const PROTO_xns_idp = 22; | ||
| 295 | pub const PROTO_iso_tp4 = 29; | ||
| 296 | pub const PROTO_ipv6 = 41; | ||
| 297 | pub const PROTO_ipv6_route = 43; | ||
| 298 | pub const PROTO_ipv6_frag = 44; | ||
| 299 | pub const PROTO_rsvp = 46; | ||
| 300 | pub const PROTO_gre = 47; | ||
| 301 | pub const PROTO_esp = 50; | ||
| 302 | pub const PROTO_ah = 51; | ||
| 303 | pub const PROTO_ipv6_icmp = 58; | ||
| 304 | pub const PROTO_ipv6_nonxt = 59; | ||
| 305 | pub const PROTO_ipv6_opts = 60; | ||
| 306 | pub const PROTO_encap = 98; | ||
| 307 | pub const PROTO_pim = 103; | ||
| 308 | pub const PROTO_raw = 255; | ||
| 309 | |||
| 310 | pub const PF_UNSPEC = 0; | ||
| 311 | pub const PF_LOCAL = 1; | ||
| 312 | pub const PF_UNIX = PF_LOCAL; | ||
| 313 | pub const PF_FILE = PF_LOCAL; | ||
| 314 | pub const PF_INET = 2; | ||
| 315 | pub const PF_APPLETALK = 16; | ||
| 316 | pub const PF_INET6 = 24; | ||
| 317 | pub const PF_DECnet = 12; | ||
| 318 | pub const PF_KEY = 29; | ||
| 319 | pub const PF_ROUTE = 34; | ||
| 320 | pub const PF_SNA = 11; | ||
| 321 | pub const PF_MPLS = 33; | ||
| 322 | pub const PF_CAN = 35; | ||
| 323 | pub const PF_BLUETOOTH = 31; | ||
| 324 | pub const PF_ISDN = 26; | ||
| 325 | pub const PF_MAX = 37; | ||
| 326 | |||
| 327 | pub const AF_UNSPEC = PF_UNSPEC; | ||
| 328 | pub const AF_LOCAL = PF_LOCAL; | ||
| 329 | pub const AF_UNIX = AF_LOCAL; | ||
| 330 | pub const AF_FILE = AF_LOCAL; | ||
| 331 | pub const AF_INET = PF_INET; | ||
| 332 | pub const AF_APPLETALK = PF_APPLETALK; | ||
| 333 | pub const AF_INET6 = PF_INET6; | ||
| 334 | pub const AF_KEY = PF_KEY; | ||
| 335 | pub const AF_ROUTE = PF_ROUTE; | ||
| 336 | pub const AF_SNA = PF_SNA; | ||
| 337 | pub const AF_MPLS = PF_MPLS; | ||
| 338 | pub const AF_CAN = PF_CAN; | ||
| 339 | pub const AF_BLUETOOTH = PF_BLUETOOTH; | ||
| 340 | pub const AF_ISDN = PF_ISDN; | ||
| 341 | pub const AF_MAX = PF_MAX; | ||
| 342 | |||
| 343 | pub const DT_UNKNOWN = 0; | ||
| 344 | pub const DT_FIFO = 1; | ||
| 345 | pub const DT_CHR = 2; | ||
| 346 | pub const DT_DIR = 4; | ||
| 347 | pub const DT_BLK = 6; | ||
| 348 | pub const DT_REG = 8; | ||
| 349 | pub const DT_LNK = 10; | ||
| 350 | pub const DT_SOCK = 12; | ||
| 351 | pub const DT_WHT = 14; | ||
| 352 | |||
| 353 | /// add event to kq (implies enable) | ||
| 354 | pub const EV_ADD = 0x0001; | ||
| 355 | |||
| 356 | /// delete event from kq | ||
| 357 | pub const EV_DELETE = 0x0002; | ||
| 358 | |||
| 359 | /// enable event | ||
| 360 | pub const EV_ENABLE = 0x0004; | ||
| 361 | |||
| 362 | /// disable event (not reported) | ||
| 363 | pub const EV_DISABLE = 0x0008; | ||
| 364 | |||
| 365 | /// only report one occurrence | ||
| 366 | pub const EV_ONESHOT = 0x0010; | ||
| 367 | |||
| 368 | /// clear event state after reporting | ||
| 369 | pub const EV_CLEAR = 0x0020; | ||
| 370 | |||
| 371 | /// force immediate event output | ||
| 372 | /// ... with or without EV_ERROR | ||
| 373 | /// ... use KEVENT_FLAG_ERROR_EVENTS | ||
| 374 | /// on syscalls supporting flags | ||
| 375 | pub const EV_RECEIPT = 0x0040; | ||
| 376 | |||
| 377 | /// disable event after reporting | ||
| 378 | pub const EV_DISPATCH = 0x0080; | ||
| 379 | |||
| 380 | pub const EVFILT_READ = 0; | ||
| 381 | pub const EVFILT_WRITE = 1; | ||
| 382 | |||
| 383 | /// attached to aio requests | ||
| 384 | pub const EVFILT_AIO = 2; | ||
| 385 | |||
| 386 | /// attached to vnodes | ||
| 387 | pub const EVFILT_VNODE = 3; | ||
| 388 | |||
| 389 | /// attached to struct proc | ||
| 390 | pub const EVFILT_PROC = 4; | ||
| 391 | |||
| 392 | /// attached to struct proc | ||
| 393 | pub const EVFILT_SIGNAL = 5; | ||
| 394 | |||
| 395 | /// timers | ||
| 396 | pub const EVFILT_TIMER = 6; | ||
| 397 | |||
| 398 | /// Filesystem events | ||
| 399 | pub const EVFILT_FS = 7; | ||
| 400 | |||
| 401 | /// On input, NOTE_TRIGGER causes the event to be triggered for output. | ||
| 402 | pub const NOTE_TRIGGER = 0x08000000; | ||
| 403 | |||
| 404 | /// low water mark | ||
| 405 | pub const NOTE_LOWAT = 0x00000001; | ||
| 406 | |||
| 407 | /// vnode was removed | ||
| 408 | pub const NOTE_DELETE = 0x00000001; | ||
| 409 | |||
| 410 | /// data contents changed | ||
| 411 | pub const NOTE_WRITE = 0x00000002; | ||
| 412 | |||
| 413 | /// size increased | ||
| 414 | pub const NOTE_EXTEND = 0x00000004; | ||
| 415 | |||
| 416 | /// attributes changed | ||
| 417 | pub const NOTE_ATTRIB = 0x00000008; | ||
| 418 | |||
| 419 | /// link count changed | ||
| 420 | pub const NOTE_LINK = 0x00000010; | ||
| 421 | |||
| 422 | /// vnode was renamed | ||
| 423 | pub const NOTE_RENAME = 0x00000020; | ||
| 424 | |||
| 425 | /// vnode access was revoked | ||
| 426 | pub const NOTE_REVOKE = 0x00000040; | ||
| 427 | |||
| 428 | /// process exited | ||
| 429 | pub const NOTE_EXIT = 0x80000000; | ||
| 430 | |||
| 431 | /// process forked | ||
| 432 | pub const NOTE_FORK = 0x40000000; | ||
| 433 | |||
| 434 | /// process exec'd | ||
| 435 | pub const NOTE_EXEC = 0x20000000; | ||
| 436 | |||
| 437 | /// mask for signal & exit status | ||
| 438 | pub const NOTE_PDATAMASK = 0x000fffff; | ||
| 439 | pub const NOTE_PCTRLMASK = 0xf0000000; | ||
| 440 | |||
| 441 | pub const TIOCCBRK = 0x2000747a; | ||
| 442 | pub const TIOCCDTR = 0x20007478; | ||
| 443 | pub const TIOCCONS = 0x80047462; | ||
| 444 | pub const TIOCDCDTIMESTAMP = 0x40107458; | ||
| 445 | pub const TIOCDRAIN = 0x2000745e; | ||
| 446 | pub const TIOCEXCL = 0x2000740d; | ||
| 447 | pub const TIOCEXT = 0x80047460; | ||
| 448 | pub const TIOCFLAG_CDTRCTS = 0x10; | ||
| 449 | pub const TIOCFLAG_CLOCAL = 0x2; | ||
| 450 | pub const TIOCFLAG_CRTSCTS = 0x4; | ||
| 451 | pub const TIOCFLAG_MDMBUF = 0x8; | ||
| 452 | pub const TIOCFLAG_SOFTCAR = 0x1; | ||
| 453 | pub const TIOCFLUSH = 0x80047410; | ||
| 454 | pub const TIOCGETA = 0x402c7413; | ||
| 455 | pub const TIOCGETD = 0x4004741a; | ||
| 456 | pub const TIOCGFLAGS = 0x4004745d; | ||
| 457 | pub const TIOCGLINED = 0x40207442; | ||
| 458 | pub const TIOCGPGRP = 0x40047477; | ||
| 459 | pub const TIOCGQSIZE = 0x40047481; | ||
| 460 | pub const TIOCGRANTPT = 0x20007447; | ||
| 461 | pub const TIOCGSID = 0x40047463; | ||
| 462 | pub const TIOCGSIZE = 0x40087468; | ||
| 463 | pub const TIOCGWINSZ = 0x40087468; | ||
| 464 | pub const TIOCMBIC = 0x8004746b; | ||
| 465 | pub const TIOCMBIS = 0x8004746c; | ||
| 466 | pub const TIOCMGET = 0x4004746a; | ||
| 467 | pub const TIOCMSET = 0x8004746d; | ||
| 468 | pub const TIOCM_CAR = 0x40; | ||
| 469 | pub const TIOCM_CD = 0x40; | ||
| 470 | pub const TIOCM_CTS = 0x20; | ||
| 471 | pub const TIOCM_DSR = 0x100; | ||
| 472 | pub const TIOCM_DTR = 0x2; | ||
| 473 | pub const TIOCM_LE = 0x1; | ||
| 474 | pub const TIOCM_RI = 0x80; | ||
| 475 | pub const TIOCM_RNG = 0x80; | ||
| 476 | pub const TIOCM_RTS = 0x4; | ||
| 477 | pub const TIOCM_SR = 0x10; | ||
| 478 | pub const TIOCM_ST = 0x8; | ||
| 479 | pub const TIOCNOTTY = 0x20007471; | ||
| 480 | pub const TIOCNXCL = 0x2000740e; | ||
| 481 | pub const TIOCOUTQ = 0x40047473; | ||
| 482 | pub const TIOCPKT = 0x80047470; | ||
| 483 | pub const TIOCPKT_DATA = 0x0; | ||
| 484 | pub const TIOCPKT_DOSTOP = 0x20; | ||
| 485 | pub const TIOCPKT_FLUSHREAD = 0x1; | ||
| 486 | pub const TIOCPKT_FLUSHWRITE = 0x2; | ||
| 487 | pub const TIOCPKT_IOCTL = 0x40; | ||
| 488 | pub const TIOCPKT_NOSTOP = 0x10; | ||
| 489 | pub const TIOCPKT_START = 0x8; | ||
| 490 | pub const TIOCPKT_STOP = 0x4; | ||
| 491 | pub const TIOCPTMGET = 0x40287446; | ||
| 492 | pub const TIOCPTSNAME = 0x40287448; | ||
| 493 | pub const TIOCRCVFRAME = 0x80087445; | ||
| 494 | pub const TIOCREMOTE = 0x80047469; | ||
| 495 | pub const TIOCSBRK = 0x2000747b; | ||
| 496 | pub const TIOCSCTTY = 0x20007461; | ||
| 497 | pub const TIOCSDTR = 0x20007479; | ||
| 498 | pub const TIOCSETA = 0x802c7414; | ||
| 499 | pub const TIOCSETAF = 0x802c7416; | ||
| 500 | pub const TIOCSETAW = 0x802c7415; | ||
| 501 | pub const TIOCSETD = 0x8004741b; | ||
| 502 | pub const TIOCSFLAGS = 0x8004745c; | ||
| 503 | pub const TIOCSIG = 0x2000745f; | ||
| 504 | pub const TIOCSLINED = 0x80207443; | ||
| 505 | pub const TIOCSPGRP = 0x80047476; | ||
| 506 | pub const TIOCSQSIZE = 0x80047480; | ||
| 507 | pub const TIOCSSIZE = 0x80087467; | ||
| 508 | pub const TIOCSTART = 0x2000746e; | ||
| 509 | pub const TIOCSTAT = 0x80047465; | ||
| 510 | pub const TIOCSTI = 0x80017472; | ||
| 511 | pub const TIOCSTOP = 0x2000746f; | ||
| 512 | pub const TIOCSWINSZ = 0x80087467; | ||
| 513 | pub const TIOCUCNTL = 0x80047466; | ||
| 514 | pub const TIOCXMTFRAME = 0x80087444; | ||
| 515 | |||
| 516 | fn unsigned(s: i32) u32 { | ||
| 517 | return @bitCast(u32, s); | ||
| 518 | } | ||
| 519 | fn signed(s: u32) i32 { | ||
| 520 | return @bitCast(i32, s); | ||
| 521 | } | ||
| 522 | pub fn WEXITSTATUS(s: i32) i32 { | ||
| 523 | return signed((unsigned(s) >> 8) & 0xff); | ||
| 524 | } | ||
| 525 | pub fn WTERMSIG(s: i32) i32 { | ||
| 526 | return signed(unsigned(s) & 0x7f); | ||
| 527 | } | ||
| 528 | pub fn WSTOPSIG(s: i32) i32 { | ||
| 529 | return WEXITSTATUS(s); | ||
| 530 | } | ||
| 531 | pub fn WIFEXITED(s: i32) bool { | ||
| 532 | return WTERMSIG(s) == 0; | ||
| 533 | } | ||
| 534 | |||
| 535 | pub fn WIFCONTINUED(s: i32) bool { | ||
| 536 | return ((s & 0x7f) == 0xffff); | ||
| 537 | } | ||
| 538 | |||
| 539 | pub fn WIFSTOPPED(s: i32) bool { | ||
| 540 | return ((s & 0x7f != 0x7f) and !WIFCONTINUED(s)); | ||
| 541 | } | ||
| 542 | |||
| 543 | pub fn WIFSIGNALED(s: i32) bool { | ||
| 544 | return !WIFSTOPPED(s) and !WIFCONTINUED(s) and !WIFEXITED(s); | ||
| 545 | } | ||
| 546 | |||
| 547 | pub const winsize = extern struct { | ||
| 548 | ws_row: u16, | ||
| 549 | ws_col: u16, | ||
| 550 | ws_xpixel: u16, | ||
| 551 | ws_ypixel: u16, | ||
| 552 | }; | ||
| 553 | |||
| 554 | const NSIG = 32; | ||
| 555 | |||
| 556 | pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize)); | ||
| 557 | pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); | ||
| 558 | pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); | ||
| 559 | |||
| 560 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | ||
| 561 | pub const Sigaction = extern struct { | ||
| 562 | /// signal handler | ||
| 563 | __sigaction_u: extern union { | ||
| 564 | __sa_handler: extern fn (i32) void, | ||
| 565 | __sa_sigaction: extern fn (i32, *__siginfo, usize) void, | ||
| 566 | }, | ||
| 567 | |||
| 568 | /// see signal options | ||
| 569 | sa_flags: u32, | ||
| 570 | |||
| 571 | /// signal mask to apply | ||
| 572 | sa_mask: sigset_t, | ||
| 573 | }; | ||
| 574 | |||
| 575 | pub const _SIG_WORDS = 4; | ||
| 576 | pub const _SIG_MAXSIG = 128; | ||
| 577 | |||
| 578 | pub inline fn _SIG_IDX(sig: usize) usize { | ||
| 579 | return sig - 1; | ||
| 580 | } | ||
| 581 | pub inline fn _SIG_WORD(sig: usize) usize { | ||
| 582 | return_SIG_IDX(sig) >> 5; | ||
| 583 | } | ||
| 584 | pub inline fn _SIG_BIT(sig: usize) usize { | ||
| 585 | return 1 << (_SIG_IDX(sig) & 31); | ||
| 586 | } | ||
| 587 | pub inline fn _SIG_VALID(sig: usize) usize { | ||
| 588 | return sig <= _SIG_MAXSIG and sig > 0; | ||
| 589 | } | ||
| 590 | |||
| 591 | pub const sigset_t = extern struct { | ||
| 592 | __bits: [_SIG_WORDS]u32, | ||
| 593 | }; | ||
| 594 | |||
| 595 | pub const EPERM = 1; // Operation not permitted | ||
| 596 | pub const ENOENT = 2; // No such file or directory | ||
| 597 | pub const ESRCH = 3; // No such process | ||
| 598 | pub const EINTR = 4; // Interrupted system call | ||
| 599 | pub const EIO = 5; // Input/output error | ||
| 600 | pub const ENXIO = 6; // Device not configured | ||
| 601 | pub const E2BIG = 7; // Argument list too long | ||
| 602 | pub const ENOEXEC = 8; // Exec format error | ||
| 603 | pub const EBADF = 9; // Bad file descriptor | ||
| 604 | pub const ECHILD = 10; // No child processes | ||
| 605 | pub const EDEADLK = 11; // Resource deadlock avoided | ||
| 606 | // 11 was EAGAIN | ||
| 607 | pub const ENOMEM = 12; // Cannot allocate memory | ||
| 608 | pub const EACCES = 13; // Permission denied | ||
| 609 | pub const EFAULT = 14; // Bad address | ||
| 610 | pub const ENOTBLK = 15; // Block device required | ||
| 611 | pub const EBUSY = 16; // Device busy | ||
| 612 | pub const EEXIST = 17; // File exists | ||
| 613 | pub const EXDEV = 18; // Cross-device link | ||
| 614 | pub const ENODEV = 19; // Operation not supported by device | ||
| 615 | pub const ENOTDIR = 20; // Not a directory | ||
| 616 | pub const EISDIR = 21; // Is a directory | ||
| 617 | pub const EINVAL = 22; // Invalid argument | ||
| 618 | pub const ENFILE = 23; // Too many open files in system | ||
| 619 | pub const EMFILE = 24; // Too many open files | ||
| 620 | pub const ENOTTY = 25; // Inappropriate ioctl for device | ||
| 621 | pub const ETXTBSY = 26; // Text file busy | ||
| 622 | pub const EFBIG = 27; // File too large | ||
| 623 | pub const ENOSPC = 28; // No space left on device | ||
| 624 | pub const ESPIPE = 29; // Illegal seek | ||
| 625 | pub const EROFS = 30; // Read-only file system | ||
| 626 | pub const EMLINK = 31; // Too many links | ||
| 627 | pub const EPIPE = 32; // Broken pipe | ||
| 628 | |||
| 629 | // math software | ||
| 630 | pub const EDOM = 33; // Numerical argument out of domain | ||
| 631 | pub const ERANGE = 34; // Result too large or too small | ||
| 632 | |||
| 633 | // non-blocking and interrupt i/o | ||
| 634 | pub const EAGAIN = 35; // Resource temporarily unavailable | ||
| 635 | pub const EWOULDBLOCK = EAGAIN; // Operation would block | ||
| 636 | pub const EINPROGRESS = 36; // Operation now in progress | ||
| 637 | pub const EALREADY = 37; // Operation already in progress | ||
| 638 | |||
| 639 | // ipc/network software -- argument errors | ||
| 640 | pub const ENOTSOCK = 38; // Socket operation on non-socket | ||
| 641 | pub const EDESTADDRREQ = 39; // Destination address required | ||
| 642 | pub const EMSGSIZE = 40; // Message too long | ||
| 643 | pub const EPROTOTYPE = 41; // Protocol wrong type for socket | ||
| 644 | pub const ENOPROTOOPT = 42; // Protocol option not available | ||
| 645 | pub const EPROTONOSUPPORT = 43; // Protocol not supported | ||
| 646 | pub const ESOCKTNOSUPPORT = 44; // Socket type not supported | ||
| 647 | pub const EOPNOTSUPP = 45; // Operation not supported | ||
| 648 | pub const EPFNOSUPPORT = 46; // Protocol family not supported | ||
| 649 | pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family | ||
| 650 | pub const EADDRINUSE = 48; // Address already in use | ||
| 651 | pub const EADDRNOTAVAIL = 49; // Can't assign requested address | ||
| 652 | |||
| 653 | // ipc/network software -- operational errors | ||
| 654 | pub const ENETDOWN = 50; // Network is down | ||
| 655 | pub const ENETUNREACH = 51; // Network is unreachable | ||
| 656 | pub const ENETRESET = 52; // Network dropped connection on reset | ||
| 657 | pub const ECONNABORTED = 53; // Software caused connection abort | ||
| 658 | pub const ECONNRESET = 54; // Connection reset by peer | ||
| 659 | pub const ENOBUFS = 55; // No buffer space available | ||
| 660 | pub const EISCONN = 56; // Socket is already connected | ||
| 661 | pub const ENOTCONN = 57; // Socket is not connected | ||
| 662 | pub const ESHUTDOWN = 58; // Can't send after socket shutdown | ||
| 663 | pub const ETOOMANYREFS = 59; // Too many references: can't splice | ||
| 664 | pub const ETIMEDOUT = 60; // Operation timed out | ||
| 665 | pub const ECONNREFUSED = 61; // Connection refused | ||
| 666 | |||
| 667 | pub const ELOOP = 62; // Too many levels of symbolic links | ||
| 668 | pub const ENAMETOOLONG = 63; // File name too long | ||
| 669 | |||
| 670 | // should be rearranged | ||
| 671 | pub const EHOSTDOWN = 64; // Host is down | ||
| 672 | pub const EHOSTUNREACH = 65; // No route to host | ||
| 673 | pub const ENOTEMPTY = 66; // Directory not empty | ||
| 674 | |||
| 675 | // quotas & mush | ||
| 676 | pub const EPROCLIM = 67; // Too many processes | ||
| 677 | pub const EUSERS = 68; // Too many users | ||
| 678 | pub const EDQUOT = 69; // Disc quota exceeded | ||
| 679 | |||
| 680 | // Network File System | ||
| 681 | pub const ESTALE = 70; // Stale NFS file handle | ||
| 682 | pub const EREMOTE = 71; // Too many levels of remote in path | ||
| 683 | pub const EBADRPC = 72; // RPC struct is bad | ||
| 684 | pub const ERPCMISMATCH = 73; // RPC version wrong | ||
| 685 | pub const EPROGUNAVAIL = 74; // RPC prog. not avail | ||
| 686 | pub const EPROGMISMATCH = 75; // Program version wrong | ||
| 687 | pub const EPROCUNAVAIL = 76; // Bad procedure for program | ||
| 688 | |||
| 689 | pub const ENOLCK = 77; // No locks available | ||
| 690 | pub const ENOSYS = 78; // Function not implemented | ||
| 691 | |||
| 692 | pub const EFTYPE = 79; // Inappropriate file type or format | ||
| 693 | pub const EAUTH = 80; // Authentication error | ||
| 694 | pub const ENEEDAUTH = 81; // Need authenticator | ||
| 695 | |||
| 696 | // SystemV IPC | ||
| 697 | pub const EIDRM = 82; // Identifier removed | ||
| 698 | pub const ENOMSG = 83; // No message of desired type | ||
| 699 | pub const EOVERFLOW = 84; // Value too large to be stored in data type | ||
| 700 | |||
| 701 | // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995 | ||
| 702 | pub const EILSEQ = 85; // Illegal byte sequence | ||
| 703 | |||
| 704 | // From IEEE Std 1003.1-2001 | ||
| 705 | // Base, Realtime, Threads or Thread Priority Scheduling option errors | ||
| 706 | pub const ENOTSUP = 86; // Not supported | ||
| 707 | |||
| 708 | // Realtime option errors | ||
| 709 | pub const ECANCELED = 87; // Operation canceled | ||
| 710 | |||
| 711 | // Realtime, XSI STREAMS option errors | ||
| 712 | pub const EBADMSG = 88; // Bad or Corrupt message | ||
| 713 | |||
| 714 | // XSI STREAMS option errors | ||
| 715 | pub const ENODATA = 89; // No message available | ||
| 716 | pub const ENOSR = 90; // No STREAM resources | ||
| 717 | pub const ENOSTR = 91; // Not a STREAM | ||
| 718 | pub const ETIME = 92; // STREAM ioctl timeout | ||
| 719 | |||
| 720 | // File system extended attribute errors | ||
| 721 | pub const ENOATTR = 93; // Attribute not found | ||
| 722 | |||
| 723 | // Realtime, XSI STREAMS option errors | ||
| 724 | pub const EMULTIHOP = 94; // Multihop attempted | ||
| 725 | pub const ENOLINK = 95; // Link has been severed | ||
| 726 | pub const EPROTO = 96; // Protocol error | ||
| 727 | |||
| 728 | pub const ELAST = 96; // Must equal largest errno | ||
std/c/posix/windows.zig created+86| ... | @@ -0,0 +1,86 @@ | ||
| 1 | pub const EPERM = 1; | ||
| 2 | pub const ENOENT = 2; | ||
| 3 | pub const ESRCH = 3; | ||
| 4 | pub const EINTR = 4; | ||
| 5 | pub const EIO = 5; | ||
| 6 | pub const ENXIO = 6; | ||
| 7 | pub const E2BIG = 7; | ||
| 8 | pub const ENOEXEC = 8; | ||
| 9 | pub const EBADF = 9; | ||
| 10 | pub const ECHILD = 10; | ||
| 11 | pub const EAGAIN = 11; | ||
| 12 | pub const ENOMEM = 12; | ||
| 13 | pub const EACCES = 13; | ||
| 14 | pub const EFAULT = 14; | ||
| 15 | pub const EBUSY = 16; | ||
| 16 | pub const EEXIST = 17; | ||
| 17 | pub const EXDEV = 18; | ||
| 18 | pub const ENODEV = 19; | ||
| 19 | pub const ENOTDIR = 20; | ||
| 20 | pub const EISDIR = 21; | ||
| 21 | pub const ENFILE = 23; | ||
| 22 | pub const EMFILE = 24; | ||
| 23 | pub const ENOTTY = 25; | ||
| 24 | pub const EFBIG = 27; | ||
| 25 | pub const ENOSPC = 28; | ||
| 26 | pub const ESPIPE = 29; | ||
| 27 | pub const EROFS = 30; | ||
| 28 | pub const EMLINK = 31; | ||
| 29 | pub const EPIPE = 32; | ||
| 30 | pub const EDOM = 33; | ||
| 31 | pub const EDEADLK = 36; | ||
| 32 | pub const ENAMETOOLONG = 38; | ||
| 33 | pub const ENOLCK = 39; | ||
| 34 | pub const ENOSYS = 40; | ||
| 35 | pub const ENOTEMPTY = 41; | ||
| 36 | |||
| 37 | pub const EINVAL = 22; | ||
| 38 | pub const ERANGE = 34; | ||
| 39 | pub const EILSEQ = 42; | ||
| 40 | pub const STRUNCATE = 80; | ||
| 41 | |||
| 42 | // Support EDEADLOCK for compatibility with older Microsoft C versions | ||
| 43 | pub const EDEADLOCK = EDEADLK; | ||
| 44 | |||
| 45 | // POSIX Supplement | ||
| 46 | pub const EADDRINUSE = 100; | ||
| 47 | pub const EADDRNOTAVAIL = 101; | ||
| 48 | pub const EAFNOSUPPORT = 102; | ||
| 49 | pub const EALREADY = 103; | ||
| 50 | pub const EBADMSG = 104; | ||
| 51 | pub const ECANCELED = 105; | ||
| 52 | pub const ECONNABORTED = 106; | ||
| 53 | pub const ECONNREFUSED = 107; | ||
| 54 | pub const ECONNRESET = 108; | ||
| 55 | pub const EDESTADDRREQ = 109; | ||
| 56 | pub const EHOSTUNREACH = 110; | ||
| 57 | pub const EIDRM = 111; | ||
| 58 | pub const EINPROGRESS = 112; | ||
| 59 | pub const EISCONN = 113; | ||
| 60 | pub const ELOOP = 114; | ||
| 61 | pub const EMSGSIZE = 115; | ||
| 62 | pub const ENETDOWN = 116; | ||
| 63 | pub const ENETRESET = 117; | ||
| 64 | pub const ENETUNREACH = 118; | ||
| 65 | pub const ENOBUFS = 119; | ||
| 66 | pub const ENODATA = 120; | ||
| 67 | pub const ENOLINK = 121; | ||
| 68 | pub const ENOMSG = 122; | ||
| 69 | pub const ENOPROTOOPT = 123; | ||
| 70 | pub const ENOSR = 124; | ||
| 71 | pub const ENOSTR = 125; | ||
| 72 | pub const ENOTCONN = 126; | ||
| 73 | pub const ENOTRECOVERABLE = 127; | ||
| 74 | pub const ENOTSOCK = 128; | ||
| 75 | pub const ENOTSUP = 129; | ||
| 76 | pub const EOPNOTSUPP = 130; | ||
| 77 | pub const EOTHER = 131; | ||
| 78 | pub const EOVERFLOW = 132; | ||
| 79 | pub const EOWNERDEAD = 133; | ||
| 80 | pub const EPROTO = 134; | ||
| 81 | pub const EPROTONOSUPPORT = 135; | ||
| 82 | pub const EPROTOTYPE = 136; | ||
| 83 | pub const ETIME = 137; | ||
| 84 | pub const ETIMEDOUT = 138; | ||
| 85 | pub const ETXTBSY = 139; | ||
| 86 | pub const EWOULDBLOCK = 140; | ||
std/event/fs.zig+25-24| ... | @@ -8,6 +8,7 @@ const mem = std.mem; | ... | @@ -8,6 +8,7 @@ const mem = std.mem; |
| 8 | const posix = os.posix; | 8 | const posix = os.posix; |
| 9 | const windows = os.windows; | 9 | const windows = os.windows; |
| 10 | const Loop = event.Loop; | 10 | const Loop = event.Loop; |
| 11 | const fd_t = posix.fd_t; | ||
| 11 | 12 | ||
| 12 | pub const RequestNode = std.atomic.Queue(Request).Node; | 13 | pub const RequestNode = std.atomic.Queue(Request).Node; |
| 13 | 14 | ||
| ... | @@ -30,7 +31,7 @@ pub const Request = struct { | ... | @@ -30,7 +31,7 @@ pub const Request = struct { |
| 30 | End, // special - means the fs thread should exit | 31 | End, // special - means the fs thread should exit |
| 31 | 32 | ||
| 32 | pub const PWriteV = struct { | 33 | pub const PWriteV = struct { |
| 33 | fd: os.FileHandle, | 34 | fd: fd_t, |
| 34 | iov: []const os.posix.iovec_const, | 35 | iov: []const os.posix.iovec_const, |
| 35 | offset: usize, | 36 | offset: usize, |
| 36 | result: Error!void, | 37 | result: Error!void, |
| ... | @@ -39,7 +40,7 @@ pub const Request = struct { | ... | @@ -39,7 +40,7 @@ pub const Request = struct { |
| 39 | }; | 40 | }; |
| 40 | 41 | ||
| 41 | pub const PReadV = struct { | 42 | pub const PReadV = struct { |
| 42 | fd: os.FileHandle, | 43 | fd: fd_t, |
| 43 | iov: []const os.posix.iovec, | 44 | iov: []const os.posix.iovec, |
| 44 | offset: usize, | 45 | offset: usize, |
| 45 | result: Error!usize, | 46 | result: Error!usize, |
| ... | @@ -52,7 +53,7 @@ pub const Request = struct { | ... | @@ -52,7 +53,7 @@ pub const Request = struct { |
| 52 | path: []const u8, | 53 | path: []const u8, |
| 53 | flags: u32, | 54 | flags: u32, |
| 54 | mode: os.File.Mode, | 55 | mode: os.File.Mode, |
| 55 | result: Error!os.FileHandle, | 56 | result: Error!fd_t, |
| 56 | 57 | ||
| 57 | pub const Error = os.File.OpenError; | 58 | pub const Error = os.File.OpenError; |
| 58 | }; | 59 | }; |
| ... | @@ -68,7 +69,7 @@ pub const Request = struct { | ... | @@ -68,7 +69,7 @@ pub const Request = struct { |
| 68 | }; | 69 | }; |
| 69 | 70 | ||
| 70 | pub const Close = struct { | 71 | pub const Close = struct { |
| 71 | fd: os.FileHandle, | 72 | fd: fd_t, |
| 72 | }; | 73 | }; |
| 73 | }; | 74 | }; |
| 74 | }; | 75 | }; |
| ... | @@ -76,7 +77,7 @@ pub const Request = struct { | ... | @@ -76,7 +77,7 @@ pub const Request = struct { |
| 76 | pub const PWriteVError = error{OutOfMemory} || os.File.WriteError; | 77 | pub const PWriteVError = error{OutOfMemory} || os.File.WriteError; |
| 77 | 78 | ||
| 78 | /// data - just the inner references - must live until pwritev promise completes. | 79 | /// data - just the inner references - must live until pwritev promise completes. |
| 79 | pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, offset: usize) PWriteVError!void { | 80 | pub async fn pwritev(loop: *Loop, fd: fd_t, data: []const []const u8, offset: usize) PWriteVError!void { |
| 80 | // workaround for https://github.com/ziglang/zig/issues/1194 | 81 | // workaround for https://github.com/ziglang/zig/issues/1194 |
| 81 | suspend { | 82 | suspend { |
| 82 | resume @handle(); | 83 | resume @handle(); |
| ... | @@ -109,7 +110,7 @@ pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, o | ... | @@ -109,7 +110,7 @@ pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, o |
| 109 | } | 110 | } |
| 110 | 111 | ||
| 111 | /// data must outlive the returned promise | 112 | /// data must outlive the returned promise |
| 112 | pub async fn pwritevWindows(loop: *Loop, fd: os.FileHandle, data: []const []const u8, offset: usize) os.WindowsWriteError!void { | 113 | pub async fn pwritevWindows(loop: *Loop, fd: fd_t, data: []const []const u8, offset: usize) os.WindowsWriteError!void { |
| 113 | if (data.len == 0) return; | 114 | if (data.len == 0) return; |
| 114 | if (data.len == 1) return await (async pwriteWindows(loop, fd, data[0], offset) catch unreachable); | 115 | if (data.len == 1) return await (async pwriteWindows(loop, fd, data[0], offset) catch unreachable); |
| 115 | 116 | ||
| ... | @@ -121,7 +122,7 @@ pub async fn pwritevWindows(loop: *Loop, fd: os.FileHandle, data: []const []cons | ... | @@ -121,7 +122,7 @@ pub async fn pwritevWindows(loop: *Loop, fd: os.FileHandle, data: []const []cons |
| 121 | } | 122 | } |
| 122 | } | 123 | } |
| 123 | 124 | ||
| 124 | pub async fn pwriteWindows(loop: *Loop, fd: os.FileHandle, data: []const u8, offset: u64) os.WindowsWriteError!void { | 125 | pub async fn pwriteWindows(loop: *Loop, fd: fd_t, data: []const u8, offset: u64) os.WindowsWriteError!void { |
| 125 | // workaround for https://github.com/ziglang/zig/issues/1194 | 126 | // workaround for https://github.com/ziglang/zig/issues/1194 |
| 126 | suspend { | 127 | suspend { |
| 127 | resume @handle(); | 128 | resume @handle(); |
| ... | @@ -169,7 +170,7 @@ pub async fn pwriteWindows(loop: *Loop, fd: os.FileHandle, data: []const u8, off | ... | @@ -169,7 +170,7 @@ pub async fn pwriteWindows(loop: *Loop, fd: os.FileHandle, data: []const u8, off |
| 169 | /// iovecs must live until pwritev promise completes. | 170 | /// iovecs must live until pwritev promise completes. |
| 170 | pub async fn pwritevPosix( | 171 | pub async fn pwritevPosix( |
| 171 | loop: *Loop, | 172 | loop: *Loop, |
| 172 | fd: os.FileHandle, | 173 | fd: fd_t, |
| 173 | iovecs: []const posix.iovec_const, | 174 | iovecs: []const posix.iovec_const, |
| 174 | offset: usize, | 175 | offset: usize, |
| 175 | ) os.PosixWriteError!void { | 176 | ) os.PosixWriteError!void { |
| ... | @@ -212,7 +213,7 @@ pub async fn pwritevPosix( | ... | @@ -212,7 +213,7 @@ pub async fn pwritevPosix( |
| 212 | pub const PReadVError = error{OutOfMemory} || os.File.ReadError; | 213 | pub const PReadVError = error{OutOfMemory} || os.File.ReadError; |
| 213 | 214 | ||
| 214 | /// data - just the inner references - must live until preadv promise completes. | 215 | /// data - just the inner references - must live until preadv promise completes. |
| 215 | pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset: usize) PReadVError!usize { | 216 | pub async fn preadv(loop: *Loop, fd: fd_t, data: []const []u8, offset: usize) PReadVError!usize { |
| 216 | // workaround for https://github.com/ziglang/zig/issues/1194 | 217 | // workaround for https://github.com/ziglang/zig/issues/1194 |
| 217 | suspend { | 218 | suspend { |
| 218 | resume @handle(); | 219 | resume @handle(); |
| ... | @@ -247,7 +248,7 @@ pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset: | ... | @@ -247,7 +248,7 @@ pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset: |
| 247 | } | 248 | } |
| 248 | 249 | ||
| 249 | /// data must outlive the returned promise | 250 | /// data must outlive the returned promise |
| 250 | pub async fn preadvWindows(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset: u64) os.WindowsReadError!usize { | 251 | pub async fn preadvWindows(loop: *Loop, fd: fd_t, data: []const []u8, offset: u64) os.WindowsReadError!usize { |
| 251 | assert(data.len != 0); | 252 | assert(data.len != 0); |
| 252 | if (data.len == 1) return await (async preadWindows(loop, fd, data[0], offset) catch unreachable); | 253 | if (data.len == 1) return await (async preadWindows(loop, fd, data[0], offset) catch unreachable); |
| 253 | 254 | ||
| ... | @@ -271,7 +272,7 @@ pub async fn preadvWindows(loop: *Loop, fd: os.FileHandle, data: []const []u8, o | ... | @@ -271,7 +272,7 @@ pub async fn preadvWindows(loop: *Loop, fd: os.FileHandle, data: []const []u8, o |
| 271 | } | 272 | } |
| 272 | } | 273 | } |
| 273 | 274 | ||
| 274 | pub async fn preadWindows(loop: *Loop, fd: os.FileHandle, data: []u8, offset: u64) !usize { | 275 | pub async fn preadWindows(loop: *Loop, fd: fd_t, data: []u8, offset: u64) !usize { |
| 275 | // workaround for https://github.com/ziglang/zig/issues/1194 | 276 | // workaround for https://github.com/ziglang/zig/issues/1194 |
| 276 | suspend { | 277 | suspend { |
| 277 | resume @handle(); | 278 | resume @handle(); |
| ... | @@ -318,7 +319,7 @@ pub async fn preadWindows(loop: *Loop, fd: os.FileHandle, data: []u8, offset: u6 | ... | @@ -318,7 +319,7 @@ pub async fn preadWindows(loop: *Loop, fd: os.FileHandle, data: []u8, offset: u6 |
| 318 | /// iovecs must live until preadv promise completes | 319 | /// iovecs must live until preadv promise completes |
| 319 | pub async fn preadvPosix( | 320 | pub async fn preadvPosix( |
| 320 | loop: *Loop, | 321 | loop: *Loop, |
| 321 | fd: os.FileHandle, | 322 | fd: fd_t, |
| 322 | iovecs: []const posix.iovec, | 323 | iovecs: []const posix.iovec, |
| 323 | offset: usize, | 324 | offset: usize, |
| 324 | ) os.PosixReadError!usize { | 325 | ) os.PosixReadError!usize { |
| ... | @@ -363,7 +364,7 @@ pub async fn openPosix( | ... | @@ -363,7 +364,7 @@ pub async fn openPosix( |
| 363 | path: []const u8, | 364 | path: []const u8, |
| 364 | flags: u32, | 365 | flags: u32, |
| 365 | mode: os.File.Mode, | 366 | mode: os.File.Mode, |
| 366 | ) os.File.OpenError!os.FileHandle { | 367 | ) os.File.OpenError!fd_t { |
| 367 | // workaround for https://github.com/ziglang/zig/issues/1194 | 368 | // workaround for https://github.com/ziglang/zig/issues/1194 |
| 368 | suspend { | 369 | suspend { |
| 369 | resume @handle(); | 370 | resume @handle(); |
| ... | @@ -402,7 +403,7 @@ pub async fn openPosix( | ... | @@ -402,7 +403,7 @@ pub async fn openPosix( |
| 402 | return req_node.data.msg.Open.result; | 403 | return req_node.data.msg.Open.result; |
| 403 | } | 404 | } |
| 404 | 405 | ||
| 405 | pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle { | 406 | pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!fd_t { |
| 406 | switch (builtin.os) { | 407 | switch (builtin.os) { |
| 407 | builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => { | 408 | builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 408 | const flags = posix.O_LARGEFILE | posix.O_RDONLY | posix.O_CLOEXEC; | 409 | const flags = posix.O_LARGEFILE | posix.O_RDONLY | posix.O_CLOEXEC; |
| ... | @@ -423,12 +424,12 @@ pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHa | ... | @@ -423,12 +424,12 @@ pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHa |
| 423 | 424 | ||
| 424 | /// Creates if does not exist. Truncates the file if it exists. | 425 | /// Creates if does not exist. Truncates the file if it exists. |
| 425 | /// Uses the default mode. | 426 | /// Uses the default mode. |
| 426 | pub async fn openWrite(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle { | 427 | pub async fn openWrite(loop: *Loop, path: []const u8) os.File.OpenError!fd_t { |
| 427 | return await (async openWriteMode(loop, path, os.File.default_mode) catch unreachable); | 428 | return await (async openWriteMode(loop, path, os.File.default_mode) catch unreachable); |
| 428 | } | 429 | } |
| 429 | 430 | ||
| 430 | /// Creates if does not exist. Truncates the file if it exists. | 431 | /// Creates if does not exist. Truncates the file if it exists. |
| 431 | pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: os.File.Mode) os.File.OpenError!os.FileHandle { | 432 | pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: os.File.Mode) os.File.OpenError!fd_t { |
| 432 | switch (builtin.os) { | 433 | switch (builtin.os) { |
| 433 | builtin.Os.macosx, | 434 | builtin.Os.macosx, |
| 434 | builtin.Os.linux, | 435 | builtin.Os.linux, |
| ... | @@ -454,7 +455,7 @@ pub async fn openReadWrite( | ... | @@ -454,7 +455,7 @@ pub async fn openReadWrite( |
| 454 | loop: *Loop, | 455 | loop: *Loop, |
| 455 | path: []const u8, | 456 | path: []const u8, |
| 456 | mode: os.File.Mode, | 457 | mode: os.File.Mode, |
| 457 | ) os.File.OpenError!os.FileHandle { | 458 | ) os.File.OpenError!fd_t { |
| 458 | switch (builtin.os) { | 459 | switch (builtin.os) { |
| 459 | builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => { | 460 | builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 460 | const flags = posix.O_LARGEFILE | posix.O_RDWR | posix.O_CREAT | posix.O_CLOEXEC; | 461 | const flags = posix.O_LARGEFILE | posix.O_RDWR | posix.O_CREAT | posix.O_CLOEXEC; |
| ... | @@ -487,7 +488,7 @@ pub const CloseOperation = struct { | ... | @@ -487,7 +488,7 @@ pub const CloseOperation = struct { |
| 487 | builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => OsDataPosix, | 488 | builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => OsDataPosix, |
| 488 | 489 | ||
| 489 | builtin.Os.windows => struct { | 490 | builtin.Os.windows => struct { |
| 490 | handle: ?os.FileHandle, | 491 | handle: ?fd_t, |
| 491 | }, | 492 | }, |
| 492 | 493 | ||
| 493 | else => @compileError("Unsupported OS"), | 494 | else => @compileError("Unsupported OS"), |
| ... | @@ -551,7 +552,7 @@ pub const CloseOperation = struct { | ... | @@ -551,7 +552,7 @@ pub const CloseOperation = struct { |
| 551 | } | 552 | } |
| 552 | } | 553 | } |
| 553 | 554 | ||
| 554 | pub fn setHandle(self: *CloseOperation, handle: os.FileHandle) void { | 555 | pub fn setHandle(self: *CloseOperation, handle: fd_t) void { |
| 555 | switch (builtin.os) { | 556 | switch (builtin.os) { |
| 556 | builtin.Os.linux, | 557 | builtin.Os.linux, |
| 557 | builtin.Os.macosx, | 558 | builtin.Os.macosx, |
| ... | @@ -585,7 +586,7 @@ pub const CloseOperation = struct { | ... | @@ -585,7 +586,7 @@ pub const CloseOperation = struct { |
| 585 | } | 586 | } |
| 586 | } | 587 | } |
| 587 | 588 | ||
| 588 | pub fn getHandle(self: *CloseOperation) os.FileHandle { | 589 | pub fn getHandle(self: *CloseOperation) fd_t { |
| 589 | switch (builtin.os) { | 590 | switch (builtin.os) { |
| 590 | builtin.Os.linux, | 591 | builtin.Os.linux, |
| 591 | builtin.Os.macosx, | 592 | builtin.Os.macosx, |
| ... | @@ -1388,7 +1389,7 @@ async fn testFsWatch(loop: *Loop) !void { | ... | @@ -1388,7 +1389,7 @@ async fn testFsWatch(loop: *Loop) !void { |
| 1388 | } | 1389 | } |
| 1389 | 1390 | ||
| 1390 | pub const OutStream = struct { | 1391 | pub const OutStream = struct { |
| 1391 | fd: os.FileHandle, | 1392 | fd: fd_t, |
| 1392 | stream: Stream, | 1393 | stream: Stream, |
| 1393 | loop: *Loop, | 1394 | loop: *Loop, |
| 1394 | offset: usize, | 1395 | offset: usize, |
| ... | @@ -1396,7 +1397,7 @@ pub const OutStream = struct { | ... | @@ -1396,7 +1397,7 @@ pub const OutStream = struct { |
| 1396 | pub const Error = os.File.WriteError; | 1397 | pub const Error = os.File.WriteError; |
| 1397 | pub const Stream = event.io.OutStream(Error); | 1398 | pub const Stream = event.io.OutStream(Error); |
| 1398 | 1399 | ||
| 1399 | pub fn init(loop: *Loop, fd: os.FileHandle, offset: usize) OutStream { | 1400 | pub fn init(loop: *Loop, fd: fd_t, offset: usize) OutStream { |
| 1400 | return OutStream{ | 1401 | return OutStream{ |
| 1401 | .fd = fd, | 1402 | .fd = fd, |
| 1402 | .loop = loop, | 1403 | .loop = loop, |
| ... | @@ -1414,7 +1415,7 @@ pub const OutStream = struct { | ... | @@ -1414,7 +1415,7 @@ pub const OutStream = struct { |
| 1414 | }; | 1415 | }; |
| 1415 | 1416 | ||
| 1416 | pub const InStream = struct { | 1417 | pub const InStream = struct { |
| 1417 | fd: os.FileHandle, | 1418 | fd: fd_t, |
| 1418 | stream: Stream, | 1419 | stream: Stream, |
| 1419 | loop: *Loop, | 1420 | loop: *Loop, |
| 1420 | offset: usize, | 1421 | offset: usize, |
| ... | @@ -1422,7 +1423,7 @@ pub const InStream = struct { | ... | @@ -1422,7 +1423,7 @@ pub const InStream = struct { |
| 1422 | pub const Error = PReadVError; // TODO make this not have OutOfMemory | 1423 | pub const Error = PReadVError; // TODO make this not have OutOfMemory |
| 1423 | pub const Stream = event.io.InStream(Error); | 1424 | pub const Stream = event.io.InStream(Error); |
| 1424 | 1425 | ||
| 1425 | pub fn init(loop: *Loop, fd: os.FileHandle, offset: usize) InStream { | 1426 | pub fn init(loop: *Loop, fd: fd_t, offset: usize) InStream { |
| 1426 | return InStream{ | 1427 | return InStream{ |
| 1427 | .fd = fd, | 1428 | .fd = fd, |
| 1428 | .loop = loop, | 1429 | .loop = loop, |
std/event/net.zig+10-8| ... | @@ -7,6 +7,8 @@ const os = std.os; | ... | @@ -7,6 +7,8 @@ const os = std.os; |
| 7 | const posix = os.posix; | 7 | const posix = os.posix; |
| 8 | const Loop = std.event.Loop; | 8 | const Loop = std.event.Loop; |
| 9 | 9 | ||
| 10 | const fd_t = posix.fd_t; | ||
| 11 | |||
| 10 | pub const Server = struct { | 12 | pub const Server = struct { |
| 11 | handleRequestFn: async<*mem.Allocator> fn (*Server, *const std.net.Address, os.File) void, | 13 | handleRequestFn: async<*mem.Allocator> fn (*Server, *const std.net.Address, os.File) void, |
| 12 | 14 | ||
| ... | @@ -139,7 +141,7 @@ pub const ReadError = error{ | ... | @@ -139,7 +141,7 @@ pub const ReadError = error{ |
| 139 | }; | 141 | }; |
| 140 | 142 | ||
| 141 | /// returns number of bytes read. 0 means EOF. | 143 | /// returns number of bytes read. 0 means EOF. |
| 142 | pub async fn read(loop: *std.event.Loop, fd: os.FileHandle, buffer: []u8) ReadError!usize { | 144 | pub async fn read(loop: *std.event.Loop, fd: fd_t, buffer: []u8) ReadError!usize { |
| 143 | const iov = posix.iovec{ | 145 | const iov = posix.iovec{ |
| 144 | .iov_base = buffer.ptr, | 146 | .iov_base = buffer.ptr, |
| 145 | .iov_len = buffer.len, | 147 | .iov_len = buffer.len, |
| ... | @@ -150,7 +152,7 @@ pub async fn read(loop: *std.event.Loop, fd: os.FileHandle, buffer: []u8) ReadEr | ... | @@ -150,7 +152,7 @@ pub async fn read(loop: *std.event.Loop, fd: os.FileHandle, buffer: []u8) ReadEr |
| 150 | 152 | ||
| 151 | pub const WriteError = error{}; | 153 | pub const WriteError = error{}; |
| 152 | 154 | ||
| 153 | pub async fn write(loop: *std.event.Loop, fd: os.FileHandle, buffer: []const u8) WriteError!void { | 155 | pub async fn write(loop: *std.event.Loop, fd: fd_t, buffer: []const u8) WriteError!void { |
| 154 | const iov = posix.iovec_const{ | 156 | const iov = posix.iovec_const{ |
| 155 | .iov_base = buffer.ptr, | 157 | .iov_base = buffer.ptr, |
| 156 | .iov_len = buffer.len, | 158 | .iov_len = buffer.len, |
| ... | @@ -220,7 +222,7 @@ pub async fn readvPosix(loop: *std.event.Loop, fd: i32, iov: [*]posix.iovec, cou | ... | @@ -220,7 +222,7 @@ pub async fn readvPosix(loop: *std.event.Loop, fd: i32, iov: [*]posix.iovec, cou |
| 220 | } | 222 | } |
| 221 | } | 223 | } |
| 222 | 224 | ||
| 223 | pub async fn writev(loop: *Loop, fd: os.FileHandle, data: []const []const u8) !void { | 225 | pub async fn writev(loop: *Loop, fd: fd_t, data: []const []const u8) !void { |
| 224 | const iovecs = try loop.allocator.alloc(os.posix.iovec_const, data.len); | 226 | const iovecs = try loop.allocator.alloc(os.posix.iovec_const, data.len); |
| 225 | defer loop.allocator.free(iovecs); | 227 | defer loop.allocator.free(iovecs); |
| 226 | 228 | ||
| ... | @@ -234,7 +236,7 @@ pub async fn writev(loop: *Loop, fd: os.FileHandle, data: []const []const u8) !v | ... | @@ -234,7 +236,7 @@ pub async fn writev(loop: *Loop, fd: os.FileHandle, data: []const []const u8) !v |
| 234 | return await (async writevPosix(loop, fd, iovecs.ptr, data.len) catch unreachable); | 236 | return await (async writevPosix(loop, fd, iovecs.ptr, data.len) catch unreachable); |
| 235 | } | 237 | } |
| 236 | 238 | ||
| 237 | pub async fn readv(loop: *Loop, fd: os.FileHandle, data: []const []u8) !usize { | 239 | pub async fn readv(loop: *Loop, fd: fd_t, data: []const []u8) !usize { |
| 238 | const iovecs = try loop.allocator.alloc(os.posix.iovec, data.len); | 240 | const iovecs = try loop.allocator.alloc(os.posix.iovec, data.len); |
| 239 | defer loop.allocator.free(iovecs); | 241 | defer loop.allocator.free(iovecs); |
| 240 | 242 | ||
| ... | @@ -324,14 +326,14 @@ async fn doAsyncTest(loop: *Loop, address: *const std.net.Address, server: *Serv | ... | @@ -324,14 +326,14 @@ async fn doAsyncTest(loop: *Loop, address: *const std.net.Address, server: *Serv |
| 324 | } | 326 | } |
| 325 | 327 | ||
| 326 | pub const OutStream = struct { | 328 | pub const OutStream = struct { |
| 327 | fd: os.FileHandle, | 329 | fd: fd_t, |
| 328 | stream: Stream, | 330 | stream: Stream, |
| 329 | loop: *Loop, | 331 | loop: *Loop, |
| 330 | 332 | ||
| 331 | pub const Error = WriteError; | 333 | pub const Error = WriteError; |
| 332 | pub const Stream = event.io.OutStream(Error); | 334 | pub const Stream = event.io.OutStream(Error); |
| 333 | 335 | ||
| 334 | pub fn init(loop: *Loop, fd: os.FileHandle) OutStream { | 336 | pub fn init(loop: *Loop, fd: fd_t) OutStream { |
| 335 | return OutStream{ | 337 | return OutStream{ |
| 336 | .fd = fd, | 338 | .fd = fd, |
| 337 | .loop = loop, | 339 | .loop = loop, |
| ... | @@ -346,14 +348,14 @@ pub const OutStream = struct { | ... | @@ -346,14 +348,14 @@ pub const OutStream = struct { |
| 346 | }; | 348 | }; |
| 347 | 349 | ||
| 348 | pub const InStream = struct { | 350 | pub const InStream = struct { |
| 349 | fd: os.FileHandle, | 351 | fd: fd_t, |
| 350 | stream: Stream, | 352 | stream: Stream, |
| 351 | loop: *Loop, | 353 | loop: *Loop, |
| 352 | 354 | ||
| 353 | pub const Error = ReadError; | 355 | pub const Error = ReadError; |
| 354 | pub const Stream = event.io.InStream(Error); | 356 | pub const Stream = event.io.InStream(Error); |
| 355 | 357 | ||
| 356 | pub fn init(loop: *Loop, fd: os.FileHandle) InStream { | 358 | pub fn init(loop: *Loop, fd: fd_t) InStream { |
| 357 | return InStream{ | 359 | return InStream{ |
| 358 | .fd = fd, | 360 | .fd = fd, |
| 359 | .loop = loop, | 361 | .loop = loop, |
std/os.zig+20-44| ... | @@ -11,7 +11,6 @@ comptime { | ... | @@ -11,7 +11,6 @@ comptime { |
| 11 | test "std.os" { | 11 | test "std.os" { |
| 12 | _ = @import("os/child_process.zig"); | 12 | _ = @import("os/child_process.zig"); |
| 13 | _ = @import("os/darwin.zig"); | 13 | _ = @import("os/darwin.zig"); |
| 14 | _ = @import("os/darwin/errno.zig"); | ||
| 15 | _ = @import("os/get_user_id.zig"); | 14 | _ = @import("os/get_user_id.zig"); |
| 16 | _ = @import("os/linux.zig"); | 15 | _ = @import("os/linux.zig"); |
| 17 | _ = @import("os/path.zig"); | 16 | _ = @import("os/path.zig"); |
| ... | @@ -32,14 +31,14 @@ pub const zen = @import("os/zen.zig"); | ... | @@ -32,14 +31,14 @@ pub const zen = @import("os/zen.zig"); |
| 32 | pub const uefi = @import("os/uefi.zig"); | 31 | pub const uefi = @import("os/uefi.zig"); |
| 33 | pub const wasi = @import("os/wasi.zig"); | 32 | pub const wasi = @import("os/wasi.zig"); |
| 34 | 33 | ||
| 35 | pub const system = if (builtin.link_libc) c else switch (builtin.os) { | 34 | pub const system = switch (builtin.os) { |
| 36 | .linux => linux, | 35 | .linux => linux, |
| 37 | .macosx, .ios, .watchos, .tvos => darwin, | 36 | .macosx, .ios, .watchos, .tvos => darwin, |
| 38 | .freebsd => freebsd, | 37 | .freebsd => freebsd, |
| 39 | .netbsd => netbsd, | 38 | .netbsd => netbsd, |
| 40 | .zen => zen, | 39 | .zen => zen, |
| 41 | .wasi => wasi, | 40 | .wasi => wasi, |
| 42 | else => @compileError("Unsupported OS"), | 41 | else => struct {}, |
| 43 | }; | 42 | }; |
| 44 | 43 | ||
| 45 | pub const net = @import("net.zig"); | 44 | pub const net = @import("net.zig"); |
| ... | @@ -93,8 +92,6 @@ pub const WindowsOpenError = windows_util.OpenError; | ... | @@ -93,8 +92,6 @@ pub const WindowsOpenError = windows_util.OpenError; |
| 93 | pub const WindowsWriteError = windows_util.WriteError; | 92 | pub const WindowsWriteError = windows_util.WriteError; |
| 94 | pub const WindowsReadError = windows_util.ReadError; | 93 | pub const WindowsReadError = windows_util.ReadError; |
| 95 | 94 | ||
| 96 | pub const FileHandle = if (is_windows) windows.HANDLE else i32; | ||
| 97 | |||
| 98 | pub const getAppDataDir = @import("os/get_app_data_dir.zig").getAppDataDir; | 95 | pub const getAppDataDir = @import("os/get_app_data_dir.zig").getAppDataDir; |
| 99 | pub const GetAppDataDirError = @import("os/get_app_data_dir.zig").GetAppDataDirError; | 96 | pub const GetAppDataDirError = @import("os/get_app_data_dir.zig").GetAppDataDirError; |
| 100 | 97 | ||
| ... | @@ -776,11 +773,13 @@ pub const Dir = struct { | ... | @@ -776,11 +773,13 @@ pub const Dir = struct { |
| 776 | } | 773 | } |
| 777 | 774 | ||
| 778 | while (true) { | 775 | while (true) { |
| 779 | const result = posix.getdirentries64(self.handle.fd, self.handle.buf.ptr, self.handle.buf.len, &self.handle.seek); | 776 | const result = system.__getdirentries64(self.handle.fd, self.handle.buf.ptr, self.handle.buf.len, &self.handle.seek); |
| 780 | const err = posix.getErrno(result); | 777 | if (result == 0) return null; |
| 781 | if (err > 0) { | 778 | if (result < 0) { |
| 782 | switch (err) { | 779 | switch (system.getErrno(result)) { |
| 783 | posix.EBADF, posix.EFAULT, posix.ENOTDIR => unreachable, | 780 | posix.EBADF => unreachable, |
| 781 | posix.EFAULT => unreachable, | ||
| 782 | posix.ENOTDIR => unreachable, | ||
| 784 | posix.EINVAL => { | 783 | posix.EINVAL => { |
| 785 | self.handle.buf = try self.allocator.realloc(self.handle.buf, self.handle.buf.len * 2); | 784 | self.handle.buf = try self.allocator.realloc(self.handle.buf, self.handle.buf.len * 2); |
| 786 | continue; | 785 | continue; |
| ... | @@ -788,9 +787,8 @@ pub const Dir = struct { | ... | @@ -788,9 +787,8 @@ pub const Dir = struct { |
| 788 | else => return unexpectedErrorPosix(err), | 787 | else => return unexpectedErrorPosix(err), |
| 789 | } | 788 | } |
| 790 | } | 789 | } |
| 791 | if (result == 0) return null; | ||
| 792 | self.handle.index = 0; | 790 | self.handle.index = 0; |
| 793 | self.handle.end_index = result; | 791 | self.handle.end_index = @intCast(usize, result); |
| 794 | break; | 792 | break; |
| 795 | } | 793 | } |
| 796 | } | 794 | } |
| ... | @@ -1357,28 +1355,16 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | ... | @@ -1357,28 +1355,16 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { |
| 1357 | Os.freebsd => { | 1355 | Os.freebsd => { |
| 1358 | var mib = [4]c_int{ posix.CTL_KERN, posix.KERN_PROC, posix.KERN_PROC_PATHNAME, -1 }; | 1356 | var mib = [4]c_int{ posix.CTL_KERN, posix.KERN_PROC, posix.KERN_PROC_PATHNAME, -1 }; |
| 1359 | var out_len: usize = out_buffer.len; | 1357 | var out_len: usize = out_buffer.len; |
| 1360 | const err = posix.getErrno(posix.sysctl(&mib, 4, out_buffer, &out_len, null, 0)); | 1358 | try posix.sysctl(&mib, out_buffer, &out_len, null, 0); |
| 1361 | 1359 | // TODO could this slice from 0 to out_len instead? | |
| 1362 | if (err == 0) return mem.toSlice(u8, out_buffer); | 1360 | return mem.toSlice(u8, out_buffer); |
| 1363 | |||
| 1364 | return switch (err) { | ||
| 1365 | posix.EFAULT => error.BadAdress, | ||
| 1366 | posix.EPERM => error.PermissionDenied, | ||
| 1367 | else => unexpectedErrorPosix(err), | ||
| 1368 | }; | ||
| 1369 | }, | 1361 | }, |
| 1370 | Os.netbsd => { | 1362 | Os.netbsd => { |
| 1371 | var mib = [4]c_int{ posix.CTL_KERN, posix.KERN_PROC_ARGS, -1, posix.KERN_PROC_PATHNAME }; | 1363 | var mib = [4]c_int{ posix.CTL_KERN, posix.KERN_PROC_ARGS, -1, posix.KERN_PROC_PATHNAME }; |
| 1372 | var out_len: usize = out_buffer.len; | 1364 | var out_len: usize = out_buffer.len; |
| 1373 | const err = posix.getErrno(posix.sysctl(&mib, 4, out_buffer, &out_len, null, 0)); | 1365 | try posix.sysctl(&mib, out_buffer, &out_len, null, 0); |
| 1374 | 1366 | // TODO could this slice from 0 to out_len instead? | |
| 1375 | if (err == 0) return mem.toSlice(u8, out_buffer); | 1367 | return mem.toSlice(u8, out_buffer); |
| 1376 | |||
| 1377 | return switch (err) { | ||
| 1378 | posix.EFAULT => error.BadAdress, | ||
| 1379 | posix.EPERM => error.PermissionDenied, | ||
| 1380 | else => unexpectedErrorPosix(err), | ||
| 1381 | }; | ||
| 1382 | }, | 1368 | }, |
| 1383 | Os.windows => { | 1369 | Os.windows => { |
| 1384 | var utf16le_buf: [posix.PATH_MAX_WIDE]u16 = undefined; | 1370 | var utf16le_buf: [posix.PATH_MAX_WIDE]u16 = undefined; |
| ... | @@ -1744,22 +1730,12 @@ pub fn cpuCount(fallback_allocator: *mem.Allocator) CpuCountError!usize { | ... | @@ -1744,22 +1730,12 @@ pub fn cpuCount(fallback_allocator: *mem.Allocator) CpuCountError!usize { |
| 1744 | .macosx, .freebsd, .netbsd => { | 1730 | .macosx, .freebsd, .netbsd => { |
| 1745 | var count: c_int = undefined; | 1731 | var count: c_int = undefined; |
| 1746 | var count_len: usize = @sizeOf(c_int); | 1732 | var count_len: usize = @sizeOf(c_int); |
| 1747 | const rc = posix.sysctlbyname(switch (builtin.os) { | 1733 | const name = switch (builtin.os) { |
| 1748 | builtin.Os.macosx => c"hw.logicalcpu", | 1734 | builtin.Os.macosx => c"hw.logicalcpu", |
| 1749 | else => c"hw.ncpu", | 1735 | else => c"hw.ncpu", |
| 1750 | }, @ptrCast(*c_void, &count), &count_len, null, 0); | 1736 | }; |
| 1751 | const err = posix.getErrno(rc); | 1737 | try posix.sysctlbyname(name, @ptrCast(*c_void, &count), &count_len, null, 0); |
| 1752 | switch (err) { | 1738 | return @intCast(usize, count); |
| 1753 | 0 => return @intCast(usize, count), | ||
| 1754 | posix.EFAULT => unreachable, | ||
| 1755 | posix.EINVAL => unreachable, | ||
| 1756 | posix.ENOMEM => return CpuCountError.OutOfMemory, | ||
| 1757 | posix.ENOTDIR => unreachable, | ||
| 1758 | posix.EISDIR => unreachable, | ||
| 1759 | posix.ENOENT => unreachable, | ||
| 1760 | posix.EPERM => unreachable, | ||
| 1761 | else => return os.unexpectedErrorPosix(err), | ||
| 1762 | } | ||
| 1763 | }, | 1739 | }, |
| 1764 | .linux => { | 1740 | .linux => { |
| 1765 | const usize_count = 16; | 1741 | const usize_count = 16; |
std/os/child_process.zig+1-8| ... | @@ -376,14 +376,7 @@ pub const ChildProcess = struct { | ... | @@ -376,14 +376,7 @@ pub const ChildProcess = struct { |
| 376 | const err_pipe = try makePipe(); | 376 | const err_pipe = try makePipe(); |
| 377 | errdefer destroyPipe(err_pipe); | 377 | errdefer destroyPipe(err_pipe); |
| 378 | 378 | ||
| 379 | const pid_result = posix.fork(); | 379 | const pid_result = try posix.fork(); |
| 380 | const pid_err = posix.getErrno(pid_result); | ||
| 381 | if (pid_err > 0) { | ||
| 382 | return switch (pid_err) { | ||
| 383 | posix.EAGAIN, posix.ENOMEM, posix.ENOSYS => error.SystemResources, | ||
| 384 | else => os.unexpectedErrorPosix(pid_err), | ||
| 385 | }; | ||
| 386 | } | ||
| 387 | if (pid_result == 0) { | 380 | if (pid_result == 0) { |
| 388 | // we are the child | 381 | // we are the child |
| 389 | setUpChildIo(self.stdin_behavior, stdin_pipe[0], posix.STDIN_FILENO, dev_null_fd) catch |err| forkChildErrReport(err_pipe[1], err); | 382 | setUpChildIo(self.stdin_behavior, stdin_pipe[0], posix.STDIN_FILENO, dev_null_fd) catch |err| forkChildErrReport(err_pipe[1], err); |
std/os/darwin.zig+2-887| ... | @@ -1,892 +1,7 @@ | ... | @@ -1,892 +1,7 @@ |
| 1 | const builtin = @import("builtin"); | 1 | const builtin = @import("builtin"); |
| 2 | const std = @import("../std.zig"); | 2 | const std = @import("../std.zig"); |
| 3 | const c = std.c; | ||
| 4 | const assert = std.debug.assert; | ||
| 5 | const maxInt = std.math.maxInt; | ||
| 6 | |||
| 7 | pub const is_the_target = switch (builtin.os) { | 3 | pub const is_the_target = switch (builtin.os) { |
| 8 | .ios, .macosx, .watchos, .tvos => true, | 4 | .macosx, .tvos, .watchos, .ios => true, |
| 9 | else => false, | 5 | else => false, |
| 10 | }; | 6 | }; |
| 11 | 7 | pub use std.c; | |
| 12 | pub const errno_codes = @import("darwin/errno.zig"); | ||
| 13 | pub use errno_codes; | ||
| 14 | |||
| 15 | pub const PATH_MAX = 1024; | ||
| 16 | |||
| 17 | pub const STDIN_FILENO = 0; | ||
| 18 | pub const STDOUT_FILENO = 1; | ||
| 19 | pub const STDERR_FILENO = 2; | ||
| 20 | |||
| 21 | /// [MC2] no permissions | ||
| 22 | pub const PROT_NONE = 0x00; | ||
| 23 | |||
| 24 | /// [MC2] pages can be read | ||
| 25 | pub const PROT_READ = 0x01; | ||
| 26 | |||
| 27 | /// [MC2] pages can be written | ||
| 28 | pub const PROT_WRITE = 0x02; | ||
| 29 | |||
| 30 | /// [MC2] pages can be executed | ||
| 31 | pub const PROT_EXEC = 0x04; | ||
| 32 | |||
| 33 | /// allocated from memory, swap space | ||
| 34 | pub const MAP_ANONYMOUS = 0x1000; | ||
| 35 | |||
| 36 | /// map from file (default) | ||
| 37 | pub const MAP_FILE = 0x0000; | ||
| 38 | |||
| 39 | /// interpret addr exactly | ||
| 40 | pub const MAP_FIXED = 0x0010; | ||
| 41 | |||
| 42 | /// region may contain semaphores | ||
| 43 | pub const MAP_HASSEMAPHORE = 0x0200; | ||
| 44 | |||
| 45 | /// changes are private | ||
| 46 | pub const MAP_PRIVATE = 0x0002; | ||
| 47 | |||
| 48 | /// share changes | ||
| 49 | pub const MAP_SHARED = 0x0001; | ||
| 50 | |||
| 51 | /// don't cache pages for this mapping | ||
| 52 | pub const MAP_NOCACHE = 0x0400; | ||
| 53 | |||
| 54 | /// don't reserve needed swap area | ||
| 55 | pub const MAP_NORESERVE = 0x0040; | ||
| 56 | pub const MAP_FAILED = maxInt(usize); | ||
| 57 | |||
| 58 | /// [XSI] no hang in wait/no child to reap | ||
| 59 | pub const WNOHANG = 0x00000001; | ||
| 60 | |||
| 61 | /// [XSI] notify on stop, untraced child | ||
| 62 | pub const WUNTRACED = 0x00000002; | ||
| 63 | |||
| 64 | /// take signal on signal stack | ||
| 65 | pub const SA_ONSTACK = 0x0001; | ||
| 66 | |||
| 67 | /// restart system on signal return | ||
| 68 | pub const SA_RESTART = 0x0002; | ||
| 69 | |||
| 70 | /// reset to SIG_DFL when taking signal | ||
| 71 | pub const SA_RESETHAND = 0x0004; | ||
| 72 | |||
| 73 | /// do not generate SIGCHLD on child stop | ||
| 74 | pub const SA_NOCLDSTOP = 0x0008; | ||
| 75 | |||
| 76 | /// don't mask the signal we're delivering | ||
| 77 | pub const SA_NODEFER = 0x0010; | ||
| 78 | |||
| 79 | /// don't keep zombies around | ||
| 80 | pub const SA_NOCLDWAIT = 0x0020; | ||
| 81 | |||
| 82 | /// signal handler with SA_SIGINFO args | ||
| 83 | pub const SA_SIGINFO = 0x0040; | ||
| 84 | |||
| 85 | /// do not bounce off kernel's sigtramp | ||
| 86 | pub const SA_USERTRAMP = 0x0100; | ||
| 87 | |||
| 88 | /// signal handler with SA_SIGINFO args with 64bit regs information | ||
| 89 | pub const SA_64REGSET = 0x0200; | ||
| 90 | |||
| 91 | pub const O_LARGEFILE = 0x0000; | ||
| 92 | pub const O_PATH = 0x0000; | ||
| 93 | |||
| 94 | pub const F_OK = 0; | ||
| 95 | pub const X_OK = 1; | ||
| 96 | pub const W_OK = 2; | ||
| 97 | pub const R_OK = 4; | ||
| 98 | |||
| 99 | /// open for reading only | ||
| 100 | pub const O_RDONLY = 0x0000; | ||
| 101 | |||
| 102 | /// open for writing only | ||
| 103 | pub const O_WRONLY = 0x0001; | ||
| 104 | |||
| 105 | /// open for reading and writing | ||
| 106 | pub const O_RDWR = 0x0002; | ||
| 107 | |||
| 108 | /// do not block on open or for data to become available | ||
| 109 | pub const O_NONBLOCK = 0x0004; | ||
| 110 | |||
| 111 | /// append on each write | ||
| 112 | pub const O_APPEND = 0x0008; | ||
| 113 | |||
| 114 | /// create file if it does not exist | ||
| 115 | pub const O_CREAT = 0x0200; | ||
| 116 | |||
| 117 | /// truncate size to 0 | ||
| 118 | pub const O_TRUNC = 0x0400; | ||
| 119 | |||
| 120 | /// error if O_CREAT and the file exists | ||
| 121 | pub const O_EXCL = 0x0800; | ||
| 122 | |||
| 123 | /// atomically obtain a shared lock | ||
| 124 | pub const O_SHLOCK = 0x0010; | ||
| 125 | |||
| 126 | /// atomically obtain an exclusive lock | ||
| 127 | pub const O_EXLOCK = 0x0020; | ||
| 128 | |||
| 129 | /// do not follow symlinks | ||
| 130 | pub const O_NOFOLLOW = 0x0100; | ||
| 131 | |||
| 132 | /// allow open of symlinks | ||
| 133 | pub const O_SYMLINK = 0x200000; | ||
| 134 | |||
| 135 | /// descriptor requested for event notifications only | ||
| 136 | pub const O_EVTONLY = 0x8000; | ||
| 137 | |||
| 138 | /// mark as close-on-exec | ||
| 139 | pub const O_CLOEXEC = 0x1000000; | ||
| 140 | |||
| 141 | pub const O_ACCMODE = 3; | ||
| 142 | pub const O_ALERT = 536870912; | ||
| 143 | pub const O_ASYNC = 64; | ||
| 144 | pub const O_DIRECTORY = 1048576; | ||
| 145 | pub const O_DP_GETRAWENCRYPTED = 1; | ||
| 146 | pub const O_DP_GETRAWUNENCRYPTED = 2; | ||
| 147 | pub const O_DSYNC = 4194304; | ||
| 148 | pub const O_FSYNC = O_SYNC; | ||
| 149 | pub const O_NOCTTY = 131072; | ||
| 150 | pub const O_POPUP = 2147483648; | ||
| 151 | pub const O_SYNC = 128; | ||
| 152 | |||
| 153 | pub const SEEK_SET = 0x0; | ||
| 154 | pub const SEEK_CUR = 0x1; | ||
| 155 | pub const SEEK_END = 0x2; | ||
| 156 | |||
| 157 | pub const DT_UNKNOWN = 0; | ||
| 158 | pub const DT_FIFO = 1; | ||
| 159 | pub const DT_CHR = 2; | ||
| 160 | pub const DT_DIR = 4; | ||
| 161 | pub const DT_BLK = 6; | ||
| 162 | pub const DT_REG = 8; | ||
| 163 | pub const DT_LNK = 10; | ||
| 164 | pub const DT_SOCK = 12; | ||
| 165 | pub const DT_WHT = 14; | ||
| 166 | |||
| 167 | /// block specified signal set | ||
| 168 | pub const SIG_BLOCK = 1; | ||
| 169 | |||
| 170 | /// unblock specified signal set | ||
| 171 | pub const SIG_UNBLOCK = 2; | ||
| 172 | |||
| 173 | /// set specified signal set | ||
| 174 | pub const SIG_SETMASK = 3; | ||
| 175 | |||
| 176 | /// hangup | ||
| 177 | pub const SIGHUP = 1; | ||
| 178 | |||
| 179 | /// interrupt | ||
| 180 | pub const SIGINT = 2; | ||
| 181 | |||
| 182 | /// quit | ||
| 183 | pub const SIGQUIT = 3; | ||
| 184 | |||
| 185 | /// illegal instruction (not reset when caught) | ||
| 186 | pub const SIGILL = 4; | ||
| 187 | |||
| 188 | /// trace trap (not reset when caught) | ||
| 189 | pub const SIGTRAP = 5; | ||
| 190 | |||
| 191 | /// abort() | ||
| 192 | pub const SIGABRT = 6; | ||
| 193 | |||
| 194 | /// pollable event ([XSR] generated, not supported) | ||
| 195 | pub const SIGPOLL = 7; | ||
| 196 | |||
| 197 | /// compatibility | ||
| 198 | pub const SIGIOT = SIGABRT; | ||
| 199 | |||
| 200 | /// EMT instruction | ||
| 201 | pub const SIGEMT = 7; | ||
| 202 | |||
| 203 | /// floating point exception | ||
| 204 | pub const SIGFPE = 8; | ||
| 205 | |||
| 206 | /// kill (cannot be caught or ignored) | ||
| 207 | pub const SIGKILL = 9; | ||
| 208 | |||
| 209 | /// bus error | ||
| 210 | pub const SIGBUS = 10; | ||
| 211 | |||
| 212 | /// segmentation violation | ||
| 213 | pub const SIGSEGV = 11; | ||
| 214 | |||
| 215 | /// bad argument to system call | ||
| 216 | pub const SIGSYS = 12; | ||
| 217 | |||
| 218 | /// write on a pipe with no one to read it | ||
| 219 | pub const SIGPIPE = 13; | ||
| 220 | |||
| 221 | /// alarm clock | ||
| 222 | pub const SIGALRM = 14; | ||
| 223 | |||
| 224 | /// software termination signal from kill | ||
| 225 | pub const SIGTERM = 15; | ||
| 226 | |||
| 227 | /// urgent condition on IO channel | ||
| 228 | pub const SIGURG = 16; | ||
| 229 | |||
| 230 | /// sendable stop signal not from tty | ||
| 231 | pub const SIGSTOP = 17; | ||
| 232 | |||
| 233 | /// stop signal from tty | ||
| 234 | pub const SIGTSTP = 18; | ||
| 235 | |||
| 236 | /// continue a stopped process | ||
| 237 | pub const SIGCONT = 19; | ||
| 238 | |||
| 239 | /// to parent on child stop or exit | ||
| 240 | pub const SIGCHLD = 20; | ||
| 241 | |||
| 242 | /// to readers pgrp upon background tty read | ||
| 243 | pub const SIGTTIN = 21; | ||
| 244 | |||
| 245 | /// like TTIN for output if (tp->t_local&LTOSTOP) | ||
| 246 | pub const SIGTTOU = 22; | ||
| 247 | |||
| 248 | /// input/output possible signal | ||
| 249 | pub const SIGIO = 23; | ||
| 250 | |||
| 251 | /// exceeded CPU time limit | ||
| 252 | pub const SIGXCPU = 24; | ||
| 253 | |||
| 254 | /// exceeded file size limit | ||
| 255 | pub const SIGXFSZ = 25; | ||
| 256 | |||
| 257 | /// virtual time alarm | ||
| 258 | pub const SIGVTALRM = 26; | ||
| 259 | |||
| 260 | /// profiling time alarm | ||
| 261 | pub const SIGPROF = 27; | ||
| 262 | |||
| 263 | /// window size changes | ||
| 264 | pub const SIGWINCH = 28; | ||
| 265 | |||
| 266 | /// information request | ||
| 267 | pub const SIGINFO = 29; | ||
| 268 | |||
| 269 | /// user defined signal 1 | ||
| 270 | pub const SIGUSR1 = 30; | ||
| 271 | |||
| 272 | /// user defined signal 2 | ||
| 273 | pub const SIGUSR2 = 31; | ||
| 274 | |||
| 275 | /// no flag value | ||
| 276 | pub const KEVENT_FLAG_NONE = 0x000; | ||
| 277 | |||
| 278 | /// immediate timeout | ||
| 279 | pub const KEVENT_FLAG_IMMEDIATE = 0x001; | ||
| 280 | |||
| 281 | /// output events only include change | ||
| 282 | pub const KEVENT_FLAG_ERROR_EVENTS = 0x002; | ||
| 283 | |||
| 284 | /// add event to kq (implies enable) | ||
| 285 | pub const EV_ADD = 0x0001; | ||
| 286 | |||
| 287 | /// delete event from kq | ||
| 288 | pub const EV_DELETE = 0x0002; | ||
| 289 | |||
| 290 | /// enable event | ||
| 291 | pub const EV_ENABLE = 0x0004; | ||
| 292 | |||
| 293 | /// disable event (not reported) | ||
| 294 | pub const EV_DISABLE = 0x0008; | ||
| 295 | |||
| 296 | /// only report one occurrence | ||
| 297 | pub const EV_ONESHOT = 0x0010; | ||
| 298 | |||
| 299 | /// clear event state after reporting | ||
| 300 | pub const EV_CLEAR = 0x0020; | ||
| 301 | |||
| 302 | /// force immediate event output | ||
| 303 | /// ... with or without EV_ERROR | ||
| 304 | /// ... use KEVENT_FLAG_ERROR_EVENTS | ||
| 305 | /// on syscalls supporting flags | ||
| 306 | pub const EV_RECEIPT = 0x0040; | ||
| 307 | |||
| 308 | /// disable event after reporting | ||
| 309 | pub const EV_DISPATCH = 0x0080; | ||
| 310 | |||
| 311 | /// unique kevent per udata value | ||
| 312 | pub const EV_UDATA_SPECIFIC = 0x0100; | ||
| 313 | |||
| 314 | /// ... in combination with EV_DELETE | ||
| 315 | /// will defer delete until udata-specific | ||
| 316 | /// event enabled. EINPROGRESS will be | ||
| 317 | /// returned to indicate the deferral | ||
| 318 | pub const EV_DISPATCH2 = EV_DISPATCH | EV_UDATA_SPECIFIC; | ||
| 319 | |||
| 320 | /// report that source has vanished | ||
| 321 | /// ... only valid with EV_DISPATCH2 | ||
| 322 | pub const EV_VANISHED = 0x0200; | ||
| 323 | |||
| 324 | /// reserved by system | ||
| 325 | pub const EV_SYSFLAGS = 0xF000; | ||
| 326 | |||
| 327 | /// filter-specific flag | ||
| 328 | pub const EV_FLAG0 = 0x1000; | ||
| 329 | |||
| 330 | /// filter-specific flag | ||
| 331 | pub const EV_FLAG1 = 0x2000; | ||
| 332 | |||
| 333 | /// EOF detected | ||
| 334 | pub const EV_EOF = 0x8000; | ||
| 335 | |||
| 336 | /// error, data contains errno | ||
| 337 | pub const EV_ERROR = 0x4000; | ||
| 338 | |||
| 339 | pub const EV_POLL = EV_FLAG0; | ||
| 340 | pub const EV_OOBAND = EV_FLAG1; | ||
| 341 | |||
| 342 | pub const EVFILT_READ = -1; | ||
| 343 | pub const EVFILT_WRITE = -2; | ||
| 344 | |||
| 345 | /// attached to aio requests | ||
| 346 | pub const EVFILT_AIO = -3; | ||
| 347 | |||
| 348 | /// attached to vnodes | ||
| 349 | pub const EVFILT_VNODE = -4; | ||
| 350 | |||
| 351 | /// attached to struct proc | ||
| 352 | pub const EVFILT_PROC = -5; | ||
| 353 | |||
| 354 | /// attached to struct proc | ||
| 355 | pub const EVFILT_SIGNAL = -6; | ||
| 356 | |||
| 357 | /// timers | ||
| 358 | pub const EVFILT_TIMER = -7; | ||
| 359 | |||
| 360 | /// Mach portsets | ||
| 361 | pub const EVFILT_MACHPORT = -8; | ||
| 362 | |||
| 363 | /// Filesystem events | ||
| 364 | pub const EVFILT_FS = -9; | ||
| 365 | |||
| 366 | /// User events | ||
| 367 | pub const EVFILT_USER = -10; | ||
| 368 | |||
| 369 | /// Virtual memory events | ||
| 370 | pub const EVFILT_VM = -12; | ||
| 371 | |||
| 372 | /// Exception events | ||
| 373 | pub const EVFILT_EXCEPT = -15; | ||
| 374 | |||
| 375 | pub const EVFILT_SYSCOUNT = 17; | ||
| 376 | |||
| 377 | /// On input, NOTE_TRIGGER causes the event to be triggered for output. | ||
| 378 | pub const NOTE_TRIGGER = 0x01000000; | ||
| 379 | |||
| 380 | /// ignore input fflags | ||
| 381 | pub const NOTE_FFNOP = 0x00000000; | ||
| 382 | |||
| 383 | /// and fflags | ||
| 384 | pub const NOTE_FFAND = 0x40000000; | ||
| 385 | |||
| 386 | /// or fflags | ||
| 387 | pub const NOTE_FFOR = 0x80000000; | ||
| 388 | |||
| 389 | /// copy fflags | ||
| 390 | pub const NOTE_FFCOPY = 0xc0000000; | ||
| 391 | |||
| 392 | /// mask for operations | ||
| 393 | pub const NOTE_FFCTRLMASK = 0xc0000000; | ||
| 394 | pub const NOTE_FFLAGSMASK = 0x00ffffff; | ||
| 395 | |||
| 396 | /// low water mark | ||
| 397 | pub const NOTE_LOWAT = 0x00000001; | ||
| 398 | |||
| 399 | /// OOB data | ||
| 400 | pub const NOTE_OOB = 0x00000002; | ||
| 401 | |||
| 402 | /// vnode was removed | ||
| 403 | pub const NOTE_DELETE = 0x00000001; | ||
| 404 | |||
| 405 | /// data contents changed | ||
| 406 | pub const NOTE_WRITE = 0x00000002; | ||
| 407 | |||
| 408 | /// size increased | ||
| 409 | pub const NOTE_EXTEND = 0x00000004; | ||
| 410 | |||
| 411 | /// attributes changed | ||
| 412 | pub const NOTE_ATTRIB = 0x00000008; | ||
| 413 | |||
| 414 | /// link count changed | ||
| 415 | pub const NOTE_LINK = 0x00000010; | ||
| 416 | |||
| 417 | /// vnode was renamed | ||
| 418 | pub const NOTE_RENAME = 0x00000020; | ||
| 419 | |||
| 420 | /// vnode access was revoked | ||
| 421 | pub const NOTE_REVOKE = 0x00000040; | ||
| 422 | |||
| 423 | /// No specific vnode event: to test for EVFILT_READ activation | ||
| 424 | pub const NOTE_NONE = 0x00000080; | ||
| 425 | |||
| 426 | /// vnode was unlocked by flock(2) | ||
| 427 | pub const NOTE_FUNLOCK = 0x00000100; | ||
| 428 | |||
| 429 | /// process exited | ||
| 430 | pub const NOTE_EXIT = 0x80000000; | ||
| 431 | |||
| 432 | /// process forked | ||
| 433 | pub const NOTE_FORK = 0x40000000; | ||
| 434 | |||
| 435 | /// process exec'd | ||
| 436 | pub const NOTE_EXEC = 0x20000000; | ||
| 437 | |||
| 438 | /// shared with EVFILT_SIGNAL | ||
| 439 | pub const NOTE_SIGNAL = 0x08000000; | ||
| 440 | |||
| 441 | /// exit status to be returned, valid for child process only | ||
| 442 | pub const NOTE_EXITSTATUS = 0x04000000; | ||
| 443 | |||
| 444 | /// provide details on reasons for exit | ||
| 445 | pub const NOTE_EXIT_DETAIL = 0x02000000; | ||
| 446 | |||
| 447 | /// mask for signal & exit status | ||
| 448 | pub const NOTE_PDATAMASK = 0x000fffff; | ||
| 449 | pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK); | ||
| 450 | |||
| 451 | pub const NOTE_EXIT_DETAIL_MASK = 0x00070000; | ||
| 452 | pub const NOTE_EXIT_DECRYPTFAIL = 0x00010000; | ||
| 453 | pub const NOTE_EXIT_MEMORY = 0x00020000; | ||
| 454 | pub const NOTE_EXIT_CSERROR = 0x00040000; | ||
| 455 | |||
| 456 | /// will react on memory pressure | ||
| 457 | pub const NOTE_VM_PRESSURE = 0x80000000; | ||
| 458 | |||
| 459 | /// will quit on memory pressure, possibly after cleaning up dirty state | ||
| 460 | pub const NOTE_VM_PRESSURE_TERMINATE = 0x40000000; | ||
| 461 | |||
| 462 | /// will quit immediately on memory pressure | ||
| 463 | pub const NOTE_VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000; | ||
| 464 | |||
| 465 | /// there was an error | ||
| 466 | pub const NOTE_VM_ERROR = 0x10000000; | ||
| 467 | |||
| 468 | /// data is seconds | ||
| 469 | pub const NOTE_SECONDS = 0x00000001; | ||
| 470 | |||
| 471 | /// data is microseconds | ||
| 472 | pub const NOTE_USECONDS = 0x00000002; | ||
| 473 | |||
| 474 | /// data is nanoseconds | ||
| 475 | pub const NOTE_NSECONDS = 0x00000004; | ||
| 476 | |||
| 477 | /// absolute timeout | ||
| 478 | pub const NOTE_ABSOLUTE = 0x00000008; | ||
| 479 | |||
| 480 | /// ext[1] holds leeway for power aware timers | ||
| 481 | pub const NOTE_LEEWAY = 0x00000010; | ||
| 482 | |||
| 483 | /// system does minimal timer coalescing | ||
| 484 | pub const NOTE_CRITICAL = 0x00000020; | ||
| 485 | |||
| 486 | /// system does maximum timer coalescing | ||
| 487 | pub const NOTE_BACKGROUND = 0x00000040; | ||
| 488 | pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080; | ||
| 489 | |||
| 490 | /// data is mach absolute time units | ||
| 491 | pub const NOTE_MACHTIME = 0x00000100; | ||
| 492 | |||
| 493 | pub const AF_UNSPEC = 0; | ||
| 494 | pub const AF_LOCAL = 1; | ||
| 495 | pub const AF_UNIX = AF_LOCAL; | ||
| 496 | pub const AF_INET = 2; | ||
| 497 | pub const AF_SYS_CONTROL = 2; | ||
| 498 | pub const AF_IMPLINK = 3; | ||
| 499 | pub const AF_PUP = 4; | ||
| 500 | pub const AF_CHAOS = 5; | ||
| 501 | pub const AF_NS = 6; | ||
| 502 | pub const AF_ISO = 7; | ||
| 503 | pub const AF_OSI = AF_ISO; | ||
| 504 | pub const AF_ECMA = 8; | ||
| 505 | pub const AF_DATAKIT = 9; | ||
| 506 | pub const AF_CCITT = 10; | ||
| 507 | pub const AF_SNA = 11; | ||
| 508 | pub const AF_DECnet = 12; | ||
| 509 | pub const AF_DLI = 13; | ||
| 510 | pub const AF_LAT = 14; | ||
| 511 | pub const AF_HYLINK = 15; | ||
| 512 | pub const AF_APPLETALK = 16; | ||
| 513 | pub const AF_ROUTE = 17; | ||
| 514 | pub const AF_LINK = 18; | ||
| 515 | pub const AF_XTP = 19; | ||
| 516 | pub const AF_COIP = 20; | ||
| 517 | pub const AF_CNT = 21; | ||
| 518 | pub const AF_RTIP = 22; | ||
| 519 | pub const AF_IPX = 23; | ||
| 520 | pub const AF_SIP = 24; | ||
| 521 | pub const AF_PIP = 25; | ||
| 522 | pub const AF_ISDN = 28; | ||
| 523 | pub const AF_E164 = AF_ISDN; | ||
| 524 | pub const AF_KEY = 29; | ||
| 525 | pub const AF_INET6 = 30; | ||
| 526 | pub const AF_NATM = 31; | ||
| 527 | pub const AF_SYSTEM = 32; | ||
| 528 | pub const AF_NETBIOS = 33; | ||
| 529 | pub const AF_PPP = 34; | ||
| 530 | pub const AF_MAX = 40; | ||
| 531 | |||
| 532 | pub const PF_UNSPEC = AF_UNSPEC; | ||
| 533 | pub const PF_LOCAL = AF_LOCAL; | ||
| 534 | pub const PF_UNIX = PF_LOCAL; | ||
| 535 | pub const PF_INET = AF_INET; | ||
| 536 | pub const PF_IMPLINK = AF_IMPLINK; | ||
| 537 | pub const PF_PUP = AF_PUP; | ||
| 538 | pub const PF_CHAOS = AF_CHAOS; | ||
| 539 | pub const PF_NS = AF_NS; | ||
| 540 | pub const PF_ISO = AF_ISO; | ||
| 541 | pub const PF_OSI = AF_ISO; | ||
| 542 | pub const PF_ECMA = AF_ECMA; | ||
| 543 | pub const PF_DATAKIT = AF_DATAKIT; | ||
| 544 | pub const PF_CCITT = AF_CCITT; | ||
| 545 | pub const PF_SNA = AF_SNA; | ||
| 546 | pub const PF_DECnet = AF_DECnet; | ||
| 547 | pub const PF_DLI = AF_DLI; | ||
| 548 | pub const PF_LAT = AF_LAT; | ||
| 549 | pub const PF_HYLINK = AF_HYLINK; | ||
| 550 | pub const PF_APPLETALK = AF_APPLETALK; | ||
| 551 | pub const PF_ROUTE = AF_ROUTE; | ||
| 552 | pub const PF_LINK = AF_LINK; | ||
| 553 | pub const PF_XTP = AF_XTP; | ||
| 554 | pub const PF_COIP = AF_COIP; | ||
| 555 | pub const PF_CNT = AF_CNT; | ||
| 556 | pub const PF_SIP = AF_SIP; | ||
| 557 | pub const PF_IPX = AF_IPX; | ||
| 558 | pub const PF_RTIP = AF_RTIP; | ||
| 559 | pub const PF_PIP = AF_PIP; | ||
| 560 | pub const PF_ISDN = AF_ISDN; | ||
| 561 | pub const PF_KEY = AF_KEY; | ||
| 562 | pub const PF_INET6 = AF_INET6; | ||
| 563 | pub const PF_NATM = AF_NATM; | ||
| 564 | pub const PF_SYSTEM = AF_SYSTEM; | ||
| 565 | pub const PF_NETBIOS = AF_NETBIOS; | ||
| 566 | pub const PF_PPP = AF_PPP; | ||
| 567 | pub const PF_MAX = AF_MAX; | ||
| 568 | |||
| 569 | pub const SYSPROTO_EVENT = 1; | ||
| 570 | pub const SYSPROTO_CONTROL = 2; | ||
| 571 | |||
| 572 | pub const SOCK_STREAM = 1; | ||
| 573 | pub const SOCK_DGRAM = 2; | ||
| 574 | pub const SOCK_RAW = 3; | ||
| 575 | pub const SOCK_RDM = 4; | ||
| 576 | pub const SOCK_SEQPACKET = 5; | ||
| 577 | pub const SOCK_MAXADDRLEN = 255; | ||
| 578 | |||
| 579 | pub const IPPROTO_ICMP = 1; | ||
| 580 | pub const IPPROTO_ICMPV6 = 58; | ||
| 581 | pub const IPPROTO_TCP = 6; | ||
| 582 | pub const IPPROTO_UDP = 17; | ||
| 583 | pub const IPPROTO_IP = 0; | ||
| 584 | pub const IPPROTO_IPV6 = 41; | ||
| 585 | |||
| 586 | fn wstatus(x: i32) i32 { | ||
| 587 | return x & 0o177; | ||
| 588 | } | ||
| 589 | const wstopped = 0o177; | ||
| 590 | pub fn WEXITSTATUS(x: i32) i32 { | ||
| 591 | return x >> 8; | ||
| 592 | } | ||
| 593 | pub fn WTERMSIG(x: i32) i32 { | ||
| 594 | return wstatus(x); | ||
| 595 | } | ||
| 596 | pub fn WSTOPSIG(x: i32) i32 { | ||
| 597 | return x >> 8; | ||
| 598 | } | ||
| 599 | pub fn WIFEXITED(x: i32) bool { | ||
| 600 | return wstatus(x) == 0; | ||
| 601 | } | ||
| 602 | pub fn WIFSTOPPED(x: i32) bool { | ||
| 603 | return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13; | ||
| 604 | } | ||
| 605 | pub fn WIFSIGNALED(x: i32) bool { | ||
| 606 | return wstatus(x) != wstopped and wstatus(x) != 0; | ||
| 607 | } | ||
| 608 | |||
| 609 | /// Get the errno from a syscall return value, or 0 for no error. | ||
| 610 | pub fn getErrno(r: usize) usize { | ||
| 611 | const signed_r = @bitCast(isize, r); | ||
| 612 | return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0; | ||
| 613 | } | ||
| 614 | |||
| 615 | pub fn close(fd: i32) usize { | ||
| 616 | return errnoWrap(c.close(fd)); | ||
| 617 | } | ||
| 618 | |||
| 619 | pub fn abort() noreturn { | ||
| 620 | c.abort(); | ||
| 621 | } | ||
| 622 | |||
| 623 | // bind(int socket, const struct sockaddr *address, socklen_t address_len) | ||
| 624 | pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize { | ||
| 625 | return errnoWrap(c.bind(@bitCast(c_int, fd), addr, len)); | ||
| 626 | } | ||
| 627 | |||
| 628 | pub fn exit(code: i32) noreturn { | ||
| 629 | c.exit(code); | ||
| 630 | } | ||
| 631 | |||
| 632 | pub fn isatty(fd: i32) bool { | ||
| 633 | return c.isatty(fd) != 0; | ||
| 634 | } | ||
| 635 | |||
| 636 | pub fn fstat(fd: i32, buf: *c.Stat) usize { | ||
| 637 | return errnoWrap(c.@"fstat$INODE64"(fd, buf)); | ||
| 638 | } | ||
| 639 | |||
| 640 | pub fn lseek(fd: i32, offset: isize, whence: c_int) usize { | ||
| 641 | return errnoWrap(c.lseek(fd, offset, whence)); | ||
| 642 | } | ||
| 643 | |||
| 644 | // TODO https://github.com/ziglang/zig/issues/265 on the whole file | ||
| 645 | pub fn open(path: [*]const u8, flags: u32, mode: usize) usize { | ||
| 646 | return errnoWrap(c.open(path, @bitCast(c_int, flags), mode)); | ||
| 647 | } | ||
| 648 | |||
| 649 | pub fn raise(sig: i32) usize { | ||
| 650 | return errnoWrap(c.raise(sig)); | ||
| 651 | } | ||
| 652 | |||
| 653 | pub fn read(fd: i32, buf: [*]u8, nbyte: usize) usize { | ||
| 654 | return errnoWrap(c.read(fd, @ptrCast(*c_void, buf), nbyte)); | ||
| 655 | } | ||
| 656 | |||
| 657 | pub fn pread(fd: i32, buf: [*]u8, nbyte: usize, offset: u64) usize { | ||
| 658 | return errnoWrap(c.pread(fd, @ptrCast(*c_void, buf), nbyte, offset)); | ||
| 659 | } | ||
| 660 | |||
| 661 | pub fn stat(noalias path: [*]const u8, noalias buf: *stat) usize { | ||
| 662 | return errnoWrap(c.stat(path, buf)); | ||
| 663 | } | ||
| 664 | |||
| 665 | pub fn write(fd: i32, buf: [*]const u8, nbyte: usize) usize { | ||
| 666 | return errnoWrap(c.write(fd, @ptrCast(*const c_void, buf), nbyte)); | ||
| 667 | } | ||
| 668 | |||
| 669 | pub fn pwrite(fd: i32, buf: [*]const u8, nbyte: usize, offset: u64) usize { | ||
| 670 | return errnoWrap(c.pwrite(fd, @ptrCast(*const c_void, buf), nbyte, offset)); | ||
| 671 | } | ||
| 672 | |||
| 673 | pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize { | ||
| 674 | const ptr_result = c.mmap( | ||
| 675 | @ptrCast(?*c_void, address), | ||
| 676 | length, | ||
| 677 | @bitCast(c_int, @intCast(c_uint, prot)), | ||
| 678 | @bitCast(c_int, c_uint(flags)), | ||
| 679 | fd, | ||
| 680 | offset, | ||
| 681 | ); | ||
| 682 | const isize_result = @bitCast(isize, @ptrToInt(ptr_result)); | ||
| 683 | return errnoWrap(isize_result); | ||
| 684 | } | ||
| 685 | |||
| 686 | pub fn munmap(address: usize, length: usize) usize { | ||
| 687 | return errnoWrap(c.munmap(@intToPtr(?*c_void, address), length)); | ||
| 688 | } | ||
| 689 | |||
| 690 | pub fn unlink(path: [*]const u8) usize { | ||
| 691 | return errnoWrap(c.unlink(path)); | ||
| 692 | } | ||
| 693 | |||
| 694 | pub fn getcwd(buf: [*]u8, size: usize) usize { | ||
| 695 | return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0; | ||
| 696 | } | ||
| 697 | |||
| 698 | pub fn waitpid(pid: i32, status: *i32, options: u32) usize { | ||
| 699 | comptime assert(i32.bit_count == c_int.bit_count); | ||
| 700 | return errnoWrap(c.waitpid(pid, @ptrCast(*c_int, status), @bitCast(c_int, options))); | ||
| 701 | } | ||
| 702 | |||
| 703 | pub fn fork() usize { | ||
| 704 | return errnoWrap(c.fork()); | ||
| 705 | } | ||
| 706 | |||
| 707 | pub fn access(path: [*]const u8, mode: u32) usize { | ||
| 708 | return errnoWrap(c.access(path, mode)); | ||
| 709 | } | ||
| 710 | |||
| 711 | pub fn pipe(fds: *[2]i32) usize { | ||
| 712 | comptime assert(i32.bit_count == c_int.bit_count); | ||
| 713 | return errnoWrap(c.pipe(@ptrCast(*[2]c_int, fds))); | ||
| 714 | } | ||
| 715 | |||
| 716 | pub fn getdirentries64(fd: i32, buf_ptr: [*]u8, buf_len: usize, basep: *i64) usize { | ||
| 717 | return errnoWrap(@bitCast(isize, c.__getdirentries64(fd, buf_ptr, buf_len, basep))); | ||
| 718 | } | ||
| 719 | |||
| 720 | pub fn kqueue() usize { | ||
| 721 | return errnoWrap(c.kqueue()); | ||
| 722 | } | ||
| 723 | |||
| 724 | pub fn kevent(kq: i32, changelist: []const Kevent, eventlist: []Kevent, timeout: ?*const timespec) usize { | ||
| 725 | return errnoWrap(c.kevent( | ||
| 726 | kq, | ||
| 727 | changelist.ptr, | ||
| 728 | @intCast(c_int, changelist.len), | ||
| 729 | eventlist.ptr, | ||
| 730 | @intCast(c_int, eventlist.len), | ||
| 731 | timeout, | ||
| 732 | )); | ||
| 733 | } | ||
| 734 | |||
| 735 | pub fn kevent64( | ||
| 736 | kq: i32, | ||
| 737 | changelist: []const kevent64_s, | ||
| 738 | eventlist: []kevent64_s, | ||
| 739 | flags: u32, | ||
| 740 | timeout: ?*const timespec, | ||
| 741 | ) usize { | ||
| 742 | return errnoWrap(c.kevent64(kq, changelist.ptr, changelist.len, eventlist.ptr, eventlist.len, flags, timeout)); | ||
| 743 | } | ||
| 744 | |||
| 745 | pub fn mkdir(path: [*]const u8, mode: u32) usize { | ||
| 746 | return errnoWrap(c.mkdir(path, mode)); | ||
| 747 | } | ||
| 748 | |||
| 749 | pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { | ||
| 750 | return errnoWrap(c.symlink(existing, new)); | ||
| 751 | } | ||
| 752 | |||
| 753 | pub fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize { | ||
| 754 | return errnoWrap(c.sysctl(name, namelen, oldp, oldlenp, newp, newlen)); | ||
| 755 | } | ||
| 756 | |||
| 757 | pub fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize { | ||
| 758 | return errnoWrap(c.sysctlbyname(name, oldp, oldlenp, newp, newlen)); | ||
| 759 | } | ||
| 760 | |||
| 761 | pub fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) usize { | ||
| 762 | return errnoWrap(c.sysctlnametomib(name, wibp, sizep)); | ||
| 763 | } | ||
| 764 | |||
| 765 | pub fn rename(old: [*]const u8, new: [*]const u8) usize { | ||
| 766 | return errnoWrap(c.rename(old, new)); | ||
| 767 | } | ||
| 768 | |||
| 769 | pub fn rmdir(path: [*]const u8) usize { | ||
| 770 | return errnoWrap(c.rmdir(path)); | ||
| 771 | } | ||
| 772 | |||
| 773 | pub fn chdir(path: [*]const u8) usize { | ||
| 774 | return errnoWrap(c.chdir(path)); | ||
| 775 | } | ||
| 776 | |||
| 777 | pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize { | ||
| 778 | return errnoWrap(c.execve(path, argv, envp)); | ||
| 779 | } | ||
| 780 | |||
| 781 | pub fn dup2(old: i32, new: i32) usize { | ||
| 782 | return errnoWrap(c.dup2(old, new)); | ||
| 783 | } | ||
| 784 | |||
| 785 | pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { | ||
| 786 | return errnoWrap(c.readlink(path, buf_ptr, buf_len)); | ||
| 787 | } | ||
| 788 | |||
| 789 | pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) usize { | ||
| 790 | return errnoWrap(c.gettimeofday(tv, tz)); | ||
| 791 | } | ||
| 792 | |||
| 793 | pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize { | ||
| 794 | return errnoWrap(c.nanosleep(req, rem)); | ||
| 795 | } | ||
| 796 | |||
| 797 | pub fn realpath(noalias filename: [*]const u8, noalias resolved_name: [*]u8) usize { | ||
| 798 | return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(c._errno().*)) else 0; | ||
| 799 | } | ||
| 800 | |||
| 801 | pub fn setreuid(ruid: u32, euid: u32) usize { | ||
| 802 | return errnoWrap(c.setreuid(ruid, euid)); | ||
| 803 | } | ||
| 804 | |||
| 805 | pub fn setregid(rgid: u32, egid: u32) usize { | ||
| 806 | return errnoWrap(c.setregid(rgid, egid)); | ||
| 807 | } | ||
| 808 | |||
| 809 | pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize { | ||
| 810 | return errnoWrap(c.sigprocmask(@bitCast(c_int, flags), set, oldset)); | ||
| 811 | } | ||
| 812 | |||
| 813 | pub fn sigaction(sig: u5, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize { | ||
| 814 | assert(sig != SIGKILL); | ||
| 815 | assert(sig != SIGSTOP); | ||
| 816 | var cact = c.Sigaction{ | ||
| 817 | .handler = @ptrCast(extern fn (c_int) void, act.handler), | ||
| 818 | .sa_flags = @bitCast(c_int, act.flags), | ||
| 819 | .sa_mask = act.mask, | ||
| 820 | }; | ||
| 821 | var coact: c.Sigaction = undefined; | ||
| 822 | const result = errnoWrap(c.sigaction(sig, &cact, &coact)); | ||
| 823 | if (result != 0) { | ||
| 824 | return result; | ||
| 825 | } | ||
| 826 | if (oact) |old| { | ||
| 827 | old.* = Sigaction{ | ||
| 828 | .handler = @ptrCast(extern fn (i32) void, coact.handler), | ||
| 829 | .flags = @bitCast(u32, coact.sa_flags), | ||
| 830 | .mask = coact.sa_mask, | ||
| 831 | }; | ||
| 832 | } | ||
| 833 | return result; | ||
| 834 | } | ||
| 835 | |||
| 836 | pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize { | ||
| 837 | return errnoWrap(c.socket(@bitCast(c_int, domain), @bitCast(c_int, socket_type), @bitCast(c_int, protocol))); | ||
| 838 | } | ||
| 839 | |||
| 840 | pub const iovec = extern struct { | ||
| 841 | iov_base: [*]u8, | ||
| 842 | iov_len: usize, | ||
| 843 | }; | ||
| 844 | |||
| 845 | pub const iovec_const = extern struct { | ||
| 846 | iov_base: [*]const u8, | ||
| 847 | iov_len: usize, | ||
| 848 | }; | ||
| 849 | |||
| 850 | pub const sigset_t = c.sigset_t; | ||
| 851 | pub const empty_sigset = sigset_t(0); | ||
| 852 | |||
| 853 | pub const timespec = c.timespec; | ||
| 854 | pub const Stat = c.Stat; | ||
| 855 | pub const dirent = c.dirent; | ||
| 856 | |||
| 857 | pub const in_port_t = c.in_port_t; | ||
| 858 | pub const sa_family_t = c.sa_family_t; | ||
| 859 | pub const socklen_t = c.socklen_t; | ||
| 860 | |||
| 861 | pub const sockaddr = c.sockaddr; | ||
| 862 | pub const sockaddr_in = c.sockaddr_in; | ||
| 863 | pub const sockaddr_in6 = c.sockaddr_in6; | ||
| 864 | |||
| 865 | /// Renamed from `kevent` to `Kevent` to avoid conflict with the syscall. | ||
| 866 | pub const Kevent = c.Kevent; | ||
| 867 | pub const kevent64_s = c.kevent64_s; | ||
| 868 | |||
| 869 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | ||
| 870 | pub const Sigaction = struct { | ||
| 871 | handler: extern fn (i32) void, | ||
| 872 | mask: sigset_t, | ||
| 873 | flags: u32, | ||
| 874 | }; | ||
| 875 | |||
| 876 | pub fn sigaddset(set: *sigset_t, signo: u5) void { | ||
| 877 | set.* |= u32(1) << (signo - 1); | ||
| 878 | } | ||
| 879 | |||
| 880 | /// Takes the return value from a syscall and formats it back in the way | ||
| 881 | /// that the kernel represents it to libc. Errno was a mistake, let's make | ||
| 882 | /// it go away forever. | ||
| 883 | fn errnoWrap(value: isize) usize { | ||
| 884 | return @bitCast(usize, if (value == -1) -isize(c._errno().*) else value); | ||
| 885 | } | ||
| 886 | |||
| 887 | pub const timezone = c.timezone; | ||
| 888 | pub const timeval = c.timeval; | ||
| 889 | pub const mach_timebase_info_data = c.mach_timebase_info_data; | ||
| 890 | |||
| 891 | pub const mach_absolute_time = c.mach_absolute_time; | ||
| 892 | pub const mach_timebase_info = c.mach_timebase_info; |
std/os/darwin/errno.zig deleted-328| ... | @@ -1,328 +0,0 @@ | ||
| 1 | /// Operation not permitted | ||
| 2 | pub const EPERM = 1; | ||
| 3 | |||
| 4 | /// No such file or directory | ||
| 5 | pub const ENOENT = 2; | ||
| 6 | |||
| 7 | /// No such process | ||
| 8 | pub const ESRCH = 3; | ||
| 9 | |||
| 10 | /// Interrupted system call | ||
| 11 | pub const EINTR = 4; | ||
| 12 | |||
| 13 | /// Input/output error | ||
| 14 | pub const EIO = 5; | ||
| 15 | |||
| 16 | /// Device not configured | ||
| 17 | pub const ENXIO = 6; | ||
| 18 | |||
| 19 | /// Argument list too long | ||
| 20 | pub const E2BIG = 7; | ||
| 21 | |||
| 22 | /// Exec format error | ||
| 23 | pub const ENOEXEC = 8; | ||
| 24 | |||
| 25 | /// Bad file descriptor | ||
| 26 | pub const EBADF = 9; | ||
| 27 | |||
| 28 | /// No child processes | ||
| 29 | pub const ECHILD = 10; | ||
| 30 | |||
| 31 | /// Resource deadlock avoided | ||
| 32 | pub const EDEADLK = 11; | ||
| 33 | |||
| 34 | /// Cannot allocate memory | ||
| 35 | pub const ENOMEM = 12; | ||
| 36 | |||
| 37 | /// Permission denied | ||
| 38 | pub const EACCES = 13; | ||
| 39 | |||
| 40 | /// Bad address | ||
| 41 | pub const EFAULT = 14; | ||
| 42 | |||
| 43 | /// Block device required | ||
| 44 | pub const ENOTBLK = 15; | ||
| 45 | |||
| 46 | /// Device / Resource busy | ||
| 47 | pub const EBUSY = 16; | ||
| 48 | |||
| 49 | /// File exists | ||
| 50 | pub const EEXIST = 17; | ||
| 51 | |||
| 52 | /// Cross-device link | ||
| 53 | pub const EXDEV = 18; | ||
| 54 | |||
| 55 | /// Operation not supported by device | ||
| 56 | pub const ENODEV = 19; | ||
| 57 | |||
| 58 | /// Not a directory | ||
| 59 | pub const ENOTDIR = 20; | ||
| 60 | |||
| 61 | /// Is a directory | ||
| 62 | pub const EISDIR = 21; | ||
| 63 | |||
| 64 | /// Invalid argument | ||
| 65 | pub const EINVAL = 22; | ||
| 66 | |||
| 67 | /// Too many open files in system | ||
| 68 | pub const ENFILE = 23; | ||
| 69 | |||
| 70 | /// Too many open files | ||
| 71 | pub const EMFILE = 24; | ||
| 72 | |||
| 73 | /// Inappropriate ioctl for device | ||
| 74 | pub const ENOTTY = 25; | ||
| 75 | |||
| 76 | /// Text file busy | ||
| 77 | pub const ETXTBSY = 26; | ||
| 78 | |||
| 79 | /// File too large | ||
| 80 | pub const EFBIG = 27; | ||
| 81 | |||
| 82 | /// No space left on device | ||
| 83 | pub const ENOSPC = 28; | ||
| 84 | |||
| 85 | /// Illegal seek | ||
| 86 | pub const ESPIPE = 29; | ||
| 87 | |||
| 88 | /// Read-only file system | ||
| 89 | pub const EROFS = 30; | ||
| 90 | |||
| 91 | /// Too many links | ||
| 92 | pub const EMLINK = 31; | ||
| 93 | /// Broken pipe | ||
| 94 | |||
| 95 | // math software | ||
| 96 | pub const EPIPE = 32; | ||
| 97 | |||
| 98 | /// Numerical argument out of domain | ||
| 99 | pub const EDOM = 33; | ||
| 100 | /// Result too large | ||
| 101 | |||
| 102 | // non-blocking and interrupt i/o | ||
| 103 | pub const ERANGE = 34; | ||
| 104 | |||
| 105 | /// Resource temporarily unavailable | ||
| 106 | pub const EAGAIN = 35; | ||
| 107 | |||
| 108 | /// Operation would block | ||
| 109 | pub const EWOULDBLOCK = EAGAIN; | ||
| 110 | |||
| 111 | /// Operation now in progress | ||
| 112 | pub const EINPROGRESS = 36; | ||
| 113 | /// Operation already in progress | ||
| 114 | |||
| 115 | // ipc/network software -- argument errors | ||
| 116 | pub const EALREADY = 37; | ||
| 117 | |||
| 118 | /// Socket operation on non-socket | ||
| 119 | pub const ENOTSOCK = 38; | ||
| 120 | |||
| 121 | /// Destination address required | ||
| 122 | pub const EDESTADDRREQ = 39; | ||
| 123 | |||
| 124 | /// Message too long | ||
| 125 | pub const EMSGSIZE = 40; | ||
| 126 | |||
| 127 | /// Protocol wrong type for socket | ||
| 128 | pub const EPROTOTYPE = 41; | ||
| 129 | |||
| 130 | /// Protocol not available | ||
| 131 | pub const ENOPROTOOPT = 42; | ||
| 132 | |||
| 133 | /// Protocol not supported | ||
| 134 | pub const EPROTONOSUPPORT = 43; | ||
| 135 | |||
| 136 | /// Socket type not supported | ||
| 137 | pub const ESOCKTNOSUPPORT = 44; | ||
| 138 | |||
| 139 | /// Operation not supported | ||
| 140 | pub const ENOTSUP = 45; | ||
| 141 | |||
| 142 | /// Protocol family not supported | ||
| 143 | pub const EPFNOSUPPORT = 46; | ||
| 144 | |||
| 145 | /// Address family not supported by protocol family | ||
| 146 | pub const EAFNOSUPPORT = 47; | ||
| 147 | |||
| 148 | /// Address already in use | ||
| 149 | pub const EADDRINUSE = 48; | ||
| 150 | /// Can't assign requested address | ||
| 151 | |||
| 152 | // ipc/network software -- operational errors | ||
| 153 | pub const EADDRNOTAVAIL = 49; | ||
| 154 | |||
| 155 | /// Network is down | ||
| 156 | pub const ENETDOWN = 50; | ||
| 157 | |||
| 158 | /// Network is unreachable | ||
| 159 | pub const ENETUNREACH = 51; | ||
| 160 | |||
| 161 | /// Network dropped connection on reset | ||
| 162 | pub const ENETRESET = 52; | ||
| 163 | |||
| 164 | /// Software caused connection abort | ||
| 165 | pub const ECONNABORTED = 53; | ||
| 166 | |||
| 167 | /// Connection reset by peer | ||
| 168 | pub const ECONNRESET = 54; | ||
| 169 | |||
| 170 | /// No buffer space available | ||
| 171 | pub const ENOBUFS = 55; | ||
| 172 | |||
| 173 | /// Socket is already connected | ||
| 174 | pub const EISCONN = 56; | ||
| 175 | |||
| 176 | /// Socket is not connected | ||
| 177 | pub const ENOTCONN = 57; | ||
| 178 | |||
| 179 | /// Can't send after socket shutdown | ||
| 180 | pub const ESHUTDOWN = 58; | ||
| 181 | |||
| 182 | /// Too many references: can't splice | ||
| 183 | pub const ETOOMANYREFS = 59; | ||
| 184 | |||
| 185 | /// Operation timed out | ||
| 186 | pub const ETIMEDOUT = 60; | ||
| 187 | |||
| 188 | /// Connection refused | ||
| 189 | pub const ECONNREFUSED = 61; | ||
| 190 | |||
| 191 | /// Too many levels of symbolic links | ||
| 192 | pub const ELOOP = 62; | ||
| 193 | |||
| 194 | /// File name too long | ||
| 195 | pub const ENAMETOOLONG = 63; | ||
| 196 | |||
| 197 | /// Host is down | ||
| 198 | pub const EHOSTDOWN = 64; | ||
| 199 | |||
| 200 | /// No route to host | ||
| 201 | pub const EHOSTUNREACH = 65; | ||
| 202 | /// Directory not empty | ||
| 203 | |||
| 204 | // quotas & mush | ||
| 205 | pub const ENOTEMPTY = 66; | ||
| 206 | |||
| 207 | /// Too many processes | ||
| 208 | pub const EPROCLIM = 67; | ||
| 209 | |||
| 210 | /// Too many users | ||
| 211 | pub const EUSERS = 68; | ||
| 212 | /// Disc quota exceeded | ||
| 213 | |||
| 214 | // Network File System | ||
| 215 | pub const EDQUOT = 69; | ||
| 216 | |||
| 217 | /// Stale NFS file handle | ||
| 218 | pub const ESTALE = 70; | ||
| 219 | |||
| 220 | /// Too many levels of remote in path | ||
| 221 | pub const EREMOTE = 71; | ||
| 222 | |||
| 223 | /// RPC struct is bad | ||
| 224 | pub const EBADRPC = 72; | ||
| 225 | |||
| 226 | /// RPC version wrong | ||
| 227 | pub const ERPCMISMATCH = 73; | ||
| 228 | |||
| 229 | /// RPC prog. not avail | ||
| 230 | pub const EPROGUNAVAIL = 74; | ||
| 231 | |||
| 232 | /// Program version wrong | ||
| 233 | pub const EPROGMISMATCH = 75; | ||
| 234 | |||
| 235 | /// Bad procedure for program | ||
| 236 | pub const EPROCUNAVAIL = 76; | ||
| 237 | |||
| 238 | /// No locks available | ||
| 239 | pub const ENOLCK = 77; | ||
| 240 | |||
| 241 | /// Function not implemented | ||
| 242 | pub const ENOSYS = 78; | ||
| 243 | |||
| 244 | /// Inappropriate file type or format | ||
| 245 | pub const EFTYPE = 79; | ||
| 246 | |||
| 247 | /// Authentication error | ||
| 248 | pub const EAUTH = 80; | ||
| 249 | /// Need authenticator | ||
| 250 | |||
| 251 | // Intelligent device errors | ||
| 252 | pub const ENEEDAUTH = 81; | ||
| 253 | |||
| 254 | /// Device power is off | ||
| 255 | pub const EPWROFF = 82; | ||
| 256 | |||
| 257 | /// Device error, e.g. paper out | ||
| 258 | pub const EDEVERR = 83; | ||
| 259 | /// Value too large to be stored in data type | ||
| 260 | |||
| 261 | // Program loading errors | ||
| 262 | pub const EOVERFLOW = 84; | ||
| 263 | |||
| 264 | /// Bad executable | ||
| 265 | pub const EBADEXEC = 85; | ||
| 266 | |||
| 267 | /// Bad CPU type in executable | ||
| 268 | pub const EBADARCH = 86; | ||
| 269 | |||
| 270 | /// Shared library version mismatch | ||
| 271 | pub const ESHLIBVERS = 87; | ||
| 272 | |||
| 273 | /// Malformed Macho file | ||
| 274 | pub const EBADMACHO = 88; | ||
| 275 | |||
| 276 | /// Operation canceled | ||
| 277 | pub const ECANCELED = 89; | ||
| 278 | |||
| 279 | /// Identifier removed | ||
| 280 | pub const EIDRM = 90; | ||
| 281 | |||
| 282 | /// No message of desired type | ||
| 283 | pub const ENOMSG = 91; | ||
| 284 | |||
| 285 | /// Illegal byte sequence | ||
| 286 | pub const EILSEQ = 92; | ||
| 287 | |||
| 288 | /// Attribute not found | ||
| 289 | pub const ENOATTR = 93; | ||
| 290 | |||
| 291 | /// Bad message | ||
| 292 | pub const EBADMSG = 94; | ||
| 293 | |||
| 294 | /// Reserved | ||
| 295 | pub const EMULTIHOP = 95; | ||
| 296 | |||
| 297 | /// No message available on STREAM | ||
| 298 | pub const ENODATA = 96; | ||
| 299 | |||
| 300 | /// Reserved | ||
| 301 | pub const ENOLINK = 97; | ||
| 302 | |||
| 303 | /// No STREAM resources | ||
| 304 | pub const ENOSR = 98; | ||
| 305 | |||
| 306 | /// Not a STREAM | ||
| 307 | pub const ENOSTR = 99; | ||
| 308 | |||
| 309 | /// Protocol error | ||
| 310 | pub const EPROTO = 100; | ||
| 311 | |||
| 312 | /// STREAM ioctl timeout | ||
| 313 | pub const ETIME = 101; | ||
| 314 | |||
| 315 | /// No such policy registered | ||
| 316 | pub const ENOPOLICY = 103; | ||
| 317 | |||
| 318 | /// State not recoverable | ||
| 319 | pub const ENOTRECOVERABLE = 104; | ||
| 320 | |||
| 321 | /// Previous owner died | ||
| 322 | pub const EOWNERDEAD = 105; | ||
| 323 | |||
| 324 | /// Interface output queue is full | ||
| 325 | pub const EQFULL = 106; | ||
| 326 | |||
| 327 | /// Must be equal largest errno | ||
| 328 | pub const ELAST = 106; | ||
std/os/file.zig+12-71| ... | @@ -16,7 +16,7 @@ const is_windows = builtin.os == builtin.Os.windows; | ... | @@ -16,7 +16,7 @@ const is_windows = builtin.os == builtin.Os.windows; |
| 16 | 16 | ||
| 17 | pub const File = struct { | 17 | pub const File = struct { |
| 18 | /// The OS-specific file descriptor or file handle. | 18 | /// The OS-specific file descriptor or file handle. |
| 19 | handle: os.FileHandle, | 19 | handle: posix.fd_t, |
| 20 | 20 | ||
| 21 | pub const Mode = switch (builtin.os) { | 21 | pub const Mode = switch (builtin.os) { |
| 22 | Os.windows => void, | 22 | Os.windows => void, |
| ... | @@ -138,83 +138,24 @@ pub const File = struct { | ... | @@ -138,83 +138,24 @@ pub const File = struct { |
| 138 | return openHandle(handle); | 138 | return openHandle(handle); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | pub fn openHandle(handle: os.FileHandle) File { | 141 | pub fn openHandle(handle: posix.fd_t) File { |
| 142 | return File{ .handle = handle }; | 142 | return File{ .handle = handle }; |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | pub const AccessError = error{ | 145 | /// Test for the existence of `path`. |
| 146 | PermissionDenied, | 146 | /// `path` is UTF8-encoded. |
| 147 | FileNotFound, | 147 | pub fn exists(path: []const u8) AccessError!void { |
| 148 | NameTooLong, | 148 | return posix.access(path, posix.F_OK); |
| 149 | InputOutput, | ||
| 150 | SystemResources, | ||
| 151 | BadPathName, | ||
| 152 | |||
| 153 | /// On Windows, file paths must be valid Unicode. | ||
| 154 | InvalidUtf8, | ||
| 155 | |||
| 156 | Unexpected, | ||
| 157 | }; | ||
| 158 | |||
| 159 | /// Call from Windows-specific code if you already have a UTF-16LE encoded, null terminated string. | ||
| 160 | /// Otherwise use `access` or `accessC`. | ||
| 161 | pub fn accessW(path: [*]const u16) AccessError!void { | ||
| 162 | if (os.windows.GetFileAttributesW(path) != os.windows.INVALID_FILE_ATTRIBUTES) { | ||
| 163 | return; | ||
| 164 | } | ||
| 165 | |||
| 166 | const err = windows.GetLastError(); | ||
| 167 | switch (err) { | ||
| 168 | windows.ERROR.FILE_NOT_FOUND => return error.FileNotFound, | ||
| 169 | windows.ERROR.PATH_NOT_FOUND => return error.FileNotFound, | ||
| 170 | windows.ERROR.ACCESS_DENIED => return error.PermissionDenied, | ||
| 171 | else => return os.unexpectedErrorWindows(err), | ||
| 172 | } | ||
| 173 | } | 149 | } |
| 174 | 150 | ||
| 175 | /// Call if you have a UTF-8 encoded, null-terminated string. | 151 | /// Same as `exists` except the parameter is null-terminated UTF16LE-encoded. |
| 176 | /// Otherwise use `access` or `accessW`. | 152 | pub fn existsW(path: [*]const u16) AccessError!void { |
| 177 | pub fn accessC(path: [*]const u8) AccessError!void { | 153 | return posix.accessW(path, posix.F_OK); |
| 178 | if (is_windows) { | ||
| 179 | const path_w = try windows_util.cStrToPrefixedFileW(path); | ||
| 180 | return accessW(&path_w); | ||
| 181 | } | ||
| 182 | if (is_posix) { | ||
| 183 | const result = posix.access(path, posix.F_OK); | ||
| 184 | const err = posix.getErrno(result); | ||
| 185 | switch (err) { | ||
| 186 | 0 => return, | ||
| 187 | posix.EACCES => return error.PermissionDenied, | ||
| 188 | posix.EROFS => return error.PermissionDenied, | ||
| 189 | posix.ELOOP => return error.PermissionDenied, | ||
| 190 | posix.ETXTBSY => return error.PermissionDenied, | ||
| 191 | posix.ENOTDIR => return error.FileNotFound, | ||
| 192 | posix.ENOENT => return error.FileNotFound, | ||
| 193 | |||
| 194 | posix.ENAMETOOLONG => return error.NameTooLong, | ||
| 195 | posix.EINVAL => unreachable, | ||
| 196 | posix.EFAULT => unreachable, | ||
| 197 | posix.EIO => return error.InputOutput, | ||
| 198 | posix.ENOMEM => return error.SystemResources, | ||
| 199 | else => return os.unexpectedErrorPosix(err), | ||
| 200 | } | ||
| 201 | } | ||
| 202 | @compileError("Unsupported OS"); | ||
| 203 | } | 154 | } |
| 204 | 155 | ||
| 205 | pub fn access(path: []const u8) AccessError!void { | 156 | /// Same as `exists` except the parameter is null-terminated. |
| 206 | if (is_windows) { | 157 | pub fn existsC(path: [*]const u8) AccessError!void { |
| 207 | const path_w = try windows_util.sliceToPrefixedFileW(path); | 158 | return posix.accessC(path, posix.F_OK); |
| 208 | return accessW(&path_w); | ||
| 209 | } | ||
| 210 | if (is_posix) { | ||
| 211 | var path_with_null: [posix.PATH_MAX]u8 = undefined; | ||
| 212 | if (path.len >= posix.PATH_MAX) return error.NameTooLong; | ||
| 213 | mem.copy(u8, path_with_null[0..], path); | ||
| 214 | path_with_null[path.len] = 0; | ||
| 215 | return accessC(&path_with_null); | ||
| 216 | } | ||
| 217 | @compileError("Unsupported OS"); | ||
| 218 | } | 159 | } |
| 219 | 160 | ||
| 220 | /// Upon success, the stream is in an uninitialized state. To continue using it, | 161 | /// Upon success, the stream is in an uninitialized state. To continue using it, |
std/os/freebsd.zig+3-844| ... | @@ -1,845 +1,4 @@ | ... | @@ -1,845 +1,4 @@ |
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | pub use @import("freebsd/errno.zig"); | ||
| 4 | |||
| 5 | const std = @import("../std.zig"); | 1 | const std = @import("../std.zig"); |
| 6 | const c = std.c; | 2 | const builtin = @import("builtin"); |
| 7 | 3 | pub const is_the_target = builtin.os == .freebsd; | |
| 8 | const assert = std.debug.assert; | 4 | pub use std.c; |
| 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 = 14; // struct: process entries | ||
| 16 | pub const KERN_PROC_PATHNAME = 12; // 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 = 4; | ||
| 33 | pub const CLOCK_UPTIME = 5; | ||
| 34 | pub const CLOCK_UPTIME_PRECISE = 7; | ||
| 35 | pub const CLOCK_UPTIME_FAST = 8; | ||
| 36 | pub const CLOCK_REALTIME_PRECISE = 9; | ||
| 37 | pub const CLOCK_REALTIME_FAST = 10; | ||
| 38 | pub const CLOCK_MONOTONIC_PRECISE = 11; | ||
| 39 | pub const CLOCK_MONOTONIC_FAST = 12; | ||
| 40 | pub const CLOCK_SECOND = 13; | ||
| 41 | pub const CLOCK_THREAD_CPUTIME_ID = 14; | ||
| 42 | pub const CLOCK_PROCESS_CPUTIME_ID = 15; | ||
| 43 | |||
| 44 | pub const MAP_FAILED = maxInt(usize); | ||
| 45 | pub const MAP_SHARED = 0x0001; | ||
| 46 | pub const MAP_PRIVATE = 0x0002; | ||
| 47 | pub const MAP_FIXED = 0x0010; | ||
| 48 | pub const MAP_STACK = 0x0400; | ||
| 49 | pub const MAP_NOSYNC = 0x0800; | ||
| 50 | pub const MAP_ANON = 0x1000; | ||
| 51 | pub const MAP_ANONYMOUS = MAP_ANON; | ||
| 52 | pub const MAP_FILE = 0; | ||
| 53 | pub const MAP_NORESERVE = 0; | ||
| 54 | |||
| 55 | pub const MAP_GUARD = 0x00002000; | ||
| 56 | pub const MAP_EXCL = 0x00004000; | ||
| 57 | pub const MAP_NOCORE = 0x00020000; | ||
| 58 | pub const MAP_PREFAULT_READ = 0x00040000; | ||
| 59 | pub const MAP_32BIT = 0x00080000; | ||
| 60 | |||
| 61 | pub const WNOHANG = 1; | ||
| 62 | pub const WUNTRACED = 2; | ||
| 63 | pub const WSTOPPED = WUNTRACED; | ||
| 64 | pub const WCONTINUED = 4; | ||
| 65 | pub const WNOWAIT = 8; | ||
| 66 | pub const WEXITED = 16; | ||
| 67 | pub const WTRAPPED = 32; | ||
| 68 | |||
| 69 | pub const SA_ONSTACK = 0x0001; | ||
| 70 | pub const SA_RESTART = 0x0002; | ||
| 71 | pub const SA_RESETHAND = 0x0004; | ||
| 72 | pub const SA_NOCLDSTOP = 0x0008; | ||
| 73 | pub const SA_NODEFER = 0x0010; | ||
| 74 | pub const SA_NOCLDWAIT = 0x0020; | ||
| 75 | pub const SA_SIGINFO = 0x0040; | ||
| 76 | |||
| 77 | pub const SIGHUP = 1; | ||
| 78 | pub const SIGINT = 2; | ||
| 79 | pub const SIGQUIT = 3; | ||
| 80 | pub const SIGILL = 4; | ||
| 81 | pub const SIGTRAP = 5; | ||
| 82 | pub const SIGABRT = 6; | ||
| 83 | pub const SIGIOT = SIGABRT; | ||
| 84 | pub const SIGEMT = 7; | ||
| 85 | pub const SIGFPE = 8; | ||
| 86 | pub const SIGKILL = 9; | ||
| 87 | pub const SIGBUS = 10; | ||
| 88 | pub const SIGSEGV = 11; | ||
| 89 | pub const SIGSYS = 12; | ||
| 90 | pub const SIGPIPE = 13; | ||
| 91 | pub const SIGALRM = 14; | ||
| 92 | pub const SIGTERM = 15; | ||
| 93 | pub const SIGURG = 16; | ||
| 94 | pub const SIGSTOP = 17; | ||
| 95 | pub const SIGTSTP = 18; | ||
| 96 | pub const SIGCONT = 19; | ||
| 97 | pub const SIGCHLD = 20; | ||
| 98 | pub const SIGTTIN = 21; | ||
| 99 | pub const SIGTTOU = 22; | ||
| 100 | pub const SIGIO = 23; | ||
| 101 | pub const SIGXCPU = 24; | ||
| 102 | pub const SIGXFSZ = 25; | ||
| 103 | pub const SIGVTALRM = 26; | ||
| 104 | pub const SIGPROF = 27; | ||
| 105 | pub const SIGWINCH = 28; | ||
| 106 | pub const SIGINFO = 29; | ||
| 107 | pub const SIGUSR1 = 30; | ||
| 108 | pub const SIGUSR2 = 31; | ||
| 109 | pub const SIGTHR = 32; | ||
| 110 | pub const SIGLWP = SIGTHR; | ||
| 111 | pub const SIGLIBRT = 33; | ||
| 112 | |||
| 113 | pub const SIGRTMIN = 65; | ||
| 114 | pub const SIGRTMAX = 126; | ||
| 115 | |||
| 116 | // access function | ||
| 117 | pub const F_OK = 0; // test for existence of file | ||
| 118 | pub const X_OK = 1; // test for execute or search permission | ||
| 119 | pub const W_OK = 2; // test for write permission | ||
| 120 | pub const R_OK = 4; // test for read permission | ||
| 121 | |||
| 122 | pub const O_RDONLY = 0x0000; | ||
| 123 | pub const O_WRONLY = 0x0001; | ||
| 124 | pub const O_RDWR = 0x0002; | ||
| 125 | pub const O_ACCMODE = 0x0003; | ||
| 126 | |||
| 127 | pub const O_CREAT = 0x0200; | ||
| 128 | pub const O_EXCL = 0x0800; | ||
| 129 | pub const O_NOCTTY = 0x8000; | ||
| 130 | pub const O_TRUNC = 0x0400; | ||
| 131 | pub const O_APPEND = 0x0008; | ||
| 132 | pub const O_NONBLOCK = 0x0004; | ||
| 133 | pub const O_DSYNC = 0o10000; | ||
| 134 | pub const O_SYNC = 0x0080; | ||
| 135 | pub const O_RSYNC = 0o4010000; | ||
| 136 | pub const O_DIRECTORY = 0o200000; | ||
| 137 | pub const O_NOFOLLOW = 0x0100; | ||
| 138 | pub const O_CLOEXEC = 0x00100000; | ||
| 139 | |||
| 140 | pub const O_ASYNC = 0x0040; | ||
| 141 | pub const O_DIRECT = 0x00010000; | ||
| 142 | pub const O_LARGEFILE = 0; | ||
| 143 | pub const O_NOATIME = 0o1000000; | ||
| 144 | pub const O_PATH = 0o10000000; | ||
| 145 | pub const O_TMPFILE = 0o20200000; | ||
| 146 | pub const O_NDELAY = O_NONBLOCK; | ||
| 147 | |||
| 148 | pub const F_DUPFD = 0; | ||
| 149 | pub const F_GETFD = 1; | ||
| 150 | pub const F_SETFD = 2; | ||
| 151 | pub const F_GETFL = 3; | ||
| 152 | pub const F_SETFL = 4; | ||
| 153 | |||
| 154 | pub const F_SETOWN = 8; | ||
| 155 | pub const F_GETOWN = 9; | ||
| 156 | pub const F_SETSIG = 10; | ||
| 157 | pub const F_GETSIG = 11; | ||
| 158 | |||
| 159 | pub const F_GETLK = 5; | ||
| 160 | pub const F_SETLK = 6; | ||
| 161 | pub const F_SETLKW = 7; | ||
| 162 | |||
| 163 | pub const F_SETOWN_EX = 15; | ||
| 164 | pub const F_GETOWN_EX = 16; | ||
| 165 | |||
| 166 | pub const F_GETOWNER_UIDS = 17; | ||
| 167 | |||
| 168 | pub const SEEK_SET = 0; | ||
| 169 | pub const SEEK_CUR = 1; | ||
| 170 | pub const SEEK_END = 2; | ||
| 171 | |||
| 172 | pub const SIG_BLOCK = 1; | ||
| 173 | pub const SIG_UNBLOCK = 2; | ||
| 174 | pub const SIG_SETMASK = 3; | ||
| 175 | |||
| 176 | pub const SOCK_STREAM = 1; | ||
| 177 | pub const SOCK_DGRAM = 2; | ||
| 178 | pub const SOCK_RAW = 3; | ||
| 179 | pub const SOCK_RDM = 4; | ||
| 180 | pub const SOCK_SEQPACKET = 5; | ||
| 181 | |||
| 182 | pub const SOCK_CLOEXEC = 0x10000000; | ||
| 183 | pub const SOCK_NONBLOCK = 0x20000000; | ||
| 184 | |||
| 185 | pub const PROTO_ip = 0o000; | ||
| 186 | pub const PROTO_icmp = 0o001; | ||
| 187 | pub const PROTO_igmp = 0o002; | ||
| 188 | pub const PROTO_ggp = 0o003; | ||
| 189 | pub const PROTO_ipencap = 0o004; | ||
| 190 | pub const PROTO_st = 0o005; | ||
| 191 | pub const PROTO_tcp = 0o006; | ||
| 192 | pub const PROTO_egp = 0o010; | ||
| 193 | pub const PROTO_pup = 0o014; | ||
| 194 | pub const PROTO_udp = 0o021; | ||
| 195 | pub const PROTO_hmp = 0o024; | ||
| 196 | pub const PROTO_xns_idp = 0o026; | ||
| 197 | pub const PROTO_rdp = 0o033; | ||
| 198 | pub const PROTO_iso_tp4 = 0o035; | ||
| 199 | pub const PROTO_xtp = 0o044; | ||
| 200 | pub const PROTO_ddp = 0o045; | ||
| 201 | pub const PROTO_idpr_cmtp = 0o046; | ||
| 202 | pub const PROTO_ipv6 = 0o051; | ||
| 203 | pub const PROTO_ipv6_route = 0o053; | ||
| 204 | pub const PROTO_ipv6_frag = 0o054; | ||
| 205 | pub const PROTO_idrp = 0o055; | ||
| 206 | pub const PROTO_rsvp = 0o056; | ||
| 207 | pub const PROTO_gre = 0o057; | ||
| 208 | pub const PROTO_esp = 0o062; | ||
| 209 | pub const PROTO_ah = 0o063; | ||
| 210 | pub const PROTO_skip = 0o071; | ||
| 211 | pub const PROTO_ipv6_icmp = 0o072; | ||
| 212 | pub const PROTO_ipv6_nonxt = 0o073; | ||
| 213 | pub const PROTO_ipv6_opts = 0o074; | ||
| 214 | pub const PROTO_rspf = 0o111; | ||
| 215 | pub const PROTO_vmtp = 0o121; | ||
| 216 | pub const PROTO_ospf = 0o131; | ||
| 217 | pub const PROTO_ipip = 0o136; | ||
| 218 | pub const PROTO_encap = 0o142; | ||
| 219 | pub const PROTO_pim = 0o147; | ||
| 220 | pub const PROTO_raw = 0o377; | ||
| 221 | |||
| 222 | pub const PF_UNSPEC = 0; | ||
| 223 | pub const PF_LOCAL = 1; | ||
| 224 | pub const PF_UNIX = PF_LOCAL; | ||
| 225 | pub const PF_FILE = PF_LOCAL; | ||
| 226 | pub const PF_INET = 2; | ||
| 227 | pub const PF_AX25 = 3; | ||
| 228 | pub const PF_IPX = 4; | ||
| 229 | pub const PF_APPLETALK = 5; | ||
| 230 | pub const PF_NETROM = 6; | ||
| 231 | pub const PF_BRIDGE = 7; | ||
| 232 | pub const PF_ATMPVC = 8; | ||
| 233 | pub const PF_X25 = 9; | ||
| 234 | pub const PF_INET6 = 10; | ||
| 235 | pub const PF_ROSE = 11; | ||
| 236 | pub const PF_DECnet = 12; | ||
| 237 | pub const PF_NETBEUI = 13; | ||
| 238 | pub const PF_SECURITY = 14; | ||
| 239 | pub const PF_KEY = 15; | ||
| 240 | pub const PF_NETLINK = 16; | ||
| 241 | pub const PF_ROUTE = PF_NETLINK; | ||
| 242 | pub const PF_PACKET = 17; | ||
| 243 | pub const PF_ASH = 18; | ||
| 244 | pub const PF_ECONET = 19; | ||
| 245 | pub const PF_ATMSVC = 20; | ||
| 246 | pub const PF_RDS = 21; | ||
| 247 | pub const PF_SNA = 22; | ||
| 248 | pub const PF_IRDA = 23; | ||
| 249 | pub const PF_PPPOX = 24; | ||
| 250 | pub const PF_WANPIPE = 25; | ||
| 251 | pub const PF_LLC = 26; | ||
| 252 | pub const PF_IB = 27; | ||
| 253 | pub const PF_MPLS = 28; | ||
| 254 | pub const PF_CAN = 29; | ||
| 255 | pub const PF_TIPC = 30; | ||
| 256 | pub const PF_BLUETOOTH = 31; | ||
| 257 | pub const PF_IUCV = 32; | ||
| 258 | pub const PF_RXRPC = 33; | ||
| 259 | pub const PF_ISDN = 34; | ||
| 260 | pub const PF_PHONET = 35; | ||
| 261 | pub const PF_IEEE802154 = 36; | ||
| 262 | pub const PF_CAIF = 37; | ||
| 263 | pub const PF_ALG = 38; | ||
| 264 | pub const PF_NFC = 39; | ||
| 265 | pub const PF_VSOCK = 40; | ||
| 266 | pub const PF_MAX = 41; | ||
| 267 | |||
| 268 | pub const AF_UNSPEC = PF_UNSPEC; | ||
| 269 | pub const AF_LOCAL = PF_LOCAL; | ||
| 270 | pub const AF_UNIX = AF_LOCAL; | ||
| 271 | pub const AF_FILE = AF_LOCAL; | ||
| 272 | pub const AF_INET = PF_INET; | ||
| 273 | pub const AF_AX25 = PF_AX25; | ||
| 274 | pub const AF_IPX = PF_IPX; | ||
| 275 | pub const AF_APPLETALK = PF_APPLETALK; | ||
| 276 | pub const AF_NETROM = PF_NETROM; | ||
| 277 | pub const AF_BRIDGE = PF_BRIDGE; | ||
| 278 | pub const AF_ATMPVC = PF_ATMPVC; | ||
| 279 | pub const AF_X25 = PF_X25; | ||
| 280 | pub const AF_INET6 = PF_INET6; | ||
| 281 | pub const AF_ROSE = PF_ROSE; | ||
| 282 | pub const AF_DECnet = PF_DECnet; | ||
| 283 | pub const AF_NETBEUI = PF_NETBEUI; | ||
| 284 | pub const AF_SECURITY = PF_SECURITY; | ||
| 285 | pub const AF_KEY = PF_KEY; | ||
| 286 | pub const AF_NETLINK = PF_NETLINK; | ||
| 287 | pub const AF_ROUTE = PF_ROUTE; | ||
| 288 | pub const AF_PACKET = PF_PACKET; | ||
| 289 | pub const AF_ASH = PF_ASH; | ||
| 290 | pub const AF_ECONET = PF_ECONET; | ||
| 291 | pub const AF_ATMSVC = PF_ATMSVC; | ||
| 292 | pub const AF_RDS = PF_RDS; | ||
| 293 | pub const AF_SNA = PF_SNA; | ||
| 294 | pub const AF_IRDA = PF_IRDA; | ||
| 295 | pub const AF_PPPOX = PF_PPPOX; | ||
| 296 | pub const AF_WANPIPE = PF_WANPIPE; | ||
| 297 | pub const AF_LLC = PF_LLC; | ||
| 298 | pub const AF_IB = PF_IB; | ||
| 299 | pub const AF_MPLS = PF_MPLS; | ||
| 300 | pub const AF_CAN = PF_CAN; | ||
| 301 | pub const AF_TIPC = PF_TIPC; | ||
| 302 | pub const AF_BLUETOOTH = PF_BLUETOOTH; | ||
| 303 | pub const AF_IUCV = PF_IUCV; | ||
| 304 | pub const AF_RXRPC = PF_RXRPC; | ||
| 305 | pub const AF_ISDN = PF_ISDN; | ||
| 306 | pub const AF_PHONET = PF_PHONET; | ||
| 307 | pub const AF_IEEE802154 = PF_IEEE802154; | ||
| 308 | pub const AF_CAIF = PF_CAIF; | ||
| 309 | pub const AF_ALG = PF_ALG; | ||
| 310 | pub const AF_NFC = PF_NFC; | ||
| 311 | pub const AF_VSOCK = PF_VSOCK; | ||
| 312 | pub const AF_MAX = PF_MAX; | ||
| 313 | |||
| 314 | pub const DT_UNKNOWN = 0; | ||
| 315 | pub const DT_FIFO = 1; | ||
| 316 | pub const DT_CHR = 2; | ||
| 317 | pub const DT_DIR = 4; | ||
| 318 | pub const DT_BLK = 6; | ||
| 319 | pub const DT_REG = 8; | ||
| 320 | pub const DT_LNK = 10; | ||
| 321 | pub const DT_SOCK = 12; | ||
| 322 | pub const DT_WHT = 14; | ||
| 323 | |||
| 324 | /// add event to kq (implies enable) | ||
| 325 | pub const EV_ADD = 0x0001; | ||
| 326 | |||
| 327 | /// delete event from kq | ||
| 328 | pub const EV_DELETE = 0x0002; | ||
| 329 | |||
| 330 | /// enable event | ||
| 331 | pub const EV_ENABLE = 0x0004; | ||
| 332 | |||
| 333 | /// disable event (not reported) | ||
| 334 | pub const EV_DISABLE = 0x0008; | ||
| 335 | |||
| 336 | /// only report one occurrence | ||
| 337 | pub const EV_ONESHOT = 0x0010; | ||
| 338 | |||
| 339 | /// clear event state after reporting | ||
| 340 | pub const EV_CLEAR = 0x0020; | ||
| 341 | |||
| 342 | /// force immediate event output | ||
| 343 | /// ... with or without EV_ERROR | ||
| 344 | /// ... use KEVENT_FLAG_ERROR_EVENTS | ||
| 345 | /// on syscalls supporting flags | ||
| 346 | pub const EV_RECEIPT = 0x0040; | ||
| 347 | |||
| 348 | /// disable event after reporting | ||
| 349 | pub const EV_DISPATCH = 0x0080; | ||
| 350 | |||
| 351 | pub const EVFILT_READ = -1; | ||
| 352 | pub const EVFILT_WRITE = -2; | ||
| 353 | |||
| 354 | /// attached to aio requests | ||
| 355 | pub const EVFILT_AIO = -3; | ||
| 356 | |||
| 357 | /// attached to vnodes | ||
| 358 | pub const EVFILT_VNODE = -4; | ||
| 359 | |||
| 360 | /// attached to struct proc | ||
| 361 | pub const EVFILT_PROC = -5; | ||
| 362 | |||
| 363 | /// attached to struct proc | ||
| 364 | pub const EVFILT_SIGNAL = -6; | ||
| 365 | |||
| 366 | /// timers | ||
| 367 | pub const EVFILT_TIMER = -7; | ||
| 368 | |||
| 369 | /// Process descriptors | ||
| 370 | pub const EVFILT_PROCDESC = -8; | ||
| 371 | |||
| 372 | /// Filesystem events | ||
| 373 | pub const EVFILT_FS = -9; | ||
| 374 | |||
| 375 | pub const EVFILT_LIO = -10; | ||
| 376 | |||
| 377 | /// User events | ||
| 378 | pub const EVFILT_USER = -11; | ||
| 379 | |||
| 380 | /// Sendfile events | ||
| 381 | pub const EVFILT_SENDFILE = -12; | ||
| 382 | |||
| 383 | pub const EVFILT_EMPTY = -13; | ||
| 384 | |||
| 385 | /// On input, NOTE_TRIGGER causes the event to be triggered for output. | ||
| 386 | pub const NOTE_TRIGGER = 0x01000000; | ||
| 387 | |||
| 388 | /// ignore input fflags | ||
| 389 | pub const NOTE_FFNOP = 0x00000000; | ||
| 390 | |||
| 391 | /// and fflags | ||
| 392 | pub const NOTE_FFAND = 0x40000000; | ||
| 393 | |||
| 394 | /// or fflags | ||
| 395 | pub const NOTE_FFOR = 0x80000000; | ||
| 396 | |||
| 397 | /// copy fflags | ||
| 398 | pub const NOTE_FFCOPY = 0xc0000000; | ||
| 399 | |||
| 400 | /// mask for operations | ||
| 401 | pub const NOTE_FFCTRLMASK = 0xc0000000; | ||
| 402 | pub const NOTE_FFLAGSMASK = 0x00ffffff; | ||
| 403 | |||
| 404 | /// low water mark | ||
| 405 | pub const NOTE_LOWAT = 0x00000001; | ||
| 406 | |||
| 407 | /// behave like poll() | ||
| 408 | pub const NOTE_FILE_POLL = 0x00000002; | ||
| 409 | |||
| 410 | /// vnode was removed | ||
| 411 | pub const NOTE_DELETE = 0x00000001; | ||
| 412 | |||
| 413 | /// data contents changed | ||
| 414 | pub const NOTE_WRITE = 0x00000002; | ||
| 415 | |||
| 416 | /// size increased | ||
| 417 | pub const NOTE_EXTEND = 0x00000004; | ||
| 418 | |||
| 419 | /// attributes changed | ||
| 420 | pub const NOTE_ATTRIB = 0x00000008; | ||
| 421 | |||
| 422 | /// link count changed | ||
| 423 | pub const NOTE_LINK = 0x00000010; | ||
| 424 | |||
| 425 | /// vnode was renamed | ||
| 426 | pub const NOTE_RENAME = 0x00000020; | ||
| 427 | |||
| 428 | /// vnode access was revoked | ||
| 429 | pub const NOTE_REVOKE = 0x00000040; | ||
| 430 | |||
| 431 | /// vnode was opened | ||
| 432 | pub const NOTE_OPEN = 0x00000080; | ||
| 433 | |||
| 434 | /// file closed, fd did not allow write | ||
| 435 | pub const NOTE_CLOSE = 0x00000100; | ||
| 436 | |||
| 437 | /// file closed, fd did allow write | ||
| 438 | pub const NOTE_CLOSE_WRITE = 0x00000200; | ||
| 439 | |||
| 440 | /// file was read | ||
| 441 | pub const NOTE_READ = 0x00000400; | ||
| 442 | |||
| 443 | /// process exited | ||
| 444 | pub const NOTE_EXIT = 0x80000000; | ||
| 445 | |||
| 446 | /// process forked | ||
| 447 | pub const NOTE_FORK = 0x40000000; | ||
| 448 | |||
| 449 | /// process exec'd | ||
| 450 | pub const NOTE_EXEC = 0x20000000; | ||
| 451 | |||
| 452 | /// mask for signal & exit status | ||
| 453 | pub const NOTE_PDATAMASK = 0x000fffff; | ||
| 454 | pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK); | ||
| 455 | |||
| 456 | /// data is seconds | ||
| 457 | pub const NOTE_SECONDS = 0x00000001; | ||
| 458 | |||
| 459 | /// data is milliseconds | ||
| 460 | pub const NOTE_MSECONDS = 0x00000002; | ||
| 461 | |||
| 462 | /// data is microseconds | ||
| 463 | pub const NOTE_USECONDS = 0x00000004; | ||
| 464 | |||
| 465 | /// data is nanoseconds | ||
| 466 | pub const NOTE_NSECONDS = 0x00000008; | ||
| 467 | |||
| 468 | /// timeout is absolute | ||
| 469 | pub const NOTE_ABSTIME = 0x00000010; | ||
| 470 | |||
| 471 | pub const TCGETS = 0x5401; | ||
| 472 | pub const TCSETS = 0x5402; | ||
| 473 | pub const TCSETSW = 0x5403; | ||
| 474 | pub const TCSETSF = 0x5404; | ||
| 475 | pub const TCGETA = 0x5405; | ||
| 476 | pub const TCSETA = 0x5406; | ||
| 477 | pub const TCSETAW = 0x5407; | ||
| 478 | pub const TCSETAF = 0x5408; | ||
| 479 | pub const TCSBRK = 0x5409; | ||
| 480 | pub const TCXONC = 0x540A; | ||
| 481 | pub const TCFLSH = 0x540B; | ||
| 482 | pub const TIOCEXCL = 0x540C; | ||
| 483 | pub const TIOCNXCL = 0x540D; | ||
| 484 | pub const TIOCSCTTY = 0x540E; | ||
| 485 | pub const TIOCGPGRP = 0x540F; | ||
| 486 | pub const TIOCSPGRP = 0x5410; | ||
| 487 | pub const TIOCOUTQ = 0x5411; | ||
| 488 | pub const TIOCSTI = 0x5412; | ||
| 489 | pub const TIOCGWINSZ = 0x5413; | ||
| 490 | pub const TIOCSWINSZ = 0x5414; | ||
| 491 | pub const TIOCMGET = 0x5415; | ||
| 492 | pub const TIOCMBIS = 0x5416; | ||
| 493 | pub const TIOCMBIC = 0x5417; | ||
| 494 | pub const TIOCMSET = 0x5418; | ||
| 495 | pub const TIOCGSOFTCAR = 0x5419; | ||
| 496 | pub const TIOCSSOFTCAR = 0x541A; | ||
| 497 | pub const FIONREAD = 0x541B; | ||
| 498 | pub const TIOCINQ = FIONREAD; | ||
| 499 | pub const TIOCLINUX = 0x541C; | ||
| 500 | pub const TIOCCONS = 0x541D; | ||
| 501 | pub const TIOCGSERIAL = 0x541E; | ||
| 502 | pub const TIOCSSERIAL = 0x541F; | ||
| 503 | pub const TIOCPKT = 0x5420; | ||
| 504 | pub const FIONBIO = 0x5421; | ||
| 505 | pub const TIOCNOTTY = 0x5422; | ||
| 506 | pub const TIOCSETD = 0x5423; | ||
| 507 | pub const TIOCGETD = 0x5424; | ||
| 508 | pub const TCSBRKP = 0x5425; | ||
| 509 | pub const TIOCSBRK = 0x5427; | ||
| 510 | pub const TIOCCBRK = 0x5428; | ||
| 511 | pub const TIOCGSID = 0x5429; | ||
| 512 | pub const TIOCGRS485 = 0x542E; | ||
| 513 | pub const TIOCSRS485 = 0x542F; | ||
| 514 | pub const TIOCGPTN = 0x80045430; | ||
| 515 | pub const TIOCSPTLCK = 0x40045431; | ||
| 516 | pub const TIOCGDEV = 0x80045432; | ||
| 517 | pub const TCGETX = 0x5432; | ||
| 518 | pub const TCSETX = 0x5433; | ||
| 519 | pub const TCSETXF = 0x5434; | ||
| 520 | pub const TCSETXW = 0x5435; | ||
| 521 | pub const TIOCSIG = 0x40045436; | ||
| 522 | pub const TIOCVHANGUP = 0x5437; | ||
| 523 | pub const TIOCGPKT = 0x80045438; | ||
| 524 | pub const TIOCGPTLCK = 0x80045439; | ||
| 525 | pub const TIOCGEXCL = 0x80045440; | ||
| 526 | |||
| 527 | pub const sockaddr = c.sockaddr; | ||
| 528 | pub const sockaddr_in = c.sockaddr_in; | ||
| 529 | pub const sockaddr_in6 = c.sockaddr_in6; | ||
| 530 | |||
| 531 | fn unsigned(s: i32) u32 { | ||
| 532 | return @bitCast(u32, s); | ||
| 533 | } | ||
| 534 | fn signed(s: u32) i32 { | ||
| 535 | return @bitCast(i32, s); | ||
| 536 | } | ||
| 537 | pub fn WEXITSTATUS(s: i32) i32 { | ||
| 538 | return signed((unsigned(s) & 0xff00) >> 8); | ||
| 539 | } | ||
| 540 | pub fn WTERMSIG(s: i32) i32 { | ||
| 541 | return signed(unsigned(s) & 0x7f); | ||
| 542 | } | ||
| 543 | pub fn WSTOPSIG(s: i32) i32 { | ||
| 544 | return WEXITSTATUS(s); | ||
| 545 | } | ||
| 546 | pub fn WIFEXITED(s: i32) bool { | ||
| 547 | return WTERMSIG(s) == 0; | ||
| 548 | } | ||
| 549 | pub fn WIFSTOPPED(s: i32) bool { | ||
| 550 | return @intCast(u16, (((unsigned(s) & 0xffff) *% 0x10001) >> 8)) > 0x7f00; | ||
| 551 | } | ||
| 552 | pub fn WIFSIGNALED(s: i32) bool { | ||
| 553 | return (unsigned(s) & 0xffff) -% 1 < 0xff; | ||
| 554 | } | ||
| 555 | |||
| 556 | pub const winsize = extern struct { | ||
| 557 | ws_row: u16, | ||
| 558 | ws_col: u16, | ||
| 559 | ws_xpixel: u16, | ||
| 560 | ws_ypixel: u16, | ||
| 561 | }; | ||
| 562 | |||
| 563 | /// Get the errno from a syscall return value, or 0 for no error. | ||
| 564 | pub fn getErrno(r: usize) usize { | ||
| 565 | const signed_r = @bitCast(isize, r); | ||
| 566 | return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0; | ||
| 567 | } | ||
| 568 | |||
| 569 | pub fn dup2(old: i32, new: i32) usize { | ||
| 570 | return errnoWrap(c.dup2(old, new)); | ||
| 571 | } | ||
| 572 | |||
| 573 | pub fn chdir(path: [*]const u8) usize { | ||
| 574 | return errnoWrap(c.chdir(path)); | ||
| 575 | } | ||
| 576 | |||
| 577 | pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize { | ||
| 578 | return errnoWrap(c.execve(path, argv, envp)); | ||
| 579 | } | ||
| 580 | |||
| 581 | pub fn fork() usize { | ||
| 582 | return errnoWrap(c.fork()); | ||
| 583 | } | ||
| 584 | |||
| 585 | pub fn access(path: [*]const u8, mode: u32) usize { | ||
| 586 | return errnoWrap(c.access(path, mode)); | ||
| 587 | } | ||
| 588 | |||
| 589 | pub fn getcwd(buf: [*]u8, size: usize) usize { | ||
| 590 | return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0; | ||
| 591 | } | ||
| 592 | |||
| 593 | pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { | ||
| 594 | return errnoWrap(@bitCast(isize, c.getdents(fd, drip, count))); | ||
| 595 | } | ||
| 596 | |||
| 597 | pub fn getdirentries(fd: i32, buf_ptr: [*]u8, buf_len: usize, basep: *i64) usize { | ||
| 598 | return errnoWrap(@bitCast(isize, c.getdirentries(fd, buf_ptr, buf_len, basep))); | ||
| 599 | } | ||
| 600 | |||
| 601 | pub fn realpath(noalias filename: [*]const u8, noalias resolved_name: [*]u8) usize { | ||
| 602 | return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(c._errno().*)) else 0; | ||
| 603 | } | ||
| 604 | |||
| 605 | pub fn isatty(fd: i32) bool { | ||
| 606 | return c.isatty(fd) != 0; | ||
| 607 | } | ||
| 608 | |||
| 609 | pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { | ||
| 610 | return errnoWrap(c.readlink(path, buf_ptr, buf_len)); | ||
| 611 | } | ||
| 612 | |||
| 613 | pub fn mkdir(path: [*]const u8, mode: u32) usize { | ||
| 614 | return errnoWrap(c.mkdir(path, mode)); | ||
| 615 | } | ||
| 616 | |||
| 617 | pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize { | ||
| 618 | const ptr_result = c.mmap( | ||
| 619 | @ptrCast(?*c_void, address), | ||
| 620 | length, | ||
| 621 | @bitCast(c_int, @intCast(c_uint, prot)), | ||
| 622 | @bitCast(c_int, c_uint(flags)), | ||
| 623 | fd, | ||
| 624 | offset, | ||
| 625 | ); | ||
| 626 | const isize_result = @bitCast(isize, @ptrToInt(ptr_result)); | ||
| 627 | return errnoWrap(isize_result); | ||
| 628 | } | ||
| 629 | |||
| 630 | pub fn munmap(address: usize, length: usize) usize { | ||
| 631 | return errnoWrap(c.munmap(@intToPtr(?*c_void, address), length)); | ||
| 632 | } | ||
| 633 | |||
| 634 | pub fn read(fd: i32, buf: [*]u8, nbyte: usize) usize { | ||
| 635 | return errnoWrap(c.read(fd, @ptrCast(*c_void, buf), nbyte)); | ||
| 636 | } | ||
| 637 | |||
| 638 | pub fn rmdir(path: [*]const u8) usize { | ||
| 639 | return errnoWrap(c.rmdir(path)); | ||
| 640 | } | ||
| 641 | |||
| 642 | pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { | ||
| 643 | return errnoWrap(c.symlink(existing, new)); | ||
| 644 | } | ||
| 645 | |||
| 646 | pub fn pread(fd: i32, buf: [*]u8, nbyte: usize, offset: u64) usize { | ||
| 647 | return errnoWrap(c.pread(fd, @ptrCast(*c_void, buf), nbyte, offset)); | ||
| 648 | } | ||
| 649 | |||
| 650 | pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: usize) usize { | ||
| 651 | return errnoWrap(c.preadv(fd, @ptrCast(*const c_void, iov), @intCast(c_int, count), offset)); | ||
| 652 | } | ||
| 653 | |||
| 654 | pub fn pipe(fd: *[2]i32) usize { | ||
| 655 | return pipe2(fd, 0); | ||
| 656 | } | ||
| 657 | |||
| 658 | pub fn pipe2(fd: *[2]i32, flags: u32) usize { | ||
| 659 | comptime assert(i32.bit_count == c_int.bit_count); | ||
| 660 | return errnoWrap(c.pipe2(@ptrCast(*[2]c_int, fd), flags)); | ||
| 661 | } | ||
| 662 | |||
| 663 | pub fn write(fd: i32, buf: [*]const u8, nbyte: usize) usize { | ||
| 664 | return errnoWrap(c.write(fd, @ptrCast(*const c_void, buf), nbyte)); | ||
| 665 | } | ||
| 666 | |||
| 667 | pub fn pwrite(fd: i32, buf: [*]const u8, nbyte: usize, offset: u64) usize { | ||
| 668 | return errnoWrap(c.pwrite(fd, @ptrCast(*const c_void, buf), nbyte, offset)); | ||
| 669 | } | ||
| 670 | |||
| 671 | pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: usize) usize { | ||
| 672 | return errnoWrap(c.pwritev(fd, @ptrCast(*const c_void, iov), @intCast(c_int, count), offset)); | ||
| 673 | } | ||
| 674 | |||
| 675 | pub fn rename(old: [*]const u8, new: [*]const u8) usize { | ||
| 676 | return errnoWrap(c.rename(old, new)); | ||
| 677 | } | ||
| 678 | |||
| 679 | pub fn open(path: [*]const u8, flags: u32, mode: usize) usize { | ||
| 680 | return errnoWrap(c.open(path, @bitCast(c_int, flags), mode)); | ||
| 681 | } | ||
| 682 | |||
| 683 | pub fn create(path: [*]const u8, perm: usize) usize { | ||
| 684 | return arch.syscall2(SYS_creat, @ptrToInt(path), perm); | ||
| 685 | } | ||
| 686 | |||
| 687 | pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize { | ||
| 688 | return errnoWrap(c.openat(@bitCast(usize, isize(dirfd)), @ptrToInt(path), flags, mode)); | ||
| 689 | } | ||
| 690 | |||
| 691 | pub fn close(fd: i32) usize { | ||
| 692 | return errnoWrap(c.close(fd)); | ||
| 693 | } | ||
| 694 | |||
| 695 | pub fn lseek(fd: i32, offset: isize, whence: c_int) usize { | ||
| 696 | return errnoWrap(c.lseek(fd, offset, whence)); | ||
| 697 | } | ||
| 698 | |||
| 699 | pub fn exit(code: i32) noreturn { | ||
| 700 | c.exit(code); | ||
| 701 | } | ||
| 702 | |||
| 703 | pub fn kill(pid: i32, sig: i32) usize { | ||
| 704 | return errnoWrap(c.kill(pid, sig)); | ||
| 705 | } | ||
| 706 | |||
| 707 | pub fn unlink(path: [*]const u8) usize { | ||
| 708 | return errnoWrap(c.unlink(path)); | ||
| 709 | } | ||
| 710 | |||
| 711 | pub fn waitpid(pid: i32, status: *i32, options: u32) usize { | ||
| 712 | comptime assert(i32.bit_count == c_int.bit_count); | ||
| 713 | return errnoWrap(c.waitpid(pid, @ptrCast(*c_int, status), @bitCast(c_int, options))); | ||
| 714 | } | ||
| 715 | |||
| 716 | pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize { | ||
| 717 | return errnoWrap(c.nanosleep(req, rem)); | ||
| 718 | } | ||
| 719 | |||
| 720 | pub fn clock_gettime(clk_id: i32, tp: *timespec) usize { | ||
| 721 | return errnoWrap(c.clock_gettime(clk_id, tp)); | ||
| 722 | } | ||
| 723 | |||
| 724 | pub fn clock_getres(clk_id: i32, tp: *timespec) usize { | ||
| 725 | return errnoWrap(c.clock_getres(clk_id, tp)); | ||
| 726 | } | ||
| 727 | |||
| 728 | pub fn setuid(uid: u32) usize { | ||
| 729 | return errnoWrap(c.setuid(uid)); | ||
| 730 | } | ||
| 731 | |||
| 732 | pub fn setgid(gid: u32) usize { | ||
| 733 | return errnoWrap(c.setgid(gid)); | ||
| 734 | } | ||
| 735 | |||
| 736 | pub fn setreuid(ruid: u32, euid: u32) usize { | ||
| 737 | return errnoWrap(c.setreuid(ruid, euid)); | ||
| 738 | } | ||
| 739 | |||
| 740 | pub fn setregid(rgid: u32, egid: u32) usize { | ||
| 741 | return errnoWrap(c.setregid(rgid, egid)); | ||
| 742 | } | ||
| 743 | |||
| 744 | const NSIG = 32; | ||
| 745 | |||
| 746 | pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize)); | ||
| 747 | pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); | ||
| 748 | pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); | ||
| 749 | |||
| 750 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | ||
| 751 | pub const Sigaction = extern struct { | ||
| 752 | /// signal handler | ||
| 753 | __sigaction_u: extern union { | ||
| 754 | __sa_handler: extern fn (i32) void, | ||
| 755 | __sa_sigaction: extern fn (i32, *__siginfo, usize) void, | ||
| 756 | }, | ||
| 757 | |||
| 758 | /// see signal options | ||
| 759 | sa_flags: u32, | ||
| 760 | |||
| 761 | /// signal mask to apply | ||
| 762 | sa_mask: sigset_t, | ||
| 763 | }; | ||
| 764 | |||
| 765 | pub const _SIG_WORDS = 4; | ||
| 766 | pub const _SIG_MAXSIG = 128; | ||
| 767 | |||
| 768 | pub inline fn _SIG_IDX(sig: usize) usize { | ||
| 769 | return sig - 1; | ||
| 770 | } | ||
| 771 | pub inline fn _SIG_WORD(sig: usize) usize { | ||
| 772 | return_SIG_IDX(sig) >> 5; | ||
| 773 | } | ||
| 774 | pub inline fn _SIG_BIT(sig: usize) usize { | ||
| 775 | return 1 << (_SIG_IDX(sig) & 31); | ||
| 776 | } | ||
| 777 | pub inline fn _SIG_VALID(sig: usize) usize { | ||
| 778 | return sig <= _SIG_MAXSIG and sig > 0; | ||
| 779 | } | ||
| 780 | |||
| 781 | pub const sigset_t = extern struct { | ||
| 782 | __bits: [_SIG_WORDS]u32, | ||
| 783 | }; | ||
| 784 | |||
| 785 | pub fn raise(sig: i32) usize { | ||
| 786 | return errnoWrap(c.raise(sig)); | ||
| 787 | } | ||
| 788 | |||
| 789 | pub const Stat = c.Stat; | ||
| 790 | pub const dirent = c.dirent; | ||
| 791 | pub const timespec = c.timespec; | ||
| 792 | |||
| 793 | pub fn fstat(fd: i32, buf: *c.Stat) usize { | ||
| 794 | return errnoWrap(c.fstat(fd, buf)); | ||
| 795 | } | ||
| 796 | pub const iovec = extern struct { | ||
| 797 | iov_base: [*]u8, | ||
| 798 | iov_len: usize, | ||
| 799 | }; | ||
| 800 | |||
| 801 | pub const iovec_const = extern struct { | ||
| 802 | iov_base: [*]const u8, | ||
| 803 | iov_len: usize, | ||
| 804 | }; | ||
| 805 | |||
| 806 | // TODO avoid libc dependency | ||
| 807 | pub fn kqueue() usize { | ||
| 808 | return errnoWrap(c.kqueue()); | ||
| 809 | } | ||
| 810 | |||
| 811 | // TODO avoid libc dependency | ||
| 812 | pub fn kevent(kq: i32, changelist: []const Kevent, eventlist: []Kevent, timeout: ?*const timespec) usize { | ||
| 813 | return errnoWrap(c.kevent( | ||
| 814 | kq, | ||
| 815 | changelist.ptr, | ||
| 816 | @intCast(c_int, changelist.len), | ||
| 817 | eventlist.ptr, | ||
| 818 | @intCast(c_int, eventlist.len), | ||
| 819 | timeout, | ||
| 820 | )); | ||
| 821 | } | ||
| 822 | |||
| 823 | // TODO avoid libc dependency | ||
| 824 | pub fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize { | ||
| 825 | return errnoWrap(c.sysctl(name, namelen, oldp, oldlenp, newp, newlen)); | ||
| 826 | } | ||
| 827 | |||
| 828 | // TODO avoid libc dependency | ||
| 829 | pub fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize { | ||
| 830 | return errnoWrap(c.sysctlbyname(name, oldp, oldlenp, newp, newlen)); | ||
| 831 | } | ||
| 832 | |||
| 833 | // TODO avoid libc dependency | ||
| 834 | pub fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) usize { | ||
| 835 | return errnoWrap(c.sysctlnametomib(name, wibp, sizep)); | ||
| 836 | } | ||
| 837 | |||
| 838 | // TODO avoid libc dependency | ||
| 839 | |||
| 840 | /// Takes the return value from a syscall and formats it back in the way | ||
| 841 | /// that the kernel represents it to libc. Errno was a mistake, let's make | ||
| 842 | /// it go away forever. | ||
| 843 | fn errnoWrap(value: isize) usize { | ||
| 844 | return @bitCast(usize, if (value == -1) -isize(c._errno().*) else value); | ||
| 845 | } |
std/os/freebsd/errno.zig deleted-121| ... | @@ -1,121 +0,0 @@ | ||
| 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 filesystem | ||
| 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 | ||
| 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 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 ENOTSUP = EOPNOTSUPP; // Operation not supported | ||
| 55 | pub const EPFNOSUPPORT = 46; // Protocol family not supported | ||
| 56 | pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family | ||
| 57 | pub const EADDRINUSE = 48; // Address already in use | ||
| 58 | pub const EADDRNOTAVAIL = 49; // Can't assign requested address | ||
| 59 | |||
| 60 | // ipc/network software -- operational errors | ||
| 61 | pub const ENETDOWN = 50; // Network is down | ||
| 62 | pub const ENETUNREACH = 51; // Network is unreachable | ||
| 63 | pub const ENETRESET = 52; // Network dropped connection on reset | ||
| 64 | pub const ECONNABORTED = 53; // Software caused connection abort | ||
| 65 | pub const ECONNRESET = 54; // Connection reset by peer | ||
| 66 | pub const ENOBUFS = 55; // No buffer space available | ||
| 67 | pub const EISCONN = 56; // Socket is already connected | ||
| 68 | pub const ENOTCONN = 57; // Socket is not connected | ||
| 69 | pub const ESHUTDOWN = 58; // Can't send after socket shutdown | ||
| 70 | pub const ETOOMANYREFS = 59; // Too many references: can't splice | ||
| 71 | pub const ETIMEDOUT = 60; // Operation timed out | ||
| 72 | pub const ECONNREFUSED = 61; // Connection refused | ||
| 73 | |||
| 74 | pub const ELOOP = 62; // Too many levels of symbolic links | ||
| 75 | pub const ENAMETOOLONG = 63; // File name too long | ||
| 76 | |||
| 77 | // should be rearranged | ||
| 78 | pub const EHOSTDOWN = 64; // Host is down | ||
| 79 | pub const EHOSTUNREACH = 65; // No route to host | ||
| 80 | pub const ENOTEMPTY = 66; // Directory not empty | ||
| 81 | |||
| 82 | // quotas & mush | ||
| 83 | pub const EPROCLIM = 67; // Too many processes | ||
| 84 | pub const EUSERS = 68; // Too many users | ||
| 85 | pub const EDQUOT = 69; // Disc quota exceeded | ||
| 86 | |||
| 87 | // Network File System | ||
| 88 | pub const ESTALE = 70; // Stale NFS file handle | ||
| 89 | pub const EREMOTE = 71; // Too many levels of remote in path | ||
| 90 | pub const EBADRPC = 72; // RPC struct is bad | ||
| 91 | pub const ERPCMISMATCH = 73; // RPC version wrong | ||
| 92 | pub const EPROGUNAVAIL = 74; // RPC prog. not avail | ||
| 93 | pub const EPROGMISMATCH = 75; // Program version wrong | ||
| 94 | pub const EPROCUNAVAIL = 76; // Bad procedure for program | ||
| 95 | |||
| 96 | pub const ENOLCK = 77; // No locks available | ||
| 97 | pub const ENOSYS = 78; // Function not implemented | ||
| 98 | |||
| 99 | pub const EFTYPE = 79; // Inappropriate file type or format | ||
| 100 | pub const EAUTH = 80; // Authentication error | ||
| 101 | pub const ENEEDAUTH = 81; // Need authenticator | ||
| 102 | pub const EIDRM = 82; // Identifier removed | ||
| 103 | pub const ENOMSG = 83; // No message of desired type | ||
| 104 | pub const EOVERFLOW = 84; // Value too large to be stored in data type | ||
| 105 | pub const ECANCELED = 85; // Operation canceled | ||
| 106 | pub const EILSEQ = 86; // Illegal byte sequence | ||
| 107 | pub const ENOATTR = 87; // Attribute not found | ||
| 108 | |||
| 109 | pub const EDOOFUS = 88; // Programming error | ||
| 110 | |||
| 111 | pub const EBADMSG = 89; // Bad message | ||
| 112 | pub const EMULTIHOP = 90; // Multihop attempted | ||
| 113 | pub const ENOLINK = 91; // Link has been severed | ||
| 114 | pub const EPROTO = 92; // Protocol error | ||
| 115 | |||
| 116 | pub const ENOTCAPABLE = 93; // Capabilities insufficient | ||
| 117 | pub const ECAPMODE = 94; // Not permitted in capability mode | ||
| 118 | pub const ENOTRECOVERABLE = 95; // State not recoverable | ||
| 119 | pub const EOWNERDEAD = 96; // Previous owner died | ||
| 120 | |||
| 121 | pub const ELAST = 96; // Must be equal largest errno | ||
std/os/linux.zig+29-924| ... | @@ -7,700 +7,17 @@ pub const tls = @import("linux/tls.zig"); | ... | @@ -7,700 +7,17 @@ pub const tls = @import("linux/tls.zig"); |
| 7 | const vdso = @import("linux/vdso.zig"); | 7 | const vdso = @import("linux/vdso.zig"); |
| 8 | const dl = @import("../dynamic_library.zig"); | 8 | const dl = @import("../dynamic_library.zig"); |
| 9 | pub use switch (builtin.arch) { | 9 | pub use switch (builtin.arch) { |
| 10 | builtin.Arch.x86_64 => @import("linux/x86_64.zig"), | 10 | .x86_64 => @import("linux/x86_64.zig"), |
| 11 | builtin.Arch.i386 => @import("linux/i386.zig"), | 11 | .aarch64 => @import("linux/arm64.zig"), |
| 12 | builtin.Arch.aarch64 => @import("linux/arm64.zig"), | 12 | else => struct {}, |
| 13 | else => @compileError("unsupported arch"), | ||
| 14 | }; | 13 | }; |
| 15 | pub const is_the_target = builtin.os == .linux; | 14 | pub const is_the_target = builtin.os == .linux; |
| 16 | pub const errno_codes = @import("linux/errno.zig"); | 15 | pub const posix = @import("linux/posix.zig"); |
| 17 | pub use errno_codes; | 16 | pub use posix; |
| 18 | 17 | ||
| 19 | /// See `std.os.posix.getauxval`. | 18 | /// See `std.os.posix.getauxval`. |
| 20 | pub var elf_aux_maybe: ?[*]std.elf.Auxv = null; | 19 | pub var elf_aux_maybe: ?[*]std.elf.Auxv = null; |
| 21 | 20 | ||
| 22 | pub const PATH_MAX = 4096; | ||
| 23 | pub const IOV_MAX = 1024; | ||
| 24 | |||
| 25 | pub const STDIN_FILENO = 0; | ||
| 26 | pub const STDOUT_FILENO = 1; | ||
| 27 | pub const STDERR_FILENO = 2; | ||
| 28 | |||
| 29 | pub const FUTEX_WAIT = 0; | ||
| 30 | pub const FUTEX_WAKE = 1; | ||
| 31 | pub const FUTEX_FD = 2; | ||
| 32 | pub const FUTEX_REQUEUE = 3; | ||
| 33 | pub const FUTEX_CMP_REQUEUE = 4; | ||
| 34 | pub const FUTEX_WAKE_OP = 5; | ||
| 35 | pub const FUTEX_LOCK_PI = 6; | ||
| 36 | pub const FUTEX_UNLOCK_PI = 7; | ||
| 37 | pub const FUTEX_TRYLOCK_PI = 8; | ||
| 38 | pub const FUTEX_WAIT_BITSET = 9; | ||
| 39 | |||
| 40 | pub const FUTEX_PRIVATE_FLAG = 128; | ||
| 41 | |||
| 42 | pub const FUTEX_CLOCK_REALTIME = 256; | ||
| 43 | |||
| 44 | pub const PROT_NONE = 0; | ||
| 45 | pub const PROT_READ = 1; | ||
| 46 | pub const PROT_WRITE = 2; | ||
| 47 | pub const PROT_EXEC = 4; | ||
| 48 | pub const PROT_GROWSDOWN = 0x01000000; | ||
| 49 | pub const PROT_GROWSUP = 0x02000000; | ||
| 50 | |||
| 51 | pub const MAP_FAILED = maxInt(usize); | ||
| 52 | pub const MAP_SHARED = 0x01; | ||
| 53 | pub const MAP_PRIVATE = 0x02; | ||
| 54 | pub const MAP_TYPE = 0x0f; | ||
| 55 | pub const MAP_FIXED = 0x10; | ||
| 56 | pub const MAP_ANONYMOUS = 0x20; | ||
| 57 | pub const MAP_NORESERVE = 0x4000; | ||
| 58 | pub const MAP_GROWSDOWN = 0x0100; | ||
| 59 | pub const MAP_DENYWRITE = 0x0800; | ||
| 60 | pub const MAP_EXECUTABLE = 0x1000; | ||
| 61 | pub const MAP_LOCKED = 0x2000; | ||
| 62 | pub const MAP_POPULATE = 0x8000; | ||
| 63 | pub const MAP_NONBLOCK = 0x10000; | ||
| 64 | pub const MAP_STACK = 0x20000; | ||
| 65 | pub const MAP_HUGETLB = 0x40000; | ||
| 66 | pub const MAP_FILE = 0; | ||
| 67 | |||
| 68 | pub const F_OK = 0; | ||
| 69 | pub const X_OK = 1; | ||
| 70 | pub const W_OK = 2; | ||
| 71 | pub const R_OK = 4; | ||
| 72 | |||
| 73 | pub const WNOHANG = 1; | ||
| 74 | pub const WUNTRACED = 2; | ||
| 75 | pub const WSTOPPED = 2; | ||
| 76 | pub const WEXITED = 4; | ||
| 77 | pub const WCONTINUED = 8; | ||
| 78 | pub const WNOWAIT = 0x1000000; | ||
| 79 | |||
| 80 | pub const SA_NOCLDSTOP = 1; | ||
| 81 | pub const SA_NOCLDWAIT = 2; | ||
| 82 | pub const SA_SIGINFO = 4; | ||
| 83 | pub const SA_ONSTACK = 0x08000000; | ||
| 84 | pub const SA_RESTART = 0x10000000; | ||
| 85 | pub const SA_NODEFER = 0x40000000; | ||
| 86 | pub const SA_RESETHAND = 0x80000000; | ||
| 87 | pub const SA_RESTORER = 0x04000000; | ||
| 88 | |||
| 89 | pub const SIGHUP = 1; | ||
| 90 | pub const SIGINT = 2; | ||
| 91 | pub const SIGQUIT = 3; | ||
| 92 | pub const SIGILL = 4; | ||
| 93 | pub const SIGTRAP = 5; | ||
| 94 | pub const SIGABRT = 6; | ||
| 95 | pub const SIGIOT = SIGABRT; | ||
| 96 | pub const SIGBUS = 7; | ||
| 97 | pub const SIGFPE = 8; | ||
| 98 | pub const SIGKILL = 9; | ||
| 99 | pub const SIGUSR1 = 10; | ||
| 100 | pub const SIGSEGV = 11; | ||
| 101 | pub const SIGUSR2 = 12; | ||
| 102 | pub const SIGPIPE = 13; | ||
| 103 | pub const SIGALRM = 14; | ||
| 104 | pub const SIGTERM = 15; | ||
| 105 | pub const SIGSTKFLT = 16; | ||
| 106 | pub const SIGCHLD = 17; | ||
| 107 | pub const SIGCONT = 18; | ||
| 108 | pub const SIGSTOP = 19; | ||
| 109 | pub const SIGTSTP = 20; | ||
| 110 | pub const SIGTTIN = 21; | ||
| 111 | pub const SIGTTOU = 22; | ||
| 112 | pub const SIGURG = 23; | ||
| 113 | pub const SIGXCPU = 24; | ||
| 114 | pub const SIGXFSZ = 25; | ||
| 115 | pub const SIGVTALRM = 26; | ||
| 116 | pub const SIGPROF = 27; | ||
| 117 | pub const SIGWINCH = 28; | ||
| 118 | pub const SIGIO = 29; | ||
| 119 | pub const SIGPOLL = 29; | ||
| 120 | pub const SIGPWR = 30; | ||
| 121 | pub const SIGSYS = 31; | ||
| 122 | pub const SIGUNUSED = SIGSYS; | ||
| 123 | |||
| 124 | pub const O_RDONLY = 0o0; | ||
| 125 | pub const O_WRONLY = 0o1; | ||
| 126 | pub const O_RDWR = 0o2; | ||
| 127 | |||
| 128 | pub const SEEK_SET = 0; | ||
| 129 | pub const SEEK_CUR = 1; | ||
| 130 | pub const SEEK_END = 2; | ||
| 131 | |||
| 132 | pub const SIG_BLOCK = 0; | ||
| 133 | pub const SIG_UNBLOCK = 1; | ||
| 134 | pub const SIG_SETMASK = 2; | ||
| 135 | |||
| 136 | pub const PROTO_ip = 0o000; | ||
| 137 | pub const PROTO_icmp = 0o001; | ||
| 138 | pub const PROTO_igmp = 0o002; | ||
| 139 | pub const PROTO_ggp = 0o003; | ||
| 140 | pub const PROTO_ipencap = 0o004; | ||
| 141 | pub const PROTO_st = 0o005; | ||
| 142 | pub const PROTO_tcp = 0o006; | ||
| 143 | pub const PROTO_egp = 0o010; | ||
| 144 | pub const PROTO_pup = 0o014; | ||
| 145 | pub const PROTO_udp = 0o021; | ||
| 146 | pub const PROTO_hmp = 0o024; | ||
| 147 | pub const PROTO_xns_idp = 0o026; | ||
| 148 | pub const PROTO_rdp = 0o033; | ||
| 149 | pub const PROTO_iso_tp4 = 0o035; | ||
| 150 | pub const PROTO_xtp = 0o044; | ||
| 151 | pub const PROTO_ddp = 0o045; | ||
| 152 | pub const PROTO_idpr_cmtp = 0o046; | ||
| 153 | pub const PROTO_ipv6 = 0o051; | ||
| 154 | pub const PROTO_ipv6_route = 0o053; | ||
| 155 | pub const PROTO_ipv6_frag = 0o054; | ||
| 156 | pub const PROTO_idrp = 0o055; | ||
| 157 | pub const PROTO_rsvp = 0o056; | ||
| 158 | pub const PROTO_gre = 0o057; | ||
| 159 | pub const PROTO_esp = 0o062; | ||
| 160 | pub const PROTO_ah = 0o063; | ||
| 161 | pub const PROTO_skip = 0o071; | ||
| 162 | pub const PROTO_ipv6_icmp = 0o072; | ||
| 163 | pub const PROTO_ipv6_nonxt = 0o073; | ||
| 164 | pub const PROTO_ipv6_opts = 0o074; | ||
| 165 | pub const PROTO_rspf = 0o111; | ||
| 166 | pub const PROTO_vmtp = 0o121; | ||
| 167 | pub const PROTO_ospf = 0o131; | ||
| 168 | pub const PROTO_ipip = 0o136; | ||
| 169 | pub const PROTO_encap = 0o142; | ||
| 170 | pub const PROTO_pim = 0o147; | ||
| 171 | pub const PROTO_raw = 0o377; | ||
| 172 | |||
| 173 | pub const SHUT_RD = 0; | ||
| 174 | pub const SHUT_WR = 1; | ||
| 175 | pub const SHUT_RDWR = 2; | ||
| 176 | |||
| 177 | pub const SOCK_STREAM = 1; | ||
| 178 | pub const SOCK_DGRAM = 2; | ||
| 179 | pub const SOCK_RAW = 3; | ||
| 180 | pub const SOCK_RDM = 4; | ||
| 181 | pub const SOCK_SEQPACKET = 5; | ||
| 182 | pub const SOCK_DCCP = 6; | ||
| 183 | pub const SOCK_PACKET = 10; | ||
| 184 | pub const SOCK_CLOEXEC = 0o2000000; | ||
| 185 | pub const SOCK_NONBLOCK = 0o4000; | ||
| 186 | |||
| 187 | pub const PF_UNSPEC = 0; | ||
| 188 | pub const PF_LOCAL = 1; | ||
| 189 | pub const PF_UNIX = PF_LOCAL; | ||
| 190 | pub const PF_FILE = PF_LOCAL; | ||
| 191 | pub const PF_INET = 2; | ||
| 192 | pub const PF_AX25 = 3; | ||
| 193 | pub const PF_IPX = 4; | ||
| 194 | pub const PF_APPLETALK = 5; | ||
| 195 | pub const PF_NETROM = 6; | ||
| 196 | pub const PF_BRIDGE = 7; | ||
| 197 | pub const PF_ATMPVC = 8; | ||
| 198 | pub const PF_X25 = 9; | ||
| 199 | pub const PF_INET6 = 10; | ||
| 200 | pub const PF_ROSE = 11; | ||
| 201 | pub const PF_DECnet = 12; | ||
| 202 | pub const PF_NETBEUI = 13; | ||
| 203 | pub const PF_SECURITY = 14; | ||
| 204 | pub const PF_KEY = 15; | ||
| 205 | pub const PF_NETLINK = 16; | ||
| 206 | pub const PF_ROUTE = PF_NETLINK; | ||
| 207 | pub const PF_PACKET = 17; | ||
| 208 | pub const PF_ASH = 18; | ||
| 209 | pub const PF_ECONET = 19; | ||
| 210 | pub const PF_ATMSVC = 20; | ||
| 211 | pub const PF_RDS = 21; | ||
| 212 | pub const PF_SNA = 22; | ||
| 213 | pub const PF_IRDA = 23; | ||
| 214 | pub const PF_PPPOX = 24; | ||
| 215 | pub const PF_WANPIPE = 25; | ||
| 216 | pub const PF_LLC = 26; | ||
| 217 | pub const PF_IB = 27; | ||
| 218 | pub const PF_MPLS = 28; | ||
| 219 | pub const PF_CAN = 29; | ||
| 220 | pub const PF_TIPC = 30; | ||
| 221 | pub const PF_BLUETOOTH = 31; | ||
| 222 | pub const PF_IUCV = 32; | ||
| 223 | pub const PF_RXRPC = 33; | ||
| 224 | pub const PF_ISDN = 34; | ||
| 225 | pub const PF_PHONET = 35; | ||
| 226 | pub const PF_IEEE802154 = 36; | ||
| 227 | pub const PF_CAIF = 37; | ||
| 228 | pub const PF_ALG = 38; | ||
| 229 | pub const PF_NFC = 39; | ||
| 230 | pub const PF_VSOCK = 40; | ||
| 231 | pub const PF_KCM = 41; | ||
| 232 | pub const PF_QIPCRTR = 42; | ||
| 233 | pub const PF_SMC = 43; | ||
| 234 | pub const PF_MAX = 44; | ||
| 235 | |||
| 236 | pub const AF_UNSPEC = PF_UNSPEC; | ||
| 237 | pub const AF_LOCAL = PF_LOCAL; | ||
| 238 | pub const AF_UNIX = AF_LOCAL; | ||
| 239 | pub const AF_FILE = AF_LOCAL; | ||
| 240 | pub const AF_INET = PF_INET; | ||
| 241 | pub const AF_AX25 = PF_AX25; | ||
| 242 | pub const AF_IPX = PF_IPX; | ||
| 243 | pub const AF_APPLETALK = PF_APPLETALK; | ||
| 244 | pub const AF_NETROM = PF_NETROM; | ||
| 245 | pub const AF_BRIDGE = PF_BRIDGE; | ||
| 246 | pub const AF_ATMPVC = PF_ATMPVC; | ||
| 247 | pub const AF_X25 = PF_X25; | ||
| 248 | pub const AF_INET6 = PF_INET6; | ||
| 249 | pub const AF_ROSE = PF_ROSE; | ||
| 250 | pub const AF_DECnet = PF_DECnet; | ||
| 251 | pub const AF_NETBEUI = PF_NETBEUI; | ||
| 252 | pub const AF_SECURITY = PF_SECURITY; | ||
| 253 | pub const AF_KEY = PF_KEY; | ||
| 254 | pub const AF_NETLINK = PF_NETLINK; | ||
| 255 | pub const AF_ROUTE = PF_ROUTE; | ||
| 256 | pub const AF_PACKET = PF_PACKET; | ||
| 257 | pub const AF_ASH = PF_ASH; | ||
| 258 | pub const AF_ECONET = PF_ECONET; | ||
| 259 | pub const AF_ATMSVC = PF_ATMSVC; | ||
| 260 | pub const AF_RDS = PF_RDS; | ||
| 261 | pub const AF_SNA = PF_SNA; | ||
| 262 | pub const AF_IRDA = PF_IRDA; | ||
| 263 | pub const AF_PPPOX = PF_PPPOX; | ||
| 264 | pub const AF_WANPIPE = PF_WANPIPE; | ||
| 265 | pub const AF_LLC = PF_LLC; | ||
| 266 | pub const AF_IB = PF_IB; | ||
| 267 | pub const AF_MPLS = PF_MPLS; | ||
| 268 | pub const AF_CAN = PF_CAN; | ||
| 269 | pub const AF_TIPC = PF_TIPC; | ||
| 270 | pub const AF_BLUETOOTH = PF_BLUETOOTH; | ||
| 271 | pub const AF_IUCV = PF_IUCV; | ||
| 272 | pub const AF_RXRPC = PF_RXRPC; | ||
| 273 | pub const AF_ISDN = PF_ISDN; | ||
| 274 | pub const AF_PHONET = PF_PHONET; | ||
| 275 | pub const AF_IEEE802154 = PF_IEEE802154; | ||
| 276 | pub const AF_CAIF = PF_CAIF; | ||
| 277 | pub const AF_ALG = PF_ALG; | ||
| 278 | pub const AF_NFC = PF_NFC; | ||
| 279 | pub const AF_VSOCK = PF_VSOCK; | ||
| 280 | pub const AF_KCM = PF_KCM; | ||
| 281 | pub const AF_QIPCRTR = PF_QIPCRTR; | ||
| 282 | pub const AF_SMC = PF_SMC; | ||
| 283 | pub const AF_MAX = PF_MAX; | ||
| 284 | |||
| 285 | pub const SO_DEBUG = 1; | ||
| 286 | pub const SO_REUSEADDR = 2; | ||
| 287 | pub const SO_TYPE = 3; | ||
| 288 | pub const SO_ERROR = 4; | ||
| 289 | pub const SO_DONTROUTE = 5; | ||
| 290 | pub const SO_BROADCAST = 6; | ||
| 291 | pub const SO_SNDBUF = 7; | ||
| 292 | pub const SO_RCVBUF = 8; | ||
| 293 | pub const SO_KEEPALIVE = 9; | ||
| 294 | pub const SO_OOBINLINE = 10; | ||
| 295 | pub const SO_NO_CHECK = 11; | ||
| 296 | pub const SO_PRIORITY = 12; | ||
| 297 | pub const SO_LINGER = 13; | ||
| 298 | pub const SO_BSDCOMPAT = 14; | ||
| 299 | pub const SO_REUSEPORT = 15; | ||
| 300 | pub const SO_PASSCRED = 16; | ||
| 301 | pub const SO_PEERCRED = 17; | ||
| 302 | pub const SO_RCVLOWAT = 18; | ||
| 303 | pub const SO_SNDLOWAT = 19; | ||
| 304 | pub const SO_RCVTIMEO = 20; | ||
| 305 | pub const SO_SNDTIMEO = 21; | ||
| 306 | pub const SO_ACCEPTCONN = 30; | ||
| 307 | pub const SO_SNDBUFFORCE = 32; | ||
| 308 | pub const SO_RCVBUFFORCE = 33; | ||
| 309 | pub const SO_PROTOCOL = 38; | ||
| 310 | pub const SO_DOMAIN = 39; | ||
| 311 | |||
| 312 | pub const SO_SECURITY_AUTHENTICATION = 22; | ||
| 313 | pub const SO_SECURITY_ENCRYPTION_TRANSPORT = 23; | ||
| 314 | pub const SO_SECURITY_ENCRYPTION_NETWORK = 24; | ||
| 315 | |||
| 316 | pub const SO_BINDTODEVICE = 25; | ||
| 317 | |||
| 318 | pub const SO_ATTACH_FILTER = 26; | ||
| 319 | pub const SO_DETACH_FILTER = 27; | ||
| 320 | pub const SO_GET_FILTER = SO_ATTACH_FILTER; | ||
| 321 | |||
| 322 | pub const SO_PEERNAME = 28; | ||
| 323 | pub const SO_TIMESTAMP = 29; | ||
| 324 | pub const SCM_TIMESTAMP = SO_TIMESTAMP; | ||
| 325 | |||
| 326 | pub const SO_PEERSEC = 31; | ||
| 327 | pub const SO_PASSSEC = 34; | ||
| 328 | pub const SO_TIMESTAMPNS = 35; | ||
| 329 | pub const SCM_TIMESTAMPNS = SO_TIMESTAMPNS; | ||
| 330 | pub const SO_MARK = 36; | ||
| 331 | pub const SO_TIMESTAMPING = 37; | ||
| 332 | pub const SCM_TIMESTAMPING = SO_TIMESTAMPING; | ||
| 333 | pub const SO_RXQ_OVFL = 40; | ||
| 334 | pub const SO_WIFI_STATUS = 41; | ||
| 335 | pub const SCM_WIFI_STATUS = SO_WIFI_STATUS; | ||
| 336 | pub const SO_PEEK_OFF = 42; | ||
| 337 | pub const SO_NOFCS = 43; | ||
| 338 | pub const SO_LOCK_FILTER = 44; | ||
| 339 | pub const SO_SELECT_ERR_QUEUE = 45; | ||
| 340 | pub const SO_BUSY_POLL = 46; | ||
| 341 | pub const SO_MAX_PACING_RATE = 47; | ||
| 342 | pub const SO_BPF_EXTENSIONS = 48; | ||
| 343 | pub const SO_INCOMING_CPU = 49; | ||
| 344 | pub const SO_ATTACH_BPF = 50; | ||
| 345 | pub const SO_DETACH_BPF = SO_DETACH_FILTER; | ||
| 346 | pub const SO_ATTACH_REUSEPORT_CBPF = 51; | ||
| 347 | pub const SO_ATTACH_REUSEPORT_EBPF = 52; | ||
| 348 | pub const SO_CNX_ADVICE = 53; | ||
| 349 | pub const SCM_TIMESTAMPING_OPT_STATS = 54; | ||
| 350 | pub const SO_MEMINFO = 55; | ||
| 351 | pub const SO_INCOMING_NAPI_ID = 56; | ||
| 352 | pub const SO_COOKIE = 57; | ||
| 353 | pub const SCM_TIMESTAMPING_PKTINFO = 58; | ||
| 354 | pub const SO_PEERGROUPS = 59; | ||
| 355 | pub const SO_ZEROCOPY = 60; | ||
| 356 | |||
| 357 | pub const SOL_SOCKET = 1; | ||
| 358 | |||
| 359 | pub const SOL_IP = 0; | ||
| 360 | pub const SOL_IPV6 = 41; | ||
| 361 | pub const SOL_ICMPV6 = 58; | ||
| 362 | |||
| 363 | pub const SOL_RAW = 255; | ||
| 364 | pub const SOL_DECNET = 261; | ||
| 365 | pub const SOL_X25 = 262; | ||
| 366 | pub const SOL_PACKET = 263; | ||
| 367 | pub const SOL_ATM = 264; | ||
| 368 | pub const SOL_AAL = 265; | ||
| 369 | pub const SOL_IRDA = 266; | ||
| 370 | pub const SOL_NETBEUI = 267; | ||
| 371 | pub const SOL_LLC = 268; | ||
| 372 | pub const SOL_DCCP = 269; | ||
| 373 | pub const SOL_NETLINK = 270; | ||
| 374 | pub const SOL_TIPC = 271; | ||
| 375 | pub const SOL_RXRPC = 272; | ||
| 376 | pub const SOL_PPPOL2TP = 273; | ||
| 377 | pub const SOL_BLUETOOTH = 274; | ||
| 378 | pub const SOL_PNPIPE = 275; | ||
| 379 | pub const SOL_RDS = 276; | ||
| 380 | pub const SOL_IUCV = 277; | ||
| 381 | pub const SOL_CAIF = 278; | ||
| 382 | pub const SOL_ALG = 279; | ||
| 383 | pub const SOL_NFC = 280; | ||
| 384 | pub const SOL_KCM = 281; | ||
| 385 | pub const SOL_TLS = 282; | ||
| 386 | |||
| 387 | pub const SOMAXCONN = 128; | ||
| 388 | |||
| 389 | pub const MSG_OOB = 0x0001; | ||
| 390 | pub const MSG_PEEK = 0x0002; | ||
| 391 | pub const MSG_DONTROUTE = 0x0004; | ||
| 392 | pub const MSG_CTRUNC = 0x0008; | ||
| 393 | pub const MSG_PROXY = 0x0010; | ||
| 394 | pub const MSG_TRUNC = 0x0020; | ||
| 395 | pub const MSG_DONTWAIT = 0x0040; | ||
| 396 | pub const MSG_EOR = 0x0080; | ||
| 397 | pub const MSG_WAITALL = 0x0100; | ||
| 398 | pub const MSG_FIN = 0x0200; | ||
| 399 | pub const MSG_SYN = 0x0400; | ||
| 400 | pub const MSG_CONFIRM = 0x0800; | ||
| 401 | pub const MSG_RST = 0x1000; | ||
| 402 | pub const MSG_ERRQUEUE = 0x2000; | ||
| 403 | pub const MSG_NOSIGNAL = 0x4000; | ||
| 404 | pub const MSG_MORE = 0x8000; | ||
| 405 | pub const MSG_WAITFORONE = 0x10000; | ||
| 406 | pub const MSG_BATCH = 0x40000; | ||
| 407 | pub const MSG_ZEROCOPY = 0x4000000; | ||
| 408 | pub const MSG_FASTOPEN = 0x20000000; | ||
| 409 | pub const MSG_CMSG_CLOEXEC = 0x40000000; | ||
| 410 | |||
| 411 | pub const DT_UNKNOWN = 0; | ||
| 412 | pub const DT_FIFO = 1; | ||
| 413 | pub const DT_CHR = 2; | ||
| 414 | pub const DT_DIR = 4; | ||
| 415 | pub const DT_BLK = 6; | ||
| 416 | pub const DT_REG = 8; | ||
| 417 | pub const DT_LNK = 10; | ||
| 418 | pub const DT_SOCK = 12; | ||
| 419 | pub const DT_WHT = 14; | ||
| 420 | |||
| 421 | pub const TCGETS = 0x5401; | ||
| 422 | pub const TCSETS = 0x5402; | ||
| 423 | pub const TCSETSW = 0x5403; | ||
| 424 | pub const TCSETSF = 0x5404; | ||
| 425 | pub const TCGETA = 0x5405; | ||
| 426 | pub const TCSETA = 0x5406; | ||
| 427 | pub const TCSETAW = 0x5407; | ||
| 428 | pub const TCSETAF = 0x5408; | ||
| 429 | pub const TCSBRK = 0x5409; | ||
| 430 | pub const TCXONC = 0x540A; | ||
| 431 | pub const TCFLSH = 0x540B; | ||
| 432 | pub const TIOCEXCL = 0x540C; | ||
| 433 | pub const TIOCNXCL = 0x540D; | ||
| 434 | pub const TIOCSCTTY = 0x540E; | ||
| 435 | pub const TIOCGPGRP = 0x540F; | ||
| 436 | pub const TIOCSPGRP = 0x5410; | ||
| 437 | pub const TIOCOUTQ = 0x5411; | ||
| 438 | pub const TIOCSTI = 0x5412; | ||
| 439 | pub const TIOCGWINSZ = 0x5413; | ||
| 440 | pub const TIOCSWINSZ = 0x5414; | ||
| 441 | pub const TIOCMGET = 0x5415; | ||
| 442 | pub const TIOCMBIS = 0x5416; | ||
| 443 | pub const TIOCMBIC = 0x5417; | ||
| 444 | pub const TIOCMSET = 0x5418; | ||
| 445 | pub const TIOCGSOFTCAR = 0x5419; | ||
| 446 | pub const TIOCSSOFTCAR = 0x541A; | ||
| 447 | pub const FIONREAD = 0x541B; | ||
| 448 | pub const TIOCINQ = FIONREAD; | ||
| 449 | pub const TIOCLINUX = 0x541C; | ||
| 450 | pub const TIOCCONS = 0x541D; | ||
| 451 | pub const TIOCGSERIAL = 0x541E; | ||
| 452 | pub const TIOCSSERIAL = 0x541F; | ||
| 453 | pub const TIOCPKT = 0x5420; | ||
| 454 | pub const FIONBIO = 0x5421; | ||
| 455 | pub const TIOCNOTTY = 0x5422; | ||
| 456 | pub const TIOCSETD = 0x5423; | ||
| 457 | pub const TIOCGETD = 0x5424; | ||
| 458 | pub const TCSBRKP = 0x5425; | ||
| 459 | pub const TIOCSBRK = 0x5427; | ||
| 460 | pub const TIOCCBRK = 0x5428; | ||
| 461 | pub const TIOCGSID = 0x5429; | ||
| 462 | pub const TIOCGRS485 = 0x542E; | ||
| 463 | pub const TIOCSRS485 = 0x542F; | ||
| 464 | pub const TIOCGPTN = 0x80045430; | ||
| 465 | pub const TIOCSPTLCK = 0x40045431; | ||
| 466 | pub const TIOCGDEV = 0x80045432; | ||
| 467 | pub const TCGETX = 0x5432; | ||
| 468 | pub const TCSETX = 0x5433; | ||
| 469 | pub const TCSETXF = 0x5434; | ||
| 470 | pub const TCSETXW = 0x5435; | ||
| 471 | pub const TIOCSIG = 0x40045436; | ||
| 472 | pub const TIOCVHANGUP = 0x5437; | ||
| 473 | pub const TIOCGPKT = 0x80045438; | ||
| 474 | pub const TIOCGPTLCK = 0x80045439; | ||
| 475 | pub const TIOCGEXCL = 0x80045440; | ||
| 476 | |||
| 477 | pub const EPOLL_CLOEXEC = O_CLOEXEC; | ||
| 478 | |||
| 479 | pub const EPOLL_CTL_ADD = 1; | ||
| 480 | pub const EPOLL_CTL_DEL = 2; | ||
| 481 | pub const EPOLL_CTL_MOD = 3; | ||
| 482 | |||
| 483 | pub const EPOLLIN = 0x001; | ||
| 484 | pub const EPOLLPRI = 0x002; | ||
| 485 | pub const EPOLLOUT = 0x004; | ||
| 486 | pub const EPOLLRDNORM = 0x040; | ||
| 487 | pub const EPOLLRDBAND = 0x080; | ||
| 488 | pub const EPOLLWRNORM = 0x100; | ||
| 489 | pub const EPOLLWRBAND = 0x200; | ||
| 490 | pub const EPOLLMSG = 0x400; | ||
| 491 | pub const EPOLLERR = 0x008; | ||
| 492 | pub const EPOLLHUP = 0x010; | ||
| 493 | pub const EPOLLRDHUP = 0x2000; | ||
| 494 | pub const EPOLLEXCLUSIVE = (u32(1) << 28); | ||
| 495 | pub const EPOLLWAKEUP = (u32(1) << 29); | ||
| 496 | pub const EPOLLONESHOT = (u32(1) << 30); | ||
| 497 | pub const EPOLLET = (u32(1) << 31); | ||
| 498 | |||
| 499 | pub const CLOCK_REALTIME = 0; | ||
| 500 | pub const CLOCK_MONOTONIC = 1; | ||
| 501 | pub const CLOCK_PROCESS_CPUTIME_ID = 2; | ||
| 502 | pub const CLOCK_THREAD_CPUTIME_ID = 3; | ||
| 503 | pub const CLOCK_MONOTONIC_RAW = 4; | ||
| 504 | pub const CLOCK_REALTIME_COARSE = 5; | ||
| 505 | pub const CLOCK_MONOTONIC_COARSE = 6; | ||
| 506 | pub const CLOCK_BOOTTIME = 7; | ||
| 507 | pub const CLOCK_REALTIME_ALARM = 8; | ||
| 508 | pub const CLOCK_BOOTTIME_ALARM = 9; | ||
| 509 | pub const CLOCK_SGI_CYCLE = 10; | ||
| 510 | pub const CLOCK_TAI = 11; | ||
| 511 | |||
| 512 | pub const CSIGNAL = 0x000000ff; | ||
| 513 | pub const CLONE_VM = 0x00000100; | ||
| 514 | pub const CLONE_FS = 0x00000200; | ||
| 515 | pub const CLONE_FILES = 0x00000400; | ||
| 516 | pub const CLONE_SIGHAND = 0x00000800; | ||
| 517 | pub const CLONE_PTRACE = 0x00002000; | ||
| 518 | pub const CLONE_VFORK = 0x00004000; | ||
| 519 | pub const CLONE_PARENT = 0x00008000; | ||
| 520 | pub const CLONE_THREAD = 0x00010000; | ||
| 521 | pub const CLONE_NEWNS = 0x00020000; | ||
| 522 | pub const CLONE_SYSVSEM = 0x00040000; | ||
| 523 | pub const CLONE_SETTLS = 0x00080000; | ||
| 524 | pub const CLONE_PARENT_SETTID = 0x00100000; | ||
| 525 | pub const CLONE_CHILD_CLEARTID = 0x00200000; | ||
| 526 | pub const CLONE_DETACHED = 0x00400000; | ||
| 527 | pub const CLONE_UNTRACED = 0x00800000; | ||
| 528 | pub const CLONE_CHILD_SETTID = 0x01000000; | ||
| 529 | pub const CLONE_NEWCGROUP = 0x02000000; | ||
| 530 | pub const CLONE_NEWUTS = 0x04000000; | ||
| 531 | pub const CLONE_NEWIPC = 0x08000000; | ||
| 532 | pub const CLONE_NEWUSER = 0x10000000; | ||
| 533 | pub const CLONE_NEWPID = 0x20000000; | ||
| 534 | pub const CLONE_NEWNET = 0x40000000; | ||
| 535 | pub const CLONE_IO = 0x80000000; | ||
| 536 | |||
| 537 | pub const EFD_SEMAPHORE = 1; | ||
| 538 | pub const EFD_CLOEXEC = O_CLOEXEC; | ||
| 539 | pub const EFD_NONBLOCK = O_NONBLOCK; | ||
| 540 | |||
| 541 | pub const MS_RDONLY = 1; | ||
| 542 | pub const MS_NOSUID = 2; | ||
| 543 | pub const MS_NODEV = 4; | ||
| 544 | pub const MS_NOEXEC = 8; | ||
| 545 | pub const MS_SYNCHRONOUS = 16; | ||
| 546 | pub const MS_REMOUNT = 32; | ||
| 547 | pub const MS_MANDLOCK = 64; | ||
| 548 | pub const MS_DIRSYNC = 128; | ||
| 549 | pub const MS_NOATIME = 1024; | ||
| 550 | pub const MS_NODIRATIME = 2048; | ||
| 551 | pub const MS_BIND = 4096; | ||
| 552 | pub const MS_MOVE = 8192; | ||
| 553 | pub const MS_REC = 16384; | ||
| 554 | pub const MS_SILENT = 32768; | ||
| 555 | pub const MS_POSIXACL = (1 << 16); | ||
| 556 | pub const MS_UNBINDABLE = (1 << 17); | ||
| 557 | pub const MS_PRIVATE = (1 << 18); | ||
| 558 | pub const MS_SLAVE = (1 << 19); | ||
| 559 | pub const MS_SHARED = (1 << 20); | ||
| 560 | pub const MS_RELATIME = (1 << 21); | ||
| 561 | pub const MS_KERNMOUNT = (1 << 22); | ||
| 562 | pub const MS_I_VERSION = (1 << 23); | ||
| 563 | pub const MS_STRICTATIME = (1 << 24); | ||
| 564 | pub const MS_LAZYTIME = (1 << 25); | ||
| 565 | pub const MS_NOREMOTELOCK = (1 << 27); | ||
| 566 | pub const MS_NOSEC = (1 << 28); | ||
| 567 | pub const MS_BORN = (1 << 29); | ||
| 568 | pub const MS_ACTIVE = (1 << 30); | ||
| 569 | pub const MS_NOUSER = (1 << 31); | ||
| 570 | |||
| 571 | pub const MS_RMT_MASK = (MS_RDONLY | MS_SYNCHRONOUS | MS_MANDLOCK | MS_I_VERSION | MS_LAZYTIME); | ||
| 572 | |||
| 573 | pub const MS_MGC_VAL = 0xc0ed0000; | ||
| 574 | pub const MS_MGC_MSK = 0xffff0000; | ||
| 575 | |||
| 576 | pub const MNT_FORCE = 1; | ||
| 577 | pub const MNT_DETACH = 2; | ||
| 578 | pub const MNT_EXPIRE = 4; | ||
| 579 | pub const UMOUNT_NOFOLLOW = 8; | ||
| 580 | |||
| 581 | pub const IN_CLOEXEC = O_CLOEXEC; | ||
| 582 | pub const IN_NONBLOCK = O_NONBLOCK; | ||
| 583 | |||
| 584 | pub const IN_ACCESS = 0x00000001; | ||
| 585 | pub const IN_MODIFY = 0x00000002; | ||
| 586 | pub const IN_ATTRIB = 0x00000004; | ||
| 587 | pub const IN_CLOSE_WRITE = 0x00000008; | ||
| 588 | pub const IN_CLOSE_NOWRITE = 0x00000010; | ||
| 589 | pub const IN_CLOSE = IN_CLOSE_WRITE | IN_CLOSE_NOWRITE; | ||
| 590 | pub const IN_OPEN = 0x00000020; | ||
| 591 | pub const IN_MOVED_FROM = 0x00000040; | ||
| 592 | pub const IN_MOVED_TO = 0x00000080; | ||
| 593 | pub const IN_MOVE = IN_MOVED_FROM | IN_MOVED_TO; | ||
| 594 | pub const IN_CREATE = 0x00000100; | ||
| 595 | pub const IN_DELETE = 0x00000200; | ||
| 596 | pub const IN_DELETE_SELF = 0x00000400; | ||
| 597 | pub const IN_MOVE_SELF = 0x00000800; | ||
| 598 | pub const IN_ALL_EVENTS = 0x00000fff; | ||
| 599 | |||
| 600 | pub const IN_UNMOUNT = 0x00002000; | ||
| 601 | pub const IN_Q_OVERFLOW = 0x00004000; | ||
| 602 | pub const IN_IGNORED = 0x00008000; | ||
| 603 | |||
| 604 | pub const IN_ONLYDIR = 0x01000000; | ||
| 605 | pub const IN_DONT_FOLLOW = 0x02000000; | ||
| 606 | pub const IN_EXCL_UNLINK = 0x04000000; | ||
| 607 | pub const IN_MASK_ADD = 0x20000000; | ||
| 608 | |||
| 609 | pub const IN_ISDIR = 0x40000000; | ||
| 610 | pub const IN_ONESHOT = 0x80000000; | ||
| 611 | |||
| 612 | pub const S_IFMT = 0o170000; | ||
| 613 | |||
| 614 | pub const S_IFDIR = 0o040000; | ||
| 615 | pub const S_IFCHR = 0o020000; | ||
| 616 | pub const S_IFBLK = 0o060000; | ||
| 617 | pub const S_IFREG = 0o100000; | ||
| 618 | pub const S_IFIFO = 0o010000; | ||
| 619 | pub const S_IFLNK = 0o120000; | ||
| 620 | pub const S_IFSOCK = 0o140000; | ||
| 621 | |||
| 622 | pub const S_ISUID = 0o4000; | ||
| 623 | pub const S_ISGID = 0o2000; | ||
| 624 | pub const S_ISVTX = 0o1000; | ||
| 625 | pub const S_IRUSR = 0o400; | ||
| 626 | pub const S_IWUSR = 0o200; | ||
| 627 | pub const S_IXUSR = 0o100; | ||
| 628 | pub const S_IRWXU = 0o700; | ||
| 629 | pub const S_IRGRP = 0o040; | ||
| 630 | pub const S_IWGRP = 0o020; | ||
| 631 | pub const S_IXGRP = 0o010; | ||
| 632 | pub const S_IRWXG = 0o070; | ||
| 633 | pub const S_IROTH = 0o004; | ||
| 634 | pub const S_IWOTH = 0o002; | ||
| 635 | pub const S_IXOTH = 0o001; | ||
| 636 | pub const S_IRWXO = 0o007; | ||
| 637 | |||
| 638 | pub fn S_ISREG(m: u32) bool { | ||
| 639 | return m & S_IFMT == S_IFREG; | ||
| 640 | } | ||
| 641 | |||
| 642 | pub fn S_ISDIR(m: u32) bool { | ||
| 643 | return m & S_IFMT == S_IFDIR; | ||
| 644 | } | ||
| 645 | |||
| 646 | pub fn S_ISCHR(m: u32) bool { | ||
| 647 | return m & S_IFMT == S_IFCHR; | ||
| 648 | } | ||
| 649 | |||
| 650 | pub fn S_ISBLK(m: u32) bool { | ||
| 651 | return m & S_IFMT == S_IFBLK; | ||
| 652 | } | ||
| 653 | |||
| 654 | pub fn S_ISFIFO(m: u32) bool { | ||
| 655 | return m & S_IFMT == S_IFIFO; | ||
| 656 | } | ||
| 657 | |||
| 658 | pub fn S_ISLNK(m: u32) bool { | ||
| 659 | return m & S_IFMT == S_IFLNK; | ||
| 660 | } | ||
| 661 | |||
| 662 | pub fn S_ISSOCK(m: u32) bool { | ||
| 663 | return m & S_IFMT == S_IFSOCK; | ||
| 664 | } | ||
| 665 | |||
| 666 | pub const TFD_NONBLOCK = O_NONBLOCK; | ||
| 667 | pub const TFD_CLOEXEC = O_CLOEXEC; | ||
| 668 | |||
| 669 | pub const TFD_TIMER_ABSTIME = 1; | ||
| 670 | pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1); | ||
| 671 | |||
| 672 | fn unsigned(s: i32) u32 { | ||
| 673 | return @bitCast(u32, s); | ||
| 674 | } | ||
| 675 | fn signed(s: u32) i32 { | ||
| 676 | return @bitCast(i32, s); | ||
| 677 | } | ||
| 678 | pub fn WEXITSTATUS(s: i32) i32 { | ||
| 679 | return signed((unsigned(s) & 0xff00) >> 8); | ||
| 680 | } | ||
| 681 | pub fn WTERMSIG(s: i32) i32 { | ||
| 682 | return signed(unsigned(s) & 0x7f); | ||
| 683 | } | ||
| 684 | pub fn WSTOPSIG(s: i32) i32 { | ||
| 685 | return WEXITSTATUS(s); | ||
| 686 | } | ||
| 687 | pub fn WIFEXITED(s: i32) bool { | ||
| 688 | return WTERMSIG(s) == 0; | ||
| 689 | } | ||
| 690 | pub fn WIFSTOPPED(s: i32) bool { | ||
| 691 | return @intCast(u16, ((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00; | ||
| 692 | } | ||
| 693 | pub fn WIFSIGNALED(s: i32) bool { | ||
| 694 | return (unsigned(s) & 0xffff) -% 1 < 0xff; | ||
| 695 | } | ||
| 696 | |||
| 697 | pub const winsize = extern struct { | ||
| 698 | ws_row: u16, | ||
| 699 | ws_col: u16, | ||
| 700 | ws_xpixel: u16, | ||
| 701 | ws_ypixel: u16, | ||
| 702 | }; | ||
| 703 | |||
| 704 | /// Get the errno from a syscall return value, or 0 for no error. | 21 | /// Get the errno from a syscall return value, or 0 for no error. |
| 705 | pub fn getErrno(r: usize) u12 { | 22 | pub fn getErrno(r: usize) u12 { |
| 706 | const signed_r = @bitCast(isize, r); | 23 | const signed_r = @bitCast(isize, r); |
| ... | @@ -708,7 +25,7 @@ pub fn getErrno(r: usize) u12 { | ... | @@ -708,7 +25,7 @@ pub fn getErrno(r: usize) u12 { |
| 708 | } | 25 | } |
| 709 | 26 | ||
| 710 | pub fn dup2(old: i32, new: i32) usize { | 27 | pub fn dup2(old: i32, new: i32) usize { |
| 711 | return dup3(old, new, 0); | 28 | return syscall2(SYS_dup2, @bitCast(usize, isize(old)), @bitCast(usize, isize(new))); |
| 712 | } | 29 | } |
| 713 | 30 | ||
| 714 | pub fn dup3(old: i32, new: i32, flags: u32) usize { | 31 | pub fn dup3(old: i32, new: i32, flags: u32) usize { |
| ... | @@ -731,7 +48,7 @@ pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[* | ... | @@ -731,7 +48,7 @@ pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[* |
| 731 | } | 48 | } |
| 732 | 49 | ||
| 733 | pub fn fork() usize { | 50 | pub fn fork() usize { |
| 734 | return clone2(SIGCHLD, 0); | 51 | return syscall0(SYS_fork); |
| 735 | } | 52 | } |
| 736 | 53 | ||
| 737 | /// This must be inline, and inline call the syscall function, because if the | 54 | /// This must be inline, and inline call the syscall function, because if the |
| ... | @@ -755,6 +72,10 @@ pub fn getcwd(buf: [*]u8, size: usize) usize { | ... | @@ -755,6 +72,10 @@ pub fn getcwd(buf: [*]u8, size: usize) usize { |
| 755 | return syscall2(SYS_getcwd, @ptrToInt(buf), size); | 72 | return syscall2(SYS_getcwd, @ptrToInt(buf), size); |
| 756 | } | 73 | } |
| 757 | 74 | ||
| 75 | pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { | ||
| 76 | return syscall3(SYS_getdents, @bitCast(usize, isize(fd)), @ptrToInt(dirp), count); | ||
| 77 | } | ||
| 78 | |||
| 758 | pub fn getdents64(fd: i32, dirp: [*]u8, count: usize) usize { | 79 | pub fn getdents64(fd: i32, dirp: [*]u8, count: usize) usize { |
| 759 | return syscall3(SYS_getdents64, @bitCast(usize, isize(fd)), @ptrToInt(dirp), count); | 80 | return syscall3(SYS_getdents64, @bitCast(usize, isize(fd)), @ptrToInt(dirp), count); |
| 760 | } | 81 | } |
| ... | @@ -773,7 +94,7 @@ pub fn inotify_rm_watch(fd: i32, wd: i32) usize { | ... | @@ -773,7 +94,7 @@ pub fn inotify_rm_watch(fd: i32, wd: i32) usize { |
| 773 | 94 | ||
| 774 | // TODO https://github.com/ziglang/zig/issues/265 | 95 | // TODO https://github.com/ziglang/zig/issues/265 |
| 775 | pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { | 96 | pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { |
| 776 | return readlinkat(AT_FDCWD, path, buf_ptr, buf_len); | 97 | return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); |
| 777 | } | 98 | } |
| 778 | 99 | ||
| 779 | // TODO https://github.com/ziglang/zig/issues/265 | 100 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | @@ -783,7 +104,7 @@ pub fn readlinkat(dirfd: i32, noalias path: [*]const u8, noalias buf_ptr: [*]u8, | ... | @@ -783,7 +104,7 @@ pub fn readlinkat(dirfd: i32, noalias path: [*]const u8, noalias buf_ptr: [*]u8, |
| 783 | 104 | ||
| 784 | // TODO https://github.com/ziglang/zig/issues/265 | 105 | // TODO https://github.com/ziglang/zig/issues/265 |
| 785 | pub fn mkdir(path: [*]const u8, mode: u32) usize { | 106 | pub fn mkdir(path: [*]const u8, mode: u32) usize { |
| 786 | return mkdirat(AT_FDCWD, path, mode); | 107 | return syscall2(SYS_mkdir, @ptrToInt(path), mode); |
| 787 | } | 108 | } |
| 788 | 109 | ||
| 789 | // TODO https://github.com/ziglang/zig/issues/265 | 110 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | @@ -840,12 +161,12 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us | ... | @@ -840,12 +161,12 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us |
| 840 | 161 | ||
| 841 | // TODO https://github.com/ziglang/zig/issues/265 | 162 | // TODO https://github.com/ziglang/zig/issues/265 |
| 842 | pub fn rmdir(path: [*]const u8) usize { | 163 | pub fn rmdir(path: [*]const u8) usize { |
| 843 | return unlinkat(AT_FDCWD, path, AT_REMOVEDIR); | 164 | return syscall1(SYS_rmdir, @ptrToInt(path)); |
| 844 | } | 165 | } |
| 845 | 166 | ||
| 846 | // TODO https://github.com/ziglang/zig/issues/265 | 167 | // TODO https://github.com/ziglang/zig/issues/265 |
| 847 | pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { | 168 | pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { |
| 848 | return symlinkat(existing, AT_FDCWD, new); | 169 | return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); |
| 849 | } | 170 | } |
| 850 | 171 | ||
| 851 | // TODO https://github.com/ziglang/zig/issues/265 | 172 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | @@ -860,9 +181,10 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { | ... | @@ -860,9 +181,10 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { |
| 860 | 181 | ||
| 861 | // TODO https://github.com/ziglang/zig/issues/265 | 182 | // TODO https://github.com/ziglang/zig/issues/265 |
| 862 | pub fn access(path: [*]const u8, mode: u32) usize { | 183 | pub fn access(path: [*]const u8, mode: u32) usize { |
| 863 | return faccessat(AT_FDCWD, path, mode); | 184 | return syscall2(SYS_access, @ptrToInt(path), mode); |
| 864 | } | 185 | } |
| 865 | 186 | ||
| 187 | // TODO https://github.com/ziglang/zig/issues/265 | ||
| 866 | pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32) usize { | 188 | pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32) usize { |
| 867 | return syscall3(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode); | 189 | return syscall3(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode); |
| 868 | } | 190 | } |
| ... | @@ -885,7 +207,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { | ... | @@ -885,7 +207,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { |
| 885 | 207 | ||
| 886 | // TODO https://github.com/ziglang/zig/issues/265 | 208 | // TODO https://github.com/ziglang/zig/issues/265 |
| 887 | pub fn rename(old: [*]const u8, new: [*]const u8) usize { | 209 | pub fn rename(old: [*]const u8, new: [*]const u8) usize { |
| 888 | return renameat2(AT_FDCWD, old, AT_FDCWD, new, 0); | 210 | return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new)); |
| 889 | } | 211 | } |
| 890 | 212 | ||
| 891 | // TODO https://github.com/ziglang/zig/issues/265 | 213 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | @@ -895,7 +217,7 @@ pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const | ... | @@ -895,7 +217,7 @@ pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const |
| 895 | 217 | ||
| 896 | // TODO https://github.com/ziglang/zig/issues/265 | 218 | // TODO https://github.com/ziglang/zig/issues/265 |
| 897 | pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { | 219 | pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { |
| 898 | return openat(AT_FDCWD, path, flags, perm); | 220 | return syscall3(SYS_open, @ptrToInt(path), flags, perm); |
| 899 | } | 221 | } |
| 900 | 222 | ||
| 901 | // TODO https://github.com/ziglang/zig/issues/265 | 223 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | @@ -947,7 +269,7 @@ pub fn kill(pid: i32, sig: i32) usize { | ... | @@ -947,7 +269,7 @@ pub fn kill(pid: i32, sig: i32) usize { |
| 947 | 269 | ||
| 948 | // TODO https://github.com/ziglang/zig/issues/265 | 270 | // TODO https://github.com/ziglang/zig/issues/265 |
| 949 | pub fn unlink(path: [*]const u8) usize { | 271 | pub fn unlink(path: [*]const u8) usize { |
| 950 | return unlinkat(AT_FDCWD, path, 0); | 272 | return syscall1(SYS_unlink, @ptrToInt(path)); |
| 951 | } | 273 | } |
| 952 | 274 | ||
| 953 | // TODO https://github.com/ziglang/zig/issues/265 | 275 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | @@ -1113,30 +435,6 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti | ... | @@ -1113,30 +435,6 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti |
| 1113 | return 0; | 435 | return 0; |
| 1114 | } | 436 | } |
| 1115 | 437 | ||
| 1116 | const NSIG = 65; | ||
| 1117 | const sigset_t = [128 / @sizeOf(usize)]usize; | ||
| 1118 | const all_mask = []u32{ 0xffffffff, 0xffffffff }; | ||
| 1119 | const app_mask = []u32{ 0xfffffffc, 0x7fffffff }; | ||
| 1120 | |||
| 1121 | const k_sigaction = extern struct { | ||
| 1122 | handler: extern fn (i32) void, | ||
| 1123 | flags: usize, | ||
| 1124 | restorer: extern fn () void, | ||
| 1125 | mask: [2]u32, | ||
| 1126 | }; | ||
| 1127 | |||
| 1128 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | ||
| 1129 | pub const Sigaction = struct { | ||
| 1130 | handler: extern fn (i32) void, | ||
| 1131 | mask: sigset_t, | ||
| 1132 | flags: u32, | ||
| 1133 | }; | ||
| 1134 | |||
| 1135 | pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize)); | ||
| 1136 | pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); | ||
| 1137 | pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); | ||
| 1138 | pub const empty_sigset = []usize{0} ** sigset_t.len; | ||
| 1139 | |||
| 1140 | fn blockAllSignals(set: *sigset_t) void { | 438 | fn blockAllSignals(set: *sigset_t) void { |
| 1141 | _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG / 8); | 439 | _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG / 8); |
| 1142 | } | 440 | } |
| ... | @@ -1159,56 +457,6 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool { | ... | @@ -1159,56 +457,6 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool { |
| 1159 | return ((set.*)[@intCast(usize, s) / usize.bit_count] & (@intCast(usize, 1) << (s & (usize.bit_count - 1)))) != 0; | 457 | return ((set.*)[@intCast(usize, s) / usize.bit_count] & (@intCast(usize, 1) << (s & (usize.bit_count - 1)))) != 0; |
| 1160 | } | 458 | } |
| 1161 | 459 | ||
| 1162 | pub const in_port_t = u16; | ||
| 1163 | pub const sa_family_t = u16; | ||
| 1164 | pub const socklen_t = u32; | ||
| 1165 | |||
| 1166 | /// This intentionally only has ip4 and ip6 | ||
| 1167 | pub const sockaddr = extern union { | ||
| 1168 | in: sockaddr_in, | ||
| 1169 | in6: sockaddr_in6, | ||
| 1170 | }; | ||
| 1171 | |||
| 1172 | pub const sockaddr_in = extern struct { | ||
| 1173 | family: sa_family_t, | ||
| 1174 | port: in_port_t, | ||
| 1175 | addr: u32, | ||
| 1176 | zero: [8]u8, | ||
| 1177 | }; | ||
| 1178 | |||
| 1179 | pub const sockaddr_in6 = extern struct { | ||
| 1180 | family: sa_family_t, | ||
| 1181 | port: in_port_t, | ||
| 1182 | flowinfo: u32, | ||
| 1183 | addr: [16]u8, | ||
| 1184 | scope_id: u32, | ||
| 1185 | }; | ||
| 1186 | |||
| 1187 | pub const sockaddr_un = extern struct { | ||
| 1188 | family: sa_family_t, | ||
| 1189 | path: [108]u8, | ||
| 1190 | }; | ||
| 1191 | |||
| 1192 | pub const iovec = extern struct { | ||
| 1193 | iov_base: [*]u8, | ||
| 1194 | iov_len: usize, | ||
| 1195 | }; | ||
| 1196 | |||
| 1197 | pub const iovec_const = extern struct { | ||
| 1198 | iov_base: [*]const u8, | ||
| 1199 | iov_len: usize, | ||
| 1200 | }; | ||
| 1201 | |||
| 1202 | pub const mmsghdr = extern struct { | ||
| 1203 | msg_hdr: msghdr, | ||
| 1204 | msg_len: u32, | ||
| 1205 | }; | ||
| 1206 | |||
| 1207 | pub const mmsghdr_const = extern struct { | ||
| 1208 | msg_hdr: msghdr_const, | ||
| 1209 | msg_len: u32, | ||
| 1210 | }; | ||
| 1211 | |||
| 1212 | pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { | 460 | pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { |
| 1213 | return syscall3(SYS_getsockname, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len)); | 461 | return syscall3(SYS_getsockname, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len)); |
| 1214 | } | 462 | } |
| ... | @@ -1319,12 +567,12 @@ pub fn fstat(fd: i32, stat_buf: *Stat) usize { | ... | @@ -1319,12 +567,12 @@ pub fn fstat(fd: i32, stat_buf: *Stat) usize { |
| 1319 | 567 | ||
| 1320 | // TODO https://github.com/ziglang/zig/issues/265 | 568 | // TODO https://github.com/ziglang/zig/issues/265 |
| 1321 | pub fn stat(pathname: [*]const u8, statbuf: *Stat) usize { | 569 | pub fn stat(pathname: [*]const u8, statbuf: *Stat) usize { |
| 1322 | return fstatat(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT); | 570 | return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf)); |
| 1323 | } | 571 | } |
| 1324 | 572 | ||
| 1325 | // TODO https://github.com/ziglang/zig/issues/265 | 573 | // TODO https://github.com/ziglang/zig/issues/265 |
| 1326 | pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize { | 574 | pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize { |
| 1327 | return fstatat(AF_FDCWD, pathname, statbuf, AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT); | 575 | return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf)); |
| 1328 | } | 576 | } |
| 1329 | 577 | ||
| 1330 | // TODO https://github.com/ziglang/zig/issues/265 | 578 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | @@ -1395,26 +643,6 @@ pub fn sched_getaffinity(pid: i32, set: []usize) usize { | ... | @@ -1395,26 +643,6 @@ pub fn sched_getaffinity(pid: i32, set: []usize) usize { |
| 1395 | return syscall3(SYS_sched_getaffinity, @bitCast(usize, isize(pid)), set.len * @sizeOf(usize), @ptrToInt(set.ptr)); | 643 | return syscall3(SYS_sched_getaffinity, @bitCast(usize, isize(pid)), set.len * @sizeOf(usize), @ptrToInt(set.ptr)); |
| 1396 | } | 644 | } |
| 1397 | 645 | ||
| 1398 | pub const epoll_data = extern union { | ||
| 1399 | ptr: usize, | ||
| 1400 | fd: i32, | ||
| 1401 | @"u32": u32, | ||
| 1402 | @"u64": u64, | ||
| 1403 | }; | ||
| 1404 | |||
| 1405 | // On x86_64 the structure is packed so that it matches the definition of its | ||
| 1406 | // 32bit counterpart | ||
| 1407 | pub const epoll_event = if (builtin.arch != .x86_64) | ||
| 1408 | extern struct { | ||
| 1409 | events: u32, | ||
| 1410 | data: epoll_data, | ||
| 1411 | } | ||
| 1412 | else | ||
| 1413 | packed struct { | ||
| 1414 | events: u32, | ||
| 1415 | data: epoll_data, | ||
| 1416 | }; | ||
| 1417 | |||
| 1418 | pub fn epoll_create() usize { | 646 | pub fn epoll_create() usize { |
| 1419 | return epoll_create1(0); | 647 | return epoll_create1(0); |
| 1420 | } | 648 | } |
| ... | @@ -1428,7 +656,13 @@ pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: *epoll_event) usize { | ... | @@ -1428,7 +656,13 @@ pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: *epoll_event) usize { |
| 1428 | } | 656 | } |
| 1429 | 657 | ||
| 1430 | pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize { | 658 | pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize { |
| 1431 | return epoll_pwait(epoll_fd, events, maxevents, timeout, null); | 659 | return syscall4( |
| 660 | SYS_epoll_wait, | ||
| 661 | @bitCast(usize, isize(epoll_fd)), | ||
| 662 | @ptrToInt(events), | ||
| 663 | maxevents, | ||
| 664 | @bitCast(usize, isize(timeout)), | ||
| 665 | ); | ||
| 1432 | } | 666 | } |
| 1433 | 667 | ||
| 1434 | pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize { | 668 | pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize { |
| ... | @@ -1464,112 +698,6 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_va | ... | @@ -1464,112 +698,6 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_va |
| 1464 | return syscall4(SYS_timerfd_settime, @bitCast(usize, isize(fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value)); | 698 | return syscall4(SYS_timerfd_settime, @bitCast(usize, isize(fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value)); |
| 1465 | } | 699 | } |
| 1466 | 700 | ||
| 1467 | pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330; | ||
| 1468 | pub const _LINUX_CAPABILITY_U32S_1 = 1; | ||
| 1469 | |||
| 1470 | pub const _LINUX_CAPABILITY_VERSION_2 = 0x20071026; | ||
| 1471 | pub const _LINUX_CAPABILITY_U32S_2 = 2; | ||
| 1472 | |||
| 1473 | pub const _LINUX_CAPABILITY_VERSION_3 = 0x20080522; | ||
| 1474 | pub const _LINUX_CAPABILITY_U32S_3 = 2; | ||
| 1475 | |||
| 1476 | pub const VFS_CAP_REVISION_MASK = 0xFF000000; | ||
| 1477 | pub const VFS_CAP_REVISION_SHIFT = 24; | ||
| 1478 | pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK; | ||
| 1479 | pub const VFS_CAP_FLAGS_EFFECTIVE = 0x000001; | ||
| 1480 | |||
| 1481 | pub const VFS_CAP_REVISION_1 = 0x01000000; | ||
| 1482 | pub const VFS_CAP_U32_1 = 1; | ||
| 1483 | pub const XATTR_CAPS_SZ_1 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_1); | ||
| 1484 | |||
| 1485 | pub const VFS_CAP_REVISION_2 = 0x02000000; | ||
| 1486 | pub const VFS_CAP_U32_2 = 2; | ||
| 1487 | pub const XATTR_CAPS_SZ_2 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_2); | ||
| 1488 | |||
| 1489 | pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2; | ||
| 1490 | pub const VFS_CAP_U32 = VFS_CAP_U32_2; | ||
| 1491 | pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2; | ||
| 1492 | |||
| 1493 | pub const vfs_cap_data = extern struct { | ||
| 1494 | //all of these are mandated as little endian | ||
| 1495 | //when on disk. | ||
| 1496 | const Data = struct { | ||
| 1497 | permitted: u32, | ||
| 1498 | inheritable: u32, | ||
| 1499 | }; | ||
| 1500 | |||
| 1501 | magic_etc: u32, | ||
| 1502 | data: [VFS_CAP_U32]Data, | ||
| 1503 | }; | ||
| 1504 | |||
| 1505 | pub const CAP_CHOWN = 0; | ||
| 1506 | pub const CAP_DAC_OVERRIDE = 1; | ||
| 1507 | pub const CAP_DAC_READ_SEARCH = 2; | ||
| 1508 | pub const CAP_FOWNER = 3; | ||
| 1509 | pub const CAP_FSETID = 4; | ||
| 1510 | pub const CAP_KILL = 5; | ||
| 1511 | pub const CAP_SETGID = 6; | ||
| 1512 | pub const CAP_SETUID = 7; | ||
| 1513 | pub const CAP_SETPCAP = 8; | ||
| 1514 | pub const CAP_LINUX_IMMUTABLE = 9; | ||
| 1515 | pub const CAP_NET_BIND_SERVICE = 10; | ||
| 1516 | pub const CAP_NET_BROADCAST = 11; | ||
| 1517 | pub const CAP_NET_ADMIN = 12; | ||
| 1518 | pub const CAP_NET_RAW = 13; | ||
| 1519 | pub const CAP_IPC_LOCK = 14; | ||
| 1520 | pub const CAP_IPC_OWNER = 15; | ||
| 1521 | pub const CAP_SYS_MODULE = 16; | ||
| 1522 | pub const CAP_SYS_RAWIO = 17; | ||
| 1523 | pub const CAP_SYS_CHROOT = 18; | ||
| 1524 | pub const CAP_SYS_PTRACE = 19; | ||
| 1525 | pub const CAP_SYS_PACCT = 20; | ||
| 1526 | pub const CAP_SYS_ADMIN = 21; | ||
| 1527 | pub const CAP_SYS_BOOT = 22; | ||
| 1528 | pub const CAP_SYS_NICE = 23; | ||
| 1529 | pub const CAP_SYS_RESOURCE = 24; | ||
| 1530 | pub const CAP_SYS_TIME = 25; | ||
| 1531 | pub const CAP_SYS_TTY_CONFIG = 26; | ||
| 1532 | pub const CAP_MKNOD = 27; | ||
| 1533 | pub const CAP_LEASE = 28; | ||
| 1534 | pub const CAP_AUDIT_WRITE = 29; | ||
| 1535 | pub const CAP_AUDIT_CONTROL = 30; | ||
| 1536 | pub const CAP_SETFCAP = 31; | ||
| 1537 | pub const CAP_MAC_OVERRIDE = 32; | ||
| 1538 | pub const CAP_MAC_ADMIN = 33; | ||
| 1539 | pub const CAP_SYSLOG = 34; | ||
| 1540 | pub const CAP_WAKE_ALARM = 35; | ||
| 1541 | pub const CAP_BLOCK_SUSPEND = 36; | ||
| 1542 | pub const CAP_AUDIT_READ = 37; | ||
| 1543 | pub const CAP_LAST_CAP = CAP_AUDIT_READ; | ||
| 1544 | |||
| 1545 | pub fn cap_valid(u8: x) bool { | ||
| 1546 | return x >= 0 and x <= CAP_LAST_CAP; | ||
| 1547 | } | ||
| 1548 | |||
| 1549 | pub fn CAP_TO_MASK(cap: u8) u32 { | ||
| 1550 | return u32(1) << u5(cap & 31); | ||
| 1551 | } | ||
| 1552 | |||
| 1553 | pub fn CAP_TO_INDEX(cap: u8) u8 { | ||
| 1554 | return cap >> 5; | ||
| 1555 | } | ||
| 1556 | |||
| 1557 | pub const cap_t = extern struct { | ||
| 1558 | hdrp: *cap_user_header_t, | ||
| 1559 | datap: *cap_user_data_t, | ||
| 1560 | }; | ||
| 1561 | |||
| 1562 | pub const cap_user_header_t = extern struct { | ||
| 1563 | version: u32, | ||
| 1564 | pid: usize, | ||
| 1565 | }; | ||
| 1566 | |||
| 1567 | pub const cap_user_data_t = extern struct { | ||
| 1568 | effective: u32, | ||
| 1569 | permitted: u32, | ||
| 1570 | inheritable: u32, | ||
| 1571 | }; | ||
| 1572 | |||
| 1573 | pub fn unshare(flags: usize) usize { | 701 | pub fn unshare(flags: usize) usize { |
| 1574 | return syscall1(SYS_unshare, flags); | 702 | return syscall1(SYS_unshare, flags); |
| 1575 | } | 703 | } |
| ... | @@ -1582,29 +710,6 @@ pub fn capset(hdrp: *cap_user_header_t, datap: *const cap_user_data_t) usize { | ... | @@ -1582,29 +710,6 @@ pub fn capset(hdrp: *cap_user_header_t, datap: *const cap_user_data_t) usize { |
| 1582 | return syscall2(SYS_capset, @ptrToInt(hdrp), @ptrToInt(datap)); | 710 | return syscall2(SYS_capset, @ptrToInt(hdrp), @ptrToInt(datap)); |
| 1583 | } | 711 | } |
| 1584 | 712 | ||
| 1585 | pub const inotify_event = extern struct { | ||
| 1586 | wd: i32, | ||
| 1587 | mask: u32, | ||
| 1588 | cookie: u32, | ||
| 1589 | len: u32, | ||
| 1590 | //name: [?]u8, | ||
| 1591 | }; | ||
| 1592 | |||
| 1593 | pub const dirent64 = extern struct { | ||
| 1594 | d_ino: u64, | ||
| 1595 | d_off: u64, | ||
| 1596 | d_reclen: u16, | ||
| 1597 | d_type: u8, | ||
| 1598 | d_name: u8, // field address is the address of first byte of name https://github.com/ziglang/zig/issues/173 | ||
| 1599 | }; | ||
| 1600 | |||
| 1601 | pub const dl_phdr_info = extern struct { | ||
| 1602 | dlpi_addr: usize, | ||
| 1603 | dlpi_name: ?[*]const u8, | ||
| 1604 | dlpi_phdr: [*]elf.Phdr, | ||
| 1605 | dlpi_phnum: u16, | ||
| 1606 | }; | ||
| 1607 | |||
| 1608 | // XXX: This should be weak | 713 | // XXX: This should be weak |
| 1609 | extern const __ehdr_start: elf.Ehdr = undefined; | 714 | extern const __ehdr_start: elf.Ehdr = undefined; |
| 1610 | 715 |
std/os/linux/arm64.zig-403| ... | @@ -1,344 +1,3 @@ | ... | @@ -1,344 +1,3 @@ |
| 1 | const std = @import("../../std.zig"); | ||
| 2 | const linux = std.os.linux; | ||
| 3 | const socklen_t = linux.socklen_t; | ||
| 4 | const iovec = linux.iovec; | ||
| 5 | const iovec_const = linux.iovec_const; | ||
| 6 | |||
| 7 | pub const SYS_io_setup = 0; | ||
| 8 | pub const SYS_io_destroy = 1; | ||
| 9 | pub const SYS_io_submit = 2; | ||
| 10 | pub const SYS_io_cancel = 3; | ||
| 11 | pub const SYS_io_getevents = 4; | ||
| 12 | pub const SYS_setxattr = 5; | ||
| 13 | pub const SYS_lsetxattr = 6; | ||
| 14 | pub const SYS_fsetxattr = 7; | ||
| 15 | pub const SYS_getxattr = 8; | ||
| 16 | pub const SYS_lgetxattr = 9; | ||
| 17 | pub const SYS_fgetxattr = 10; | ||
| 18 | pub const SYS_listxattr = 11; | ||
| 19 | pub const SYS_llistxattr = 12; | ||
| 20 | pub const SYS_flistxattr = 13; | ||
| 21 | pub const SYS_removexattr = 14; | ||
| 22 | pub const SYS_lremovexattr = 15; | ||
| 23 | pub const SYS_fremovexattr = 16; | ||
| 24 | pub const SYS_getcwd = 17; | ||
| 25 | pub const SYS_lookup_dcookie = 18; | ||
| 26 | pub const SYS_eventfd2 = 19; | ||
| 27 | pub const SYS_epoll_create1 = 20; | ||
| 28 | pub const SYS_epoll_ctl = 21; | ||
| 29 | pub const SYS_epoll_pwait = 22; | ||
| 30 | pub const SYS_dup = 23; | ||
| 31 | pub const SYS_dup3 = 24; | ||
| 32 | pub const SYS_fcntl = 25; | ||
| 33 | pub const SYS_inotify_init1 = 26; | ||
| 34 | pub const SYS_inotify_add_watch = 27; | ||
| 35 | pub const SYS_inotify_rm_watch = 28; | ||
| 36 | pub const SYS_ioctl = 29; | ||
| 37 | pub const SYS_ioprio_set = 30; | ||
| 38 | pub const SYS_ioprio_get = 31; | ||
| 39 | pub const SYS_flock = 32; | ||
| 40 | pub const SYS_mknodat = 33; | ||
| 41 | pub const SYS_mkdirat = 34; | ||
| 42 | pub const SYS_unlinkat = 35; | ||
| 43 | pub const SYS_symlinkat = 36; | ||
| 44 | pub const SYS_linkat = 37; | ||
| 45 | pub const SYS_renameat = 38; | ||
| 46 | pub const SYS_umount2 = 39; | ||
| 47 | pub const SYS_mount = 40; | ||
| 48 | pub const SYS_pivot_root = 41; | ||
| 49 | pub const SYS_nfsservctl = 42; | ||
| 50 | pub const SYS_statfs = 43; | ||
| 51 | pub const SYS_fstatfs = 44; | ||
| 52 | pub const SYS_truncate = 45; | ||
| 53 | pub const SYS_ftruncate = 46; | ||
| 54 | pub const SYS_fallocate = 47; | ||
| 55 | pub const SYS_faccessat = 48; | ||
| 56 | pub const SYS_chdir = 49; | ||
| 57 | pub const SYS_fchdir = 50; | ||
| 58 | pub const SYS_chroot = 51; | ||
| 59 | pub const SYS_fchmod = 52; | ||
| 60 | pub const SYS_fchmodat = 53; | ||
| 61 | pub const SYS_fchownat = 54; | ||
| 62 | pub const SYS_fchown = 55; | ||
| 63 | pub const SYS_openat = 56; | ||
| 64 | pub const SYS_close = 57; | ||
| 65 | pub const SYS_vhangup = 58; | ||
| 66 | pub const SYS_pipe2 = 59; | ||
| 67 | pub const SYS_quotactl = 60; | ||
| 68 | pub const SYS_getdents64 = 61; | ||
| 69 | pub const SYS_lseek = 62; | ||
| 70 | pub const SYS_read = 63; | ||
| 71 | pub const SYS_write = 64; | ||
| 72 | pub const SYS_readv = 65; | ||
| 73 | pub const SYS_writev = 66; | ||
| 74 | pub const SYS_pread64 = 67; | ||
| 75 | pub const SYS_pwrite64 = 68; | ||
| 76 | pub const SYS_preadv = 69; | ||
| 77 | pub const SYS_pwritev = 70; | ||
| 78 | pub const SYS_pselect6 = 72; | ||
| 79 | pub const SYS_ppoll = 73; | ||
| 80 | pub const SYS_signalfd4 = 74; | ||
| 81 | pub const SYS_vmsplice = 75; | ||
| 82 | pub const SYS_splice = 76; | ||
| 83 | pub const SYS_tee = 77; | ||
| 84 | pub const SYS_readlinkat = 78; | ||
| 85 | pub const SYS_fstatat = 79; | ||
| 86 | pub const SYS_fstat = 80; | ||
| 87 | pub const SYS_sync = 81; | ||
| 88 | pub const SYS_fsync = 82; | ||
| 89 | pub const SYS_fdatasync = 83; | ||
| 90 | pub const SYS_sync_file_range2 = 84; | ||
| 91 | pub const SYS_sync_file_range = 84; | ||
| 92 | pub const SYS_timerfd_create = 85; | ||
| 93 | pub const SYS_timerfd_settime = 86; | ||
| 94 | pub const SYS_timerfd_gettime = 87; | ||
| 95 | pub const SYS_utimensat = 88; | ||
| 96 | pub const SYS_acct = 89; | ||
| 97 | pub const SYS_capget = 90; | ||
| 98 | pub const SYS_capset = 91; | ||
| 99 | pub const SYS_personality = 92; | ||
| 100 | pub const SYS_exit = 93; | ||
| 101 | pub const SYS_exit_group = 94; | ||
| 102 | pub const SYS_waitid = 95; | ||
| 103 | pub const SYS_set_tid_address = 96; | ||
| 104 | pub const SYS_unshare = 97; | ||
| 105 | pub const SYS_futex = 98; | ||
| 106 | pub const SYS_set_robust_list = 99; | ||
| 107 | pub const SYS_get_robust_list = 100; | ||
| 108 | pub const SYS_nanosleep = 101; | ||
| 109 | pub const SYS_getitimer = 102; | ||
| 110 | pub const SYS_setitimer = 103; | ||
| 111 | pub const SYS_kexec_load = 104; | ||
| 112 | pub const SYS_init_module = 105; | ||
| 113 | pub const SYS_delete_module = 106; | ||
| 114 | pub const SYS_timer_create = 107; | ||
| 115 | pub const SYS_timer_gettime = 108; | ||
| 116 | pub const SYS_timer_getoverrun = 109; | ||
| 117 | pub const SYS_timer_settime = 110; | ||
| 118 | pub const SYS_timer_delete = 111; | ||
| 119 | pub const SYS_clock_settime = 112; | ||
| 120 | pub const SYS_clock_gettime = 113; | ||
| 121 | pub const SYS_clock_getres = 114; | ||
| 122 | pub const SYS_clock_nanosleep = 115; | ||
| 123 | pub const SYS_syslog = 116; | ||
| 124 | pub const SYS_ptrace = 117; | ||
| 125 | pub const SYS_sched_setparam = 118; | ||
| 126 | pub const SYS_sched_setscheduler = 119; | ||
| 127 | pub const SYS_sched_getscheduler = 120; | ||
| 128 | pub const SYS_sched_getparam = 121; | ||
| 129 | pub const SYS_sched_setaffinity = 122; | ||
| 130 | pub const SYS_sched_getaffinity = 123; | ||
| 131 | pub const SYS_sched_yield = 124; | ||
| 132 | pub const SYS_sched_get_priority_max = 125; | ||
| 133 | pub const SYS_sched_get_priority_min = 126; | ||
| 134 | pub const SYS_sched_rr_get_interval = 127; | ||
| 135 | pub const SYS_restart_syscall = 128; | ||
| 136 | pub const SYS_kill = 129; | ||
| 137 | pub const SYS_tkill = 130; | ||
| 138 | pub const SYS_tgkill = 131; | ||
| 139 | pub const SYS_sigaltstack = 132; | ||
| 140 | pub const SYS_rt_sigsuspend = 133; | ||
| 141 | pub const SYS_rt_sigaction = 134; | ||
| 142 | pub const SYS_rt_sigprocmask = 135; | ||
| 143 | pub const SYS_rt_sigpending = 136; | ||
| 144 | pub const SYS_rt_sigtimedwait = 137; | ||
| 145 | pub const SYS_rt_sigqueueinfo = 138; | ||
| 146 | pub const SYS_rt_sigreturn = 139; | ||
| 147 | pub const SYS_setpriority = 140; | ||
| 148 | pub const SYS_getpriority = 141; | ||
| 149 | pub const SYS_reboot = 142; | ||
| 150 | pub const SYS_setregid = 143; | ||
| 151 | pub const SYS_setgid = 144; | ||
| 152 | pub const SYS_setreuid = 145; | ||
| 153 | pub const SYS_setuid = 146; | ||
| 154 | pub const SYS_setresuid = 147; | ||
| 155 | pub const SYS_getresuid = 148; | ||
| 156 | pub const SYS_setresgid = 149; | ||
| 157 | pub const SYS_getresgid = 150; | ||
| 158 | pub const SYS_setfsuid = 151; | ||
| 159 | pub const SYS_setfsgid = 152; | ||
| 160 | pub const SYS_times = 153; | ||
| 161 | pub const SYS_setpgid = 154; | ||
| 162 | pub const SYS_getpgid = 155; | ||
| 163 | pub const SYS_getsid = 156; | ||
| 164 | pub const SYS_setsid = 157; | ||
| 165 | pub const SYS_getgroups = 158; | ||
| 166 | pub const SYS_setgroups = 159; | ||
| 167 | pub const SYS_uname = 160; | ||
| 168 | pub const SYS_sethostname = 161; | ||
| 169 | pub const SYS_setdomainname = 162; | ||
| 170 | pub const SYS_getrlimit = 163; | ||
| 171 | pub const SYS_setrlimit = 164; | ||
| 172 | pub const SYS_getrusage = 165; | ||
| 173 | pub const SYS_umask = 166; | ||
| 174 | pub const SYS_prctl = 167; | ||
| 175 | pub const SYS_getcpu = 168; | ||
| 176 | pub const SYS_gettimeofday = 169; | ||
| 177 | pub const SYS_settimeofday = 170; | ||
| 178 | pub const SYS_adjtimex = 171; | ||
| 179 | pub const SYS_getpid = 172; | ||
| 180 | pub const SYS_getppid = 173; | ||
| 181 | pub const SYS_getuid = 174; | ||
| 182 | pub const SYS_geteuid = 175; | ||
| 183 | pub const SYS_getgid = 176; | ||
| 184 | pub const SYS_getegid = 177; | ||
| 185 | pub const SYS_gettid = 178; | ||
| 186 | pub const SYS_sysinfo = 179; | ||
| 187 | pub const SYS_mq_open = 180; | ||
| 188 | pub const SYS_mq_unlink = 181; | ||
| 189 | pub const SYS_mq_timedsend = 182; | ||
| 190 | pub const SYS_mq_timedreceive = 183; | ||
| 191 | pub const SYS_mq_notify = 184; | ||
| 192 | pub const SYS_mq_getsetattr = 185; | ||
| 193 | pub const SYS_msgget = 186; | ||
| 194 | pub const SYS_msgctl = 187; | ||
| 195 | pub const SYS_msgrcv = 188; | ||
| 196 | pub const SYS_msgsnd = 189; | ||
| 197 | pub const SYS_semget = 190; | ||
| 198 | pub const SYS_semctl = 191; | ||
| 199 | pub const SYS_semtimedop = 192; | ||
| 200 | pub const SYS_semop = 193; | ||
| 201 | pub const SYS_shmget = 194; | ||
| 202 | pub const SYS_shmctl = 195; | ||
| 203 | pub const SYS_shmat = 196; | ||
| 204 | pub const SYS_shmdt = 197; | ||
| 205 | pub const SYS_socket = 198; | ||
| 206 | pub const SYS_socketpair = 199; | ||
| 207 | pub const SYS_bind = 200; | ||
| 208 | pub const SYS_listen = 201; | ||
| 209 | pub const SYS_accept = 202; | ||
| 210 | pub const SYS_connect = 203; | ||
| 211 | pub const SYS_getsockname = 204; | ||
| 212 | pub const SYS_getpeername = 205; | ||
| 213 | pub const SYS_sendto = 206; | ||
| 214 | pub const SYS_recvfrom = 207; | ||
| 215 | pub const SYS_setsockopt = 208; | ||
| 216 | pub const SYS_getsockopt = 209; | ||
| 217 | pub const SYS_shutdown = 210; | ||
| 218 | pub const SYS_sendmsg = 211; | ||
| 219 | pub const SYS_recvmsg = 212; | ||
| 220 | pub const SYS_readahead = 213; | ||
| 221 | pub const SYS_brk = 214; | ||
| 222 | pub const SYS_munmap = 215; | ||
| 223 | pub const SYS_mremap = 216; | ||
| 224 | pub const SYS_add_key = 217; | ||
| 225 | pub const SYS_request_key = 218; | ||
| 226 | pub const SYS_keyctl = 219; | ||
| 227 | pub const SYS_clone = 220; | ||
| 228 | pub const SYS_execve = 221; | ||
| 229 | pub const SYS_mmap = 222; | ||
| 230 | pub const SYS_fadvise64 = 223; | ||
| 231 | pub const SYS_swapon = 224; | ||
| 232 | pub const SYS_swapoff = 225; | ||
| 233 | pub const SYS_mprotect = 226; | ||
| 234 | pub const SYS_msync = 227; | ||
| 235 | pub const SYS_mlock = 228; | ||
| 236 | pub const SYS_munlock = 229; | ||
| 237 | pub const SYS_mlockall = 230; | ||
| 238 | pub const SYS_munlockall = 231; | ||
| 239 | pub const SYS_mincore = 232; | ||
| 240 | pub const SYS_madvise = 233; | ||
| 241 | pub const SYS_remap_file_pages = 234; | ||
| 242 | pub const SYS_mbind = 235; | ||
| 243 | pub const SYS_get_mempolicy = 236; | ||
| 244 | pub const SYS_set_mempolicy = 237; | ||
| 245 | pub const SYS_migrate_pages = 238; | ||
| 246 | pub const SYS_move_pages = 239; | ||
| 247 | pub const SYS_rt_tgsigqueueinfo = 240; | ||
| 248 | pub const SYS_perf_event_open = 241; | ||
| 249 | pub const SYS_accept4 = 242; | ||
| 250 | pub const SYS_recvmmsg = 243; | ||
| 251 | pub const SYS_arch_specific_syscall = 244; | ||
| 252 | pub const SYS_wait4 = 260; | ||
| 253 | pub const SYS_prlimit64 = 261; | ||
| 254 | pub const SYS_fanotify_init = 262; | ||
| 255 | pub const SYS_fanotify_mark = 263; | ||
| 256 | pub const SYS_clock_adjtime = 266; | ||
| 257 | pub const SYS_syncfs = 267; | ||
| 258 | pub const SYS_setns = 268; | ||
| 259 | pub const SYS_sendmmsg = 269; | ||
| 260 | pub const SYS_process_vm_readv = 270; | ||
| 261 | pub const SYS_process_vm_writev = 271; | ||
| 262 | pub const SYS_kcmp = 272; | ||
| 263 | pub const SYS_finit_module = 273; | ||
| 264 | pub const SYS_sched_setattr = 274; | ||
| 265 | pub const SYS_sched_getattr = 275; | ||
| 266 | pub const SYS_renameat2 = 276; | ||
| 267 | pub const SYS_seccomp = 277; | ||
| 268 | pub const SYS_getrandom = 278; | ||
| 269 | pub const SYS_memfd_create = 279; | ||
| 270 | pub const SYS_bpf = 280; | ||
| 271 | pub const SYS_execveat = 281; | ||
| 272 | pub const SYS_userfaultfd = 282; | ||
| 273 | pub const SYS_membarrier = 283; | ||
| 274 | pub const SYS_mlock2 = 284; | ||
| 275 | pub const SYS_copy_file_range = 285; | ||
| 276 | pub const SYS_preadv2 = 286; | ||
| 277 | pub const SYS_pwritev2 = 287; | ||
| 278 | pub const SYS_pkey_mprotect = 288; | ||
| 279 | pub const SYS_pkey_alloc = 289; | ||
| 280 | pub const SYS_pkey_free = 290; | ||
| 281 | pub const SYS_statx = 291; | ||
| 282 | pub const SYS_io_pgetevents = 292; | ||
| 283 | pub const SYS_rseq = 293; | ||
| 284 | pub const SYS_kexec_file_load = 294; | ||
| 285 | pub const SYS_pidfd_send_signal = 424; | ||
| 286 | pub const SYS_io_uring_setup = 425; | ||
| 287 | pub const SYS_io_uring_enter = 426; | ||
| 288 | pub const SYS_io_uring_register = 427; | ||
| 289 | |||
| 290 | pub const O_CREAT = 0o100; | ||
| 291 | pub const O_EXCL = 0o200; | ||
| 292 | pub const O_NOCTTY = 0o400; | ||
| 293 | pub const O_TRUNC = 0o1000; | ||
| 294 | pub const O_APPEND = 0o2000; | ||
| 295 | pub const O_NONBLOCK = 0o4000; | ||
| 296 | pub const O_DSYNC = 0o10000; | ||
| 297 | pub const O_SYNC = 0o4010000; | ||
| 298 | pub const O_RSYNC = 0o4010000; | ||
| 299 | pub const O_DIRECTORY = 0o200000; | ||
| 300 | pub const O_NOFOLLOW = 0o400000; | ||
| 301 | pub const O_CLOEXEC = 0o2000000; | ||
| 302 | |||
| 303 | pub const O_ASYNC = 0o20000; | ||
| 304 | pub const O_DIRECT = 0o40000; | ||
| 305 | pub const O_LARGEFILE = 0; | ||
| 306 | pub const O_NOATIME = 0o1000000; | ||
| 307 | pub const O_PATH = 0o10000000; | ||
| 308 | pub const O_TMPFILE = 0o20200000; | ||
| 309 | pub const O_NDELAY = O_NONBLOCK; | ||
| 310 | |||
| 311 | pub const F_DUPFD = 0; | ||
| 312 | pub const F_GETFD = 1; | ||
| 313 | pub const F_SETFD = 2; | ||
| 314 | pub const F_GETFL = 3; | ||
| 315 | pub const F_SETFL = 4; | ||
| 316 | |||
| 317 | pub const F_SETOWN = 8; | ||
| 318 | pub const F_GETOWN = 9; | ||
| 319 | pub const F_SETSIG = 10; | ||
| 320 | pub const F_GETSIG = 11; | ||
| 321 | |||
| 322 | pub const F_GETLK = 5; | ||
| 323 | pub const F_SETLK = 6; | ||
| 324 | pub const F_SETLKW = 7; | ||
| 325 | |||
| 326 | pub const F_SETOWN_EX = 15; | ||
| 327 | pub const F_GETOWN_EX = 16; | ||
| 328 | |||
| 329 | pub const F_GETOWNER_UIDS = 17; | ||
| 330 | |||
| 331 | pub const AT_FDCWD = -100; | ||
| 332 | pub const AT_SYMLINK_NOFOLLOW = 0x100; | ||
| 333 | pub const AT_REMOVEDIR = 0x200; | ||
| 334 | pub const AT_SYMLINK_FOLLOW = 0x400; | ||
| 335 | pub const AT_NO_AUTOMOUNT = 0x800; | ||
| 336 | pub const AT_EMPTY_PATH = 0x1000; | ||
| 337 | |||
| 338 | pub const VDSO_USEFUL = true; | ||
| 339 | pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; | ||
| 340 | pub const VDSO_CGT_VER = "LINUX_2.6.39"; | ||
| 341 | |||
| 342 | pub fn syscall0(number: usize) usize { | 1 | pub fn syscall0(number: usize) usize { |
| 343 | return asm volatile ("svc #0" | 2 | return asm volatile ("svc #0" |
| 344 | : [ret] "={x0}" (-> usize) | 3 | : [ret] "={x0}" (-> usize) |
| ... | @@ -419,65 +78,3 @@ pub fn syscall6( | ... | @@ -419,65 +78,3 @@ pub fn syscall6( |
| 419 | 78 | ||
| 420 | /// This matches the libc clone function. | 79 | /// This matches the libc clone function. |
| 421 | pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize; | 80 | pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize; |
| 422 | |||
| 423 | pub const msghdr = extern struct { | ||
| 424 | msg_name: ?*sockaddr, | ||
| 425 | msg_namelen: socklen_t, | ||
| 426 | msg_iov: [*]iovec, | ||
| 427 | msg_iovlen: i32, | ||
| 428 | __pad1: i32, | ||
| 429 | msg_control: ?*c_void, | ||
| 430 | msg_controllen: socklen_t, | ||
| 431 | __pad2: socklen_t, | ||
| 432 | msg_flags: i32, | ||
| 433 | }; | ||
| 434 | |||
| 435 | pub const msghdr_const = extern struct { | ||
| 436 | msg_name: ?*const sockaddr, | ||
| 437 | msg_namelen: socklen_t, | ||
| 438 | msg_iov: [*]iovec_const, | ||
| 439 | msg_iovlen: i32, | ||
| 440 | __pad1: i32, | ||
| 441 | msg_control: ?*c_void, | ||
| 442 | msg_controllen: socklen_t, | ||
| 443 | __pad2: socklen_t, | ||
| 444 | msg_flags: i32, | ||
| 445 | }; | ||
| 446 | |||
| 447 | /// Renamed to Stat to not conflict with the stat function. | ||
| 448 | pub const Stat = extern struct { | ||
| 449 | dev: u64, | ||
| 450 | ino: u64, | ||
| 451 | nlink: usize, | ||
| 452 | |||
| 453 | mode: u32, | ||
| 454 | uid: u32, | ||
| 455 | gid: u32, | ||
| 456 | __pad0: u32, | ||
| 457 | rdev: u64, | ||
| 458 | size: i64, | ||
| 459 | blksize: isize, | ||
| 460 | blocks: i64, | ||
| 461 | |||
| 462 | atim: timespec, | ||
| 463 | mtim: timespec, | ||
| 464 | ctim: timespec, | ||
| 465 | __unused: [3]isize, | ||
| 466 | }; | ||
| 467 | |||
| 468 | pub const timespec = extern struct { | ||
| 469 | tv_sec: isize, | ||
| 470 | tv_nsec: isize, | ||
| 471 | }; | ||
| 472 | |||
| 473 | pub const timeval = extern struct { | ||
| 474 | tv_sec: isize, | ||
| 475 | tv_usec: isize, | ||
| 476 | }; | ||
| 477 | |||
| 478 | pub const timezone = extern struct { | ||
| 479 | tz_minuteswest: i32, | ||
| 480 | tz_dsttime: i32, | ||
| 481 | }; | ||
| 482 | |||
| 483 | pub const Elf_Symndx = u32; |
std/os/linux/posix.zig created+917| ... | @@ -0,0 +1,917 @@ | ||
| 1 | // Declarations that are intended to be imported into the POSIX namespace. | ||
| 2 | // This includes Linux-only APIs. | ||
| 3 | |||
| 4 | pub use @import("errno.zig"); | ||
| 5 | pub use switch (builtin.arch) { | ||
| 6 | .x86_64 => @import("posix/x86_64.zig"), | ||
| 7 | .aarch64 => @import("posix/arm64.zig"), | ||
| 8 | else => struct {}, | ||
| 9 | }; | ||
| 10 | |||
| 11 | pub const pid_t = i32; | ||
| 12 | pub const fd_t = i32; | ||
| 13 | |||
| 14 | pub const PATH_MAX = 4096; | ||
| 15 | pub const IOV_MAX = 1024; | ||
| 16 | |||
| 17 | pub const STDIN_FILENO = 0; | ||
| 18 | pub const STDOUT_FILENO = 1; | ||
| 19 | pub const STDERR_FILENO = 2; | ||
| 20 | |||
| 21 | pub const FUTEX_WAIT = 0; | ||
| 22 | pub const FUTEX_WAKE = 1; | ||
| 23 | pub const FUTEX_FD = 2; | ||
| 24 | pub const FUTEX_REQUEUE = 3; | ||
| 25 | pub const FUTEX_CMP_REQUEUE = 4; | ||
| 26 | pub const FUTEX_WAKE_OP = 5; | ||
| 27 | pub const FUTEX_LOCK_PI = 6; | ||
| 28 | pub const FUTEX_UNLOCK_PI = 7; | ||
| 29 | pub const FUTEX_TRYLOCK_PI = 8; | ||
| 30 | pub const FUTEX_WAIT_BITSET = 9; | ||
| 31 | |||
| 32 | pub const FUTEX_PRIVATE_FLAG = 128; | ||
| 33 | |||
| 34 | pub const FUTEX_CLOCK_REALTIME = 256; | ||
| 35 | |||
| 36 | pub const PROT_NONE = 0; | ||
| 37 | pub const PROT_READ = 1; | ||
| 38 | pub const PROT_WRITE = 2; | ||
| 39 | pub const PROT_EXEC = 4; | ||
| 40 | pub const PROT_GROWSDOWN = 0x01000000; | ||
| 41 | pub const PROT_GROWSUP = 0x02000000; | ||
| 42 | |||
| 43 | pub const MAP_FAILED = maxInt(usize); | ||
| 44 | pub const MAP_SHARED = 0x01; | ||
| 45 | pub const MAP_PRIVATE = 0x02; | ||
| 46 | pub const MAP_TYPE = 0x0f; | ||
| 47 | pub const MAP_FIXED = 0x10; | ||
| 48 | pub const MAP_ANONYMOUS = 0x20; | ||
| 49 | pub const MAP_NORESERVE = 0x4000; | ||
| 50 | pub const MAP_GROWSDOWN = 0x0100; | ||
| 51 | pub const MAP_DENYWRITE = 0x0800; | ||
| 52 | pub const MAP_EXECUTABLE = 0x1000; | ||
| 53 | pub const MAP_LOCKED = 0x2000; | ||
| 54 | pub const MAP_POPULATE = 0x8000; | ||
| 55 | pub const MAP_NONBLOCK = 0x10000; | ||
| 56 | pub const MAP_STACK = 0x20000; | ||
| 57 | pub const MAP_HUGETLB = 0x40000; | ||
| 58 | pub const MAP_FILE = 0; | ||
| 59 | |||
| 60 | pub const F_OK = 0; | ||
| 61 | pub const X_OK = 1; | ||
| 62 | pub const W_OK = 2; | ||
| 63 | pub const R_OK = 4; | ||
| 64 | |||
| 65 | pub const WNOHANG = 1; | ||
| 66 | pub const WUNTRACED = 2; | ||
| 67 | pub const WSTOPPED = 2; | ||
| 68 | pub const WEXITED = 4; | ||
| 69 | pub const WCONTINUED = 8; | ||
| 70 | pub const WNOWAIT = 0x1000000; | ||
| 71 | |||
| 72 | pub const SA_NOCLDSTOP = 1; | ||
| 73 | pub const SA_NOCLDWAIT = 2; | ||
| 74 | pub const SA_SIGINFO = 4; | ||
| 75 | pub const SA_ONSTACK = 0x08000000; | ||
| 76 | pub const SA_RESTART = 0x10000000; | ||
| 77 | pub const SA_NODEFER = 0x40000000; | ||
| 78 | pub const SA_RESETHAND = 0x80000000; | ||
| 79 | pub const SA_RESTORER = 0x04000000; | ||
| 80 | |||
| 81 | pub const SIGHUP = 1; | ||
| 82 | pub const SIGINT = 2; | ||
| 83 | pub const SIGQUIT = 3; | ||
| 84 | pub const SIGILL = 4; | ||
| 85 | pub const SIGTRAP = 5; | ||
| 86 | pub const SIGABRT = 6; | ||
| 87 | pub const SIGIOT = SIGABRT; | ||
| 88 | pub const SIGBUS = 7; | ||
| 89 | pub const SIGFPE = 8; | ||
| 90 | pub const SIGKILL = 9; | ||
| 91 | pub const SIGUSR1 = 10; | ||
| 92 | pub const SIGSEGV = 11; | ||
| 93 | pub const SIGUSR2 = 12; | ||
| 94 | pub const SIGPIPE = 13; | ||
| 95 | pub const SIGALRM = 14; | ||
| 96 | pub const SIGTERM = 15; | ||
| 97 | pub const SIGSTKFLT = 16; | ||
| 98 | pub const SIGCHLD = 17; | ||
| 99 | pub const SIGCONT = 18; | ||
| 100 | pub const SIGSTOP = 19; | ||
| 101 | pub const SIGTSTP = 20; | ||
| 102 | pub const SIGTTIN = 21; | ||
| 103 | pub const SIGTTOU = 22; | ||
| 104 | pub const SIGURG = 23; | ||
| 105 | pub const SIGXCPU = 24; | ||
| 106 | pub const SIGXFSZ = 25; | ||
| 107 | pub const SIGVTALRM = 26; | ||
| 108 | pub const SIGPROF = 27; | ||
| 109 | pub const SIGWINCH = 28; | ||
| 110 | pub const SIGIO = 29; | ||
| 111 | pub const SIGPOLL = 29; | ||
| 112 | pub const SIGPWR = 30; | ||
| 113 | pub const SIGSYS = 31; | ||
| 114 | pub const SIGUNUSED = SIGSYS; | ||
| 115 | |||
| 116 | pub const O_RDONLY = 0o0; | ||
| 117 | pub const O_WRONLY = 0o1; | ||
| 118 | pub const O_RDWR = 0o2; | ||
| 119 | |||
| 120 | pub const SEEK_SET = 0; | ||
| 121 | pub const SEEK_CUR = 1; | ||
| 122 | pub const SEEK_END = 2; | ||
| 123 | |||
| 124 | pub const SIG_BLOCK = 0; | ||
| 125 | pub const SIG_UNBLOCK = 1; | ||
| 126 | pub const SIG_SETMASK = 2; | ||
| 127 | |||
| 128 | pub const PROTO_ip = 0o000; | ||
| 129 | pub const PROTO_icmp = 0o001; | ||
| 130 | pub const PROTO_igmp = 0o002; | ||
| 131 | pub const PROTO_ggp = 0o003; | ||
| 132 | pub const PROTO_ipencap = 0o004; | ||
| 133 | pub const PROTO_st = 0o005; | ||
| 134 | pub const PROTO_tcp = 0o006; | ||
| 135 | pub const PROTO_egp = 0o010; | ||
| 136 | pub const PROTO_pup = 0o014; | ||
| 137 | pub const PROTO_udp = 0o021; | ||
| 138 | pub const PROTO_hmp = 0o024; | ||
| 139 | pub const PROTO_xns_idp = 0o026; | ||
| 140 | pub const PROTO_rdp = 0o033; | ||
| 141 | pub const PROTO_iso_tp4 = 0o035; | ||
| 142 | pub const PROTO_xtp = 0o044; | ||
| 143 | pub const PROTO_ddp = 0o045; | ||
| 144 | pub const PROTO_idpr_cmtp = 0o046; | ||
| 145 | pub const PROTO_ipv6 = 0o051; | ||
| 146 | pub const PROTO_ipv6_route = 0o053; | ||
| 147 | pub const PROTO_ipv6_frag = 0o054; | ||
| 148 | pub const PROTO_idrp = 0o055; | ||
| 149 | pub const PROTO_rsvp = 0o056; | ||
| 150 | pub const PROTO_gre = 0o057; | ||
| 151 | pub const PROTO_esp = 0o062; | ||
| 152 | pub const PROTO_ah = 0o063; | ||
| 153 | pub const PROTO_skip = 0o071; | ||
| 154 | pub const PROTO_ipv6_icmp = 0o072; | ||
| 155 | pub const PROTO_ipv6_nonxt = 0o073; | ||
| 156 | pub const PROTO_ipv6_opts = 0o074; | ||
| 157 | pub const PROTO_rspf = 0o111; | ||
| 158 | pub const PROTO_vmtp = 0o121; | ||
| 159 | pub const PROTO_ospf = 0o131; | ||
| 160 | pub const PROTO_ipip = 0o136; | ||
| 161 | pub const PROTO_encap = 0o142; | ||
| 162 | pub const PROTO_pim = 0o147; | ||
| 163 | pub const PROTO_raw = 0o377; | ||
| 164 | |||
| 165 | pub const SHUT_RD = 0; | ||
| 166 | pub const SHUT_WR = 1; | ||
| 167 | pub const SHUT_RDWR = 2; | ||
| 168 | |||
| 169 | pub const SOCK_STREAM = 1; | ||
| 170 | pub const SOCK_DGRAM = 2; | ||
| 171 | pub const SOCK_RAW = 3; | ||
| 172 | pub const SOCK_RDM = 4; | ||
| 173 | pub const SOCK_SEQPACKET = 5; | ||
| 174 | pub const SOCK_DCCP = 6; | ||
| 175 | pub const SOCK_PACKET = 10; | ||
| 176 | pub const SOCK_CLOEXEC = 0o2000000; | ||
| 177 | pub const SOCK_NONBLOCK = 0o4000; | ||
| 178 | |||
| 179 | pub const PF_UNSPEC = 0; | ||
| 180 | pub const PF_LOCAL = 1; | ||
| 181 | pub const PF_UNIX = PF_LOCAL; | ||
| 182 | pub const PF_FILE = PF_LOCAL; | ||
| 183 | pub const PF_INET = 2; | ||
| 184 | pub const PF_AX25 = 3; | ||
| 185 | pub const PF_IPX = 4; | ||
| 186 | pub const PF_APPLETALK = 5; | ||
| 187 | pub const PF_NETROM = 6; | ||
| 188 | pub const PF_BRIDGE = 7; | ||
| 189 | pub const PF_ATMPVC = 8; | ||
| 190 | pub const PF_X25 = 9; | ||
| 191 | pub const PF_INET6 = 10; | ||
| 192 | pub const PF_ROSE = 11; | ||
| 193 | pub const PF_DECnet = 12; | ||
| 194 | pub const PF_NETBEUI = 13; | ||
| 195 | pub const PF_SECURITY = 14; | ||
| 196 | pub const PF_KEY = 15; | ||
| 197 | pub const PF_NETLINK = 16; | ||
| 198 | pub const PF_ROUTE = PF_NETLINK; | ||
| 199 | pub const PF_PACKET = 17; | ||
| 200 | pub const PF_ASH = 18; | ||
| 201 | pub const PF_ECONET = 19; | ||
| 202 | pub const PF_ATMSVC = 20; | ||
| 203 | pub const PF_RDS = 21; | ||
| 204 | pub const PF_SNA = 22; | ||
| 205 | pub const PF_IRDA = 23; | ||
| 206 | pub const PF_PPPOX = 24; | ||
| 207 | pub const PF_WANPIPE = 25; | ||
| 208 | pub const PF_LLC = 26; | ||
| 209 | pub const PF_IB = 27; | ||
| 210 | pub const PF_MPLS = 28; | ||
| 211 | pub const PF_CAN = 29; | ||
| 212 | pub const PF_TIPC = 30; | ||
| 213 | pub const PF_BLUETOOTH = 31; | ||
| 214 | pub const PF_IUCV = 32; | ||
| 215 | pub const PF_RXRPC = 33; | ||
| 216 | pub const PF_ISDN = 34; | ||
| 217 | pub const PF_PHONET = 35; | ||
| 218 | pub const PF_IEEE802154 = 36; | ||
| 219 | pub const PF_CAIF = 37; | ||
| 220 | pub const PF_ALG = 38; | ||
| 221 | pub const PF_NFC = 39; | ||
| 222 | pub const PF_VSOCK = 40; | ||
| 223 | pub const PF_KCM = 41; | ||
| 224 | pub const PF_QIPCRTR = 42; | ||
| 225 | pub const PF_SMC = 43; | ||
| 226 | pub const PF_MAX = 44; | ||
| 227 | |||
| 228 | pub const AF_UNSPEC = PF_UNSPEC; | ||
| 229 | pub const AF_LOCAL = PF_LOCAL; | ||
| 230 | pub const AF_UNIX = AF_LOCAL; | ||
| 231 | pub const AF_FILE = AF_LOCAL; | ||
| 232 | pub const AF_INET = PF_INET; | ||
| 233 | pub const AF_AX25 = PF_AX25; | ||
| 234 | pub const AF_IPX = PF_IPX; | ||
| 235 | pub const AF_APPLETALK = PF_APPLETALK; | ||
| 236 | pub const AF_NETROM = PF_NETROM; | ||
| 237 | pub const AF_BRIDGE = PF_BRIDGE; | ||
| 238 | pub const AF_ATMPVC = PF_ATMPVC; | ||
| 239 | pub const AF_X25 = PF_X25; | ||
| 240 | pub const AF_INET6 = PF_INET6; | ||
| 241 | pub const AF_ROSE = PF_ROSE; | ||
| 242 | pub const AF_DECnet = PF_DECnet; | ||
| 243 | pub const AF_NETBEUI = PF_NETBEUI; | ||
| 244 | pub const AF_SECURITY = PF_SECURITY; | ||
| 245 | pub const AF_KEY = PF_KEY; | ||
| 246 | pub const AF_NETLINK = PF_NETLINK; | ||
| 247 | pub const AF_ROUTE = PF_ROUTE; | ||
| 248 | pub const AF_PACKET = PF_PACKET; | ||
| 249 | pub const AF_ASH = PF_ASH; | ||
| 250 | pub const AF_ECONET = PF_ECONET; | ||
| 251 | pub const AF_ATMSVC = PF_ATMSVC; | ||
| 252 | pub const AF_RDS = PF_RDS; | ||
| 253 | pub const AF_SNA = PF_SNA; | ||
| 254 | pub const AF_IRDA = PF_IRDA; | ||
| 255 | pub const AF_PPPOX = PF_PPPOX; | ||
| 256 | pub const AF_WANPIPE = PF_WANPIPE; | ||
| 257 | pub const AF_LLC = PF_LLC; | ||
| 258 | pub const AF_IB = PF_IB; | ||
| 259 | pub const AF_MPLS = PF_MPLS; | ||
| 260 | pub const AF_CAN = PF_CAN; | ||
| 261 | pub const AF_TIPC = PF_TIPC; | ||
| 262 | pub const AF_BLUETOOTH = PF_BLUETOOTH; | ||
| 263 | pub const AF_IUCV = PF_IUCV; | ||
| 264 | pub const AF_RXRPC = PF_RXRPC; | ||
| 265 | pub const AF_ISDN = PF_ISDN; | ||
| 266 | pub const AF_PHONET = PF_PHONET; | ||
| 267 | pub const AF_IEEE802154 = PF_IEEE802154; | ||
| 268 | pub const AF_CAIF = PF_CAIF; | ||
| 269 | pub const AF_ALG = PF_ALG; | ||
| 270 | pub const AF_NFC = PF_NFC; | ||
| 271 | pub const AF_VSOCK = PF_VSOCK; | ||
| 272 | pub const AF_KCM = PF_KCM; | ||
| 273 | pub const AF_QIPCRTR = PF_QIPCRTR; | ||
| 274 | pub const AF_SMC = PF_SMC; | ||
| 275 | pub const AF_MAX = PF_MAX; | ||
| 276 | |||
| 277 | pub const SO_DEBUG = 1; | ||
| 278 | pub const SO_REUSEADDR = 2; | ||
| 279 | pub const SO_TYPE = 3; | ||
| 280 | pub const SO_ERROR = 4; | ||
| 281 | pub const SO_DONTROUTE = 5; | ||
| 282 | pub const SO_BROADCAST = 6; | ||
| 283 | pub const SO_SNDBUF = 7; | ||
| 284 | pub const SO_RCVBUF = 8; | ||
| 285 | pub const SO_KEEPALIVE = 9; | ||
| 286 | pub const SO_OOBINLINE = 10; | ||
| 287 | pub const SO_NO_CHECK = 11; | ||
| 288 | pub const SO_PRIORITY = 12; | ||
| 289 | pub const SO_LINGER = 13; | ||
| 290 | pub const SO_BSDCOMPAT = 14; | ||
| 291 | pub const SO_REUSEPORT = 15; | ||
| 292 | pub const SO_PASSCRED = 16; | ||
| 293 | pub const SO_PEERCRED = 17; | ||
| 294 | pub const SO_RCVLOWAT = 18; | ||
| 295 | pub const SO_SNDLOWAT = 19; | ||
| 296 | pub const SO_RCVTIMEO = 20; | ||
| 297 | pub const SO_SNDTIMEO = 21; | ||
| 298 | pub const SO_ACCEPTCONN = 30; | ||
| 299 | pub const SO_SNDBUFFORCE = 32; | ||
| 300 | pub const SO_RCVBUFFORCE = 33; | ||
| 301 | pub const SO_PROTOCOL = 38; | ||
| 302 | pub const SO_DOMAIN = 39; | ||
| 303 | |||
| 304 | pub const SO_SECURITY_AUTHENTICATION = 22; | ||
| 305 | pub const SO_SECURITY_ENCRYPTION_TRANSPORT = 23; | ||
| 306 | pub const SO_SECURITY_ENCRYPTION_NETWORK = 24; | ||
| 307 | |||
| 308 | pub const SO_BINDTODEVICE = 25; | ||
| 309 | |||
| 310 | pub const SO_ATTACH_FILTER = 26; | ||
| 311 | pub const SO_DETACH_FILTER = 27; | ||
| 312 | pub const SO_GET_FILTER = SO_ATTACH_FILTER; | ||
| 313 | |||
| 314 | pub const SO_PEERNAME = 28; | ||
| 315 | pub const SO_TIMESTAMP = 29; | ||
| 316 | pub const SCM_TIMESTAMP = SO_TIMESTAMP; | ||
| 317 | |||
| 318 | pub const SO_PEERSEC = 31; | ||
| 319 | pub const SO_PASSSEC = 34; | ||
| 320 | pub const SO_TIMESTAMPNS = 35; | ||
| 321 | pub const SCM_TIMESTAMPNS = SO_TIMESTAMPNS; | ||
| 322 | pub const SO_MARK = 36; | ||
| 323 | pub const SO_TIMESTAMPING = 37; | ||
| 324 | pub const SCM_TIMESTAMPING = SO_TIMESTAMPING; | ||
| 325 | pub const SO_RXQ_OVFL = 40; | ||
| 326 | pub const SO_WIFI_STATUS = 41; | ||
| 327 | pub const SCM_WIFI_STATUS = SO_WIFI_STATUS; | ||
| 328 | pub const SO_PEEK_OFF = 42; | ||
| 329 | pub const SO_NOFCS = 43; | ||
| 330 | pub const SO_LOCK_FILTER = 44; | ||
| 331 | pub const SO_SELECT_ERR_QUEUE = 45; | ||
| 332 | pub const SO_BUSY_POLL = 46; | ||
| 333 | pub const SO_MAX_PACING_RATE = 47; | ||
| 334 | pub const SO_BPF_EXTENSIONS = 48; | ||
| 335 | pub const SO_INCOMING_CPU = 49; | ||
| 336 | pub const SO_ATTACH_BPF = 50; | ||
| 337 | pub const SO_DETACH_BPF = SO_DETACH_FILTER; | ||
| 338 | pub const SO_ATTACH_REUSEPORT_CBPF = 51; | ||
| 339 | pub const SO_ATTACH_REUSEPORT_EBPF = 52; | ||
| 340 | pub const SO_CNX_ADVICE = 53; | ||
| 341 | pub const SCM_TIMESTAMPING_OPT_STATS = 54; | ||
| 342 | pub const SO_MEMINFO = 55; | ||
| 343 | pub const SO_INCOMING_NAPI_ID = 56; | ||
| 344 | pub const SO_COOKIE = 57; | ||
| 345 | pub const SCM_TIMESTAMPING_PKTINFO = 58; | ||
| 346 | pub const SO_PEERGROUPS = 59; | ||
| 347 | pub const SO_ZEROCOPY = 60; | ||
| 348 | |||
| 349 | pub const SOL_SOCKET = 1; | ||
| 350 | |||
| 351 | pub const SOL_IP = 0; | ||
| 352 | pub const SOL_IPV6 = 41; | ||
| 353 | pub const SOL_ICMPV6 = 58; | ||
| 354 | |||
| 355 | pub const SOL_RAW = 255; | ||
| 356 | pub const SOL_DECNET = 261; | ||
| 357 | pub const SOL_X25 = 262; | ||
| 358 | pub const SOL_PACKET = 263; | ||
| 359 | pub const SOL_ATM = 264; | ||
| 360 | pub const SOL_AAL = 265; | ||
| 361 | pub const SOL_IRDA = 266; | ||
| 362 | pub const SOL_NETBEUI = 267; | ||
| 363 | pub const SOL_LLC = 268; | ||
| 364 | pub const SOL_DCCP = 269; | ||
| 365 | pub const SOL_NETLINK = 270; | ||
| 366 | pub const SOL_TIPC = 271; | ||
| 367 | pub const SOL_RXRPC = 272; | ||
| 368 | pub const SOL_PPPOL2TP = 273; | ||
| 369 | pub const SOL_BLUETOOTH = 274; | ||
| 370 | pub const SOL_PNPIPE = 275; | ||
| 371 | pub const SOL_RDS = 276; | ||
| 372 | pub const SOL_IUCV = 277; | ||
| 373 | pub const SOL_CAIF = 278; | ||
| 374 | pub const SOL_ALG = 279; | ||
| 375 | pub const SOL_NFC = 280; | ||
| 376 | pub const SOL_KCM = 281; | ||
| 377 | pub const SOL_TLS = 282; | ||
| 378 | |||
| 379 | pub const SOMAXCONN = 128; | ||
| 380 | |||
| 381 | pub const MSG_OOB = 0x0001; | ||
| 382 | pub const MSG_PEEK = 0x0002; | ||
| 383 | pub const MSG_DONTROUTE = 0x0004; | ||
| 384 | pub const MSG_CTRUNC = 0x0008; | ||
| 385 | pub const MSG_PROXY = 0x0010; | ||
| 386 | pub const MSG_TRUNC = 0x0020; | ||
| 387 | pub const MSG_DONTWAIT = 0x0040; | ||
| 388 | pub const MSG_EOR = 0x0080; | ||
| 389 | pub const MSG_WAITALL = 0x0100; | ||
| 390 | pub const MSG_FIN = 0x0200; | ||
| 391 | pub const MSG_SYN = 0x0400; | ||
| 392 | pub const MSG_CONFIRM = 0x0800; | ||
| 393 | pub const MSG_RST = 0x1000; | ||
| 394 | pub const MSG_ERRQUEUE = 0x2000; | ||
| 395 | pub const MSG_NOSIGNAL = 0x4000; | ||
| 396 | pub const MSG_MORE = 0x8000; | ||
| 397 | pub const MSG_WAITFORONE = 0x10000; | ||
| 398 | pub const MSG_BATCH = 0x40000; | ||
| 399 | pub const MSG_ZEROCOPY = 0x4000000; | ||
| 400 | pub const MSG_FASTOPEN = 0x20000000; | ||
| 401 | pub const MSG_CMSG_CLOEXEC = 0x40000000; | ||
| 402 | |||
| 403 | pub const DT_UNKNOWN = 0; | ||
| 404 | pub const DT_FIFO = 1; | ||
| 405 | pub const DT_CHR = 2; | ||
| 406 | pub const DT_DIR = 4; | ||
| 407 | pub const DT_BLK = 6; | ||
| 408 | pub const DT_REG = 8; | ||
| 409 | pub const DT_LNK = 10; | ||
| 410 | pub const DT_SOCK = 12; | ||
| 411 | pub const DT_WHT = 14; | ||
| 412 | |||
| 413 | pub const TCGETS = 0x5401; | ||
| 414 | pub const TCSETS = 0x5402; | ||
| 415 | pub const TCSETSW = 0x5403; | ||
| 416 | pub const TCSETSF = 0x5404; | ||
| 417 | pub const TCGETA = 0x5405; | ||
| 418 | pub const TCSETA = 0x5406; | ||
| 419 | pub const TCSETAW = 0x5407; | ||
| 420 | pub const TCSETAF = 0x5408; | ||
| 421 | pub const TCSBRK = 0x5409; | ||
| 422 | pub const TCXONC = 0x540A; | ||
| 423 | pub const TCFLSH = 0x540B; | ||
| 424 | pub const TIOCEXCL = 0x540C; | ||
| 425 | pub const TIOCNXCL = 0x540D; | ||
| 426 | pub const TIOCSCTTY = 0x540E; | ||
| 427 | pub const TIOCGPGRP = 0x540F; | ||
| 428 | pub const TIOCSPGRP = 0x5410; | ||
| 429 | pub const TIOCOUTQ = 0x5411; | ||
| 430 | pub const TIOCSTI = 0x5412; | ||
| 431 | pub const TIOCGWINSZ = 0x5413; | ||
| 432 | pub const TIOCSWINSZ = 0x5414; | ||
| 433 | pub const TIOCMGET = 0x5415; | ||
| 434 | pub const TIOCMBIS = 0x5416; | ||
| 435 | pub const TIOCMBIC = 0x5417; | ||
| 436 | pub const TIOCMSET = 0x5418; | ||
| 437 | pub const TIOCGSOFTCAR = 0x5419; | ||
| 438 | pub const TIOCSSOFTCAR = 0x541A; | ||
| 439 | pub const FIONREAD = 0x541B; | ||
| 440 | pub const TIOCINQ = FIONREAD; | ||
| 441 | pub const TIOCLINUX = 0x541C; | ||
| 442 | pub const TIOCCONS = 0x541D; | ||
| 443 | pub const TIOCGSERIAL = 0x541E; | ||
| 444 | pub const TIOCSSERIAL = 0x541F; | ||
| 445 | pub const TIOCPKT = 0x5420; | ||
| 446 | pub const FIONBIO = 0x5421; | ||
| 447 | pub const TIOCNOTTY = 0x5422; | ||
| 448 | pub const TIOCSETD = 0x5423; | ||
| 449 | pub const TIOCGETD = 0x5424; | ||
| 450 | pub const TCSBRKP = 0x5425; | ||
| 451 | pub const TIOCSBRK = 0x5427; | ||
| 452 | pub const TIOCCBRK = 0x5428; | ||
| 453 | pub const TIOCGSID = 0x5429; | ||
| 454 | pub const TIOCGRS485 = 0x542E; | ||
| 455 | pub const TIOCSRS485 = 0x542F; | ||
| 456 | pub const TIOCGPTN = 0x80045430; | ||
| 457 | pub const TIOCSPTLCK = 0x40045431; | ||
| 458 | pub const TIOCGDEV = 0x80045432; | ||
| 459 | pub const TCGETX = 0x5432; | ||
| 460 | pub const TCSETX = 0x5433; | ||
| 461 | pub const TCSETXF = 0x5434; | ||
| 462 | pub const TCSETXW = 0x5435; | ||
| 463 | pub const TIOCSIG = 0x40045436; | ||
| 464 | pub const TIOCVHANGUP = 0x5437; | ||
| 465 | pub const TIOCGPKT = 0x80045438; | ||
| 466 | pub const TIOCGPTLCK = 0x80045439; | ||
| 467 | pub const TIOCGEXCL = 0x80045440; | ||
| 468 | |||
| 469 | pub const EPOLL_CLOEXEC = O_CLOEXEC; | ||
| 470 | |||
| 471 | pub const EPOLL_CTL_ADD = 1; | ||
| 472 | pub const EPOLL_CTL_DEL = 2; | ||
| 473 | pub const EPOLL_CTL_MOD = 3; | ||
| 474 | |||
| 475 | pub const EPOLLIN = 0x001; | ||
| 476 | pub const EPOLLPRI = 0x002; | ||
| 477 | pub const EPOLLOUT = 0x004; | ||
| 478 | pub const EPOLLRDNORM = 0x040; | ||
| 479 | pub const EPOLLRDBAND = 0x080; | ||
| 480 | pub const EPOLLWRNORM = 0x100; | ||
| 481 | pub const EPOLLWRBAND = 0x200; | ||
| 482 | pub const EPOLLMSG = 0x400; | ||
| 483 | pub const EPOLLERR = 0x008; | ||
| 484 | pub const EPOLLHUP = 0x010; | ||
| 485 | pub const EPOLLRDHUP = 0x2000; | ||
| 486 | pub const EPOLLEXCLUSIVE = (u32(1) << 28); | ||
| 487 | pub const EPOLLWAKEUP = (u32(1) << 29); | ||
| 488 | pub const EPOLLONESHOT = (u32(1) << 30); | ||
| 489 | pub const EPOLLET = (u32(1) << 31); | ||
| 490 | |||
| 491 | pub const CLOCK_REALTIME = 0; | ||
| 492 | pub const CLOCK_MONOTONIC = 1; | ||
| 493 | pub const CLOCK_PROCESS_CPUTIME_ID = 2; | ||
| 494 | pub const CLOCK_THREAD_CPUTIME_ID = 3; | ||
| 495 | pub const CLOCK_MONOTONIC_RAW = 4; | ||
| 496 | pub const CLOCK_REALTIME_COARSE = 5; | ||
| 497 | pub const CLOCK_MONOTONIC_COARSE = 6; | ||
| 498 | pub const CLOCK_BOOTTIME = 7; | ||
| 499 | pub const CLOCK_REALTIME_ALARM = 8; | ||
| 500 | pub const CLOCK_BOOTTIME_ALARM = 9; | ||
| 501 | pub const CLOCK_SGI_CYCLE = 10; | ||
| 502 | pub const CLOCK_TAI = 11; | ||
| 503 | |||
| 504 | pub const CSIGNAL = 0x000000ff; | ||
| 505 | pub const CLONE_VM = 0x00000100; | ||
| 506 | pub const CLONE_FS = 0x00000200; | ||
| 507 | pub const CLONE_FILES = 0x00000400; | ||
| 508 | pub const CLONE_SIGHAND = 0x00000800; | ||
| 509 | pub const CLONE_PTRACE = 0x00002000; | ||
| 510 | pub const CLONE_VFORK = 0x00004000; | ||
| 511 | pub const CLONE_PARENT = 0x00008000; | ||
| 512 | pub const CLONE_THREAD = 0x00010000; | ||
| 513 | pub const CLONE_NEWNS = 0x00020000; | ||
| 514 | pub const CLONE_SYSVSEM = 0x00040000; | ||
| 515 | pub const CLONE_SETTLS = 0x00080000; | ||
| 516 | pub const CLONE_PARENT_SETTID = 0x00100000; | ||
| 517 | pub const CLONE_CHILD_CLEARTID = 0x00200000; | ||
| 518 | pub const CLONE_DETACHED = 0x00400000; | ||
| 519 | pub const CLONE_UNTRACED = 0x00800000; | ||
| 520 | pub const CLONE_CHILD_SETTID = 0x01000000; | ||
| 521 | pub const CLONE_NEWCGROUP = 0x02000000; | ||
| 522 | pub const CLONE_NEWUTS = 0x04000000; | ||
| 523 | pub const CLONE_NEWIPC = 0x08000000; | ||
| 524 | pub const CLONE_NEWUSER = 0x10000000; | ||
| 525 | pub const CLONE_NEWPID = 0x20000000; | ||
| 526 | pub const CLONE_NEWNET = 0x40000000; | ||
| 527 | pub const CLONE_IO = 0x80000000; | ||
| 528 | |||
| 529 | pub const EFD_SEMAPHORE = 1; | ||
| 530 | pub const EFD_CLOEXEC = O_CLOEXEC; | ||
| 531 | pub const EFD_NONBLOCK = O_NONBLOCK; | ||
| 532 | |||
| 533 | pub const MS_RDONLY = 1; | ||
| 534 | pub const MS_NOSUID = 2; | ||
| 535 | pub const MS_NODEV = 4; | ||
| 536 | pub const MS_NOEXEC = 8; | ||
| 537 | pub const MS_SYNCHRONOUS = 16; | ||
| 538 | pub const MS_REMOUNT = 32; | ||
| 539 | pub const MS_MANDLOCK = 64; | ||
| 540 | pub const MS_DIRSYNC = 128; | ||
| 541 | pub const MS_NOATIME = 1024; | ||
| 542 | pub const MS_NODIRATIME = 2048; | ||
| 543 | pub const MS_BIND = 4096; | ||
| 544 | pub const MS_MOVE = 8192; | ||
| 545 | pub const MS_REC = 16384; | ||
| 546 | pub const MS_SILENT = 32768; | ||
| 547 | pub const MS_POSIXACL = (1 << 16); | ||
| 548 | pub const MS_UNBINDABLE = (1 << 17); | ||
| 549 | pub const MS_PRIVATE = (1 << 18); | ||
| 550 | pub const MS_SLAVE = (1 << 19); | ||
| 551 | pub const MS_SHARED = (1 << 20); | ||
| 552 | pub const MS_RELATIME = (1 << 21); | ||
| 553 | pub const MS_KERNMOUNT = (1 << 22); | ||
| 554 | pub const MS_I_VERSION = (1 << 23); | ||
| 555 | pub const MS_STRICTATIME = (1 << 24); | ||
| 556 | pub const MS_LAZYTIME = (1 << 25); | ||
| 557 | pub const MS_NOREMOTELOCK = (1 << 27); | ||
| 558 | pub const MS_NOSEC = (1 << 28); | ||
| 559 | pub const MS_BORN = (1 << 29); | ||
| 560 | pub const MS_ACTIVE = (1 << 30); | ||
| 561 | pub const MS_NOUSER = (1 << 31); | ||
| 562 | |||
| 563 | pub const MS_RMT_MASK = (MS_RDONLY | MS_SYNCHRONOUS | MS_MANDLOCK | MS_I_VERSION | MS_LAZYTIME); | ||
| 564 | |||
| 565 | pub const MS_MGC_VAL = 0xc0ed0000; | ||
| 566 | pub const MS_MGC_MSK = 0xffff0000; | ||
| 567 | |||
| 568 | pub const MNT_FORCE = 1; | ||
| 569 | pub const MNT_DETACH = 2; | ||
| 570 | pub const MNT_EXPIRE = 4; | ||
| 571 | pub const UMOUNT_NOFOLLOW = 8; | ||
| 572 | |||
| 573 | pub const IN_CLOEXEC = O_CLOEXEC; | ||
| 574 | pub const IN_NONBLOCK = O_NONBLOCK; | ||
| 575 | |||
| 576 | pub const IN_ACCESS = 0x00000001; | ||
| 577 | pub const IN_MODIFY = 0x00000002; | ||
| 578 | pub const IN_ATTRIB = 0x00000004; | ||
| 579 | pub const IN_CLOSE_WRITE = 0x00000008; | ||
| 580 | pub const IN_CLOSE_NOWRITE = 0x00000010; | ||
| 581 | pub const IN_CLOSE = IN_CLOSE_WRITE | IN_CLOSE_NOWRITE; | ||
| 582 | pub const IN_OPEN = 0x00000020; | ||
| 583 | pub const IN_MOVED_FROM = 0x00000040; | ||
| 584 | pub const IN_MOVED_TO = 0x00000080; | ||
| 585 | pub const IN_MOVE = IN_MOVED_FROM | IN_MOVED_TO; | ||
| 586 | pub const IN_CREATE = 0x00000100; | ||
| 587 | pub const IN_DELETE = 0x00000200; | ||
| 588 | pub const IN_DELETE_SELF = 0x00000400; | ||
| 589 | pub const IN_MOVE_SELF = 0x00000800; | ||
| 590 | pub const IN_ALL_EVENTS = 0x00000fff; | ||
| 591 | |||
| 592 | pub const IN_UNMOUNT = 0x00002000; | ||
| 593 | pub const IN_Q_OVERFLOW = 0x00004000; | ||
| 594 | pub const IN_IGNORED = 0x00008000; | ||
| 595 | |||
| 596 | pub const IN_ONLYDIR = 0x01000000; | ||
| 597 | pub const IN_DONT_FOLLOW = 0x02000000; | ||
| 598 | pub const IN_EXCL_UNLINK = 0x04000000; | ||
| 599 | pub const IN_MASK_ADD = 0x20000000; | ||
| 600 | |||
| 601 | pub const IN_ISDIR = 0x40000000; | ||
| 602 | pub const IN_ONESHOT = 0x80000000; | ||
| 603 | |||
| 604 | pub const S_IFMT = 0o170000; | ||
| 605 | |||
| 606 | pub const S_IFDIR = 0o040000; | ||
| 607 | pub const S_IFCHR = 0o020000; | ||
| 608 | pub const S_IFBLK = 0o060000; | ||
| 609 | pub const S_IFREG = 0o100000; | ||
| 610 | pub const S_IFIFO = 0o010000; | ||
| 611 | pub const S_IFLNK = 0o120000; | ||
| 612 | pub const S_IFSOCK = 0o140000; | ||
| 613 | |||
| 614 | pub const S_ISUID = 0o4000; | ||
| 615 | pub const S_ISGID = 0o2000; | ||
| 616 | pub const S_ISVTX = 0o1000; | ||
| 617 | pub const S_IRUSR = 0o400; | ||
| 618 | pub const S_IWUSR = 0o200; | ||
| 619 | pub const S_IXUSR = 0o100; | ||
| 620 | pub const S_IRWXU = 0o700; | ||
| 621 | pub const S_IRGRP = 0o040; | ||
| 622 | pub const S_IWGRP = 0o020; | ||
| 623 | pub const S_IXGRP = 0o010; | ||
| 624 | pub const S_IRWXG = 0o070; | ||
| 625 | pub const S_IROTH = 0o004; | ||
| 626 | pub const S_IWOTH = 0o002; | ||
| 627 | pub const S_IXOTH = 0o001; | ||
| 628 | pub const S_IRWXO = 0o007; | ||
| 629 | |||
| 630 | pub fn S_ISREG(m: u32) bool { | ||
| 631 | return m & S_IFMT == S_IFREG; | ||
| 632 | } | ||
| 633 | |||
| 634 | pub fn S_ISDIR(m: u32) bool { | ||
| 635 | return m & S_IFMT == S_IFDIR; | ||
| 636 | } | ||
| 637 | |||
| 638 | pub fn S_ISCHR(m: u32) bool { | ||
| 639 | return m & S_IFMT == S_IFCHR; | ||
| 640 | } | ||
| 641 | |||
| 642 | pub fn S_ISBLK(m: u32) bool { | ||
| 643 | return m & S_IFMT == S_IFBLK; | ||
| 644 | } | ||
| 645 | |||
| 646 | pub fn S_ISFIFO(m: u32) bool { | ||
| 647 | return m & S_IFMT == S_IFIFO; | ||
| 648 | } | ||
| 649 | |||
| 650 | pub fn S_ISLNK(m: u32) bool { | ||
| 651 | return m & S_IFMT == S_IFLNK; | ||
| 652 | } | ||
| 653 | |||
| 654 | pub fn S_ISSOCK(m: u32) bool { | ||
| 655 | return m & S_IFMT == S_IFSOCK; | ||
| 656 | } | ||
| 657 | |||
| 658 | pub const TFD_NONBLOCK = O_NONBLOCK; | ||
| 659 | pub const TFD_CLOEXEC = O_CLOEXEC; | ||
| 660 | |||
| 661 | pub const TFD_TIMER_ABSTIME = 1; | ||
| 662 | pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1); | ||
| 663 | |||
| 664 | fn unsigned(s: i32) u32 { | ||
| 665 | return @bitCast(u32, s); | ||
| 666 | } | ||
| 667 | fn signed(s: u32) i32 { | ||
| 668 | return @bitCast(i32, s); | ||
| 669 | } | ||
| 670 | pub fn WEXITSTATUS(s: i32) i32 { | ||
| 671 | return signed((unsigned(s) & 0xff00) >> 8); | ||
| 672 | } | ||
| 673 | pub fn WTERMSIG(s: i32) i32 { | ||
| 674 | return signed(unsigned(s) & 0x7f); | ||
| 675 | } | ||
| 676 | pub fn WSTOPSIG(s: i32) i32 { | ||
| 677 | return WEXITSTATUS(s); | ||
| 678 | } | ||
| 679 | pub fn WIFEXITED(s: i32) bool { | ||
| 680 | return WTERMSIG(s) == 0; | ||
| 681 | } | ||
| 682 | pub fn WIFSTOPPED(s: i32) bool { | ||
| 683 | return @intCast(u16, ((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00; | ||
| 684 | } | ||
| 685 | pub fn WIFSIGNALED(s: i32) bool { | ||
| 686 | return (unsigned(s) & 0xffff) -% 1 < 0xff; | ||
| 687 | } | ||
| 688 | |||
| 689 | pub const winsize = extern struct { | ||
| 690 | ws_row: u16, | ||
| 691 | ws_col: u16, | ||
| 692 | ws_xpixel: u16, | ||
| 693 | ws_ypixel: u16, | ||
| 694 | }; | ||
| 695 | |||
| 696 | const NSIG = 65; | ||
| 697 | const sigset_t = [128 / @sizeOf(usize)]usize; | ||
| 698 | const all_mask = []u32{ 0xffffffff, 0xffffffff }; | ||
| 699 | const app_mask = []u32{ 0xfffffffc, 0x7fffffff }; | ||
| 700 | |||
| 701 | const k_sigaction = extern struct { | ||
| 702 | handler: extern fn (i32) void, | ||
| 703 | flags: usize, | ||
| 704 | restorer: extern fn () void, | ||
| 705 | mask: [2]u32, | ||
| 706 | }; | ||
| 707 | |||
| 708 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | ||
| 709 | pub const Sigaction = struct { | ||
| 710 | handler: extern fn (i32) void, | ||
| 711 | mask: sigset_t, | ||
| 712 | flags: u32, | ||
| 713 | }; | ||
| 714 | |||
| 715 | pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize)); | ||
| 716 | pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); | ||
| 717 | pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); | ||
| 718 | pub const empty_sigset = []usize{0} ** sigset_t.len; | ||
| 719 | |||
| 720 | pub const in_port_t = u16; | ||
| 721 | pub const sa_family_t = u16; | ||
| 722 | pub const socklen_t = u32; | ||
| 723 | |||
| 724 | /// This intentionally only has ip4 and ip6 | ||
| 725 | pub const sockaddr = extern union { | ||
| 726 | in: sockaddr_in, | ||
| 727 | in6: sockaddr_in6, | ||
| 728 | }; | ||
| 729 | |||
| 730 | pub const sockaddr_in = extern struct { | ||
| 731 | family: sa_family_t, | ||
| 732 | port: in_port_t, | ||
| 733 | addr: u32, | ||
| 734 | zero: [8]u8, | ||
| 735 | }; | ||
| 736 | |||
| 737 | pub const sockaddr_in6 = extern struct { | ||
| 738 | family: sa_family_t, | ||
| 739 | port: in_port_t, | ||
| 740 | flowinfo: u32, | ||
| 741 | addr: [16]u8, | ||
| 742 | scope_id: u32, | ||
| 743 | }; | ||
| 744 | |||
| 745 | pub const sockaddr_un = extern struct { | ||
| 746 | family: sa_family_t, | ||
| 747 | path: [108]u8, | ||
| 748 | }; | ||
| 749 | |||
| 750 | pub const iovec = extern struct { | ||
| 751 | iov_base: [*]u8, | ||
| 752 | iov_len: usize, | ||
| 753 | }; | ||
| 754 | |||
| 755 | pub const iovec_const = extern struct { | ||
| 756 | iov_base: [*]const u8, | ||
| 757 | iov_len: usize, | ||
| 758 | }; | ||
| 759 | |||
| 760 | pub const mmsghdr = extern struct { | ||
| 761 | msg_hdr: msghdr, | ||
| 762 | msg_len: u32, | ||
| 763 | }; | ||
| 764 | |||
| 765 | pub const mmsghdr_const = extern struct { | ||
| 766 | msg_hdr: msghdr_const, | ||
| 767 | msg_len: u32, | ||
| 768 | }; | ||
| 769 | |||
| 770 | pub const epoll_data = extern union { | ||
| 771 | ptr: usize, | ||
| 772 | fd: i32, | ||
| 773 | @"u32": u32, | ||
| 774 | @"u64": u64, | ||
| 775 | }; | ||
| 776 | |||
| 777 | // On x86_64 the structure is packed so that it matches the definition of its | ||
| 778 | // 32bit counterpart | ||
| 779 | pub const epoll_event = if (builtin.arch != .x86_64) | ||
| 780 | extern struct { | ||
| 781 | events: u32, | ||
| 782 | data: epoll_data, | ||
| 783 | } | ||
| 784 | else | ||
| 785 | packed struct { | ||
| 786 | events: u32, | ||
| 787 | data: epoll_data, | ||
| 788 | }; | ||
| 789 | |||
| 790 | pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330; | ||
| 791 | pub const _LINUX_CAPABILITY_U32S_1 = 1; | ||
| 792 | |||
| 793 | pub const _LINUX_CAPABILITY_VERSION_2 = 0x20071026; | ||
| 794 | pub const _LINUX_CAPABILITY_U32S_2 = 2; | ||
| 795 | |||
| 796 | pub const _LINUX_CAPABILITY_VERSION_3 = 0x20080522; | ||
| 797 | pub const _LINUX_CAPABILITY_U32S_3 = 2; | ||
| 798 | |||
| 799 | pub const VFS_CAP_REVISION_MASK = 0xFF000000; | ||
| 800 | pub const VFS_CAP_REVISION_SHIFT = 24; | ||
| 801 | pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK; | ||
| 802 | pub const VFS_CAP_FLAGS_EFFECTIVE = 0x000001; | ||
| 803 | |||
| 804 | pub const VFS_CAP_REVISION_1 = 0x01000000; | ||
| 805 | pub const VFS_CAP_U32_1 = 1; | ||
| 806 | pub const XATTR_CAPS_SZ_1 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_1); | ||
| 807 | |||
| 808 | pub const VFS_CAP_REVISION_2 = 0x02000000; | ||
| 809 | pub const VFS_CAP_U32_2 = 2; | ||
| 810 | pub const XATTR_CAPS_SZ_2 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_2); | ||
| 811 | |||
| 812 | pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2; | ||
| 813 | pub const VFS_CAP_U32 = VFS_CAP_U32_2; | ||
| 814 | pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2; | ||
| 815 | |||
| 816 | pub const vfs_cap_data = extern struct { | ||
| 817 | //all of these are mandated as little endian | ||
| 818 | //when on disk. | ||
| 819 | const Data = struct { | ||
| 820 | permitted: u32, | ||
| 821 | inheritable: u32, | ||
| 822 | }; | ||
| 823 | |||
| 824 | magic_etc: u32, | ||
| 825 | data: [VFS_CAP_U32]Data, | ||
| 826 | }; | ||
| 827 | |||
| 828 | pub const CAP_CHOWN = 0; | ||
| 829 | pub const CAP_DAC_OVERRIDE = 1; | ||
| 830 | pub const CAP_DAC_READ_SEARCH = 2; | ||
| 831 | pub const CAP_FOWNER = 3; | ||
| 832 | pub const CAP_FSETID = 4; | ||
| 833 | pub const CAP_KILL = 5; | ||
| 834 | pub const CAP_SETGID = 6; | ||
| 835 | pub const CAP_SETUID = 7; | ||
| 836 | pub const CAP_SETPCAP = 8; | ||
| 837 | pub const CAP_LINUX_IMMUTABLE = 9; | ||
| 838 | pub const CAP_NET_BIND_SERVICE = 10; | ||
| 839 | pub const CAP_NET_BROADCAST = 11; | ||
| 840 | pub const CAP_NET_ADMIN = 12; | ||
| 841 | pub const CAP_NET_RAW = 13; | ||
| 842 | pub const CAP_IPC_LOCK = 14; | ||
| 843 | pub const CAP_IPC_OWNER = 15; | ||
| 844 | pub const CAP_SYS_MODULE = 16; | ||
| 845 | pub const CAP_SYS_RAWIO = 17; | ||
| 846 | pub const CAP_SYS_CHROOT = 18; | ||
| 847 | pub const CAP_SYS_PTRACE = 19; | ||
| 848 | pub const CAP_SYS_PACCT = 20; | ||
| 849 | pub const CAP_SYS_ADMIN = 21; | ||
| 850 | pub const CAP_SYS_BOOT = 22; | ||
| 851 | pub const CAP_SYS_NICE = 23; | ||
| 852 | pub const CAP_SYS_RESOURCE = 24; | ||
| 853 | pub const CAP_SYS_TIME = 25; | ||
| 854 | pub const CAP_SYS_TTY_CONFIG = 26; | ||
| 855 | pub const CAP_MKNOD = 27; | ||
| 856 | pub const CAP_LEASE = 28; | ||
| 857 | pub const CAP_AUDIT_WRITE = 29; | ||
| 858 | pub const CAP_AUDIT_CONTROL = 30; | ||
| 859 | pub const CAP_SETFCAP = 31; | ||
| 860 | pub const CAP_MAC_OVERRIDE = 32; | ||
| 861 | pub const CAP_MAC_ADMIN = 33; | ||
| 862 | pub const CAP_SYSLOG = 34; | ||
| 863 | pub const CAP_WAKE_ALARM = 35; | ||
| 864 | pub const CAP_BLOCK_SUSPEND = 36; | ||
| 865 | pub const CAP_AUDIT_READ = 37; | ||
| 866 | pub const CAP_LAST_CAP = CAP_AUDIT_READ; | ||
| 867 | |||
| 868 | pub fn cap_valid(u8: x) bool { | ||
| 869 | return x >= 0 and x <= CAP_LAST_CAP; | ||
| 870 | } | ||
| 871 | |||
| 872 | pub fn CAP_TO_MASK(cap: u8) u32 { | ||
| 873 | return u32(1) << u5(cap & 31); | ||
| 874 | } | ||
| 875 | |||
| 876 | pub fn CAP_TO_INDEX(cap: u8) u8 { | ||
| 877 | return cap >> 5; | ||
| 878 | } | ||
| 879 | |||
| 880 | pub const cap_t = extern struct { | ||
| 881 | hdrp: *cap_user_header_t, | ||
| 882 | datap: *cap_user_data_t, | ||
| 883 | }; | ||
| 884 | |||
| 885 | pub const cap_user_header_t = extern struct { | ||
| 886 | version: u32, | ||
| 887 | pid: usize, | ||
| 888 | }; | ||
| 889 | |||
| 890 | pub const cap_user_data_t = extern struct { | ||
| 891 | effective: u32, | ||
| 892 | permitted: u32, | ||
| 893 | inheritable: u32, | ||
| 894 | }; | ||
| 895 | |||
| 896 | pub const inotify_event = extern struct { | ||
| 897 | wd: i32, | ||
| 898 | mask: u32, | ||
| 899 | cookie: u32, | ||
| 900 | len: u32, | ||
| 901 | //name: [?]u8, | ||
| 902 | }; | ||
| 903 | |||
| 904 | pub const dirent64 = extern struct { | ||
| 905 | d_ino: u64, | ||
| 906 | d_off: u64, | ||
| 907 | d_reclen: u16, | ||
| 908 | d_type: u8, | ||
| 909 | d_name: u8, // field address is the address of first byte of name https://github.com/ziglang/zig/issues/173 | ||
| 910 | }; | ||
| 911 | |||
| 912 | pub const dl_phdr_info = extern struct { | ||
| 913 | dlpi_addr: usize, | ||
| 914 | dlpi_name: ?[*]const u8, | ||
| 915 | dlpi_phdr: [*]elf.Phdr, | ||
| 916 | dlpi_phnum: u16, | ||
| 917 | }; | ||
std/os/linux/posix/arm64.zig created+405| ... | @@ -0,0 +1,405 @@ | ||
| 1 | // arm64-specific declarations that are intended to be imported into the POSIX namespace. | ||
| 2 | // This does include Linux-only APIs. | ||
| 3 | |||
| 4 | const std = @import("../../std.zig"); | ||
| 5 | const linux = std.os.linux; | ||
| 6 | const socklen_t = linux.socklen_t; | ||
| 7 | const iovec = linux.iovec; | ||
| 8 | const iovec_const = linux.iovec_const; | ||
| 9 | |||
| 10 | pub const SYS_io_setup = 0; | ||
| 11 | pub const SYS_io_destroy = 1; | ||
| 12 | pub const SYS_io_submit = 2; | ||
| 13 | pub const SYS_io_cancel = 3; | ||
| 14 | pub const SYS_io_getevents = 4; | ||
| 15 | pub const SYS_setxattr = 5; | ||
| 16 | pub const SYS_lsetxattr = 6; | ||
| 17 | pub const SYS_fsetxattr = 7; | ||
| 18 | pub const SYS_getxattr = 8; | ||
| 19 | pub const SYS_lgetxattr = 9; | ||
| 20 | pub const SYS_fgetxattr = 10; | ||
| 21 | pub const SYS_listxattr = 11; | ||
| 22 | pub const SYS_llistxattr = 12; | ||
| 23 | pub const SYS_flistxattr = 13; | ||
| 24 | pub const SYS_removexattr = 14; | ||
| 25 | pub const SYS_lremovexattr = 15; | ||
| 26 | pub const SYS_fremovexattr = 16; | ||
| 27 | pub const SYS_getcwd = 17; | ||
| 28 | pub const SYS_lookup_dcookie = 18; | ||
| 29 | pub const SYS_eventfd2 = 19; | ||
| 30 | pub const SYS_epoll_create1 = 20; | ||
| 31 | pub const SYS_epoll_ctl = 21; | ||
| 32 | pub const SYS_epoll_pwait = 22; | ||
| 33 | pub const SYS_dup = 23; | ||
| 34 | pub const SYS_dup3 = 24; | ||
| 35 | pub const SYS_fcntl = 25; | ||
| 36 | pub const SYS_inotify_init1 = 26; | ||
| 37 | pub const SYS_inotify_add_watch = 27; | ||
| 38 | pub const SYS_inotify_rm_watch = 28; | ||
| 39 | pub const SYS_ioctl = 29; | ||
| 40 | pub const SYS_ioprio_set = 30; | ||
| 41 | pub const SYS_ioprio_get = 31; | ||
| 42 | pub const SYS_flock = 32; | ||
| 43 | pub const SYS_mknodat = 33; | ||
| 44 | pub const SYS_mkdirat = 34; | ||
| 45 | pub const SYS_unlinkat = 35; | ||
| 46 | pub const SYS_symlinkat = 36; | ||
| 47 | pub const SYS_linkat = 37; | ||
| 48 | pub const SYS_renameat = 38; | ||
| 49 | pub const SYS_umount2 = 39; | ||
| 50 | pub const SYS_mount = 40; | ||
| 51 | pub const SYS_pivot_root = 41; | ||
| 52 | pub const SYS_nfsservctl = 42; | ||
| 53 | pub const SYS_statfs = 43; | ||
| 54 | pub const SYS_fstatfs = 44; | ||
| 55 | pub const SYS_truncate = 45; | ||
| 56 | pub const SYS_ftruncate = 46; | ||
| 57 | pub const SYS_fallocate = 47; | ||
| 58 | pub const SYS_faccessat = 48; | ||
| 59 | pub const SYS_chdir = 49; | ||
| 60 | pub const SYS_fchdir = 50; | ||
| 61 | pub const SYS_chroot = 51; | ||
| 62 | pub const SYS_fchmod = 52; | ||
| 63 | pub const SYS_fchmodat = 53; | ||
| 64 | pub const SYS_fchownat = 54; | ||
| 65 | pub const SYS_fchown = 55; | ||
| 66 | pub const SYS_openat = 56; | ||
| 67 | pub const SYS_close = 57; | ||
| 68 | pub const SYS_vhangup = 58; | ||
| 69 | pub const SYS_pipe2 = 59; | ||
| 70 | pub const SYS_quotactl = 60; | ||
| 71 | pub const SYS_getdents64 = 61; | ||
| 72 | pub const SYS_lseek = 62; | ||
| 73 | pub const SYS_read = 63; | ||
| 74 | pub const SYS_write = 64; | ||
| 75 | pub const SYS_readv = 65; | ||
| 76 | pub const SYS_writev = 66; | ||
| 77 | pub const SYS_pread64 = 67; | ||
| 78 | pub const SYS_pwrite64 = 68; | ||
| 79 | pub const SYS_preadv = 69; | ||
| 80 | pub const SYS_pwritev = 70; | ||
| 81 | pub const SYS_pselect6 = 72; | ||
| 82 | pub const SYS_ppoll = 73; | ||
| 83 | pub const SYS_signalfd4 = 74; | ||
| 84 | pub const SYS_vmsplice = 75; | ||
| 85 | pub const SYS_splice = 76; | ||
| 86 | pub const SYS_tee = 77; | ||
| 87 | pub const SYS_readlinkat = 78; | ||
| 88 | pub const SYS_fstatat = 79; | ||
| 89 | pub const SYS_fstat = 80; | ||
| 90 | pub const SYS_sync = 81; | ||
| 91 | pub const SYS_fsync = 82; | ||
| 92 | pub const SYS_fdatasync = 83; | ||
| 93 | pub const SYS_sync_file_range2 = 84; | ||
| 94 | pub const SYS_sync_file_range = 84; | ||
| 95 | pub const SYS_timerfd_create = 85; | ||
| 96 | pub const SYS_timerfd_settime = 86; | ||
| 97 | pub const SYS_timerfd_gettime = 87; | ||
| 98 | pub const SYS_utimensat = 88; | ||
| 99 | pub const SYS_acct = 89; | ||
| 100 | pub const SYS_capget = 90; | ||
| 101 | pub const SYS_capset = 91; | ||
| 102 | pub const SYS_personality = 92; | ||
| 103 | pub const SYS_exit = 93; | ||
| 104 | pub const SYS_exit_group = 94; | ||
| 105 | pub const SYS_waitid = 95; | ||
| 106 | pub const SYS_set_tid_address = 96; | ||
| 107 | pub const SYS_unshare = 97; | ||
| 108 | pub const SYS_futex = 98; | ||
| 109 | pub const SYS_set_robust_list = 99; | ||
| 110 | pub const SYS_get_robust_list = 100; | ||
| 111 | pub const SYS_nanosleep = 101; | ||
| 112 | pub const SYS_getitimer = 102; | ||
| 113 | pub const SYS_setitimer = 103; | ||
| 114 | pub const SYS_kexec_load = 104; | ||
| 115 | pub const SYS_init_module = 105; | ||
| 116 | pub const SYS_delete_module = 106; | ||
| 117 | pub const SYS_timer_create = 107; | ||
| 118 | pub const SYS_timer_gettime = 108; | ||
| 119 | pub const SYS_timer_getoverrun = 109; | ||
| 120 | pub const SYS_timer_settime = 110; | ||
| 121 | pub const SYS_timer_delete = 111; | ||
| 122 | pub const SYS_clock_settime = 112; | ||
| 123 | pub const SYS_clock_gettime = 113; | ||
| 124 | pub const SYS_clock_getres = 114; | ||
| 125 | pub const SYS_clock_nanosleep = 115; | ||
| 126 | pub const SYS_syslog = 116; | ||
| 127 | pub const SYS_ptrace = 117; | ||
| 128 | pub const SYS_sched_setparam = 118; | ||
| 129 | pub const SYS_sched_setscheduler = 119; | ||
| 130 | pub const SYS_sched_getscheduler = 120; | ||
| 131 | pub const SYS_sched_getparam = 121; | ||
| 132 | pub const SYS_sched_setaffinity = 122; | ||
| 133 | pub const SYS_sched_getaffinity = 123; | ||
| 134 | pub const SYS_sched_yield = 124; | ||
| 135 | pub const SYS_sched_get_priority_max = 125; | ||
| 136 | pub const SYS_sched_get_priority_min = 126; | ||
| 137 | pub const SYS_sched_rr_get_interval = 127; | ||
| 138 | pub const SYS_restart_syscall = 128; | ||
| 139 | pub const SYS_kill = 129; | ||
| 140 | pub const SYS_tkill = 130; | ||
| 141 | pub const SYS_tgkill = 131; | ||
| 142 | pub const SYS_sigaltstack = 132; | ||
| 143 | pub const SYS_rt_sigsuspend = 133; | ||
| 144 | pub const SYS_rt_sigaction = 134; | ||
| 145 | pub const SYS_rt_sigprocmask = 135; | ||
| 146 | pub const SYS_rt_sigpending = 136; | ||
| 147 | pub const SYS_rt_sigtimedwait = 137; | ||
| 148 | pub const SYS_rt_sigqueueinfo = 138; | ||
| 149 | pub const SYS_rt_sigreturn = 139; | ||
| 150 | pub const SYS_setpriority = 140; | ||
| 151 | pub const SYS_getpriority = 141; | ||
| 152 | pub const SYS_reboot = 142; | ||
| 153 | pub const SYS_setregid = 143; | ||
| 154 | pub const SYS_setgid = 144; | ||
| 155 | pub const SYS_setreuid = 145; | ||
| 156 | pub const SYS_setuid = 146; | ||
| 157 | pub const SYS_setresuid = 147; | ||
| 158 | pub const SYS_getresuid = 148; | ||
| 159 | pub const SYS_setresgid = 149; | ||
| 160 | pub const SYS_getresgid = 150; | ||
| 161 | pub const SYS_setfsuid = 151; | ||
| 162 | pub const SYS_setfsgid = 152; | ||
| 163 | pub const SYS_times = 153; | ||
| 164 | pub const SYS_setpgid = 154; | ||
| 165 | pub const SYS_getpgid = 155; | ||
| 166 | pub const SYS_getsid = 156; | ||
| 167 | pub const SYS_setsid = 157; | ||
| 168 | pub const SYS_getgroups = 158; | ||
| 169 | pub const SYS_setgroups = 159; | ||
| 170 | pub const SYS_uname = 160; | ||
| 171 | pub const SYS_sethostname = 161; | ||
| 172 | pub const SYS_setdomainname = 162; | ||
| 173 | pub const SYS_getrlimit = 163; | ||
| 174 | pub const SYS_setrlimit = 164; | ||
| 175 | pub const SYS_getrusage = 165; | ||
| 176 | pub const SYS_umask = 166; | ||
| 177 | pub const SYS_prctl = 167; | ||
| 178 | pub const SYS_getcpu = 168; | ||
| 179 | pub const SYS_gettimeofday = 169; | ||
| 180 | pub const SYS_settimeofday = 170; | ||
| 181 | pub const SYS_adjtimex = 171; | ||
| 182 | pub const SYS_getpid = 172; | ||
| 183 | pub const SYS_getppid = 173; | ||
| 184 | pub const SYS_getuid = 174; | ||
| 185 | pub const SYS_geteuid = 175; | ||
| 186 | pub const SYS_getgid = 176; | ||
| 187 | pub const SYS_getegid = 177; | ||
| 188 | pub const SYS_gettid = 178; | ||
| 189 | pub const SYS_sysinfo = 179; | ||
| 190 | pub const SYS_mq_open = 180; | ||
| 191 | pub const SYS_mq_unlink = 181; | ||
| 192 | pub const SYS_mq_timedsend = 182; | ||
| 193 | pub const SYS_mq_timedreceive = 183; | ||
| 194 | pub const SYS_mq_notify = 184; | ||
| 195 | pub const SYS_mq_getsetattr = 185; | ||
| 196 | pub const SYS_msgget = 186; | ||
| 197 | pub const SYS_msgctl = 187; | ||
| 198 | pub const SYS_msgrcv = 188; | ||
| 199 | pub const SYS_msgsnd = 189; | ||
| 200 | pub const SYS_semget = 190; | ||
| 201 | pub const SYS_semctl = 191; | ||
| 202 | pub const SYS_semtimedop = 192; | ||
| 203 | pub const SYS_semop = 193; | ||
| 204 | pub const SYS_shmget = 194; | ||
| 205 | pub const SYS_shmctl = 195; | ||
| 206 | pub const SYS_shmat = 196; | ||
| 207 | pub const SYS_shmdt = 197; | ||
| 208 | pub const SYS_socket = 198; | ||
| 209 | pub const SYS_socketpair = 199; | ||
| 210 | pub const SYS_bind = 200; | ||
| 211 | pub const SYS_listen = 201; | ||
| 212 | pub const SYS_accept = 202; | ||
| 213 | pub const SYS_connect = 203; | ||
| 214 | pub const SYS_getsockname = 204; | ||
| 215 | pub const SYS_getpeername = 205; | ||
| 216 | pub const SYS_sendto = 206; | ||
| 217 | pub const SYS_recvfrom = 207; | ||
| 218 | pub const SYS_setsockopt = 208; | ||
| 219 | pub const SYS_getsockopt = 209; | ||
| 220 | pub const SYS_shutdown = 210; | ||
| 221 | pub const SYS_sendmsg = 211; | ||
| 222 | pub const SYS_recvmsg = 212; | ||
| 223 | pub const SYS_readahead = 213; | ||
| 224 | pub const SYS_brk = 214; | ||
| 225 | pub const SYS_munmap = 215; | ||
| 226 | pub const SYS_mremap = 216; | ||
| 227 | pub const SYS_add_key = 217; | ||
| 228 | pub const SYS_request_key = 218; | ||
| 229 | pub const SYS_keyctl = 219; | ||
| 230 | pub const SYS_clone = 220; | ||
| 231 | pub const SYS_execve = 221; | ||
| 232 | pub const SYS_mmap = 222; | ||
| 233 | pub const SYS_fadvise64 = 223; | ||
| 234 | pub const SYS_swapon = 224; | ||
| 235 | pub const SYS_swapoff = 225; | ||
| 236 | pub const SYS_mprotect = 226; | ||
| 237 | pub const SYS_msync = 227; | ||
| 238 | pub const SYS_mlock = 228; | ||
| 239 | pub const SYS_munlock = 229; | ||
| 240 | pub const SYS_mlockall = 230; | ||
| 241 | pub const SYS_munlockall = 231; | ||
| 242 | pub const SYS_mincore = 232; | ||
| 243 | pub const SYS_madvise = 233; | ||
| 244 | pub const SYS_remap_file_pages = 234; | ||
| 245 | pub const SYS_mbind = 235; | ||
| 246 | pub const SYS_get_mempolicy = 236; | ||
| 247 | pub const SYS_set_mempolicy = 237; | ||
| 248 | pub const SYS_migrate_pages = 238; | ||
| 249 | pub const SYS_move_pages = 239; | ||
| 250 | pub const SYS_rt_tgsigqueueinfo = 240; | ||
| 251 | pub const SYS_perf_event_open = 241; | ||
| 252 | pub const SYS_accept4 = 242; | ||
| 253 | pub const SYS_recvmmsg = 243; | ||
| 254 | pub const SYS_arch_specific_syscall = 244; | ||
| 255 | pub const SYS_wait4 = 260; | ||
| 256 | pub const SYS_prlimit64 = 261; | ||
| 257 | pub const SYS_fanotify_init = 262; | ||
| 258 | pub const SYS_fanotify_mark = 263; | ||
| 259 | pub const SYS_clock_adjtime = 266; | ||
| 260 | pub const SYS_syncfs = 267; | ||
| 261 | pub const SYS_setns = 268; | ||
| 262 | pub const SYS_sendmmsg = 269; | ||
| 263 | pub const SYS_process_vm_readv = 270; | ||
| 264 | pub const SYS_process_vm_writev = 271; | ||
| 265 | pub const SYS_kcmp = 272; | ||
| 266 | pub const SYS_finit_module = 273; | ||
| 267 | pub const SYS_sched_setattr = 274; | ||
| 268 | pub const SYS_sched_getattr = 275; | ||
| 269 | pub const SYS_renameat2 = 276; | ||
| 270 | pub const SYS_seccomp = 277; | ||
| 271 | pub const SYS_getrandom = 278; | ||
| 272 | pub const SYS_memfd_create = 279; | ||
| 273 | pub const SYS_bpf = 280; | ||
| 274 | pub const SYS_execveat = 281; | ||
| 275 | pub const SYS_userfaultfd = 282; | ||
| 276 | pub const SYS_membarrier = 283; | ||
| 277 | pub const SYS_mlock2 = 284; | ||
| 278 | pub const SYS_copy_file_range = 285; | ||
| 279 | pub const SYS_preadv2 = 286; | ||
| 280 | pub const SYS_pwritev2 = 287; | ||
| 281 | pub const SYS_pkey_mprotect = 288; | ||
| 282 | pub const SYS_pkey_alloc = 289; | ||
| 283 | pub const SYS_pkey_free = 290; | ||
| 284 | pub const SYS_statx = 291; | ||
| 285 | pub const SYS_io_pgetevents = 292; | ||
| 286 | pub const SYS_rseq = 293; | ||
| 287 | pub const SYS_kexec_file_load = 294; | ||
| 288 | pub const SYS_pidfd_send_signal = 424; | ||
| 289 | pub const SYS_io_uring_setup = 425; | ||
| 290 | pub const SYS_io_uring_enter = 426; | ||
| 291 | pub const SYS_io_uring_register = 427; | ||
| 292 | |||
| 293 | pub const O_CREAT = 0o100; | ||
| 294 | pub const O_EXCL = 0o200; | ||
| 295 | pub const O_NOCTTY = 0o400; | ||
| 296 | pub const O_TRUNC = 0o1000; | ||
| 297 | pub const O_APPEND = 0o2000; | ||
| 298 | pub const O_NONBLOCK = 0o4000; | ||
| 299 | pub const O_DSYNC = 0o10000; | ||
| 300 | pub const O_SYNC = 0o4010000; | ||
| 301 | pub const O_RSYNC = 0o4010000; | ||
| 302 | pub const O_DIRECTORY = 0o200000; | ||
| 303 | pub const O_NOFOLLOW = 0o400000; | ||
| 304 | pub const O_CLOEXEC = 0o2000000; | ||
| 305 | |||
| 306 | pub const O_ASYNC = 0o20000; | ||
| 307 | pub const O_DIRECT = 0o40000; | ||
| 308 | pub const O_LARGEFILE = 0; | ||
| 309 | pub const O_NOATIME = 0o1000000; | ||
| 310 | pub const O_PATH = 0o10000000; | ||
| 311 | pub const O_TMPFILE = 0o20200000; | ||
| 312 | pub const O_NDELAY = O_NONBLOCK; | ||
| 313 | |||
| 314 | pub const F_DUPFD = 0; | ||
| 315 | pub const F_GETFD = 1; | ||
| 316 | pub const F_SETFD = 2; | ||
| 317 | pub const F_GETFL = 3; | ||
| 318 | pub const F_SETFL = 4; | ||
| 319 | |||
| 320 | pub const F_SETOWN = 8; | ||
| 321 | pub const F_GETOWN = 9; | ||
| 322 | pub const F_SETSIG = 10; | ||
| 323 | pub const F_GETSIG = 11; | ||
| 324 | |||
| 325 | pub const F_GETLK = 5; | ||
| 326 | pub const F_SETLK = 6; | ||
| 327 | pub const F_SETLKW = 7; | ||
| 328 | |||
| 329 | pub const F_SETOWN_EX = 15; | ||
| 330 | pub const F_GETOWN_EX = 16; | ||
| 331 | |||
| 332 | pub const F_GETOWNER_UIDS = 17; | ||
| 333 | |||
| 334 | pub const AT_FDCWD = -100; | ||
| 335 | pub const AT_SYMLINK_NOFOLLOW = 0x100; | ||
| 336 | pub const AT_REMOVEDIR = 0x200; | ||
| 337 | pub const AT_SYMLINK_FOLLOW = 0x400; | ||
| 338 | pub const AT_NO_AUTOMOUNT = 0x800; | ||
| 339 | pub const AT_EMPTY_PATH = 0x1000; | ||
| 340 | |||
| 341 | pub const VDSO_USEFUL = true; | ||
| 342 | pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; | ||
| 343 | pub const VDSO_CGT_VER = "LINUX_2.6.39"; | ||
| 344 | |||
| 345 | pub const msghdr = extern struct { | ||
| 346 | msg_name: ?*sockaddr, | ||
| 347 | msg_namelen: socklen_t, | ||
| 348 | msg_iov: [*]iovec, | ||
| 349 | msg_iovlen: i32, | ||
| 350 | __pad1: i32, | ||
| 351 | msg_control: ?*c_void, | ||
| 352 | msg_controllen: socklen_t, | ||
| 353 | __pad2: socklen_t, | ||
| 354 | msg_flags: i32, | ||
| 355 | }; | ||
| 356 | |||
| 357 | pub const msghdr_const = extern struct { | ||
| 358 | msg_name: ?*const sockaddr, | ||
| 359 | msg_namelen: socklen_t, | ||
| 360 | msg_iov: [*]iovec_const, | ||
| 361 | msg_iovlen: i32, | ||
| 362 | __pad1: i32, | ||
| 363 | msg_control: ?*c_void, | ||
| 364 | msg_controllen: socklen_t, | ||
| 365 | __pad2: socklen_t, | ||
| 366 | msg_flags: i32, | ||
| 367 | }; | ||
| 368 | |||
| 369 | /// Renamed to Stat to not conflict with the stat function. | ||
| 370 | pub const Stat = extern struct { | ||
| 371 | dev: u64, | ||
| 372 | ino: u64, | ||
| 373 | nlink: usize, | ||
| 374 | |||
| 375 | mode: u32, | ||
| 376 | uid: u32, | ||
| 377 | gid: u32, | ||
| 378 | __pad0: u32, | ||
| 379 | rdev: u64, | ||
| 380 | size: i64, | ||
| 381 | blksize: isize, | ||
| 382 | blocks: i64, | ||
| 383 | |||
| 384 | atim: timespec, | ||
| 385 | mtim: timespec, | ||
| 386 | ctim: timespec, | ||
| 387 | __unused: [3]isize, | ||
| 388 | }; | ||
| 389 | |||
| 390 | pub const timespec = extern struct { | ||
| 391 | tv_sec: isize, | ||
| 392 | tv_nsec: isize, | ||
| 393 | }; | ||
| 394 | |||
| 395 | pub const timeval = extern struct { | ||
| 396 | tv_sec: isize, | ||
| 397 | tv_usec: isize, | ||
| 398 | }; | ||
| 399 | |||
| 400 | pub const timezone = extern struct { | ||
| 401 | tz_minuteswest: i32, | ||
| 402 | tz_dsttime: i32, | ||
| 403 | }; | ||
| 404 | |||
| 405 | pub const Elf_Symndx = u32; | ||
std/os/linux/posix/x86_64.zig created+470| ... | @@ -0,0 +1,470 @@ | ||
| 1 | // x86-64-specific declarations that are intended to be imported into the POSIX namespace. | ||
| 2 | const std = @import("../../../std.zig"); | ||
| 3 | |||
| 4 | const linux = std.os.linux; | ||
| 5 | const sockaddr = linux.sockaddr; | ||
| 6 | const socklen_t = linux.socklen_t; | ||
| 7 | const iovec = linux.iovec; | ||
| 8 | const iovec_const = linux.iovec_const; | ||
| 9 | |||
| 10 | pub const SYS_read = 0; | ||
| 11 | pub const SYS_write = 1; | ||
| 12 | pub const SYS_open = 2; | ||
| 13 | pub const SYS_close = 3; | ||
| 14 | pub const SYS_stat = 4; | ||
| 15 | pub const SYS_fstat = 5; | ||
| 16 | pub const SYS_lstat = 6; | ||
| 17 | pub const SYS_poll = 7; | ||
| 18 | pub const SYS_lseek = 8; | ||
| 19 | pub const SYS_mmap = 9; | ||
| 20 | pub const SYS_mprotect = 10; | ||
| 21 | pub const SYS_munmap = 11; | ||
| 22 | pub const SYS_brk = 12; | ||
| 23 | pub const SYS_rt_sigaction = 13; | ||
| 24 | pub const SYS_rt_sigprocmask = 14; | ||
| 25 | pub const SYS_rt_sigreturn = 15; | ||
| 26 | pub const SYS_ioctl = 16; | ||
| 27 | pub const SYS_pread = 17; | ||
| 28 | pub const SYS_pwrite = 18; | ||
| 29 | pub const SYS_readv = 19; | ||
| 30 | pub const SYS_writev = 20; | ||
| 31 | pub const SYS_access = 21; | ||
| 32 | pub const SYS_pipe = 22; | ||
| 33 | pub const SYS_select = 23; | ||
| 34 | pub const SYS_sched_yield = 24; | ||
| 35 | pub const SYS_mremap = 25; | ||
| 36 | pub const SYS_msync = 26; | ||
| 37 | pub const SYS_mincore = 27; | ||
| 38 | pub const SYS_madvise = 28; | ||
| 39 | pub const SYS_shmget = 29; | ||
| 40 | pub const SYS_shmat = 30; | ||
| 41 | pub const SYS_shmctl = 31; | ||
| 42 | pub const SYS_dup = 32; | ||
| 43 | pub const SYS_dup2 = 33; | ||
| 44 | pub const SYS_pause = 34; | ||
| 45 | pub const SYS_nanosleep = 35; | ||
| 46 | pub const SYS_getitimer = 36; | ||
| 47 | pub const SYS_alarm = 37; | ||
| 48 | pub const SYS_setitimer = 38; | ||
| 49 | pub const SYS_getpid = 39; | ||
| 50 | pub const SYS_sendfile = 40; | ||
| 51 | pub const SYS_socket = 41; | ||
| 52 | pub const SYS_connect = 42; | ||
| 53 | pub const SYS_accept = 43; | ||
| 54 | pub const SYS_sendto = 44; | ||
| 55 | pub const SYS_recvfrom = 45; | ||
| 56 | pub const SYS_sendmsg = 46; | ||
| 57 | pub const SYS_recvmsg = 47; | ||
| 58 | pub const SYS_shutdown = 48; | ||
| 59 | pub const SYS_bind = 49; | ||
| 60 | pub const SYS_listen = 50; | ||
| 61 | pub const SYS_getsockname = 51; | ||
| 62 | pub const SYS_getpeername = 52; | ||
| 63 | pub const SYS_socketpair = 53; | ||
| 64 | pub const SYS_setsockopt = 54; | ||
| 65 | pub const SYS_getsockopt = 55; | ||
| 66 | pub const SYS_clone = 56; | ||
| 67 | pub const SYS_fork = 57; | ||
| 68 | pub const SYS_vfork = 58; | ||
| 69 | pub const SYS_execve = 59; | ||
| 70 | pub const SYS_exit = 60; | ||
| 71 | pub const SYS_wait4 = 61; | ||
| 72 | pub const SYS_kill = 62; | ||
| 73 | pub const SYS_uname = 63; | ||
| 74 | pub const SYS_semget = 64; | ||
| 75 | pub const SYS_semop = 65; | ||
| 76 | pub const SYS_semctl = 66; | ||
| 77 | pub const SYS_shmdt = 67; | ||
| 78 | pub const SYS_msgget = 68; | ||
| 79 | pub const SYS_msgsnd = 69; | ||
| 80 | pub const SYS_msgrcv = 70; | ||
| 81 | pub const SYS_msgctl = 71; | ||
| 82 | pub const SYS_fcntl = 72; | ||
| 83 | pub const SYS_flock = 73; | ||
| 84 | pub const SYS_fsync = 74; | ||
| 85 | pub const SYS_fdatasync = 75; | ||
| 86 | pub const SYS_truncate = 76; | ||
| 87 | pub const SYS_ftruncate = 77; | ||
| 88 | pub const SYS_getdents = 78; | ||
| 89 | pub const SYS_getcwd = 79; | ||
| 90 | pub const SYS_chdir = 80; | ||
| 91 | pub const SYS_fchdir = 81; | ||
| 92 | pub const SYS_rename = 82; | ||
| 93 | pub const SYS_mkdir = 83; | ||
| 94 | pub const SYS_rmdir = 84; | ||
| 95 | pub const SYS_creat = 85; | ||
| 96 | pub const SYS_link = 86; | ||
| 97 | pub const SYS_unlink = 87; | ||
| 98 | pub const SYS_symlink = 88; | ||
| 99 | pub const SYS_readlink = 89; | ||
| 100 | pub const SYS_chmod = 90; | ||
| 101 | pub const SYS_fchmod = 91; | ||
| 102 | pub const SYS_chown = 92; | ||
| 103 | pub const SYS_fchown = 93; | ||
| 104 | pub const SYS_lchown = 94; | ||
| 105 | pub const SYS_umask = 95; | ||
| 106 | pub const SYS_gettimeofday = 96; | ||
| 107 | pub const SYS_getrlimit = 97; | ||
| 108 | pub const SYS_getrusage = 98; | ||
| 109 | pub const SYS_sysinfo = 99; | ||
| 110 | pub const SYS_times = 100; | ||
| 111 | pub const SYS_ptrace = 101; | ||
| 112 | pub const SYS_getuid = 102; | ||
| 113 | pub const SYS_syslog = 103; | ||
| 114 | pub const SYS_getgid = 104; | ||
| 115 | pub const SYS_setuid = 105; | ||
| 116 | pub const SYS_setgid = 106; | ||
| 117 | pub const SYS_geteuid = 107; | ||
| 118 | pub const SYS_getegid = 108; | ||
| 119 | pub const SYS_setpgid = 109; | ||
| 120 | pub const SYS_getppid = 110; | ||
| 121 | pub const SYS_getpgrp = 111; | ||
| 122 | pub const SYS_setsid = 112; | ||
| 123 | pub const SYS_setreuid = 113; | ||
| 124 | pub const SYS_setregid = 114; | ||
| 125 | pub const SYS_getgroups = 115; | ||
| 126 | pub const SYS_setgroups = 116; | ||
| 127 | pub const SYS_setresuid = 117; | ||
| 128 | pub const SYS_getresuid = 118; | ||
| 129 | pub const SYS_setresgid = 119; | ||
| 130 | pub const SYS_getresgid = 120; | ||
| 131 | pub const SYS_getpgid = 121; | ||
| 132 | pub const SYS_setfsuid = 122; | ||
| 133 | pub const SYS_setfsgid = 123; | ||
| 134 | pub const SYS_getsid = 124; | ||
| 135 | pub const SYS_capget = 125; | ||
| 136 | pub const SYS_capset = 126; | ||
| 137 | pub const SYS_rt_sigpending = 127; | ||
| 138 | pub const SYS_rt_sigtimedwait = 128; | ||
| 139 | pub const SYS_rt_sigqueueinfo = 129; | ||
| 140 | pub const SYS_rt_sigsuspend = 130; | ||
| 141 | pub const SYS_sigaltstack = 131; | ||
| 142 | pub const SYS_utime = 132; | ||
| 143 | pub const SYS_mknod = 133; | ||
| 144 | pub const SYS_uselib = 134; | ||
| 145 | pub const SYS_personality = 135; | ||
| 146 | pub const SYS_ustat = 136; | ||
| 147 | pub const SYS_statfs = 137; | ||
| 148 | pub const SYS_fstatfs = 138; | ||
| 149 | pub const SYS_sysfs = 139; | ||
| 150 | pub const SYS_getpriority = 140; | ||
| 151 | pub const SYS_setpriority = 141; | ||
| 152 | pub const SYS_sched_setparam = 142; | ||
| 153 | pub const SYS_sched_getparam = 143; | ||
| 154 | pub const SYS_sched_setscheduler = 144; | ||
| 155 | pub const SYS_sched_getscheduler = 145; | ||
| 156 | pub const SYS_sched_get_priority_max = 146; | ||
| 157 | pub const SYS_sched_get_priority_min = 147; | ||
| 158 | pub const SYS_sched_rr_get_interval = 148; | ||
| 159 | pub const SYS_mlock = 149; | ||
| 160 | pub const SYS_munlock = 150; | ||
| 161 | pub const SYS_mlockall = 151; | ||
| 162 | pub const SYS_munlockall = 152; | ||
| 163 | pub const SYS_vhangup = 153; | ||
| 164 | pub const SYS_modify_ldt = 154; | ||
| 165 | pub const SYS_pivot_root = 155; | ||
| 166 | pub const SYS__sysctl = 156; | ||
| 167 | pub const SYS_prctl = 157; | ||
| 168 | pub const SYS_arch_prctl = 158; | ||
| 169 | pub const SYS_adjtimex = 159; | ||
| 170 | pub const SYS_setrlimit = 160; | ||
| 171 | pub const SYS_chroot = 161; | ||
| 172 | pub const SYS_sync = 162; | ||
| 173 | pub const SYS_acct = 163; | ||
| 174 | pub const SYS_settimeofday = 164; | ||
| 175 | pub const SYS_mount = 165; | ||
| 176 | pub const SYS_umount2 = 166; | ||
| 177 | pub const SYS_swapon = 167; | ||
| 178 | pub const SYS_swapoff = 168; | ||
| 179 | pub const SYS_reboot = 169; | ||
| 180 | pub const SYS_sethostname = 170; | ||
| 181 | pub const SYS_setdomainname = 171; | ||
| 182 | pub const SYS_iopl = 172; | ||
| 183 | pub const SYS_ioperm = 173; | ||
| 184 | pub const SYS_create_module = 174; | ||
| 185 | pub const SYS_init_module = 175; | ||
| 186 | pub const SYS_delete_module = 176; | ||
| 187 | pub const SYS_get_kernel_syms = 177; | ||
| 188 | pub const SYS_query_module = 178; | ||
| 189 | pub const SYS_quotactl = 179; | ||
| 190 | pub const SYS_nfsservctl = 180; | ||
| 191 | pub const SYS_getpmsg = 181; | ||
| 192 | pub const SYS_putpmsg = 182; | ||
| 193 | pub const SYS_afs_syscall = 183; | ||
| 194 | pub const SYS_tuxcall = 184; | ||
| 195 | pub const SYS_security = 185; | ||
| 196 | pub const SYS_gettid = 186; | ||
| 197 | pub const SYS_readahead = 187; | ||
| 198 | pub const SYS_setxattr = 188; | ||
| 199 | pub const SYS_lsetxattr = 189; | ||
| 200 | pub const SYS_fsetxattr = 190; | ||
| 201 | pub const SYS_getxattr = 191; | ||
| 202 | pub const SYS_lgetxattr = 192; | ||
| 203 | pub const SYS_fgetxattr = 193; | ||
| 204 | pub const SYS_listxattr = 194; | ||
| 205 | pub const SYS_llistxattr = 195; | ||
| 206 | pub const SYS_flistxattr = 196; | ||
| 207 | pub const SYS_removexattr = 197; | ||
| 208 | pub const SYS_lremovexattr = 198; | ||
| 209 | pub const SYS_fremovexattr = 199; | ||
| 210 | pub const SYS_tkill = 200; | ||
| 211 | pub const SYS_time = 201; | ||
| 212 | pub const SYS_futex = 202; | ||
| 213 | pub const SYS_sched_setaffinity = 203; | ||
| 214 | pub const SYS_sched_getaffinity = 204; | ||
| 215 | pub const SYS_set_thread_area = 205; | ||
| 216 | pub const SYS_io_setup = 206; | ||
| 217 | pub const SYS_io_destroy = 207; | ||
| 218 | pub const SYS_io_getevents = 208; | ||
| 219 | pub const SYS_io_submit = 209; | ||
| 220 | pub const SYS_io_cancel = 210; | ||
| 221 | pub const SYS_get_thread_area = 211; | ||
| 222 | pub const SYS_lookup_dcookie = 212; | ||
| 223 | pub const SYS_epoll_create = 213; | ||
| 224 | pub const SYS_epoll_ctl_old = 214; | ||
| 225 | pub const SYS_epoll_wait_old = 215; | ||
| 226 | pub const SYS_remap_file_pages = 216; | ||
| 227 | pub const SYS_getdents64 = 217; | ||
| 228 | pub const SYS_set_tid_address = 218; | ||
| 229 | pub const SYS_restart_syscall = 219; | ||
| 230 | pub const SYS_semtimedop = 220; | ||
| 231 | pub const SYS_fadvise64 = 221; | ||
| 232 | pub const SYS_timer_create = 222; | ||
| 233 | pub const SYS_timer_settime = 223; | ||
| 234 | pub const SYS_timer_gettime = 224; | ||
| 235 | pub const SYS_timer_getoverrun = 225; | ||
| 236 | pub const SYS_timer_delete = 226; | ||
| 237 | pub const SYS_clock_settime = 227; | ||
| 238 | pub const SYS_clock_gettime = 228; | ||
| 239 | pub const SYS_clock_getres = 229; | ||
| 240 | pub const SYS_clock_nanosleep = 230; | ||
| 241 | pub const SYS_exit_group = 231; | ||
| 242 | pub const SYS_epoll_wait = 232; | ||
| 243 | pub const SYS_epoll_ctl = 233; | ||
| 244 | pub const SYS_tgkill = 234; | ||
| 245 | pub const SYS_utimes = 235; | ||
| 246 | pub const SYS_vserver = 236; | ||
| 247 | pub const SYS_mbind = 237; | ||
| 248 | pub const SYS_set_mempolicy = 238; | ||
| 249 | pub const SYS_get_mempolicy = 239; | ||
| 250 | pub const SYS_mq_open = 240; | ||
| 251 | pub const SYS_mq_unlink = 241; | ||
| 252 | pub const SYS_mq_timedsend = 242; | ||
| 253 | pub const SYS_mq_timedreceive = 243; | ||
| 254 | pub const SYS_mq_notify = 244; | ||
| 255 | pub const SYS_mq_getsetattr = 245; | ||
| 256 | pub const SYS_kexec_load = 246; | ||
| 257 | pub const SYS_waitid = 247; | ||
| 258 | pub const SYS_add_key = 248; | ||
| 259 | pub const SYS_request_key = 249; | ||
| 260 | pub const SYS_keyctl = 250; | ||
| 261 | pub const SYS_ioprio_set = 251; | ||
| 262 | pub const SYS_ioprio_get = 252; | ||
| 263 | pub const SYS_inotify_init = 253; | ||
| 264 | pub const SYS_inotify_add_watch = 254; | ||
| 265 | pub const SYS_inotify_rm_watch = 255; | ||
| 266 | pub const SYS_migrate_pages = 256; | ||
| 267 | pub const SYS_openat = 257; | ||
| 268 | pub const SYS_mkdirat = 258; | ||
| 269 | pub const SYS_mknodat = 259; | ||
| 270 | pub const SYS_fchownat = 260; | ||
| 271 | pub const SYS_futimesat = 261; | ||
| 272 | pub const SYS_newfstatat = 262; | ||
| 273 | pub const SYS_fstatat = 262; | ||
| 274 | pub const SYS_unlinkat = 263; | ||
| 275 | pub const SYS_renameat = 264; | ||
| 276 | pub const SYS_linkat = 265; | ||
| 277 | pub const SYS_symlinkat = 266; | ||
| 278 | pub const SYS_readlinkat = 267; | ||
| 279 | pub const SYS_fchmodat = 268; | ||
| 280 | pub const SYS_faccessat = 269; | ||
| 281 | pub const SYS_pselect6 = 270; | ||
| 282 | pub const SYS_ppoll = 271; | ||
| 283 | pub const SYS_unshare = 272; | ||
| 284 | pub const SYS_set_robust_list = 273; | ||
| 285 | pub const SYS_get_robust_list = 274; | ||
| 286 | pub const SYS_splice = 275; | ||
| 287 | pub const SYS_tee = 276; | ||
| 288 | pub const SYS_sync_file_range = 277; | ||
| 289 | pub const SYS_vmsplice = 278; | ||
| 290 | pub const SYS_move_pages = 279; | ||
| 291 | pub const SYS_utimensat = 280; | ||
| 292 | pub const SYS_epoll_pwait = 281; | ||
| 293 | pub const SYS_signalfd = 282; | ||
| 294 | pub const SYS_timerfd_create = 283; | ||
| 295 | pub const SYS_eventfd = 284; | ||
| 296 | pub const SYS_fallocate = 285; | ||
| 297 | pub const SYS_timerfd_settime = 286; | ||
| 298 | pub const SYS_timerfd_gettime = 287; | ||
| 299 | pub const SYS_accept4 = 288; | ||
| 300 | pub const SYS_signalfd4 = 289; | ||
| 301 | pub const SYS_eventfd2 = 290; | ||
| 302 | pub const SYS_epoll_create1 = 291; | ||
| 303 | pub const SYS_dup3 = 292; | ||
| 304 | pub const SYS_pipe2 = 293; | ||
| 305 | pub const SYS_inotify_init1 = 294; | ||
| 306 | pub const SYS_preadv = 295; | ||
| 307 | pub const SYS_pwritev = 296; | ||
| 308 | pub const SYS_rt_tgsigqueueinfo = 297; | ||
| 309 | pub const SYS_perf_event_open = 298; | ||
| 310 | pub const SYS_recvmmsg = 299; | ||
| 311 | pub const SYS_fanotify_init = 300; | ||
| 312 | pub const SYS_fanotify_mark = 301; | ||
| 313 | pub const SYS_prlimit64 = 302; | ||
| 314 | pub const SYS_name_to_handle_at = 303; | ||
| 315 | pub const SYS_open_by_handle_at = 304; | ||
| 316 | pub const SYS_clock_adjtime = 305; | ||
| 317 | pub const SYS_syncfs = 306; | ||
| 318 | pub const SYS_sendmmsg = 307; | ||
| 319 | pub const SYS_setns = 308; | ||
| 320 | pub const SYS_getcpu = 309; | ||
| 321 | pub const SYS_process_vm_readv = 310; | ||
| 322 | pub const SYS_process_vm_writev = 311; | ||
| 323 | pub const SYS_kcmp = 312; | ||
| 324 | pub const SYS_finit_module = 313; | ||
| 325 | pub const SYS_sched_setattr = 314; | ||
| 326 | pub const SYS_sched_getattr = 315; | ||
| 327 | pub const SYS_renameat2 = 316; | ||
| 328 | pub const SYS_seccomp = 317; | ||
| 329 | pub const SYS_getrandom = 318; | ||
| 330 | pub const SYS_memfd_create = 319; | ||
| 331 | pub const SYS_kexec_file_load = 320; | ||
| 332 | pub const SYS_bpf = 321; | ||
| 333 | pub const SYS_execveat = 322; | ||
| 334 | pub const SYS_userfaultfd = 323; | ||
| 335 | pub const SYS_membarrier = 324; | ||
| 336 | pub const SYS_mlock2 = 325; | ||
| 337 | pub const SYS_copy_file_range = 326; | ||
| 338 | pub const SYS_preadv2 = 327; | ||
| 339 | pub const SYS_pwritev2 = 328; | ||
| 340 | pub const SYS_pkey_mprotect = 329; | ||
| 341 | pub const SYS_pkey_alloc = 330; | ||
| 342 | pub const SYS_pkey_free = 331; | ||
| 343 | pub const SYS_statx = 332; | ||
| 344 | pub const SYS_io_pgetevents = 333; | ||
| 345 | pub const SYS_rseq = 334; | ||
| 346 | pub const SYS_pidfd_send_signal = 424; | ||
| 347 | pub const SYS_io_uring_setup = 425; | ||
| 348 | pub const SYS_io_uring_enter = 426; | ||
| 349 | pub const SYS_io_uring_register = 427; | ||
| 350 | |||
| 351 | pub const O_CREAT = 0o100; | ||
| 352 | pub const O_EXCL = 0o200; | ||
| 353 | pub const O_NOCTTY = 0o400; | ||
| 354 | pub const O_TRUNC = 0o1000; | ||
| 355 | pub const O_APPEND = 0o2000; | ||
| 356 | pub const O_NONBLOCK = 0o4000; | ||
| 357 | pub const O_DSYNC = 0o10000; | ||
| 358 | pub const O_SYNC = 0o4010000; | ||
| 359 | pub const O_RSYNC = 0o4010000; | ||
| 360 | pub const O_DIRECTORY = 0o200000; | ||
| 361 | pub const O_NOFOLLOW = 0o400000; | ||
| 362 | pub const O_CLOEXEC = 0o2000000; | ||
| 363 | |||
| 364 | pub const O_ASYNC = 0o20000; | ||
| 365 | pub const O_DIRECT = 0o40000; | ||
| 366 | pub const O_LARGEFILE = 0; | ||
| 367 | pub const O_NOATIME = 0o1000000; | ||
| 368 | pub const O_PATH = 0o10000000; | ||
| 369 | pub const O_TMPFILE = 0o20200000; | ||
| 370 | pub const O_NDELAY = O_NONBLOCK; | ||
| 371 | |||
| 372 | pub const F_DUPFD = 0; | ||
| 373 | pub const F_GETFD = 1; | ||
| 374 | pub const F_SETFD = 2; | ||
| 375 | pub const F_GETFL = 3; | ||
| 376 | pub const F_SETFL = 4; | ||
| 377 | |||
| 378 | pub const F_SETOWN = 8; | ||
| 379 | pub const F_GETOWN = 9; | ||
| 380 | pub const F_SETSIG = 10; | ||
| 381 | pub const F_GETSIG = 11; | ||
| 382 | |||
| 383 | pub const F_GETLK = 5; | ||
| 384 | pub const F_SETLK = 6; | ||
| 385 | pub const F_SETLKW = 7; | ||
| 386 | |||
| 387 | pub const F_SETOWN_EX = 15; | ||
| 388 | pub const F_GETOWN_EX = 16; | ||
| 389 | |||
| 390 | pub const F_GETOWNER_UIDS = 17; | ||
| 391 | |||
| 392 | pub const AT_FDCWD = -100; | ||
| 393 | pub const AT_SYMLINK_NOFOLLOW = 0x100; | ||
| 394 | pub const AT_REMOVEDIR = 0x200; | ||
| 395 | pub const AT_SYMLINK_FOLLOW = 0x400; | ||
| 396 | pub const AT_NO_AUTOMOUNT = 0x800; | ||
| 397 | pub const AT_EMPTY_PATH = 0x1000; | ||
| 398 | |||
| 399 | pub const VDSO_USEFUL = true; | ||
| 400 | pub const VDSO_CGT_SYM = "__vdso_clock_gettime"; | ||
| 401 | pub const VDSO_CGT_VER = "LINUX_2.6"; | ||
| 402 | pub const VDSO_GETCPU_SYM = "__vdso_getcpu"; | ||
| 403 | pub const VDSO_GETCPU_VER = "LINUX_2.6"; | ||
| 404 | |||
| 405 | pub const ARCH_SET_GS = 0x1001; | ||
| 406 | pub const ARCH_SET_FS = 0x1002; | ||
| 407 | pub const ARCH_GET_FS = 0x1003; | ||
| 408 | pub const ARCH_GET_GS = 0x1004; | ||
| 409 | |||
| 410 | pub const msghdr = extern struct { | ||
| 411 | msg_name: ?*sockaddr, | ||
| 412 | msg_namelen: socklen_t, | ||
| 413 | msg_iov: [*]iovec, | ||
| 414 | msg_iovlen: i32, | ||
| 415 | __pad1: i32, | ||
| 416 | msg_control: ?*c_void, | ||
| 417 | msg_controllen: socklen_t, | ||
| 418 | __pad2: socklen_t, | ||
| 419 | msg_flags: i32, | ||
| 420 | }; | ||
| 421 | |||
| 422 | pub const msghdr_const = extern struct { | ||
| 423 | msg_name: ?*const sockaddr, | ||
| 424 | msg_namelen: socklen_t, | ||
| 425 | msg_iov: [*]iovec_const, | ||
| 426 | msg_iovlen: i32, | ||
| 427 | __pad1: i32, | ||
| 428 | msg_control: ?*c_void, | ||
| 429 | msg_controllen: socklen_t, | ||
| 430 | __pad2: socklen_t, | ||
| 431 | msg_flags: i32, | ||
| 432 | }; | ||
| 433 | |||
| 434 | /// Renamed to Stat to not conflict with the stat function. | ||
| 435 | pub const Stat = extern struct { | ||
| 436 | dev: u64, | ||
| 437 | ino: u64, | ||
| 438 | nlink: usize, | ||
| 439 | |||
| 440 | mode: u32, | ||
| 441 | uid: u32, | ||
| 442 | gid: u32, | ||
| 443 | __pad0: u32, | ||
| 444 | rdev: u64, | ||
| 445 | size: i64, | ||
| 446 | blksize: isize, | ||
| 447 | blocks: i64, | ||
| 448 | |||
| 449 | atim: timespec, | ||
| 450 | mtim: timespec, | ||
| 451 | ctim: timespec, | ||
| 452 | __unused: [3]isize, | ||
| 453 | }; | ||
| 454 | |||
| 455 | pub const timespec = extern struct { | ||
| 456 | tv_sec: isize, | ||
| 457 | tv_nsec: isize, | ||
| 458 | }; | ||
| 459 | |||
| 460 | pub const timeval = extern struct { | ||
| 461 | tv_sec: isize, | ||
| 462 | tv_usec: isize, | ||
| 463 | }; | ||
| 464 | |||
| 465 | pub const timezone = extern struct { | ||
| 466 | tz_minuteswest: i32, | ||
| 467 | tz_dsttime: i32, | ||
| 468 | }; | ||
| 469 | |||
| 470 | pub const Elf_Symndx = u32; | ||
std/os/linux/x86_64.zig+1-469| ... | @@ -1,410 +1,4 @@ | ... | @@ -1,410 +1,4 @@ |
| 1 | const std = @import("../../std.zig"); | 1 | use @import("posix/x86_64.zig"); |
| 2 | const linux = std.os.linux; | ||
| 3 | const sockaddr = linux.sockaddr; | ||
| 4 | const socklen_t = linux.socklen_t; | ||
| 5 | const iovec = linux.iovec; | ||
| 6 | const iovec_const = linux.iovec_const; | ||
| 7 | |||
| 8 | pub const SYS_read = 0; | ||
| 9 | pub const SYS_write = 1; | ||
| 10 | pub const SYS_open = 2; | ||
| 11 | pub const SYS_close = 3; | ||
| 12 | pub const SYS_stat = 4; | ||
| 13 | pub const SYS_fstat = 5; | ||
| 14 | pub const SYS_lstat = 6; | ||
| 15 | pub const SYS_poll = 7; | ||
| 16 | pub const SYS_lseek = 8; | ||
| 17 | pub const SYS_mmap = 9; | ||
| 18 | pub const SYS_mprotect = 10; | ||
| 19 | pub const SYS_munmap = 11; | ||
| 20 | pub const SYS_brk = 12; | ||
| 21 | pub const SYS_rt_sigaction = 13; | ||
| 22 | pub const SYS_rt_sigprocmask = 14; | ||
| 23 | pub const SYS_rt_sigreturn = 15; | ||
| 24 | pub const SYS_ioctl = 16; | ||
| 25 | pub const SYS_pread = 17; | ||
| 26 | pub const SYS_pwrite = 18; | ||
| 27 | pub const SYS_readv = 19; | ||
| 28 | pub const SYS_writev = 20; | ||
| 29 | pub const SYS_access = 21; | ||
| 30 | pub const SYS_pipe = 22; | ||
| 31 | pub const SYS_select = 23; | ||
| 32 | pub const SYS_sched_yield = 24; | ||
| 33 | pub const SYS_mremap = 25; | ||
| 34 | pub const SYS_msync = 26; | ||
| 35 | pub const SYS_mincore = 27; | ||
| 36 | pub const SYS_madvise = 28; | ||
| 37 | pub const SYS_shmget = 29; | ||
| 38 | pub const SYS_shmat = 30; | ||
| 39 | pub const SYS_shmctl = 31; | ||
| 40 | pub const SYS_dup = 32; | ||
| 41 | pub const SYS_dup2 = 33; | ||
| 42 | pub const SYS_pause = 34; | ||
| 43 | pub const SYS_nanosleep = 35; | ||
| 44 | pub const SYS_getitimer = 36; | ||
| 45 | pub const SYS_alarm = 37; | ||
| 46 | pub const SYS_setitimer = 38; | ||
| 47 | pub const SYS_getpid = 39; | ||
| 48 | pub const SYS_sendfile = 40; | ||
| 49 | pub const SYS_socket = 41; | ||
| 50 | pub const SYS_connect = 42; | ||
| 51 | pub const SYS_accept = 43; | ||
| 52 | pub const SYS_sendto = 44; | ||
| 53 | pub const SYS_recvfrom = 45; | ||
| 54 | pub const SYS_sendmsg = 46; | ||
| 55 | pub const SYS_recvmsg = 47; | ||
| 56 | pub const SYS_shutdown = 48; | ||
| 57 | pub const SYS_bind = 49; | ||
| 58 | pub const SYS_listen = 50; | ||
| 59 | pub const SYS_getsockname = 51; | ||
| 60 | pub const SYS_getpeername = 52; | ||
| 61 | pub const SYS_socketpair = 53; | ||
| 62 | pub const SYS_setsockopt = 54; | ||
| 63 | pub const SYS_getsockopt = 55; | ||
| 64 | pub const SYS_clone = 56; | ||
| 65 | pub const SYS_fork = 57; | ||
| 66 | pub const SYS_vfork = 58; | ||
| 67 | pub const SYS_execve = 59; | ||
| 68 | pub const SYS_exit = 60; | ||
| 69 | pub const SYS_wait4 = 61; | ||
| 70 | pub const SYS_kill = 62; | ||
| 71 | pub const SYS_uname = 63; | ||
| 72 | pub const SYS_semget = 64; | ||
| 73 | pub const SYS_semop = 65; | ||
| 74 | pub const SYS_semctl = 66; | ||
| 75 | pub const SYS_shmdt = 67; | ||
| 76 | pub const SYS_msgget = 68; | ||
| 77 | pub const SYS_msgsnd = 69; | ||
| 78 | pub const SYS_msgrcv = 70; | ||
| 79 | pub const SYS_msgctl = 71; | ||
| 80 | pub const SYS_fcntl = 72; | ||
| 81 | pub const SYS_flock = 73; | ||
| 82 | pub const SYS_fsync = 74; | ||
| 83 | pub const SYS_fdatasync = 75; | ||
| 84 | pub const SYS_truncate = 76; | ||
| 85 | pub const SYS_ftruncate = 77; | ||
| 86 | pub const SYS_getdents = 78; | ||
| 87 | pub const SYS_getcwd = 79; | ||
| 88 | pub const SYS_chdir = 80; | ||
| 89 | pub const SYS_fchdir = 81; | ||
| 90 | pub const SYS_rename = 82; | ||
| 91 | pub const SYS_mkdir = 83; | ||
| 92 | pub const SYS_rmdir = 84; | ||
| 93 | pub const SYS_creat = 85; | ||
| 94 | pub const SYS_link = 86; | ||
| 95 | pub const SYS_unlink = 87; | ||
| 96 | pub const SYS_symlink = 88; | ||
| 97 | pub const SYS_readlink = 89; | ||
| 98 | pub const SYS_chmod = 90; | ||
| 99 | pub const SYS_fchmod = 91; | ||
| 100 | pub const SYS_chown = 92; | ||
| 101 | pub const SYS_fchown = 93; | ||
| 102 | pub const SYS_lchown = 94; | ||
| 103 | pub const SYS_umask = 95; | ||
| 104 | pub const SYS_gettimeofday = 96; | ||
| 105 | pub const SYS_getrlimit = 97; | ||
| 106 | pub const SYS_getrusage = 98; | ||
| 107 | pub const SYS_sysinfo = 99; | ||
| 108 | pub const SYS_times = 100; | ||
| 109 | pub const SYS_ptrace = 101; | ||
| 110 | pub const SYS_getuid = 102; | ||
| 111 | pub const SYS_syslog = 103; | ||
| 112 | pub const SYS_getgid = 104; | ||
| 113 | pub const SYS_setuid = 105; | ||
| 114 | pub const SYS_setgid = 106; | ||
| 115 | pub const SYS_geteuid = 107; | ||
| 116 | pub const SYS_getegid = 108; | ||
| 117 | pub const SYS_setpgid = 109; | ||
| 118 | pub const SYS_getppid = 110; | ||
| 119 | pub const SYS_getpgrp = 111; | ||
| 120 | pub const SYS_setsid = 112; | ||
| 121 | pub const SYS_setreuid = 113; | ||
| 122 | pub const SYS_setregid = 114; | ||
| 123 | pub const SYS_getgroups = 115; | ||
| 124 | pub const SYS_setgroups = 116; | ||
| 125 | pub const SYS_setresuid = 117; | ||
| 126 | pub const SYS_getresuid = 118; | ||
| 127 | pub const SYS_setresgid = 119; | ||
| 128 | pub const SYS_getresgid = 120; | ||
| 129 | pub const SYS_getpgid = 121; | ||
| 130 | pub const SYS_setfsuid = 122; | ||
| 131 | pub const SYS_setfsgid = 123; | ||
| 132 | pub const SYS_getsid = 124; | ||
| 133 | pub const SYS_capget = 125; | ||
| 134 | pub const SYS_capset = 126; | ||
| 135 | pub const SYS_rt_sigpending = 127; | ||
| 136 | pub const SYS_rt_sigtimedwait = 128; | ||
| 137 | pub const SYS_rt_sigqueueinfo = 129; | ||
| 138 | pub const SYS_rt_sigsuspend = 130; | ||
| 139 | pub const SYS_sigaltstack = 131; | ||
| 140 | pub const SYS_utime = 132; | ||
| 141 | pub const SYS_mknod = 133; | ||
| 142 | pub const SYS_uselib = 134; | ||
| 143 | pub const SYS_personality = 135; | ||
| 144 | pub const SYS_ustat = 136; | ||
| 145 | pub const SYS_statfs = 137; | ||
| 146 | pub const SYS_fstatfs = 138; | ||
| 147 | pub const SYS_sysfs = 139; | ||
| 148 | pub const SYS_getpriority = 140; | ||
| 149 | pub const SYS_setpriority = 141; | ||
| 150 | pub const SYS_sched_setparam = 142; | ||
| 151 | pub const SYS_sched_getparam = 143; | ||
| 152 | pub const SYS_sched_setscheduler = 144; | ||
| 153 | pub const SYS_sched_getscheduler = 145; | ||
| 154 | pub const SYS_sched_get_priority_max = 146; | ||
| 155 | pub const SYS_sched_get_priority_min = 147; | ||
| 156 | pub const SYS_sched_rr_get_interval = 148; | ||
| 157 | pub const SYS_mlock = 149; | ||
| 158 | pub const SYS_munlock = 150; | ||
| 159 | pub const SYS_mlockall = 151; | ||
| 160 | pub const SYS_munlockall = 152; | ||
| 161 | pub const SYS_vhangup = 153; | ||
| 162 | pub const SYS_modify_ldt = 154; | ||
| 163 | pub const SYS_pivot_root = 155; | ||
| 164 | pub const SYS__sysctl = 156; | ||
| 165 | pub const SYS_prctl = 157; | ||
| 166 | pub const SYS_arch_prctl = 158; | ||
| 167 | pub const SYS_adjtimex = 159; | ||
| 168 | pub const SYS_setrlimit = 160; | ||
| 169 | pub const SYS_chroot = 161; | ||
| 170 | pub const SYS_sync = 162; | ||
| 171 | pub const SYS_acct = 163; | ||
| 172 | pub const SYS_settimeofday = 164; | ||
| 173 | pub const SYS_mount = 165; | ||
| 174 | pub const SYS_umount2 = 166; | ||
| 175 | pub const SYS_swapon = 167; | ||
| 176 | pub const SYS_swapoff = 168; | ||
| 177 | pub const SYS_reboot = 169; | ||
| 178 | pub const SYS_sethostname = 170; | ||
| 179 | pub const SYS_setdomainname = 171; | ||
| 180 | pub const SYS_iopl = 172; | ||
| 181 | pub const SYS_ioperm = 173; | ||
| 182 | pub const SYS_create_module = 174; | ||
| 183 | pub const SYS_init_module = 175; | ||
| 184 | pub const SYS_delete_module = 176; | ||
| 185 | pub const SYS_get_kernel_syms = 177; | ||
| 186 | pub const SYS_query_module = 178; | ||
| 187 | pub const SYS_quotactl = 179; | ||
| 188 | pub const SYS_nfsservctl = 180; | ||
| 189 | pub const SYS_getpmsg = 181; | ||
| 190 | pub const SYS_putpmsg = 182; | ||
| 191 | pub const SYS_afs_syscall = 183; | ||
| 192 | pub const SYS_tuxcall = 184; | ||
| 193 | pub const SYS_security = 185; | ||
| 194 | pub const SYS_gettid = 186; | ||
| 195 | pub const SYS_readahead = 187; | ||
| 196 | pub const SYS_setxattr = 188; | ||
| 197 | pub const SYS_lsetxattr = 189; | ||
| 198 | pub const SYS_fsetxattr = 190; | ||
| 199 | pub const SYS_getxattr = 191; | ||
| 200 | pub const SYS_lgetxattr = 192; | ||
| 201 | pub const SYS_fgetxattr = 193; | ||
| 202 | pub const SYS_listxattr = 194; | ||
| 203 | pub const SYS_llistxattr = 195; | ||
| 204 | pub const SYS_flistxattr = 196; | ||
| 205 | pub const SYS_removexattr = 197; | ||
| 206 | pub const SYS_lremovexattr = 198; | ||
| 207 | pub const SYS_fremovexattr = 199; | ||
| 208 | pub const SYS_tkill = 200; | ||
| 209 | pub const SYS_time = 201; | ||
| 210 | pub const SYS_futex = 202; | ||
| 211 | pub const SYS_sched_setaffinity = 203; | ||
| 212 | pub const SYS_sched_getaffinity = 204; | ||
| 213 | pub const SYS_set_thread_area = 205; | ||
| 214 | pub const SYS_io_setup = 206; | ||
| 215 | pub const SYS_io_destroy = 207; | ||
| 216 | pub const SYS_io_getevents = 208; | ||
| 217 | pub const SYS_io_submit = 209; | ||
| 218 | pub const SYS_io_cancel = 210; | ||
| 219 | pub const SYS_get_thread_area = 211; | ||
| 220 | pub const SYS_lookup_dcookie = 212; | ||
| 221 | pub const SYS_epoll_create = 213; | ||
| 222 | pub const SYS_epoll_ctl_old = 214; | ||
| 223 | pub const SYS_epoll_wait_old = 215; | ||
| 224 | pub const SYS_remap_file_pages = 216; | ||
| 225 | pub const SYS_getdents64 = 217; | ||
| 226 | pub const SYS_set_tid_address = 218; | ||
| 227 | pub const SYS_restart_syscall = 219; | ||
| 228 | pub const SYS_semtimedop = 220; | ||
| 229 | pub const SYS_fadvise64 = 221; | ||
| 230 | pub const SYS_timer_create = 222; | ||
| 231 | pub const SYS_timer_settime = 223; | ||
| 232 | pub const SYS_timer_gettime = 224; | ||
| 233 | pub const SYS_timer_getoverrun = 225; | ||
| 234 | pub const SYS_timer_delete = 226; | ||
| 235 | pub const SYS_clock_settime = 227; | ||
| 236 | pub const SYS_clock_gettime = 228; | ||
| 237 | pub const SYS_clock_getres = 229; | ||
| 238 | pub const SYS_clock_nanosleep = 230; | ||
| 239 | pub const SYS_exit_group = 231; | ||
| 240 | pub const SYS_epoll_wait = 232; | ||
| 241 | pub const SYS_epoll_ctl = 233; | ||
| 242 | pub const SYS_tgkill = 234; | ||
| 243 | pub const SYS_utimes = 235; | ||
| 244 | pub const SYS_vserver = 236; | ||
| 245 | pub const SYS_mbind = 237; | ||
| 246 | pub const SYS_set_mempolicy = 238; | ||
| 247 | pub const SYS_get_mempolicy = 239; | ||
| 248 | pub const SYS_mq_open = 240; | ||
| 249 | pub const SYS_mq_unlink = 241; | ||
| 250 | pub const SYS_mq_timedsend = 242; | ||
| 251 | pub const SYS_mq_timedreceive = 243; | ||
| 252 | pub const SYS_mq_notify = 244; | ||
| 253 | pub const SYS_mq_getsetattr = 245; | ||
| 254 | pub const SYS_kexec_load = 246; | ||
| 255 | pub const SYS_waitid = 247; | ||
| 256 | pub const SYS_add_key = 248; | ||
| 257 | pub const SYS_request_key = 249; | ||
| 258 | pub const SYS_keyctl = 250; | ||
| 259 | pub const SYS_ioprio_set = 251; | ||
| 260 | pub const SYS_ioprio_get = 252; | ||
| 261 | pub const SYS_inotify_init = 253; | ||
| 262 | pub const SYS_inotify_add_watch = 254; | ||
| 263 | pub const SYS_inotify_rm_watch = 255; | ||
| 264 | pub const SYS_migrate_pages = 256; | ||
| 265 | pub const SYS_openat = 257; | ||
| 266 | pub const SYS_mkdirat = 258; | ||
| 267 | pub const SYS_mknodat = 259; | ||
| 268 | pub const SYS_fchownat = 260; | ||
| 269 | pub const SYS_futimesat = 261; | ||
| 270 | pub const SYS_newfstatat = 262; | ||
| 271 | // https://github.com/ziglang/zig/issues/1439 | ||
| 272 | pub const SYS_fstatat = 262; | ||
| 273 | pub const SYS_unlinkat = 263; | ||
| 274 | pub const SYS_renameat = 264; | ||
| 275 | pub const SYS_linkat = 265; | ||
| 276 | pub const SYS_symlinkat = 266; | ||
| 277 | pub const SYS_readlinkat = 267; | ||
| 278 | pub const SYS_fchmodat = 268; | ||
| 279 | pub const SYS_faccessat = 269; | ||
| 280 | pub const SYS_pselect6 = 270; | ||
| 281 | pub const SYS_ppoll = 271; | ||
| 282 | pub const SYS_unshare = 272; | ||
| 283 | pub const SYS_set_robust_list = 273; | ||
| 284 | pub const SYS_get_robust_list = 274; | ||
| 285 | pub const SYS_splice = 275; | ||
| 286 | pub const SYS_tee = 276; | ||
| 287 | pub const SYS_sync_file_range = 277; | ||
| 288 | pub const SYS_vmsplice = 278; | ||
| 289 | pub const SYS_move_pages = 279; | ||
| 290 | pub const SYS_utimensat = 280; | ||
| 291 | pub const SYS_epoll_pwait = 281; | ||
| 292 | pub const SYS_signalfd = 282; | ||
| 293 | pub const SYS_timerfd_create = 283; | ||
| 294 | pub const SYS_eventfd = 284; | ||
| 295 | pub const SYS_fallocate = 285; | ||
| 296 | pub const SYS_timerfd_settime = 286; | ||
| 297 | pub const SYS_timerfd_gettime = 287; | ||
| 298 | pub const SYS_accept4 = 288; | ||
| 299 | pub const SYS_signalfd4 = 289; | ||
| 300 | pub const SYS_eventfd2 = 290; | ||
| 301 | pub const SYS_epoll_create1 = 291; | ||
| 302 | pub const SYS_dup3 = 292; | ||
| 303 | pub const SYS_pipe2 = 293; | ||
| 304 | pub const SYS_inotify_init1 = 294; | ||
| 305 | pub const SYS_preadv = 295; | ||
| 306 | pub const SYS_pwritev = 296; | ||
| 307 | pub const SYS_rt_tgsigqueueinfo = 297; | ||
| 308 | pub const SYS_perf_event_open = 298; | ||
| 309 | pub const SYS_recvmmsg = 299; | ||
| 310 | pub const SYS_fanotify_init = 300; | ||
| 311 | pub const SYS_fanotify_mark = 301; | ||
| 312 | pub const SYS_prlimit64 = 302; | ||
| 313 | pub const SYS_name_to_handle_at = 303; | ||
| 314 | pub const SYS_open_by_handle_at = 304; | ||
| 315 | pub const SYS_clock_adjtime = 305; | ||
| 316 | pub const SYS_syncfs = 306; | ||
| 317 | pub const SYS_sendmmsg = 307; | ||
| 318 | pub const SYS_setns = 308; | ||
| 319 | pub const SYS_getcpu = 309; | ||
| 320 | pub const SYS_process_vm_readv = 310; | ||
| 321 | pub const SYS_process_vm_writev = 311; | ||
| 322 | pub const SYS_kcmp = 312; | ||
| 323 | pub const SYS_finit_module = 313; | ||
| 324 | pub const SYS_sched_setattr = 314; | ||
| 325 | pub const SYS_sched_getattr = 315; | ||
| 326 | pub const SYS_renameat2 = 316; | ||
| 327 | pub const SYS_seccomp = 317; | ||
| 328 | pub const SYS_getrandom = 318; | ||
| 329 | pub const SYS_memfd_create = 319; | ||
| 330 | pub const SYS_kexec_file_load = 320; | ||
| 331 | pub const SYS_bpf = 321; | ||
| 332 | pub const SYS_execveat = 322; | ||
| 333 | pub const SYS_userfaultfd = 323; | ||
| 334 | pub const SYS_membarrier = 324; | ||
| 335 | pub const SYS_mlock2 = 325; | ||
| 336 | pub const SYS_copy_file_range = 326; | ||
| 337 | pub const SYS_preadv2 = 327; | ||
| 338 | pub const SYS_pwritev2 = 328; | ||
| 339 | pub const SYS_pkey_mprotect = 329; | ||
| 340 | pub const SYS_pkey_alloc = 330; | ||
| 341 | pub const SYS_pkey_free = 331; | ||
| 342 | pub const SYS_statx = 332; | ||
| 343 | pub const SYS_io_pgetevents = 333; | ||
| 344 | pub const SYS_rseq = 334; | ||
| 345 | pub const SYS_pidfd_send_signal = 424; | ||
| 346 | pub const SYS_io_uring_setup = 425; | ||
| 347 | pub const SYS_io_uring_enter = 426; | ||
| 348 | pub const SYS_io_uring_register = 427; | ||
| 349 | |||
| 350 | pub const O_CREAT = 0o100; | ||
| 351 | pub const O_EXCL = 0o200; | ||
| 352 | pub const O_NOCTTY = 0o400; | ||
| 353 | pub const O_TRUNC = 0o1000; | ||
| 354 | pub const O_APPEND = 0o2000; | ||
| 355 | pub const O_NONBLOCK = 0o4000; | ||
| 356 | pub const O_DSYNC = 0o10000; | ||
| 357 | pub const O_SYNC = 0o4010000; | ||
| 358 | pub const O_RSYNC = 0o4010000; | ||
| 359 | pub const O_DIRECTORY = 0o200000; | ||
| 360 | pub const O_NOFOLLOW = 0o400000; | ||
| 361 | pub const O_CLOEXEC = 0o2000000; | ||
| 362 | |||
| 363 | pub const O_ASYNC = 0o20000; | ||
| 364 | pub const O_DIRECT = 0o40000; | ||
| 365 | pub const O_LARGEFILE = 0; | ||
| 366 | pub const O_NOATIME = 0o1000000; | ||
| 367 | pub const O_PATH = 0o10000000; | ||
| 368 | pub const O_TMPFILE = 0o20200000; | ||
| 369 | pub const O_NDELAY = O_NONBLOCK; | ||
| 370 | |||
| 371 | pub const F_DUPFD = 0; | ||
| 372 | pub const F_GETFD = 1; | ||
| 373 | pub const F_SETFD = 2; | ||
| 374 | pub const F_GETFL = 3; | ||
| 375 | pub const F_SETFL = 4; | ||
| 376 | |||
| 377 | pub const F_SETOWN = 8; | ||
| 378 | pub const F_GETOWN = 9; | ||
| 379 | pub const F_SETSIG = 10; | ||
| 380 | pub const F_GETSIG = 11; | ||
| 381 | |||
| 382 | pub const F_GETLK = 5; | ||
| 383 | pub const F_SETLK = 6; | ||
| 384 | pub const F_SETLKW = 7; | ||
| 385 | |||
| 386 | pub const F_SETOWN_EX = 15; | ||
| 387 | pub const F_GETOWN_EX = 16; | ||
| 388 | |||
| 389 | pub const F_GETOWNER_UIDS = 17; | ||
| 390 | |||
| 391 | pub const AT_FDCWD = -100; | ||
| 392 | pub const AT_SYMLINK_NOFOLLOW = 0x100; | ||
| 393 | pub const AT_REMOVEDIR = 0x200; | ||
| 394 | pub const AT_SYMLINK_FOLLOW = 0x400; | ||
| 395 | pub const AT_NO_AUTOMOUNT = 0x800; | ||
| 396 | pub const AT_EMPTY_PATH = 0x1000; | ||
| 397 | |||
| 398 | pub const VDSO_USEFUL = true; | ||
| 399 | pub const VDSO_CGT_SYM = "__vdso_clock_gettime"; | ||
| 400 | pub const VDSO_CGT_VER = "LINUX_2.6"; | ||
| 401 | pub const VDSO_GETCPU_SYM = "__vdso_getcpu"; | ||
| 402 | pub const VDSO_GETCPU_VER = "LINUX_2.6"; | ||
| 403 | |||
| 404 | pub const ARCH_SET_GS = 0x1001; | ||
| 405 | pub const ARCH_SET_FS = 0x1002; | ||
| 406 | pub const ARCH_GET_FS = 0x1003; | ||
| 407 | pub const ARCH_GET_GS = 0x1004; | ||
| 408 | 2 | ||
| 409 | pub fn syscall0(number: usize) usize { | 3 | pub fn syscall0(number: usize) usize { |
| 410 | return asm volatile ("syscall" | 4 | return asm volatile ("syscall" |
| ... | @@ -501,65 +95,3 @@ pub nakedcc fn restore_rt() void { | ... | @@ -501,65 +95,3 @@ pub nakedcc fn restore_rt() void { |
| 501 | : "rcx", "r11" | 95 | : "rcx", "r11" |
| 502 | ); | 96 | ); |
| 503 | } | 97 | } |
| 504 | |||
| 505 | pub const msghdr = extern struct { | ||
| 506 | msg_name: ?*sockaddr, | ||
| 507 | msg_namelen: socklen_t, | ||
| 508 | msg_iov: [*]iovec, | ||
| 509 | msg_iovlen: i32, | ||
| 510 | __pad1: i32, | ||
| 511 | msg_control: ?*c_void, | ||
| 512 | msg_controllen: socklen_t, | ||
| 513 | __pad2: socklen_t, | ||
| 514 | msg_flags: i32, | ||
| 515 | }; | ||
| 516 | |||
| 517 | pub const msghdr_const = extern struct { | ||
| 518 | msg_name: ?*const sockaddr, | ||
| 519 | msg_namelen: socklen_t, | ||
| 520 | msg_iov: [*]iovec_const, | ||
| 521 | msg_iovlen: i32, | ||
| 522 | __pad1: i32, | ||
| 523 | msg_control: ?*c_void, | ||
| 524 | msg_controllen: socklen_t, | ||
| 525 | __pad2: socklen_t, | ||
| 526 | msg_flags: i32, | ||
| 527 | }; | ||
| 528 | |||
| 529 | /// Renamed to Stat to not conflict with the stat function. | ||
| 530 | pub const Stat = extern struct { | ||
| 531 | dev: u64, | ||
| 532 | ino: u64, | ||
| 533 | nlink: usize, | ||
| 534 | |||
| 535 | mode: u32, | ||
| 536 | uid: u32, | ||
| 537 | gid: u32, | ||
| 538 | __pad0: u32, | ||
| 539 | rdev: u64, | ||
| 540 | size: i64, | ||
| 541 | blksize: isize, | ||
| 542 | blocks: i64, | ||
| 543 | |||
| 544 | atim: timespec, | ||
| 545 | mtim: timespec, | ||
| 546 | ctim: timespec, | ||
| 547 | __unused: [3]isize, | ||
| 548 | }; | ||
| 549 | |||
| 550 | pub const timespec = extern struct { | ||
| 551 | tv_sec: isize, | ||
| 552 | tv_nsec: isize, | ||
| 553 | }; | ||
| 554 | |||
| 555 | pub const timeval = extern struct { | ||
| 556 | tv_sec: isize, | ||
| 557 | tv_usec: isize, | ||
| 558 | }; | ||
| 559 | |||
| 560 | pub const timezone = extern struct { | ||
| 561 | tz_minuteswest: i32, | ||
| 562 | tz_dsttime: i32, | ||
| 563 | }; | ||
| 564 | |||
| 565 | pub const Elf_Symndx = u32; |
std/os/netbsd.zig+2-722| ... | @@ -1,724 +1,4 @@ | ... | @@ -1,724 +1,4 @@ |
| 1 | const builtin = @import("builtin"); | 1 | const builtin = @import("builtin"); |
| 2 | |||
| 3 | pub use @import("netbsd/errno.zig"); | ||
| 4 | |||
| 5 | const std = @import("../std.zig"); | 2 | const std = @import("../std.zig"); |
| 6 | const c = std.c; | 3 | pub const is_the_target = builtin.os == .netbsd; |
| 7 | 4 | pub use std.c; | |
| 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 | pub const O_RDONLY = 0x0000; | ||
| 114 | pub const O_WRONLY = 0x0001; | ||
| 115 | pub const O_RDWR = 0x0002; | ||
| 116 | pub const O_ACCMODE = 0x0003; | ||
| 117 | |||
| 118 | pub const O_CREAT = 0x0200; | ||
| 119 | pub const O_EXCL = 0x0800; | ||
| 120 | pub const O_NOCTTY = 0x8000; | ||
| 121 | pub const O_TRUNC = 0x0400; | ||
| 122 | pub const O_APPEND = 0x0008; | ||
| 123 | pub const O_NONBLOCK = 0x0004; | ||
| 124 | pub const O_DSYNC = 0x00010000; | ||
| 125 | pub const O_SYNC = 0x0080; | ||
| 126 | pub const O_RSYNC = 0x00020000; | ||
| 127 | pub const O_DIRECTORY = 0x00080000; | ||
| 128 | pub const O_NOFOLLOW = 0x00000100; | ||
| 129 | pub const O_CLOEXEC = 0x00400000; | ||
| 130 | |||
| 131 | pub const O_ASYNC = 0x0040; | ||
| 132 | pub const O_DIRECT = 0x00080000; | ||
| 133 | pub const O_LARGEFILE = 0; | ||
| 134 | pub const O_NOATIME = 0; | ||
| 135 | pub const O_PATH = 0; | ||
| 136 | pub const O_TMPFILE = 0; | ||
| 137 | pub const O_NDELAY = O_NONBLOCK; | ||
| 138 | |||
| 139 | pub const F_DUPFD = 0; | ||
| 140 | pub const F_GETFD = 1; | ||
| 141 | pub const F_SETFD = 2; | ||
| 142 | pub const F_GETFL = 3; | ||
| 143 | pub const F_SETFL = 4; | ||
| 144 | |||
| 145 | pub const F_GETOWN = 5; | ||
| 146 | pub const F_SETOWN = 6; | ||
| 147 | |||
| 148 | pub const F_GETLK = 7; | ||
| 149 | pub const F_SETLK = 8; | ||
| 150 | pub const F_SETLKW = 9; | ||
| 151 | |||
| 152 | pub const SEEK_SET = 0; | ||
| 153 | pub const SEEK_CUR = 1; | ||
| 154 | pub const SEEK_END = 2; | ||
| 155 | |||
| 156 | pub const SIG_BLOCK = 1; | ||
| 157 | pub const SIG_UNBLOCK = 2; | ||
| 158 | pub const SIG_SETMASK = 3; | ||
| 159 | |||
| 160 | pub const SOCK_STREAM = 1; | ||
| 161 | pub const SOCK_DGRAM = 2; | ||
| 162 | pub const SOCK_RAW = 3; | ||
| 163 | pub const SOCK_RDM = 4; | ||
| 164 | pub const SOCK_SEQPACKET = 5; | ||
| 165 | |||
| 166 | pub const SOCK_CLOEXEC = 0x10000000; | ||
| 167 | pub const SOCK_NONBLOCK = 0x20000000; | ||
| 168 | |||
| 169 | pub const PROTO_ip = 0; | ||
| 170 | pub const PROTO_icmp = 1; | ||
| 171 | pub const PROTO_igmp = 2; | ||
| 172 | pub const PROTO_ggp = 3; | ||
| 173 | pub const PROTO_ipencap = 4; | ||
| 174 | pub const PROTO_tcp = 6; | ||
| 175 | pub const PROTO_egp = 8; | ||
| 176 | pub const PROTO_pup = 12; | ||
| 177 | pub const PROTO_udp = 17; | ||
| 178 | pub const PROTO_xns_idp = 22; | ||
| 179 | pub const PROTO_iso_tp4 = 29; | ||
| 180 | pub const PROTO_ipv6 = 41; | ||
| 181 | pub const PROTO_ipv6_route = 43; | ||
| 182 | pub const PROTO_ipv6_frag = 44; | ||
| 183 | pub const PROTO_rsvp = 46; | ||
| 184 | pub const PROTO_gre = 47; | ||
| 185 | pub const PROTO_esp = 50; | ||
| 186 | pub const PROTO_ah = 51; | ||
| 187 | pub const PROTO_ipv6_icmp = 58; | ||
| 188 | pub const PROTO_ipv6_nonxt = 59; | ||
| 189 | pub const PROTO_ipv6_opts = 60; | ||
| 190 | pub const PROTO_encap = 98; | ||
| 191 | pub const PROTO_pim = 103; | ||
| 192 | pub const PROTO_raw = 255; | ||
| 193 | |||
| 194 | pub const PF_UNSPEC = 0; | ||
| 195 | pub const PF_LOCAL = 1; | ||
| 196 | pub const PF_UNIX = PF_LOCAL; | ||
| 197 | pub const PF_FILE = PF_LOCAL; | ||
| 198 | pub const PF_INET = 2; | ||
| 199 | pub const PF_APPLETALK = 16; | ||
| 200 | pub const PF_INET6 = 24; | ||
| 201 | pub const PF_DECnet = 12; | ||
| 202 | pub const PF_KEY = 29; | ||
| 203 | pub const PF_ROUTE = 34; | ||
| 204 | pub const PF_SNA = 11; | ||
| 205 | pub const PF_MPLS = 33; | ||
| 206 | pub const PF_CAN = 35; | ||
| 207 | pub const PF_BLUETOOTH = 31; | ||
| 208 | pub const PF_ISDN = 26; | ||
| 209 | pub const PF_MAX = 37; | ||
| 210 | |||
| 211 | pub const AF_UNSPEC = PF_UNSPEC; | ||
| 212 | pub const AF_LOCAL = PF_LOCAL; | ||
| 213 | pub const AF_UNIX = AF_LOCAL; | ||
| 214 | pub const AF_FILE = AF_LOCAL; | ||
| 215 | pub const AF_INET = PF_INET; | ||
| 216 | pub const AF_APPLETALK = PF_APPLETALK; | ||
| 217 | pub const AF_INET6 = PF_INET6; | ||
| 218 | pub const AF_KEY = PF_KEY; | ||
| 219 | pub const AF_ROUTE = PF_ROUTE; | ||
| 220 | pub const AF_SNA = PF_SNA; | ||
| 221 | pub const AF_MPLS = PF_MPLS; | ||
| 222 | pub const AF_CAN = PF_CAN; | ||
| 223 | pub const AF_BLUETOOTH = PF_BLUETOOTH; | ||
| 224 | pub const AF_ISDN = PF_ISDN; | ||
| 225 | pub const AF_MAX = PF_MAX; | ||
| 226 | |||
| 227 | pub const DT_UNKNOWN = 0; | ||
| 228 | pub const DT_FIFO = 1; | ||
| 229 | pub const DT_CHR = 2; | ||
| 230 | pub const DT_DIR = 4; | ||
| 231 | pub const DT_BLK = 6; | ||
| 232 | pub const DT_REG = 8; | ||
| 233 | pub const DT_LNK = 10; | ||
| 234 | pub const DT_SOCK = 12; | ||
| 235 | pub const DT_WHT = 14; | ||
| 236 | |||
| 237 | /// add event to kq (implies enable) | ||
| 238 | pub const EV_ADD = 0x0001; | ||
| 239 | |||
| 240 | /// delete event from kq | ||
| 241 | pub const EV_DELETE = 0x0002; | ||
| 242 | |||
| 243 | /// enable event | ||
| 244 | pub const EV_ENABLE = 0x0004; | ||
| 245 | |||
| 246 | /// disable event (not reported) | ||
| 247 | pub const EV_DISABLE = 0x0008; | ||
| 248 | |||
| 249 | /// only report one occurrence | ||
| 250 | pub const EV_ONESHOT = 0x0010; | ||
| 251 | |||
| 252 | /// clear event state after reporting | ||
| 253 | pub const EV_CLEAR = 0x0020; | ||
| 254 | |||
| 255 | /// force immediate event output | ||
| 256 | /// ... with or without EV_ERROR | ||
| 257 | /// ... use KEVENT_FLAG_ERROR_EVENTS | ||
| 258 | /// on syscalls supporting flags | ||
| 259 | pub const EV_RECEIPT = 0x0040; | ||
| 260 | |||
| 261 | /// disable event after reporting | ||
| 262 | pub const EV_DISPATCH = 0x0080; | ||
| 263 | |||
| 264 | pub const EVFILT_READ = 0; | ||
| 265 | pub const EVFILT_WRITE = 1; | ||
| 266 | |||
| 267 | /// attached to aio requests | ||
| 268 | pub const EVFILT_AIO = 2; | ||
| 269 | |||
| 270 | /// attached to vnodes | ||
| 271 | pub const EVFILT_VNODE = 3; | ||
| 272 | |||
| 273 | /// attached to struct proc | ||
| 274 | pub const EVFILT_PROC = 4; | ||
| 275 | |||
| 276 | /// attached to struct proc | ||
| 277 | pub const EVFILT_SIGNAL = 5; | ||
| 278 | |||
| 279 | /// timers | ||
| 280 | pub const EVFILT_TIMER = 6; | ||
| 281 | |||
| 282 | /// Filesystem events | ||
| 283 | pub const EVFILT_FS = 7; | ||
| 284 | |||
| 285 | /// On input, NOTE_TRIGGER causes the event to be triggered for output. | ||
| 286 | pub const NOTE_TRIGGER = 0x08000000; | ||
| 287 | |||
| 288 | /// low water mark | ||
| 289 | pub const NOTE_LOWAT = 0x00000001; | ||
| 290 | |||
| 291 | /// vnode was removed | ||
| 292 | pub const NOTE_DELETE = 0x00000001; | ||
| 293 | |||
| 294 | /// data contents changed | ||
| 295 | pub const NOTE_WRITE = 0x00000002; | ||
| 296 | |||
| 297 | /// size increased | ||
| 298 | pub const NOTE_EXTEND = 0x00000004; | ||
| 299 | |||
| 300 | /// attributes changed | ||
| 301 | pub const NOTE_ATTRIB = 0x00000008; | ||
| 302 | |||
| 303 | /// link count changed | ||
| 304 | pub const NOTE_LINK = 0x00000010; | ||
| 305 | |||
| 306 | /// vnode was renamed | ||
| 307 | pub const NOTE_RENAME = 0x00000020; | ||
| 308 | |||
| 309 | /// vnode access was revoked | ||
| 310 | pub const NOTE_REVOKE = 0x00000040; | ||
| 311 | |||
| 312 | /// process exited | ||
| 313 | pub const NOTE_EXIT = 0x80000000; | ||
| 314 | |||
| 315 | /// process forked | ||
| 316 | pub const NOTE_FORK = 0x40000000; | ||
| 317 | |||
| 318 | /// process exec'd | ||
| 319 | pub const NOTE_EXEC = 0x20000000; | ||
| 320 | |||
| 321 | /// mask for signal & exit status | ||
| 322 | pub const NOTE_PDATAMASK = 0x000fffff; | ||
| 323 | pub const NOTE_PCTRLMASK = 0xf0000000; | ||
| 324 | |||
| 325 | pub const TIOCCBRK = 0x2000747a; | ||
| 326 | pub const TIOCCDTR = 0x20007478; | ||
| 327 | pub const TIOCCONS = 0x80047462; | ||
| 328 | pub const TIOCDCDTIMESTAMP = 0x40107458; | ||
| 329 | pub const TIOCDRAIN = 0x2000745e; | ||
| 330 | pub const TIOCEXCL = 0x2000740d; | ||
| 331 | pub const TIOCEXT = 0x80047460; | ||
| 332 | pub const TIOCFLAG_CDTRCTS = 0x10; | ||
| 333 | pub const TIOCFLAG_CLOCAL = 0x2; | ||
| 334 | pub const TIOCFLAG_CRTSCTS = 0x4; | ||
| 335 | pub const TIOCFLAG_MDMBUF = 0x8; | ||
| 336 | pub const TIOCFLAG_SOFTCAR = 0x1; | ||
| 337 | pub const TIOCFLUSH = 0x80047410; | ||
| 338 | pub const TIOCGETA = 0x402c7413; | ||
| 339 | pub const TIOCGETD = 0x4004741a; | ||
| 340 | pub const TIOCGFLAGS = 0x4004745d; | ||
| 341 | pub const TIOCGLINED = 0x40207442; | ||
| 342 | pub const TIOCGPGRP = 0x40047477; | ||
| 343 | pub const TIOCGQSIZE = 0x40047481; | ||
| 344 | pub const TIOCGRANTPT = 0x20007447; | ||
| 345 | pub const TIOCGSID = 0x40047463; | ||
| 346 | pub const TIOCGSIZE = 0x40087468; | ||
| 347 | pub const TIOCGWINSZ = 0x40087468; | ||
| 348 | pub const TIOCMBIC = 0x8004746b; | ||
| 349 | pub const TIOCMBIS = 0x8004746c; | ||
| 350 | pub const TIOCMGET = 0x4004746a; | ||
| 351 | pub const TIOCMSET = 0x8004746d; | ||
| 352 | pub const TIOCM_CAR = 0x40; | ||
| 353 | pub const TIOCM_CD = 0x40; | ||
| 354 | pub const TIOCM_CTS = 0x20; | ||
| 355 | pub const TIOCM_DSR = 0x100; | ||
| 356 | pub const TIOCM_DTR = 0x2; | ||
| 357 | pub const TIOCM_LE = 0x1; | ||
| 358 | pub const TIOCM_RI = 0x80; | ||
| 359 | pub const TIOCM_RNG = 0x80; | ||
| 360 | pub const TIOCM_RTS = 0x4; | ||
| 361 | pub const TIOCM_SR = 0x10; | ||
| 362 | pub const TIOCM_ST = 0x8; | ||
| 363 | pub const TIOCNOTTY = 0x20007471; | ||
| 364 | pub const TIOCNXCL = 0x2000740e; | ||
| 365 | pub const TIOCOUTQ = 0x40047473; | ||
| 366 | pub const TIOCPKT = 0x80047470; | ||
| 367 | pub const TIOCPKT_DATA = 0x0; | ||
| 368 | pub const TIOCPKT_DOSTOP = 0x20; | ||
| 369 | pub const TIOCPKT_FLUSHREAD = 0x1; | ||
| 370 | pub const TIOCPKT_FLUSHWRITE = 0x2; | ||
| 371 | pub const TIOCPKT_IOCTL = 0x40; | ||
| 372 | pub const TIOCPKT_NOSTOP = 0x10; | ||
| 373 | pub const TIOCPKT_START = 0x8; | ||
| 374 | pub const TIOCPKT_STOP = 0x4; | ||
| 375 | pub const TIOCPTMGET = 0x40287446; | ||
| 376 | pub const TIOCPTSNAME = 0x40287448; | ||
| 377 | pub const TIOCRCVFRAME = 0x80087445; | ||
| 378 | pub const TIOCREMOTE = 0x80047469; | ||
| 379 | pub const TIOCSBRK = 0x2000747b; | ||
| 380 | pub const TIOCSCTTY = 0x20007461; | ||
| 381 | pub const TIOCSDTR = 0x20007479; | ||
| 382 | pub const TIOCSETA = 0x802c7414; | ||
| 383 | pub const TIOCSETAF = 0x802c7416; | ||
| 384 | pub const TIOCSETAW = 0x802c7415; | ||
| 385 | pub const TIOCSETD = 0x8004741b; | ||
| 386 | pub const TIOCSFLAGS = 0x8004745c; | ||
| 387 | pub const TIOCSIG = 0x2000745f; | ||
| 388 | pub const TIOCSLINED = 0x80207443; | ||
| 389 | pub const TIOCSPGRP = 0x80047476; | ||
| 390 | pub const TIOCSQSIZE = 0x80047480; | ||
| 391 | pub const TIOCSSIZE = 0x80087467; | ||
| 392 | pub const TIOCSTART = 0x2000746e; | ||
| 393 | pub const TIOCSTAT = 0x80047465; | ||
| 394 | pub const TIOCSTI = 0x80017472; | ||
| 395 | pub const TIOCSTOP = 0x2000746f; | ||
| 396 | pub const TIOCSWINSZ = 0x80087467; | ||
| 397 | pub const TIOCUCNTL = 0x80047466; | ||
| 398 | pub const TIOCXMTFRAME = 0x80087444; | ||
| 399 | |||
| 400 | pub const sockaddr = c.sockaddr; | ||
| 401 | pub const sockaddr_in = c.sockaddr_in; | ||
| 402 | pub const sockaddr_in6 = c.sockaddr_in6; | ||
| 403 | |||
| 404 | fn unsigned(s: i32) u32 { | ||
| 405 | return @bitCast(u32, s); | ||
| 406 | } | ||
| 407 | fn signed(s: u32) i32 { | ||
| 408 | return @bitCast(i32, s); | ||
| 409 | } | ||
| 410 | pub fn WEXITSTATUS(s: i32) i32 { | ||
| 411 | return signed((unsigned(s) >> 8) & 0xff); | ||
| 412 | } | ||
| 413 | pub fn WTERMSIG(s: i32) i32 { | ||
| 414 | return signed(unsigned(s) & 0x7f); | ||
| 415 | } | ||
| 416 | pub fn WSTOPSIG(s: i32) i32 { | ||
| 417 | return WEXITSTATUS(s); | ||
| 418 | } | ||
| 419 | pub fn WIFEXITED(s: i32) bool { | ||
| 420 | return WTERMSIG(s) == 0; | ||
| 421 | } | ||
| 422 | |||
| 423 | pub fn WIFCONTINUED(s: i32) bool { | ||
| 424 | return ((s & 0x7f) == 0xffff); | ||
| 425 | } | ||
| 426 | |||
| 427 | pub fn WIFSTOPPED(s: i32) bool { | ||
| 428 | return ((s & 0x7f != 0x7f) and !WIFCONTINUED(s)); | ||
| 429 | } | ||
| 430 | |||
| 431 | pub fn WIFSIGNALED(s: i32) bool { | ||
| 432 | return !WIFSTOPPED(s) and !WIFCONTINUED(s) and !WIFEXITED(s); | ||
| 433 | } | ||
| 434 | |||
| 435 | pub const winsize = extern struct { | ||
| 436 | ws_row: u16, | ||
| 437 | ws_col: u16, | ||
| 438 | ws_xpixel: u16, | ||
| 439 | ws_ypixel: u16, | ||
| 440 | }; | ||
| 441 | |||
| 442 | /// Get the errno from a syscall return value, or 0 for no error. | ||
| 443 | pub fn getErrno(r: usize) usize { | ||
| 444 | const signed_r = @bitCast(isize, r); | ||
| 445 | return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0; | ||
| 446 | } | ||
| 447 | |||
| 448 | pub fn dup2(old: i32, new: i32) usize { | ||
| 449 | return errnoWrap(c.dup2(old, new)); | ||
| 450 | } | ||
| 451 | |||
| 452 | pub fn chdir(path: [*]const u8) usize { | ||
| 453 | return errnoWrap(c.chdir(path)); | ||
| 454 | } | ||
| 455 | |||
| 456 | pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize { | ||
| 457 | return errnoWrap(c.execve(path, argv, envp)); | ||
| 458 | } | ||
| 459 | |||
| 460 | pub fn fork() usize { | ||
| 461 | return errnoWrap(c.fork()); | ||
| 462 | } | ||
| 463 | |||
| 464 | pub fn access(path: [*]const u8, mode: u32) usize { | ||
| 465 | return errnoWrap(c.access(path, mode)); | ||
| 466 | } | ||
| 467 | |||
| 468 | pub fn getcwd(buf: [*]u8, size: usize) usize { | ||
| 469 | return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0; | ||
| 470 | } | ||
| 471 | |||
| 472 | pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { | ||
| 473 | return errnoWrap(@bitCast(isize, c.getdents(fd, drip, count))); | ||
| 474 | } | ||
| 475 | |||
| 476 | pub fn getdirentries(fd: i32, buf_ptr: [*]u8, buf_len: usize, basep: *i64) usize { | ||
| 477 | return errnoWrap(@bitCast(isize, c.getdirentries(fd, buf_ptr, buf_len, basep))); | ||
| 478 | } | ||
| 479 | |||
| 480 | pub fn realpath(noalias filename: [*]const u8, noalias resolved_name: [*]u8) usize { | ||
| 481 | return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(c._errno().*)) else 0; | ||
| 482 | } | ||
| 483 | |||
| 484 | pub fn isatty(fd: i32) bool { | ||
| 485 | return c.isatty(fd) != 0; | ||
| 486 | } | ||
| 487 | |||
| 488 | pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { | ||
| 489 | return errnoWrap(c.readlink(path, buf_ptr, buf_len)); | ||
| 490 | } | ||
| 491 | |||
| 492 | pub fn mkdir(path: [*]const u8, mode: u32) usize { | ||
| 493 | return errnoWrap(c.mkdir(path, mode)); | ||
| 494 | } | ||
| 495 | |||
| 496 | pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize { | ||
| 497 | const ptr_result = c.mmap( | ||
| 498 | @ptrCast(?*c_void, address), | ||
| 499 | length, | ||
| 500 | @bitCast(c_int, @intCast(c_uint, prot)), | ||
| 501 | @bitCast(c_int, c_uint(flags)), | ||
| 502 | fd, | ||
| 503 | offset, | ||
| 504 | ); | ||
| 505 | const isize_result = @bitCast(isize, @ptrToInt(ptr_result)); | ||
| 506 | return errnoWrap(isize_result); | ||
| 507 | } | ||
| 508 | |||
| 509 | pub fn munmap(address: usize, length: usize) usize { | ||
| 510 | return errnoWrap(c.munmap(@intToPtr(*c_void, address), length)); | ||
| 511 | } | ||
| 512 | |||
| 513 | pub fn read(fd: i32, buf: [*]u8, nbyte: usize) usize { | ||
| 514 | return errnoWrap(c.read(fd, @ptrCast(*c_void, buf), nbyte)); | ||
| 515 | } | ||
| 516 | |||
| 517 | pub fn rmdir(path: [*]const u8) usize { | ||
| 518 | return errnoWrap(c.rmdir(path)); | ||
| 519 | } | ||
| 520 | |||
| 521 | pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { | ||
| 522 | return errnoWrap(c.symlink(existing, new)); | ||
| 523 | } | ||
| 524 | |||
| 525 | pub fn pread(fd: i32, buf: [*]u8, nbyte: usize, offset: u64) usize { | ||
| 526 | return errnoWrap(c.pread(fd, @ptrCast(*c_void, buf), nbyte, offset)); | ||
| 527 | } | ||
| 528 | |||
| 529 | pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: usize) usize { | ||
| 530 | return errnoWrap(c.preadv(fd, @ptrCast(*const c_void, iov), @intCast(c_int, count), offset)); | ||
| 531 | } | ||
| 532 | |||
| 533 | pub fn pipe(fd: *[2]i32) usize { | ||
| 534 | return pipe2(fd, 0); | ||
| 535 | } | ||
| 536 | |||
| 537 | pub fn pipe2(fd: *[2]i32, flags: u32) usize { | ||
| 538 | comptime assert(i32.bit_count == c_int.bit_count); | ||
| 539 | return errnoWrap(c.pipe2(@ptrCast(*[2]c_int, fd), flags)); | ||
| 540 | } | ||
| 541 | |||
| 542 | pub fn write(fd: i32, buf: [*]const u8, nbyte: usize) usize { | ||
| 543 | return errnoWrap(c.write(fd, @ptrCast(*const c_void, buf), nbyte)); | ||
| 544 | } | ||
| 545 | |||
| 546 | pub fn pwrite(fd: i32, buf: [*]const u8, nbyte: usize, offset: u64) usize { | ||
| 547 | return errnoWrap(c.pwrite(fd, @ptrCast(*const c_void, buf), nbyte, offset)); | ||
| 548 | } | ||
| 549 | |||
| 550 | pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: usize) usize { | ||
| 551 | return errnoWrap(c.pwritev(fd, @ptrCast(*const c_void, iov), @intCast(c_int, count), offset)); | ||
| 552 | } | ||
| 553 | |||
| 554 | pub fn rename(old: [*]const u8, new: [*]const u8) usize { | ||
| 555 | return errnoWrap(c.rename(old, new)); | ||
| 556 | } | ||
| 557 | |||
| 558 | pub fn open(path: [*]const u8, flags: u32, mode: usize) usize { | ||
| 559 | return errnoWrap(c.open(path, @bitCast(c_int, flags), mode)); | ||
| 560 | } | ||
| 561 | |||
| 562 | pub fn create(path: [*]const u8, perm: usize) usize { | ||
| 563 | return arch.syscall2(SYS_creat, @ptrToInt(path), perm); | ||
| 564 | } | ||
| 565 | |||
| 566 | pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize { | ||
| 567 | return errnoWrap(c.openat(@bitCast(usize, isize(dirfd)), @ptrToInt(path), flags, mode)); | ||
| 568 | } | ||
| 569 | |||
| 570 | pub fn close(fd: i32) usize { | ||
| 571 | return errnoWrap(c.close(fd)); | ||
| 572 | } | ||
| 573 | |||
| 574 | pub fn lseek(fd: i32, offset: isize, whence: c_int) usize { | ||
| 575 | return errnoWrap(c.lseek(fd, offset, whence)); | ||
| 576 | } | ||
| 577 | |||
| 578 | pub fn exit(code: i32) noreturn { | ||
| 579 | c.exit(code); | ||
| 580 | } | ||
| 581 | |||
| 582 | pub fn kill(pid: i32, sig: i32) usize { | ||
| 583 | return errnoWrap(c.kill(pid, sig)); | ||
| 584 | } | ||
| 585 | |||
| 586 | pub fn unlink(path: [*]const u8) usize { | ||
| 587 | return errnoWrap(c.unlink(path)); | ||
| 588 | } | ||
| 589 | |||
| 590 | pub fn waitpid(pid: i32, status: *i32, options: u32) usize { | ||
| 591 | comptime assert(i32.bit_count == c_int.bit_count); | ||
| 592 | return errnoWrap(c.waitpid(pid, @ptrCast(*c_int, status), @bitCast(c_int, options))); | ||
| 593 | } | ||
| 594 | |||
| 595 | pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize { | ||
| 596 | return errnoWrap(c.nanosleep(req, rem)); | ||
| 597 | } | ||
| 598 | |||
| 599 | pub fn clock_gettime(clk_id: i32, tp: *timespec) usize { | ||
| 600 | return errnoWrap(c.clock_gettime(clk_id, tp)); | ||
| 601 | } | ||
| 602 | |||
| 603 | pub fn clock_getres(clk_id: i32, tp: *timespec) usize { | ||
| 604 | return errnoWrap(c.clock_getres(clk_id, tp)); | ||
| 605 | } | ||
| 606 | |||
| 607 | pub fn setuid(uid: u32) usize { | ||
| 608 | return errnoWrap(c.setuid(uid)); | ||
| 609 | } | ||
| 610 | |||
| 611 | pub fn setgid(gid: u32) usize { | ||
| 612 | return errnoWrap(c.setgid(gid)); | ||
| 613 | } | ||
| 614 | |||
| 615 | pub fn setreuid(ruid: u32, euid: u32) usize { | ||
| 616 | return errnoWrap(c.setreuid(ruid, euid)); | ||
| 617 | } | ||
| 618 | |||
| 619 | pub fn setregid(rgid: u32, egid: u32) usize { | ||
| 620 | return errnoWrap(c.setregid(rgid, egid)); | ||
| 621 | } | ||
| 622 | |||
| 623 | const NSIG = 32; | ||
| 624 | |||
| 625 | pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize)); | ||
| 626 | pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); | ||
| 627 | pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); | ||
| 628 | |||
| 629 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | ||
| 630 | pub const Sigaction = extern struct { | ||
| 631 | /// signal handler | ||
| 632 | __sigaction_u: extern union { | ||
| 633 | __sa_handler: extern fn (i32) void, | ||
| 634 | __sa_sigaction: extern fn (i32, *__siginfo, usize) void, | ||
| 635 | }, | ||
| 636 | |||
| 637 | /// see signal options | ||
| 638 | sa_flags: u32, | ||
| 639 | |||
| 640 | /// signal mask to apply | ||
| 641 | sa_mask: sigset_t, | ||
| 642 | }; | ||
| 643 | |||
| 644 | pub const _SIG_WORDS = 4; | ||
| 645 | pub const _SIG_MAXSIG = 128; | ||
| 646 | |||
| 647 | pub inline fn _SIG_IDX(sig: usize) usize { | ||
| 648 | return sig - 1; | ||
| 649 | } | ||
| 650 | pub inline fn _SIG_WORD(sig: usize) usize { | ||
| 651 | return_SIG_IDX(sig) >> 5; | ||
| 652 | } | ||
| 653 | pub inline fn _SIG_BIT(sig: usize) usize { | ||
| 654 | return 1 << (_SIG_IDX(sig) & 31); | ||
| 655 | } | ||
| 656 | pub inline fn _SIG_VALID(sig: usize) usize { | ||
| 657 | return sig <= _SIG_MAXSIG and sig > 0; | ||
| 658 | } | ||
| 659 | |||
| 660 | pub const sigset_t = extern struct { | ||
| 661 | __bits: [_SIG_WORDS]u32, | ||
| 662 | }; | ||
| 663 | |||
| 664 | pub fn raise(sig: i32) usize { | ||
| 665 | return errnoWrap(c.raise(sig)); | ||
| 666 | } | ||
| 667 | |||
| 668 | pub const Stat = c.Stat; | ||
| 669 | pub const dirent = c.dirent; | ||
| 670 | pub const timespec = c.timespec; | ||
| 671 | |||
| 672 | pub fn fstat(fd: i32, buf: *c.Stat) usize { | ||
| 673 | return errnoWrap(c.fstat(fd, buf)); | ||
| 674 | } | ||
| 675 | pub const iovec = extern struct { | ||
| 676 | iov_base: [*]u8, | ||
| 677 | iov_len: usize, | ||
| 678 | }; | ||
| 679 | |||
| 680 | pub const iovec_const = extern struct { | ||
| 681 | iov_base: [*]const u8, | ||
| 682 | iov_len: usize, | ||
| 683 | }; | ||
| 684 | |||
| 685 | // TODO avoid libc dependency | ||
| 686 | pub fn kqueue() usize { | ||
| 687 | return errnoWrap(c.kqueue()); | ||
| 688 | } | ||
| 689 | |||
| 690 | // TODO avoid libc dependency | ||
| 691 | pub fn kevent(kq: i32, changelist: []const Kevent, eventlist: []Kevent, timeout: ?*const timespec) usize { | ||
| 692 | return errnoWrap(c.kevent( | ||
| 693 | kq, | ||
| 694 | changelist.ptr, | ||
| 695 | @intCast(c_int, changelist.len), | ||
| 696 | eventlist.ptr, | ||
| 697 | @intCast(c_int, eventlist.len), | ||
| 698 | timeout, | ||
| 699 | )); | ||
| 700 | } | ||
| 701 | |||
| 702 | // TODO avoid libc dependency | ||
| 703 | pub fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize { | ||
| 704 | return errnoWrap(c.sysctl(name, namelen, oldp, oldlenp, newp, newlen)); | ||
| 705 | } | ||
| 706 | |||
| 707 | // TODO avoid libc dependency | ||
| 708 | pub fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize { | ||
| 709 | return errnoWrap(c.sysctlbyname(name, oldp, oldlenp, newp, newlen)); | ||
| 710 | } | ||
| 711 | |||
| 712 | // TODO avoid libc dependency | ||
| 713 | pub fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) usize { | ||
| 714 | return errnoWrap(c.sysctlnametomib(name, wibp, sizep)); | ||
| 715 | } | ||
| 716 | |||
| 717 | // TODO avoid libc dependency | ||
| 718 | |||
| 719 | /// Takes the return value from a syscall and formats it back in the way | ||
| 720 | /// that the kernel represents it to libc. Errno was a mistake, let's make | ||
| 721 | /// it go away forever. | ||
| 722 | fn errnoWrap(value: isize) usize { | ||
| 723 | return @bitCast(usize, if (value == -1) -isize(c._errno().*) else value); | ||
| 724 | } |
std/os/netbsd/errno.zig deleted-134| ... | @@ -1,134 +0,0 @@ | ||
| 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/path.zig-2| ... | @@ -1162,10 +1162,8 @@ pub const RealError = error{ | ... | @@ -1162,10 +1162,8 @@ pub const RealError = error{ |
| 1162 | /// On Windows, file paths must be valid Unicode. | 1162 | /// On Windows, file paths must be valid Unicode. |
| 1163 | InvalidUtf8, | 1163 | InvalidUtf8, |
| 1164 | 1164 | ||
| 1165 | /// TODO remove this possibility | ||
| 1166 | PathAlreadyExists, | 1165 | PathAlreadyExists, |
| 1167 | 1166 | ||
| 1168 | /// TODO remove this possibility | ||
| 1169 | Unexpected, | 1167 | Unexpected, |
| 1170 | }; | 1168 | }; |
| 1171 | 1169 |
std/os/posix.zig+343-132| ... | @@ -33,10 +33,7 @@ const wasi = os.wasi; | ... | @@ -33,10 +33,7 @@ const wasi = os.wasi; |
| 33 | const linux = os.linux; | 33 | const linux = os.linux; |
| 34 | const testing = std.testing; | 34 | const testing = std.testing; |
| 35 | 35 | ||
| 36 | pub const FileHandle = if (windows.is_the_target) windows.HANDLE else if (wasi.is_the_target) wasi.fd_t else i32; | 36 | pub use system.posix; |
| 37 | pub use system.errno_codes; | ||
| 38 | |||
| 39 | pub const PATH_MAX = system.PATH_MAX; | ||
| 40 | 37 | ||
| 41 | /// > The maximum path of 32,767 characters is approximate, because the "\\?\" | 38 | /// > The maximum path of 32,767 characters is approximate, because the "\\?\" |
| 42 | /// > prefix may be expanded to a longer string by the system at run time, and | 39 | /// > prefix may be expanded to a longer string by the system at run time, and |
| ... | @@ -44,9 +41,6 @@ pub const PATH_MAX = system.PATH_MAX; | ... | @@ -44,9 +41,6 @@ pub const PATH_MAX = system.PATH_MAX; |
| 44 | /// from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation | 41 | /// from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation |
| 45 | pub const PATH_MAX_WIDE = 32767; | 42 | pub const PATH_MAX_WIDE = 32767; |
| 46 | 43 | ||
| 47 | pub const iovec = system.iovec; | ||
| 48 | pub const iovec_const = system.iovec_const; | ||
| 49 | |||
| 50 | /// See also `getenv`. | 44 | /// See also `getenv`. |
| 51 | pub var environ: [][*]u8 = undefined; | 45 | pub var environ: [][*]u8 = undefined; |
| 52 | 46 | ||
| ... | @@ -58,23 +52,23 @@ pub var environ: [][*]u8 = undefined; | ... | @@ -58,23 +52,23 @@ pub var environ: [][*]u8 = undefined; |
| 58 | /// value of. | 52 | /// value of. |
| 59 | pub const errno = system.getErrno; | 53 | pub const errno = system.getErrno; |
| 60 | 54 | ||
| 61 | /// Closes the file handle. | 55 | /// Closes the file descriptor. |
| 62 | /// This function is not capable of returning any indication of failure. An | 56 | /// This function is not capable of returning any indication of failure. An |
| 63 | /// application which wants to ensure writes have succeeded before closing | 57 | /// application which wants to ensure writes have succeeded before closing |
| 64 | /// must call `fsync` before `close`. | 58 | /// must call `fsync` before `close`. |
| 65 | /// Note: The Zig standard library does not support POSIX thread cancellation. | 59 | /// Note: The Zig standard library does not support POSIX thread cancellation. |
| 66 | pub fn close(handle: FileHandle) void { | 60 | pub fn close(fd: fd_t) void { |
| 67 | if (windows.is_the_target and !builtin.link_libc) { | 61 | if (windows.is_the_target and !builtin.link_libc) { |
| 68 | assert(windows.CloseHandle(handle) != 0); | 62 | assert(windows.CloseHandle(fd) != 0); |
| 69 | return; | 63 | return; |
| 70 | } | 64 | } |
| 71 | if (wasi.is_the_target) { | 65 | if (wasi.is_the_target) { |
| 72 | switch (wasi.fd_close(handle)) { | 66 | switch (wasi.fd_close(fd)) { |
| 73 | 0 => return, | 67 | 0 => return, |
| 74 | else => |err| return unexpectedErrno(err), | 68 | else => |err| return unexpectedErrno(err), |
| 75 | } | 69 | } |
| 76 | } | 70 | } |
| 77 | switch (system.getErrno(system.close(handle))) { | 71 | switch (errno(system.close(fd))) { |
| 78 | EBADF => unreachable, // Always a race condition. | 72 | EBADF => unreachable, // Always a race condition. |
| 79 | EINTR => return, // This is still a success. See https://github.com/ziglang/zig/issues/2425 | 73 | EINTR => return, // This is still a success. See https://github.com/ziglang/zig/issues/2425 |
| 80 | else => return, | 74 | else => return, |
| ... | @@ -103,7 +97,7 @@ pub fn getrandom(buf: []u8) GetRandomError!void { | ... | @@ -103,7 +97,7 @@ pub fn getrandom(buf: []u8) GetRandomError!void { |
| 103 | } | 97 | } |
| 104 | if (linux.is_the_target) { | 98 | if (linux.is_the_target) { |
| 105 | while (true) { | 99 | while (true) { |
| 106 | switch (system.getErrno(system.getrandom(buf.ptr, buf.len, 0))) { | 100 | switch (errno(system.getrandom(buf.ptr, buf.len, 0))) { |
| 107 | 0 => return, | 101 | 0 => return, |
| 108 | EINVAL => unreachable, | 102 | EINVAL => unreachable, |
| 109 | EFAULT => unreachable, | 103 | EFAULT => unreachable, |
| ... | @@ -146,7 +140,7 @@ test "os.getRandomBytes" { | ... | @@ -146,7 +140,7 @@ test "os.getRandomBytes" { |
| 146 | pub fn abort() noreturn { | 140 | pub fn abort() noreturn { |
| 147 | @setCold(true); | 141 | @setCold(true); |
| 148 | if (builtin.link_libc) { | 142 | if (builtin.link_libc) { |
| 149 | c.abort(); | 143 | system.abort(); |
| 150 | } | 144 | } |
| 151 | if (windows.is_the_target) { | 145 | if (windows.is_the_target) { |
| 152 | if (builtin.mode == .Debug) { | 146 | if (builtin.mode == .Debug) { |
| ... | @@ -171,7 +165,7 @@ pub const RaiseError = error{}; | ... | @@ -171,7 +165,7 @@ pub const RaiseError = error{}; |
| 171 | 165 | ||
| 172 | pub fn raise(sig: u8) RaiseError!void { | 166 | pub fn raise(sig: u8) RaiseError!void { |
| 173 | if (builtin.link_libc) { | 167 | if (builtin.link_libc) { |
| 174 | switch (system.getErrno(system.raise(sig))) { | 168 | switch (errno(system.raise(sig))) { |
| 175 | 0 => return, | 169 | 0 => return, |
| 176 | else => |err| return unexpectedErrno(err), | 170 | else => |err| return unexpectedErrno(err), |
| 177 | } | 171 | } |
| ... | @@ -193,7 +187,7 @@ pub fn raise(sig: u8) RaiseError!void { | ... | @@ -193,7 +187,7 @@ pub fn raise(sig: u8) RaiseError!void { |
| 193 | const tid = system.syscall0(system.SYS_gettid); | 187 | const tid = system.syscall0(system.SYS_gettid); |
| 194 | const rc = system.syscall2(system.SYS_tkill, tid, sig); | 188 | const rc = system.syscall2(system.SYS_tkill, tid, sig); |
| 195 | system.restoreSignals(&set); | 189 | system.restoreSignals(&set); |
| 196 | switch (system.getErrno(rc)) { | 190 | switch (errno(rc)) { |
| 197 | 0 => return, | 191 | 0 => return, |
| 198 | else => |err| return unexpectedErrno(err), | 192 | else => |err| return unexpectedErrno(err), |
| 199 | } | 193 | } |
| ... | @@ -202,7 +196,7 @@ pub fn raise(sig: u8) RaiseError!void { | ... | @@ -202,7 +196,7 @@ pub fn raise(sig: u8) RaiseError!void { |
| 202 | /// Exits the program cleanly with the specified status code. | 196 | /// Exits the program cleanly with the specified status code. |
| 203 | pub fn exit(status: u8) noreturn { | 197 | pub fn exit(status: u8) noreturn { |
| 204 | if (builtin.link_libc) { | 198 | if (builtin.link_libc) { |
| 205 | std.c.exit(status); | 199 | system.exit(status); |
| 206 | } | 200 | } |
| 207 | if (windows.is_the_target) { | 201 | if (windows.is_the_target) { |
| 208 | windows.ExitProcess(status); | 202 | windows.ExitProcess(status); |
| ... | @@ -229,7 +223,7 @@ pub const ReadError = error{ | ... | @@ -229,7 +223,7 @@ pub const ReadError = error{ |
| 229 | /// buf.len. If 0 bytes were read, that means EOF. | 223 | /// buf.len. If 0 bytes were read, that means EOF. |
| 230 | /// This function is for blocking file descriptors only. For non-blocking, see | 224 | /// This function is for blocking file descriptors only. For non-blocking, see |
| 231 | /// `readAsync`. | 225 | /// `readAsync`. |
| 232 | pub fn read(fd: FileHandle, buf: []u8) ReadError!usize { | 226 | pub fn read(fd: fd_t, buf: []u8) ReadError!usize { |
| 233 | if (windows.is_the_target and !builtin.link_libc) { | 227 | if (windows.is_the_target and !builtin.link_libc) { |
| 234 | var index: usize = 0; | 228 | var index: usize = 0; |
| 235 | while (index < buffer.len) { | 229 | while (index < buffer.len) { |
| ... | @@ -270,7 +264,7 @@ pub fn read(fd: FileHandle, buf: []u8) ReadError!usize { | ... | @@ -270,7 +264,7 @@ pub fn read(fd: FileHandle, buf: []u8) ReadError!usize { |
| 270 | while (index < buf.len) { | 264 | while (index < buf.len) { |
| 271 | const want_to_read = math.min(buf.len - index, usize(max_buf_len)); | 265 | const want_to_read = math.min(buf.len - index, usize(max_buf_len)); |
| 272 | const rc = system.read(fd, buf.ptr + index, want_to_read); | 266 | const rc = system.read(fd, buf.ptr + index, want_to_read); |
| 273 | switch (system.getErrno(rc)) { | 267 | switch (errno(rc)) { |
| 274 | 0 => { | 268 | 0 => { |
| 275 | index += rc; | 269 | index += rc; |
| 276 | if (rc == want_to_read) continue; | 270 | if (rc == want_to_read) continue; |
| ... | @@ -295,7 +289,7 @@ pub fn read(fd: FileHandle, buf: []u8) ReadError!usize { | ... | @@ -295,7 +289,7 @@ pub fn read(fd: FileHandle, buf: []u8) ReadError!usize { |
| 295 | /// Number of bytes read is returned. Upon reading end-of-file, zero is returned. | 289 | /// Number of bytes read is returned. Upon reading end-of-file, zero is returned. |
| 296 | /// This function is for blocking file descriptors only. For non-blocking, see | 290 | /// This function is for blocking file descriptors only. For non-blocking, see |
| 297 | /// `preadvAsync`. | 291 | /// `preadvAsync`. |
| 298 | pub fn preadv(fd: FileHandle, iov: [*]const iovec, count: usize, offset: u64) ReadError!usize { | 292 | pub fn preadv(fd: fd_t, iov: [*]const iovec, count: usize, offset: u64) ReadError!usize { |
| 299 | if (os.darwin.is_the_target) { | 293 | if (os.darwin.is_the_target) { |
| 300 | // Darwin does not have preadv but it does have pread. | 294 | // Darwin does not have preadv but it does have pread. |
| 301 | var off: usize = 0; | 295 | var off: usize = 0; |
| ... | @@ -335,8 +329,7 @@ pub fn preadv(fd: FileHandle, iov: [*]const iovec, count: usize, offset: u64) Re | ... | @@ -335,8 +329,7 @@ pub fn preadv(fd: FileHandle, iov: [*]const iovec, count: usize, offset: u64) Re |
| 335 | } | 329 | } |
| 336 | while (true) { | 330 | while (true) { |
| 337 | const rc = system.preadv(fd, iov, count, offset); | 331 | const rc = system.preadv(fd, iov, count, offset); |
| 338 | const err = system.getErrno(rc); | 332 | switch (errno(rc)) { |
| 339 | switch (err) { | ||
| 340 | 0 => return rc, | 333 | 0 => return rc, |
| 341 | EINTR => continue, | 334 | EINTR => continue, |
| 342 | EINVAL => unreachable, | 335 | EINVAL => unreachable, |
| ... | @@ -347,7 +340,7 @@ pub fn preadv(fd: FileHandle, iov: [*]const iovec, count: usize, offset: u64) Re | ... | @@ -347,7 +340,7 @@ pub fn preadv(fd: FileHandle, iov: [*]const iovec, count: usize, offset: u64) Re |
| 347 | EISDIR => return error.IsDir, | 340 | EISDIR => return error.IsDir, |
| 348 | ENOBUFS => return error.SystemResources, | 341 | ENOBUFS => return error.SystemResources, |
| 349 | ENOMEM => return error.SystemResources, | 342 | ENOMEM => return error.SystemResources, |
| 350 | else => return unexpectedErrno(err), | 343 | else => |err| return unexpectedErrno(err), |
| 351 | } | 344 | } |
| 352 | } | 345 | } |
| 353 | } | 346 | } |
| ... | @@ -367,7 +360,7 @@ pub const WriteError = error{ | ... | @@ -367,7 +360,7 @@ pub const WriteError = error{ |
| 367 | /// Write to a file descriptor. Keeps trying if it gets interrupted. | 360 | /// Write to a file descriptor. Keeps trying if it gets interrupted. |
| 368 | /// This function is for blocking file descriptors only. For non-blocking, see | 361 | /// This function is for blocking file descriptors only. For non-blocking, see |
| 369 | /// `writeAsync`. | 362 | /// `writeAsync`. |
| 370 | pub fn write(fd: FileHandle, bytes: []const u8) WriteError!void { | 363 | pub fn write(fd: fd_t, bytes: []const u8) WriteError!void { |
| 371 | if (windows.is_the_target and !builtin.link_libc) { | 364 | if (windows.is_the_target and !builtin.link_libc) { |
| 372 | var bytes_written: windows.DWORD = undefined; | 365 | var bytes_written: windows.DWORD = undefined; |
| 373 | // TODO replace this @intCast with a loop that writes all the bytes | 366 | // TODO replace this @intCast with a loop that writes all the bytes |
| ... | @@ -404,8 +397,7 @@ pub fn write(fd: FileHandle, bytes: []const u8) WriteError!void { | ... | @@ -404,8 +397,7 @@ pub fn write(fd: FileHandle, bytes: []const u8) WriteError!void { |
| 404 | while (index < bytes.len) { | 397 | while (index < bytes.len) { |
| 405 | const amt_to_write = math.min(bytes.len - index, usize(max_bytes_len)); | 398 | const amt_to_write = math.min(bytes.len - index, usize(max_bytes_len)); |
| 406 | const rc = system.write(fd, bytes.ptr + index, amt_to_write); | 399 | const rc = system.write(fd, bytes.ptr + index, amt_to_write); |
| 407 | const write_err = system.getErrno(rc); | 400 | switch (errno(rc)) { |
| 408 | switch (write_err) { | ||
| 409 | 0 => { | 401 | 0 => { |
| 410 | index += rc; | 402 | index += rc; |
| 411 | continue; | 403 | continue; |
| ... | @@ -422,7 +414,7 @@ pub fn write(fd: FileHandle, bytes: []const u8) WriteError!void { | ... | @@ -422,7 +414,7 @@ pub fn write(fd: FileHandle, bytes: []const u8) WriteError!void { |
| 422 | ENOSPC => return error.NoSpaceLeft, | 414 | ENOSPC => return error.NoSpaceLeft, |
| 423 | EPERM => return error.AccessDenied, | 415 | EPERM => return error.AccessDenied, |
| 424 | EPIPE => return error.BrokenPipe, | 416 | EPIPE => return error.BrokenPipe, |
| 425 | else => return unexpectedErrno(write_err), | 417 | else => |err| return unexpectedErrno(err), |
| 426 | } | 418 | } |
| 427 | } | 419 | } |
| 428 | } | 420 | } |
| ... | @@ -430,7 +422,7 @@ pub fn write(fd: FileHandle, bytes: []const u8) WriteError!void { | ... | @@ -430,7 +422,7 @@ pub fn write(fd: FileHandle, bytes: []const u8) WriteError!void { |
| 430 | /// Write multiple buffers to a file descriptor. Keeps trying if it gets interrupted. | 422 | /// Write multiple buffers to a file descriptor. Keeps trying if it gets interrupted. |
| 431 | /// This function is for blocking file descriptors only. For non-blocking, see | 423 | /// This function is for blocking file descriptors only. For non-blocking, see |
| 432 | /// `pwritevAsync`. | 424 | /// `pwritevAsync`. |
| 433 | pub fn pwritev(fd: FileHandle, iov: [*]const iovec_const, count: usize, offset: u64) WriteError!void { | 425 | pub fn pwritev(fd: fd_t, iov: [*]const iovec_const, count: usize, offset: u64) WriteError!void { |
| 434 | if (darwin.is_the_target) { | 426 | if (darwin.is_the_target) { |
| 435 | // Darwin does not have pwritev but it does have pwrite. | 427 | // Darwin does not have pwritev but it does have pwrite. |
| 436 | var off: usize = 0; | 428 | var off: usize = 0; |
| ... | @@ -473,8 +465,7 @@ pub fn pwritev(fd: FileHandle, iov: [*]const iovec_const, count: usize, offset: | ... | @@ -473,8 +465,7 @@ pub fn pwritev(fd: FileHandle, iov: [*]const iovec_const, count: usize, offset: |
| 473 | 465 | ||
| 474 | while (true) { | 466 | while (true) { |
| 475 | const rc = system.pwritev(fd, iov, count, offset); | 467 | const rc = system.pwritev(fd, iov, count, offset); |
| 476 | const err = system.getErrno(rc); | 468 | switch (errno(rc)) { |
| 477 | switch (err) { | ||
| 478 | 0 => return, | 469 | 0 => return, |
| 479 | EINTR => continue, | 470 | EINTR => continue, |
| 480 | EINVAL => unreachable, | 471 | EINVAL => unreachable, |
| ... | @@ -488,7 +479,7 @@ pub fn pwritev(fd: FileHandle, iov: [*]const iovec_const, count: usize, offset: | ... | @@ -488,7 +479,7 @@ pub fn pwritev(fd: FileHandle, iov: [*]const iovec_const, count: usize, offset: |
| 488 | ENOSPC => return error.NoSpaceLeft, | 479 | ENOSPC => return error.NoSpaceLeft, |
| 489 | EPERM => return error.AccessDenied, | 480 | EPERM => return error.AccessDenied, |
| 490 | EPIPE => return error.BrokenPipe, | 481 | EPIPE => return error.BrokenPipe, |
| 491 | else => return unexpectedErrno(err), | 482 | else => |err| return unexpectedErrno(err), |
| 492 | } | 483 | } |
| 493 | } | 484 | } |
| 494 | } | 485 | } |
| ... | @@ -514,7 +505,7 @@ pub const OpenError = error{ | ... | @@ -514,7 +505,7 @@ pub const OpenError = error{ |
| 514 | /// Open and possibly create a file. Keeps trying if it gets interrupted. | 505 | /// Open and possibly create a file. Keeps trying if it gets interrupted. |
| 515 | /// `file_path` needs to be copied in memory to add a null terminating byte. | 506 | /// `file_path` needs to be copied in memory to add a null terminating byte. |
| 516 | /// See also `openC`. | 507 | /// See also `openC`. |
| 517 | pub fn open(file_path: []const u8, flags: u32, perm: usize) OpenError!FileHandle { | 508 | pub fn open(file_path: []const u8, flags: u32, perm: usize) OpenError!fd_t { |
| 518 | const file_path_c = try toPosixPath(file_path); | 509 | const file_path_c = try toPosixPath(file_path); |
| 519 | return openC(&file_path_c, flags, perm); | 510 | return openC(&file_path_c, flags, perm); |
| 520 | } | 511 | } |
| ... | @@ -522,11 +513,11 @@ pub fn open(file_path: []const u8, flags: u32, perm: usize) OpenError!FileHandle | ... | @@ -522,11 +513,11 @@ pub fn open(file_path: []const u8, flags: u32, perm: usize) OpenError!FileHandle |
| 522 | /// Open and possibly create a file. Keeps trying if it gets interrupted. | 513 | /// Open and possibly create a file. Keeps trying if it gets interrupted. |
| 523 | /// See also `open`. | 514 | /// See also `open`. |
| 524 | /// TODO https://github.com/ziglang/zig/issues/265 | 515 | /// TODO https://github.com/ziglang/zig/issues/265 |
| 525 | pub fn openC(file_path: [*]const u8, flags: u32, perm: usize) OpenError!FileHandle { | 516 | pub fn openC(file_path: [*]const u8, flags: u32, perm: usize) OpenError!fd_t { |
| 526 | while (true) { | 517 | while (true) { |
| 527 | const rc = system.open(file_path, flags, perm); | 518 | const rc = system.open(file_path, flags, perm); |
| 528 | switch (system.getErrno(rc)) { | 519 | switch (errno(rc)) { |
| 529 | 0 => return @intCast(FileHandle, rc), | 520 | 0 => return @intCast(fd_t, rc), |
| 530 | EINTR => continue, | 521 | EINTR => continue, |
| 531 | 522 | ||
| 532 | EFAULT => unreachable, | 523 | EFAULT => unreachable, |
| ... | @@ -582,7 +573,7 @@ pub fn openWindows( | ... | @@ -582,7 +573,7 @@ pub fn openWindows( |
| 582 | share_mode: windows.DWORD, | 573 | share_mode: windows.DWORD, |
| 583 | creation_disposition: windows.DWORD, | 574 | creation_disposition: windows.DWORD, |
| 584 | flags_and_attrs: windows.DWORD, | 575 | flags_and_attrs: windows.DWORD, |
| 585 | ) WindowsOpenError!FileHandle { | 576 | ) WindowsOpenError!fd_t { |
| 586 | const file_path_w = try sliceToPrefixedFileW(file_path); | 577 | const file_path_w = try sliceToPrefixedFileW(file_path); |
| 587 | return openW(&file_path_w, desired_access, share_mode, creation_disposition, flags_and_attrs); | 578 | return openW(&file_path_w, desired_access, share_mode, creation_disposition, flags_and_attrs); |
| 588 | } | 579 | } |
| ... | @@ -613,9 +604,9 @@ pub fn openW( | ... | @@ -613,9 +604,9 @@ pub fn openW( |
| 613 | return result; | 604 | return result; |
| 614 | } | 605 | } |
| 615 | 606 | ||
| 616 | pub fn dup2(old_fd: FileHandle, new_fd: FileHandle) !void { | 607 | pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void { |
| 617 | while (true) { | 608 | while (true) { |
| 618 | switch (system.getErrno(system.dup2(old_fd, new_fd))) { | 609 | switch (errno(system.dup2(old_fd, new_fd))) { |
| 619 | 0 => return, | 610 | 0 => return, |
| 620 | EBUSY, EINTR => continue, | 611 | EBUSY, EINTR => continue, |
| 621 | EMFILE => return error.ProcessFdQuotaExceeded, | 612 | EMFILE => return error.ProcessFdQuotaExceeded, |
| ... | @@ -630,6 +621,7 @@ pub fn dup2(old_fd: FileHandle, new_fd: FileHandle) !void { | ... | @@ -630,6 +621,7 @@ pub fn dup2(old_fd: FileHandle, new_fd: FileHandle) !void { |
| 630 | /// pointers after the args and after the environment variables. | 621 | /// pointers after the args and after the environment variables. |
| 631 | /// `argv[0]` is the executable path. | 622 | /// `argv[0]` is the executable path. |
| 632 | /// This function also uses the PATH environment variable to get the full path to the executable. | 623 | /// This function also uses the PATH environment variable to get the full path to the executable. |
| 624 | /// TODO provide execveC which does not take an allocator | ||
| 633 | pub fn execve(allocator: *Allocator, argv: []const []const u8, env_map: *const BufMap) !void { | 625 | pub fn execve(allocator: *Allocator, argv: []const []const u8, env_map: *const BufMap) !void { |
| 634 | const argv_buf = try allocator.alloc(?[*]u8, argv.len + 1); | 626 | const argv_buf = try allocator.alloc(?[*]u8, argv.len + 1); |
| 635 | mem.set(?[*]u8, argv_buf, null); | 627 | mem.set(?[*]u8, argv_buf, null); |
| ... | @@ -654,7 +646,7 @@ pub fn execve(allocator: *Allocator, argv: []const []const u8, env_map: *const B | ... | @@ -654,7 +646,7 @@ pub fn execve(allocator: *Allocator, argv: []const []const u8, env_map: *const B |
| 654 | 646 | ||
| 655 | const exe_path = argv[0]; | 647 | const exe_path = argv[0]; |
| 656 | if (mem.indexOfScalar(u8, exe_path, '/') != null) { | 648 | if (mem.indexOfScalar(u8, exe_path, '/') != null) { |
| 657 | return execveErrnoToErr(system.getErrno(system.execve(argv_buf[0].?, argv_buf.ptr, envp_buf.ptr))); | 649 | return execveErrnoToErr(errno(system.execve(argv_buf[0].?, argv_buf.ptr, envp_buf.ptr))); |
| 658 | } | 650 | } |
| 659 | 651 | ||
| 660 | const PATH = getenv("PATH") orelse "/usr/local/bin:/bin/:/usr/bin"; | 652 | const PATH = getenv("PATH") orelse "/usr/local/bin:/bin/:/usr/bin"; |
| ... | @@ -671,7 +663,7 @@ pub fn execve(allocator: *Allocator, argv: []const []const u8, env_map: *const B | ... | @@ -671,7 +663,7 @@ pub fn execve(allocator: *Allocator, argv: []const []const u8, env_map: *const B |
| 671 | path_buf[search_path.len] = '/'; | 663 | path_buf[search_path.len] = '/'; |
| 672 | mem.copy(u8, path_buf[search_path.len + 1 ..], exe_path); | 664 | mem.copy(u8, path_buf[search_path.len + 1 ..], exe_path); |
| 673 | path_buf[search_path.len + exe_path.len + 1] = 0; | 665 | path_buf[search_path.len + exe_path.len + 1] = 0; |
| 674 | err = system.getErrno(system.execve(path_buf.ptr, argv_buf.ptr, envp_buf.ptr)); | 666 | err = errno(system.execve(path_buf.ptr, argv_buf.ptr, envp_buf.ptr)); |
| 675 | assert(err > 0); | 667 | assert(err > 0); |
| 676 | if (err == EACCES) { | 668 | if (err == EACCES) { |
| 677 | seen_eacces = true; | 669 | seen_eacces = true; |
| ... | @@ -776,7 +768,7 @@ pub fn getenv(key: []const u8) ?[]const u8 { | ... | @@ -776,7 +768,7 @@ pub fn getenv(key: []const u8) ?[]const u8 { |
| 776 | /// TODO https://github.com/ziglang/zig/issues/265 | 768 | /// TODO https://github.com/ziglang/zig/issues/265 |
| 777 | pub fn getenvC(key: [*]const u8) ?[]const u8 { | 769 | pub fn getenvC(key: [*]const u8) ?[]const u8 { |
| 778 | if (builtin.link_libc) { | 770 | if (builtin.link_libc) { |
| 779 | const value = std.c.getenv(key) orelse return null; | 771 | const value = system.getenv(key) orelse return null; |
| 780 | return mem.toSliceConst(u8, value); | 772 | return mem.toSliceConst(u8, value); |
| 781 | } | 773 | } |
| 782 | return getenv(mem.toSliceConst(u8, key)); | 774 | return getenv(mem.toSliceConst(u8, key)); |
| ... | @@ -785,7 +777,7 @@ pub fn getenvC(key: [*]const u8) ?[]const u8 { | ... | @@ -785,7 +777,7 @@ pub fn getenvC(key: [*]const u8) ?[]const u8 { |
| 785 | /// See std.elf for the constants. | 777 | /// See std.elf for the constants. |
| 786 | pub fn getauxval(index: usize) usize { | 778 | pub fn getauxval(index: usize) usize { |
| 787 | if (builtin.link_libc) { | 779 | if (builtin.link_libc) { |
| 788 | return usize(std.c.getauxval(index)); | 780 | return usize(system.getauxval(index)); |
| 789 | } else if (linux.elf_aux_maybe) |auxv| { | 781 | } else if (linux.elf_aux_maybe) |auxv| { |
| 790 | var i: usize = 0; | 782 | var i: usize = 0; |
| 791 | while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) { | 783 | while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) { |
| ... | @@ -829,9 +821,9 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 { | ... | @@ -829,9 +821,9 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 { |
| 829 | } | 821 | } |
| 830 | 822 | ||
| 831 | const err = if (builtin.link_libc) blk: { | 823 | const err = if (builtin.link_libc) blk: { |
| 832 | break :blk if (std.c.getcwd(out_buffer.ptr, out_buffer.len)) |_| 0 else std.c._errno().*; | 824 | break :blk if (system.getcwd(out_buffer.ptr, out_buffer.len)) |_| 0 else system._errno().*; |
| 833 | } else blk: { | 825 | } else blk: { |
| 834 | break :blk system.getErrno(system.getcwd(out_buffer, out_buffer.len)); | 826 | break :blk errno(system.getcwd(out_buffer, out_buffer.len)); |
| 835 | }; | 827 | }; |
| 836 | switch (err) { | 828 | switch (err) { |
| 837 | 0 => return mem.toSlice(u8, out_buffer), | 829 | 0 => return mem.toSlice(u8, out_buffer), |
| ... | @@ -883,21 +875,14 @@ pub fn symlink(target_path: []const u8, new_path: []const u8) SymLinkError!void | ... | @@ -883,21 +875,14 @@ pub fn symlink(target_path: []const u8, new_path: []const u8) SymLinkError!void |
| 883 | } | 875 | } |
| 884 | } | 876 | } |
| 885 | 877 | ||
| 886 | pub fn symlinkat(target_path: []const u8, newdirfd: FileHandle, new_path: []const u8) SymLinkError!void { | 878 | pub fn symlinkat(target_path: []const u8, newdirfd: fd_t, new_path: []const u8) SymLinkError!void { |
| 887 | const target_path_c = try toPosixPath(target_path); | 879 | const target_path_c = try toPosixPath(target_path); |
| 888 | const new_path_c = try toPosixPath(new_path); | 880 | const new_path_c = try toPosixPath(new_path); |
| 889 | return symlinkatC(target_path_c, newdirfd, new_path_c); | 881 | return symlinkatC(target_path_c, newdirfd, new_path_c); |
| 890 | } | 882 | } |
| 891 | 883 | ||
| 892 | pub fn symlinkatC(target_path: [*]const u8, newdirfd: FileHandle, new_path: [*]const u8) SymLinkError!void { | 884 | pub fn symlinkatC(target_path: [*]const u8, newdirfd: fd_t, new_path: [*]const u8) SymLinkError!void { |
| 893 | const err = blk: { | 885 | switch (errno(system.symlinkat(target_path, newdirfd, new_path))) { |
| 894 | if (builtin.link_libc) { | ||
| 895 | break :blk if (std.c.symlinkat(target_path, newdirfd, new_path) == -1) errno().* else 0; | ||
| 896 | } else { | ||
| 897 | break :blk system.getErrno(system.symlinkat(target_path, newdirfd, new_path)); | ||
| 898 | } | ||
| 899 | }; | ||
| 900 | switch (err) { | ||
| 901 | 0 => return, | 886 | 0 => return, |
| 902 | EFAULT => unreachable, | 887 | EFAULT => unreachable, |
| 903 | EINVAL => unreachable, | 888 | EINVAL => unreachable, |
| ... | @@ -913,7 +898,7 @@ pub fn symlinkatC(target_path: [*]const u8, newdirfd: FileHandle, new_path: [*]c | ... | @@ -913,7 +898,7 @@ pub fn symlinkatC(target_path: [*]const u8, newdirfd: FileHandle, new_path: [*]c |
| 913 | ENOMEM => return error.SystemResources, | 898 | ENOMEM => return error.SystemResources, |
| 914 | ENOSPC => return error.NoSpaceLeft, | 899 | ENOSPC => return error.NoSpaceLeft, |
| 915 | EROFS => return error.ReadOnlyFileSystem, | 900 | EROFS => return error.ReadOnlyFileSystem, |
| 916 | else => return unexpectedErrno(err), | 901 | else => |err| return unexpectedErrno(err), |
| 917 | } | 902 | } |
| 918 | } | 903 | } |
| 919 | 904 | ||
| ... | @@ -925,12 +910,10 @@ pub fn symlinkC(target_path: [*]const u8, new_path: [*]const u8) SymLinkError!vo | ... | @@ -925,12 +910,10 @@ pub fn symlinkC(target_path: [*]const u8, new_path: [*]const u8) SymLinkError!vo |
| 925 | const new_path_w = try cStrToPrefixedFileW(new_path); | 910 | const new_path_w = try cStrToPrefixedFileW(new_path); |
| 926 | return symlinkW(&target_path_w, &new_path_w); | 911 | return symlinkW(&target_path_w, &new_path_w); |
| 927 | } | 912 | } |
| 928 | const err = if (builtin.link_libc) blk: { | 913 | const err = if (builtin.link_libc or @hasDecl(system, "SYS_symlink")) blk: { |
| 929 | break :blk if (std.c.symlink(target_path, new_path) == -1) errno().* else 0; | 914 | break :blk errno(system.symlink(target_path, new_path)); |
| 930 | } else if (@hasDecl(system, "symlink")) blk: { | ||
| 931 | break :blk system.getErrno(system.symlink(target_path, new_path)); | ||
| 932 | } else blk: { | 915 | } else blk: { |
| 933 | break :blk system.getErrno(system.symlinkat(target_path, AT_FDCWD, new_path)); | 916 | break :blk errno(system.symlinkat(target_path, AT_FDCWD, new_path)); |
| 934 | }; | 917 | }; |
| 935 | switch (err) { | 918 | switch (err) { |
| 936 | 0 => return, | 919 | 0 => return, |
| ... | @@ -1018,12 +1001,10 @@ pub fn unlinkC(file_path: [*]const u8) UnlinkError!void { | ... | @@ -1018,12 +1001,10 @@ pub fn unlinkC(file_path: [*]const u8) UnlinkError!void { |
| 1018 | const file_path_w = try cStrToPrefixedFileW(file_path); | 1001 | const file_path_w = try cStrToPrefixedFileW(file_path); |
| 1019 | return unlinkW(&file_path_w); | 1002 | return unlinkW(&file_path_w); |
| 1020 | } | 1003 | } |
| 1021 | const err = if (builtin.link_libc) blk: { | 1004 | const err = if (builtin.link_libc or @hasDecl(system, "SYS_unlink")) blk: { |
| 1022 | break :blk if (std.c.unlink(file_path) == -1) errno().* else 0; | 1005 | break :blk errno(system.unlink(file_path)); |
| 1023 | } else if (@hasDecl(system, "unlink")) blk: { | ||
| 1024 | break :blk system.getErrno(system.unlink(file_path)); | ||
| 1025 | } else blk: { | 1006 | } else blk: { |
| 1026 | break :blk system.getErrno(system.unlinkat(AT_FDCWD, file_path, 0)); | 1007 | break :blk errno(system.unlinkat(AT_FDCWD, file_path, 0)); |
| 1027 | }; | 1008 | }; |
| 1028 | switch (err) { | 1009 | switch (err) { |
| 1029 | 0 => return, | 1010 | 0 => return, |
| ... | @@ -1066,14 +1047,12 @@ pub fn renameC(old_path: [*]const u8, new_path: [*]const u8) RenameError!void { | ... | @@ -1066,14 +1047,12 @@ pub fn renameC(old_path: [*]const u8, new_path: [*]const u8) RenameError!void { |
| 1066 | const new_path_w = try cStrToPrefixedFileW(new_path); | 1047 | const new_path_w = try cStrToPrefixedFileW(new_path); |
| 1067 | return renameW(&old_path_w, &new_path_w); | 1048 | return renameW(&old_path_w, &new_path_w); |
| 1068 | } | 1049 | } |
| 1069 | const err = if (builtin.link_libc) blk: { | 1050 | const err = if (builtin.link_libc or @hasDecl(system, "SYS_rename")) blk: { |
| 1070 | break :blk if (std.c.rename(old_path, new_path) == -1) errno().* else 0; | 1051 | break :blk errno(system.rename(old_path, new_path)); |
| 1071 | } else if (@hasDecl(system, "rename")) blk: { | 1052 | } else if (@hasDecl(system, "SYS_renameat")) blk: { |
| 1072 | break :blk system.getErrno(system.rename(old_path, new_path)); | 1053 | break :blk errno(system.renameat(AT_FDCWD, old_path, AT_FDCWD, new_path)); |
| 1073 | } else if (@hasDecl(system, "renameat")) blk: { | ||
| 1074 | break :blk system.getErrno(system.renameat(AT_FDCWD, old_path, AT_FDCWD, new_path)); | ||
| 1075 | } else blk: { | 1054 | } else blk: { |
| 1076 | break :blk system.getErrno(system.renameat2(AT_FDCWD, old_path, AT_FDCWD, new_path, 0)); | 1055 | break :blk errno(system.renameat2(AT_FDCWD, old_path, AT_FDCWD, new_path, 0)); |
| 1077 | }; | 1056 | }; |
| 1078 | switch (err) { | 1057 | switch (err) { |
| 1079 | 0 => return, | 1058 | 0 => return, |
| ... | @@ -1131,12 +1110,10 @@ pub fn mkdirC(dir_path: [*]const u8, mode: u32) MakeDirError!void { | ... | @@ -1131,12 +1110,10 @@ pub fn mkdirC(dir_path: [*]const u8, mode: u32) MakeDirError!void { |
| 1131 | const dir_path_w = try cStrToPrefixedFileW(dir_path); | 1110 | const dir_path_w = try cStrToPrefixedFileW(dir_path); |
| 1132 | return mkdirW(&dir_path_w, mode); | 1111 | return mkdirW(&dir_path_w, mode); |
| 1133 | } | 1112 | } |
| 1134 | const err = if (builtin.link_libc) blk: { | 1113 | const err = if (builtin.link_libc or @hasDecl(system, "SYS_mkdir")) blk: { |
| 1135 | break :blk if (std.c.mkdir(dir_path, mode) == -1) errno().* else 0; | 1114 | break :blk errno(system.mkdir(dir_path, mode)); |
| 1136 | } else if (@hasDecl(system, "mkdir")) blk: { | ||
| 1137 | break :blk system.getErrno(system.mkdir(dir_path, mode)); | ||
| 1138 | } else blk: { | 1115 | } else blk: { |
| 1139 | break :blk system.getErrno(system.mkdirat(AT_FDCWD, dir_path, mode)); | 1116 | break :blk errno(system.mkdirat(AT_FDCWD, dir_path, mode)); |
| 1140 | }; | 1117 | }; |
| 1141 | switch (err) { | 1118 | switch (err) { |
| 1142 | 0 => return, | 1119 | 0 => return, |
| ... | @@ -1203,12 +1180,10 @@ pub fn rmdirC(dir_path: [*]const u8) DeleteDirError!void { | ... | @@ -1203,12 +1180,10 @@ pub fn rmdirC(dir_path: [*]const u8) DeleteDirError!void { |
| 1203 | const dir_path_w = try cStrToPrefixedFileW(dir_path); | 1180 | const dir_path_w = try cStrToPrefixedFileW(dir_path); |
| 1204 | return rmdirW(&dir_path_w); | 1181 | return rmdirW(&dir_path_w); |
| 1205 | } | 1182 | } |
| 1206 | const err = if (builtin.link_libc) blk: { | 1183 | const err = if (builtin.link_libc or @hasDecl(system, "SYS_rmdir")) blk: { |
| 1207 | break :blk if (std.c.rmdir(dir_path) == -1) errno().* else 0; | 1184 | break :blk errno(system.rmdir(dir_path)); |
| 1208 | } else if (@hasDecl(system, "rmdir")) blk: { | ||
| 1209 | break :blk system.getErrno(system.rmdir(dir_path)); | ||
| 1210 | } else blk: { | 1185 | } else blk: { |
| 1211 | break :blk system.getErrno(system.unlinkat(AT_FDCWD, dir_path, AT_REMOVEDIR)); | 1186 | break :blk errno(system.unlinkat(AT_FDCWD, dir_path, AT_REMOVEDIR)); |
| 1212 | }; | 1187 | }; |
| 1213 | switch (err) { | 1188 | switch (err) { |
| 1214 | 0 => return, | 1189 | 0 => return, |
| ... | @@ -1262,12 +1237,7 @@ pub fn chdirC(dir_path: [*]const u8) ChangeCurDirError!void { | ... | @@ -1262,12 +1237,7 @@ pub fn chdirC(dir_path: [*]const u8) ChangeCurDirError!void { |
| 1262 | const dir_path_w = try cStrToPrefixedFileW(dir_path); | 1237 | const dir_path_w = try cStrToPrefixedFileW(dir_path); |
| 1263 | return chdirW(&dir_path_w); | 1238 | return chdirW(&dir_path_w); |
| 1264 | } | 1239 | } |
| 1265 | const err = if (builtin.link_libc) blk: { | 1240 | switch (errno(system.chdir(dir_path))) { |
| 1266 | break :blk if (std.c.chdir(dir_path) == -1) errno().* else 0; | ||
| 1267 | } else blk: { | ||
| 1268 | break :blk system.getErrno(system.chdir(dir_path)); | ||
| 1269 | }; | ||
| 1270 | switch (err) { | ||
| 1271 | 0 => return, | 1241 | 0 => return, |
| 1272 | EACCES => return error.AccessDenied, | 1242 | EACCES => return error.AccessDenied, |
| 1273 | EFAULT => unreachable, | 1243 | EFAULT => unreachable, |
| ... | @@ -1277,7 +1247,7 @@ pub fn chdirC(dir_path: [*]const u8) ChangeCurDirError!void { | ... | @@ -1277,7 +1247,7 @@ pub fn chdirC(dir_path: [*]const u8) ChangeCurDirError!void { |
| 1277 | ENOENT => return error.FileNotFound, | 1247 | ENOENT => return error.FileNotFound, |
| 1278 | ENOMEM => return error.SystemResources, | 1248 | ENOMEM => return error.SystemResources, |
| 1279 | ENOTDIR => return error.NotDir, | 1249 | ENOTDIR => return error.NotDir, |
| 1280 | else => return unexpectedErrno(err), | 1250 | else => |err| return unexpectedErrno(err), |
| 1281 | } | 1251 | } |
| 1282 | } | 1252 | } |
| 1283 | 1253 | ||
| ... | @@ -1307,15 +1277,12 @@ pub fn readlinkC(file_path: [*]const u8, out_buffer: []u8) ReadLinkError![]u8 { | ... | @@ -1307,15 +1277,12 @@ pub fn readlinkC(file_path: [*]const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| 1307 | const file_path_w = try cStrToPrefixedFileW(file_path); | 1277 | const file_path_w = try cStrToPrefixedFileW(file_path); |
| 1308 | return readlinkW(&file_path_w, out_buffer); | 1278 | return readlinkW(&file_path_w, out_buffer); |
| 1309 | } | 1279 | } |
| 1310 | const err = if (builtin.link_libc) blk: { | 1280 | const rc = if (builtin.link_libc or @hasDecl(system, "SYS_readlink")) blk: { |
| 1311 | break :blk if (std.c.readlink(file_path, out_buffer.ptr, out_buffer.len) == -1) errno().* else 0; | 1281 | break :blk system.readlink(file_path, out_buffer.ptr, out_buffer.len); |
| 1312 | } else if (@hasDecl(system, "readlink")) blk: { | ||
| 1313 | break :blk system.getErrno(system.readlink(file_path, out_buffer.ptr, out_buffer.len)); | ||
| 1314 | } else blk: { | 1282 | } else blk: { |
| 1315 | break :blk system.getErrno(system.readlinkat(AT_FDCWD, file_path, out_buffer.ptr, out_buffer.len)); | 1283 | break :blk system.readlinkat(AT_FDCWD, file_path, out_buffer.ptr, out_buffer.len); |
| 1316 | }; | 1284 | }; |
| 1317 | const rc = system.readlink(file_path, out_buffer, out_buffer.len); | 1285 | switch (errno(rc)) { |
| 1318 | switch (system.getErrno(rc)) { | ||
| 1319 | 0 => return out_buffer[0..rc], | 1286 | 0 => return out_buffer[0..rc], |
| 1320 | EACCES => return error.AccessDenied, | 1287 | EACCES => return error.AccessDenied, |
| 1321 | EFAULT => unreachable, | 1288 | EFAULT => unreachable, |
| ... | @@ -1338,7 +1305,7 @@ pub const SetIdError = error{ | ... | @@ -1338,7 +1305,7 @@ pub const SetIdError = error{ |
| 1338 | }; | 1305 | }; |
| 1339 | 1306 | ||
| 1340 | pub fn setuid(uid: u32) SetIdError!void { | 1307 | pub fn setuid(uid: u32) SetIdError!void { |
| 1341 | switch (system.getErrno(system.setuid(uid))) { | 1308 | switch (errno(system.setuid(uid))) { |
| 1342 | 0 => return, | 1309 | 0 => return, |
| 1343 | EAGAIN => return error.ResourceLimitReached, | 1310 | EAGAIN => return error.ResourceLimitReached, |
| 1344 | EINVAL => return error.InvalidUserId, | 1311 | EINVAL => return error.InvalidUserId, |
| ... | @@ -1348,7 +1315,7 @@ pub fn setuid(uid: u32) SetIdError!void { | ... | @@ -1348,7 +1315,7 @@ pub fn setuid(uid: u32) SetIdError!void { |
| 1348 | } | 1315 | } |
| 1349 | 1316 | ||
| 1350 | pub fn setreuid(ruid: u32, euid: u32) SetIdError!void { | 1317 | pub fn setreuid(ruid: u32, euid: u32) SetIdError!void { |
| 1351 | switch (system.getErrno(system.setreuid(ruid, euid))) { | 1318 | switch (errno(system.setreuid(ruid, euid))) { |
| 1352 | 0 => return, | 1319 | 0 => return, |
| 1353 | EAGAIN => return error.ResourceLimitReached, | 1320 | EAGAIN => return error.ResourceLimitReached, |
| 1354 | EINVAL => return error.InvalidUserId, | 1321 | EINVAL => return error.InvalidUserId, |
| ... | @@ -1358,7 +1325,7 @@ pub fn setreuid(ruid: u32, euid: u32) SetIdError!void { | ... | @@ -1358,7 +1325,7 @@ pub fn setreuid(ruid: u32, euid: u32) SetIdError!void { |
| 1358 | } | 1325 | } |
| 1359 | 1326 | ||
| 1360 | pub fn setgid(gid: u32) SetIdError!void { | 1327 | pub fn setgid(gid: u32) SetIdError!void { |
| 1361 | switch (system.getErrno(system.setgid(gid))) { | 1328 | switch (errno(system.setgid(gid))) { |
| 1362 | 0 => return, | 1329 | 0 => return, |
| 1363 | EAGAIN => return error.ResourceLimitReached, | 1330 | EAGAIN => return error.ResourceLimitReached, |
| 1364 | EINVAL => return error.InvalidUserId, | 1331 | EINVAL => return error.InvalidUserId, |
| ... | @@ -1368,7 +1335,7 @@ pub fn setgid(gid: u32) SetIdError!void { | ... | @@ -1368,7 +1335,7 @@ pub fn setgid(gid: u32) SetIdError!void { |
| 1368 | } | 1335 | } |
| 1369 | 1336 | ||
| 1370 | pub fn setregid(rgid: u32, egid: u32) SetIdError!void { | 1337 | pub fn setregid(rgid: u32, egid: u32) SetIdError!void { |
| 1371 | switch (system.getErrno(system.setregid(rgid, egid))) { | 1338 | switch (errno(system.setregid(rgid, egid))) { |
| 1372 | 0 => return, | 1339 | 0 => return, |
| 1373 | EAGAIN => return error.ResourceLimitReached, | 1340 | EAGAIN => return error.ResourceLimitReached, |
| 1374 | EINVAL => return error.InvalidUserId, | 1341 | EINVAL => return error.InvalidUserId, |
| ... | @@ -1382,7 +1349,7 @@ pub const GetStdHandleError = error{ | ... | @@ -1382,7 +1349,7 @@ pub const GetStdHandleError = error{ |
| 1382 | Unexpected, | 1349 | Unexpected, |
| 1383 | }; | 1350 | }; |
| 1384 | 1351 | ||
| 1385 | pub fn GetStdHandle(handle_id: windows.DWORD) GetStdHandleError!FileHandle { | 1352 | pub fn GetStdHandle(handle_id: windows.DWORD) GetStdHandleError!fd_t { |
| 1386 | if (windows.is_the_target) { | 1353 | if (windows.is_the_target) { |
| 1387 | const handle = windows.GetStdHandle(handle_id) orelse return error.NoStandardHandleAttached; | 1354 | const handle = windows.GetStdHandle(handle_id) orelse return error.NoStandardHandleAttached; |
| 1388 | if (handle == windows.INVALID_HANDLE_VALUE) { | 1355 | if (handle == windows.INVALID_HANDLE_VALUE) { |
| ... | @@ -1402,9 +1369,9 @@ pub fn GetStdHandle(handle_id: windows.DWORD) GetStdHandleError!FileHandle { | ... | @@ -1402,9 +1369,9 @@ pub fn GetStdHandle(handle_id: windows.DWORD) GetStdHandleError!FileHandle { |
| 1402 | } | 1369 | } |
| 1403 | 1370 | ||
| 1404 | /// Test whether a file descriptor refers to a terminal. | 1371 | /// Test whether a file descriptor refers to a terminal. |
| 1405 | pub fn isatty(handle: FileHandle) bool { | 1372 | pub fn isatty(handle: fd_t) bool { |
| 1406 | if (builtin.link_libc) { | 1373 | if (builtin.link_libc) { |
| 1407 | return c.isatty(handle) != 0; | 1374 | return system.isatty(handle) != 0; |
| 1408 | } | 1375 | } |
| 1409 | if (windows.is_the_target) { | 1376 | if (windows.is_the_target) { |
| 1410 | if (isCygwinPty(handle)) | 1377 | if (isCygwinPty(handle)) |
| ... | @@ -1421,7 +1388,7 @@ pub fn isatty(handle: FileHandle) bool { | ... | @@ -1421,7 +1388,7 @@ pub fn isatty(handle: FileHandle) bool { |
| 1421 | return system.syscall3(system.SYS_ioctl, @bitCast(usize, isize(handle)), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; | 1388 | return system.syscall3(system.SYS_ioctl, @bitCast(usize, isize(handle)), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; |
| 1422 | } | 1389 | } |
| 1423 | 1390 | ||
| 1424 | pub fn isCygwinPty(handle: FileHandle) bool { | 1391 | pub fn isCygwinPty(handle: fd_t) bool { |
| 1425 | if (!windows.is_the_target) return false; | 1392 | if (!windows.is_the_target) return false; |
| 1426 | 1393 | ||
| 1427 | const size = @sizeOf(windows.FILE_NAME_INFO); | 1394 | const size = @sizeOf(windows.FILE_NAME_INFO); |
| ... | @@ -1472,7 +1439,7 @@ pub const SocketError = error{ | ... | @@ -1472,7 +1439,7 @@ pub const SocketError = error{ |
| 1472 | 1439 | ||
| 1473 | pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!i32 { | 1440 | pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!i32 { |
| 1474 | const rc = system.socket(domain, socket_type, protocol); | 1441 | const rc = system.socket(domain, socket_type, protocol); |
| 1475 | switch (system.getErrno(rc)) { | 1442 | switch (errno(rc)) { |
| 1476 | 0 => return @intCast(i32, rc), | 1443 | 0 => return @intCast(i32, rc), |
| 1477 | EACCES => return error.PermissionDenied, | 1444 | EACCES => return error.PermissionDenied, |
| 1478 | EAFNOSUPPORT => return error.AddressFamilyNotSupported, | 1445 | EAFNOSUPPORT => return error.AddressFamilyNotSupported, |
| ... | @@ -1525,7 +1492,7 @@ pub const BindError = error{ | ... | @@ -1525,7 +1492,7 @@ pub const BindError = error{ |
| 1525 | /// addr is `*const T` where T is one of the sockaddr | 1492 | /// addr is `*const T` where T is one of the sockaddr |
| 1526 | pub fn bind(fd: i32, addr: *const sockaddr) BindError!void { | 1493 | pub fn bind(fd: i32, addr: *const sockaddr) BindError!void { |
| 1527 | const rc = system.bind(fd, system, @sizeOf(sockaddr)); | 1494 | const rc = system.bind(fd, system, @sizeOf(sockaddr)); |
| 1528 | switch (system.getErrno(rc)) { | 1495 | switch (errno(rc)) { |
| 1529 | 0 => return, | 1496 | 0 => return, |
| 1530 | EACCES => return error.AccessDenied, | 1497 | EACCES => return error.AccessDenied, |
| 1531 | EADDRINUSE => return error.AddressInUse, | 1498 | EADDRINUSE => return error.AddressInUse, |
| ... | @@ -1563,7 +1530,7 @@ const ListenError = error{ | ... | @@ -1563,7 +1530,7 @@ const ListenError = error{ |
| 1563 | 1530 | ||
| 1564 | pub fn listen(sockfd: i32, backlog: u32) ListenError!void { | 1531 | pub fn listen(sockfd: i32, backlog: u32) ListenError!void { |
| 1565 | const rc = system.listen(sockfd, backlog); | 1532 | const rc = system.listen(sockfd, backlog); |
| 1566 | switch (system.getErrno(rc)) { | 1533 | switch (errno(rc)) { |
| 1567 | 0 => return, | 1534 | 0 => return, |
| 1568 | EADDRINUSE => return error.AddressInUse, | 1535 | EADDRINUSE => return error.AddressInUse, |
| 1569 | EBADF => unreachable, | 1536 | EBADF => unreachable, |
| ... | @@ -1606,7 +1573,7 @@ pub fn accept4(fd: i32, addr: *sockaddr, flags: u32) AcceptError!i32 { | ... | @@ -1606,7 +1573,7 @@ pub fn accept4(fd: i32, addr: *sockaddr, flags: u32) AcceptError!i32 { |
| 1606 | while (true) { | 1573 | while (true) { |
| 1607 | var sockaddr_size = u32(@sizeOf(sockaddr)); | 1574 | var sockaddr_size = u32(@sizeOf(sockaddr)); |
| 1608 | const rc = system.accept4(fd, addr, &sockaddr_size, flags); | 1575 | const rc = system.accept4(fd, addr, &sockaddr_size, flags); |
| 1609 | switch (system.getErrno(rc)) { | 1576 | switch (errno(rc)) { |
| 1610 | 0 => return @intCast(i32, rc), | 1577 | 0 => return @intCast(i32, rc), |
| 1611 | EINTR => continue, | 1578 | EINTR => continue, |
| 1612 | else => |err| return unexpectedErrno(err), | 1579 | else => |err| return unexpectedErrno(err), |
| ... | @@ -1634,7 +1601,7 @@ pub fn accept4_async(fd: i32, addr: *sockaddr, flags: u32) AcceptError!i32 { | ... | @@ -1634,7 +1601,7 @@ pub fn accept4_async(fd: i32, addr: *sockaddr, flags: u32) AcceptError!i32 { |
| 1634 | while (true) { | 1601 | while (true) { |
| 1635 | var sockaddr_size = u32(@sizeOf(sockaddr)); | 1602 | var sockaddr_size = u32(@sizeOf(sockaddr)); |
| 1636 | const rc = system.accept4(fd, addr, &sockaddr_size, flags); | 1603 | const rc = system.accept4(fd, addr, &sockaddr_size, flags); |
| 1637 | switch (system.getErrno(rc)) { | 1604 | switch (errno(rc)) { |
| 1638 | 0 => return @intCast(i32, rc), | 1605 | 0 => return @intCast(i32, rc), |
| 1639 | EINTR => continue, | 1606 | EINTR => continue, |
| 1640 | else => |err| return unexpectedErrno(err), | 1607 | else => |err| return unexpectedErrno(err), |
| ... | @@ -1674,7 +1641,7 @@ pub const EpollCreateError = error{ | ... | @@ -1674,7 +1641,7 @@ pub const EpollCreateError = error{ |
| 1674 | 1641 | ||
| 1675 | pub fn epoll_create1(flags: u32) EpollCreateError!i32 { | 1642 | pub fn epoll_create1(flags: u32) EpollCreateError!i32 { |
| 1676 | const rc = system.epoll_create1(flags); | 1643 | const rc = system.epoll_create1(flags); |
| 1677 | switch (system.getErrno(rc)) { | 1644 | switch (errno(rc)) { |
| 1678 | 0 => return @intCast(i32, rc), | 1645 | 0 => return @intCast(i32, rc), |
| 1679 | else => |err| return unexpectedErrno(err), | 1646 | else => |err| return unexpectedErrno(err), |
| 1680 | 1647 | ||
| ... | @@ -1715,7 +1682,7 @@ pub const EpollCtlError = error{ | ... | @@ -1715,7 +1682,7 @@ pub const EpollCtlError = error{ |
| 1715 | 1682 | ||
| 1716 | pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: *epoll_event) EpollCtlError!void { | 1683 | pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: *epoll_event) EpollCtlError!void { |
| 1717 | const rc = system.epoll_ctl(epfd, op, fd, event); | 1684 | const rc = system.epoll_ctl(epfd, op, fd, event); |
| 1718 | switch (system.getErrno(rc)) { | 1685 | switch (errno(rc)) { |
| 1719 | 0 => return, | 1686 | 0 => return, |
| 1720 | else => |err| return unexpectedErrno(err), | 1687 | else => |err| return unexpectedErrno(err), |
| 1721 | 1688 | ||
| ... | @@ -1737,7 +1704,7 @@ pub fn epoll_wait(epfd: i32, events: []epoll_event, timeout: i32) usize { | ... | @@ -1737,7 +1704,7 @@ pub fn epoll_wait(epfd: i32, events: []epoll_event, timeout: i32) usize { |
| 1737 | while (true) { | 1704 | while (true) { |
| 1738 | // TODO get rid of the @intCast | 1705 | // TODO get rid of the @intCast |
| 1739 | const rc = system.epoll_wait(epfd, events.ptr, @intCast(u32, events.len), timeout); | 1706 | const rc = system.epoll_wait(epfd, events.ptr, @intCast(u32, events.len), timeout); |
| 1740 | switch (system.getErrno(rc)) { | 1707 | switch (errno(rc)) { |
| 1741 | 0 => return rc, | 1708 | 0 => return rc, |
| 1742 | EINTR => continue, | 1709 | EINTR => continue, |
| 1743 | EBADF => unreachable, | 1710 | EBADF => unreachable, |
| ... | @@ -1757,7 +1724,7 @@ pub const EventFdError = error{ | ... | @@ -1757,7 +1724,7 @@ pub const EventFdError = error{ |
| 1757 | 1724 | ||
| 1758 | pub fn eventfd(initval: u32, flags: u32) EventFdError!i32 { | 1725 | pub fn eventfd(initval: u32, flags: u32) EventFdError!i32 { |
| 1759 | const rc = system.eventfd(initval, flags); | 1726 | const rc = system.eventfd(initval, flags); |
| 1760 | switch (system.getErrno(rc)) { | 1727 | switch (errno(rc)) { |
| 1761 | 0 => return @intCast(i32, rc), | 1728 | 0 => return @intCast(i32, rc), |
| 1762 | else => |err| return unexpectedErrno(err), | 1729 | else => |err| return unexpectedErrno(err), |
| 1763 | 1730 | ||
| ... | @@ -1779,7 +1746,7 @@ pub const GetSockNameError = error{ | ... | @@ -1779,7 +1746,7 @@ pub const GetSockNameError = error{ |
| 1779 | pub fn getsockname(sockfd: i32) GetSockNameError!sockaddr { | 1746 | pub fn getsockname(sockfd: i32) GetSockNameError!sockaddr { |
| 1780 | var addr: sockaddr = undefined; | 1747 | var addr: sockaddr = undefined; |
| 1781 | var addrlen: socklen_t = @sizeOf(sockaddr); | 1748 | var addrlen: socklen_t = @sizeOf(sockaddr); |
| 1782 | switch (system.getErrno(system.getsockname(sockfd, &addr, &addrlen))) { | 1749 | switch (errno(system.getsockname(sockfd, &addr, &addrlen))) { |
| 1783 | 0 => return addr, | 1750 | 0 => return addr, |
| 1784 | else => |err| return unexpectedErrno(err), | 1751 | else => |err| return unexpectedErrno(err), |
| 1785 | 1752 | ||
| ... | @@ -1832,7 +1799,7 @@ pub const ConnectError = error{ | ... | @@ -1832,7 +1799,7 @@ pub const ConnectError = error{ |
| 1832 | /// For non-blocking, see `connect_async`. | 1799 | /// For non-blocking, see `connect_async`. |
| 1833 | pub fn connect(sockfd: i32, sockaddr: *const sockaddr) ConnectError!void { | 1800 | pub fn connect(sockfd: i32, sockaddr: *const sockaddr) ConnectError!void { |
| 1834 | while (true) { | 1801 | while (true) { |
| 1835 | switch (system.getErrno(system.connect(sockfd, sockaddr, @sizeOf(sockaddr)))) { | 1802 | switch (errno(system.connect(sockfd, sockaddr, @sizeOf(sockaddr)))) { |
| 1836 | 0 => return, | 1803 | 0 => return, |
| 1837 | else => |err| return unexpectedErrno(err), | 1804 | else => |err| return unexpectedErrno(err), |
| 1838 | 1805 | ||
| ... | @@ -1861,10 +1828,10 @@ pub fn connect(sockfd: i32, sockaddr: *const sockaddr) ConnectError!void { | ... | @@ -1861,10 +1828,10 @@ pub fn connect(sockfd: i32, sockaddr: *const sockaddr) ConnectError!void { |
| 1861 | /// It expects to receive EINPROGRESS`. | 1828 | /// It expects to receive EINPROGRESS`. |
| 1862 | pub fn connect_async(sockfd: i32, sockaddr: *const c_void, len: u32) ConnectError!void { | 1829 | pub fn connect_async(sockfd: i32, sockaddr: *const c_void, len: u32) ConnectError!void { |
| 1863 | while (true) { | 1830 | while (true) { |
| 1864 | switch (system.getErrno(system.connect(sockfd, sockaddr, len))) { | 1831 | switch (errno(system.connect(sockfd, sockaddr, len))) { |
| 1865 | 0, EINPROGRESS => return, | 1832 | 0, EINPROGRESS => return, |
| 1866 | EINTR => continue, | 1833 | EINTR => continue, |
| 1867 | else => return unexpectedErrno(err), | 1834 | else => |err| return unexpectedErrno(err), |
| 1868 | 1835 | ||
| 1869 | EACCES => return error.PermissionDenied, | 1836 | EACCES => return error.PermissionDenied, |
| 1870 | EPERM => return error.PermissionDenied, | 1837 | EPERM => return error.PermissionDenied, |
| ... | @@ -1890,7 +1857,7 @@ pub fn getsockoptError(sockfd: i32) ConnectError!void { | ... | @@ -1890,7 +1857,7 @@ pub fn getsockoptError(sockfd: i32) ConnectError!void { |
| 1890 | var size: u32 = @sizeOf(i32); | 1857 | var size: u32 = @sizeOf(i32); |
| 1891 | const rc = system.getsockopt(sockfd, SOL_SOCKET, SO_ERROR, @ptrCast([*]u8, &err_code), &size); | 1858 | const rc = system.getsockopt(sockfd, SOL_SOCKET, SO_ERROR, @ptrCast([*]u8, &err_code), &size); |
| 1892 | assert(size == 4); | 1859 | assert(size == 4); |
| 1893 | switch (system.getErrno(rc)) { | 1860 | switch (errno(rc)) { |
| 1894 | 0 => switch (err_code) { | 1861 | 0 => switch (err_code) { |
| 1895 | 0 => return, | 1862 | 0 => return, |
| 1896 | EACCES => return error.PermissionDenied, | 1863 | EACCES => return error.PermissionDenied, |
| ... | @@ -1919,10 +1886,10 @@ pub fn getsockoptError(sockfd: i32) ConnectError!void { | ... | @@ -1919,10 +1886,10 @@ pub fn getsockoptError(sockfd: i32) ConnectError!void { |
| 1919 | } | 1886 | } |
| 1920 | } | 1887 | } |
| 1921 | 1888 | ||
| 1922 | pub fn wait(pid: i32) i32 { | 1889 | pub fn waitpid(pid: i32) i32 { |
| 1923 | var status: i32 = undefined; | 1890 | var status: i32 = undefined; |
| 1924 | while (true) { | 1891 | while (true) { |
| 1925 | switch (system.getErrno(system.waitpid(pid, &status, 0))) { | 1892 | switch (errno(system.waitpid(pid, &status, 0))) { |
| 1926 | 0 => return status, | 1893 | 0 => return status, |
| 1927 | EINTR => continue, | 1894 | EINTR => continue, |
| 1928 | ECHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error. | 1895 | ECHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error. |
| ... | @@ -1932,16 +1899,28 @@ pub fn wait(pid: i32) i32 { | ... | @@ -1932,16 +1899,28 @@ pub fn wait(pid: i32) i32 { |
| 1932 | } | 1899 | } |
| 1933 | } | 1900 | } |
| 1934 | 1901 | ||
| 1935 | pub fn fstat(fd: FileHandle) !Stat { | 1902 | pub const FStatError = error{ |
| 1903 | SystemResources, | ||
| 1904 | Unexpected, | ||
| 1905 | }; | ||
| 1906 | |||
| 1907 | pub fn fstat(fd: fd_t) FStatError!Stat { | ||
| 1936 | var stat: Stat = undefined; | 1908 | var stat: Stat = undefined; |
| 1937 | switch (system.getErrno(system.fstat(fd, &stat))) { | 1909 | if (os.darwin.is_the_target) { |
| 1910 | switch (errno(system.@"fstat$INODE64"(fd, buf))) { | ||
| 1911 | 0 => return stat, | ||
| 1912 | EBADF => unreachable, // Always a race condition. | ||
| 1913 | ENOMEM => return error.SystemResources, | ||
| 1914 | else => |err| return unexpectedErrno(err), | ||
| 1915 | } | ||
| 1916 | } | ||
| 1917 | |||
| 1918 | switch (errno(system.fstat(fd, &stat))) { | ||
| 1938 | 0 => return stat, | 1919 | 0 => return stat, |
| 1939 | EBADF => unreachable, // Always a race condition. | 1920 | EBADF => unreachable, // Always a race condition. |
| 1940 | ENOMEM => return error.SystemResources, | 1921 | ENOMEM => return error.SystemResources, |
| 1941 | else => |err| return unexpectedErrno(err), | 1922 | else => |err| return unexpectedErrno(err), |
| 1942 | } | 1923 | } |
| 1943 | |||
| 1944 | return stat; | ||
| 1945 | } | 1924 | } |
| 1946 | 1925 | ||
| 1947 | pub const KQueueError = error{ | 1926 | pub const KQueueError = error{ |
| ... | @@ -1956,7 +1935,7 @@ pub const KQueueError = error{ | ... | @@ -1956,7 +1935,7 @@ pub const KQueueError = error{ |
| 1956 | 1935 | ||
| 1957 | pub fn kqueue() KQueueError!i32 { | 1936 | pub fn kqueue() KQueueError!i32 { |
| 1958 | const rc = system.kqueue(); | 1937 | const rc = system.kqueue(); |
| 1959 | switch (system.getErrno(rc)) { | 1938 | switch (errno(rc)) { |
| 1960 | 0 => return @intCast(i32, rc), | 1939 | 0 => return @intCast(i32, rc), |
| 1961 | EMFILE => return error.ProcessFdQuotaExceeded, | 1940 | EMFILE => return error.ProcessFdQuotaExceeded, |
| 1962 | ENFILE => return error.SystemFdQuotaExceeded, | 1941 | ENFILE => return error.SystemFdQuotaExceeded, |
| ... | @@ -1986,7 +1965,7 @@ pub fn kevent( | ... | @@ -1986,7 +1965,7 @@ pub fn kevent( |
| 1986 | ) KEventError!usize { | 1965 | ) KEventError!usize { |
| 1987 | while (true) { | 1966 | while (true) { |
| 1988 | const rc = system.kevent(kq, changelist, eventlist, timeout); | 1967 | const rc = system.kevent(kq, changelist, eventlist, timeout); |
| 1989 | switch (system.getErrno(rc)) { | 1968 | switch (errno(rc)) { |
| 1990 | 0 => return rc, | 1969 | 0 => return rc, |
| 1991 | EACCES => return error.AccessDenied, | 1970 | EACCES => return error.AccessDenied, |
| 1992 | EFAULT => unreachable, | 1971 | EFAULT => unreachable, |
| ... | @@ -2011,7 +1990,7 @@ pub const INotifyInitError = error{ | ... | @@ -2011,7 +1990,7 @@ pub const INotifyInitError = error{ |
| 2011 | /// initialize an inotify instance | 1990 | /// initialize an inotify instance |
| 2012 | pub fn inotify_init1(flags: u32) INotifyInitError!i32 { | 1991 | pub fn inotify_init1(flags: u32) INotifyInitError!i32 { |
| 2013 | const rc = system.inotify_init1(flags); | 1992 | const rc = system.inotify_init1(flags); |
| 2014 | switch (system.getErrno(rc)) { | 1993 | switch (errno(rc)) { |
| 2015 | 0 => return @intCast(i32, rc), | 1994 | 0 => return @intCast(i32, rc), |
| 2016 | EINVAL => unreachable, | 1995 | EINVAL => unreachable, |
| 2017 | EMFILE => return error.ProcessFdQuotaExceeded, | 1996 | EMFILE => return error.ProcessFdQuotaExceeded, |
| ... | @@ -2039,7 +2018,7 @@ pub fn inotify_add_watch(inotify_fd: i32, pathname: []const u8, mask: u32) INoti | ... | @@ -2039,7 +2018,7 @@ pub fn inotify_add_watch(inotify_fd: i32, pathname: []const u8, mask: u32) INoti |
| 2039 | /// Same as `inotify_add_watch` except pathname is null-terminated. | 2018 | /// Same as `inotify_add_watch` except pathname is null-terminated. |
| 2040 | pub fn inotify_add_watchC(inotify_fd: i32, pathname: [*]const u8, mask: u32) INotifyAddWatchError!i32 { | 2019 | pub fn inotify_add_watchC(inotify_fd: i32, pathname: [*]const u8, mask: u32) INotifyAddWatchError!i32 { |
| 2041 | const rc = system.inotify_add_watch(inotify_fd, pathname, mask); | 2020 | const rc = system.inotify_add_watch(inotify_fd, pathname, mask); |
| 2042 | switch (system.getErrno(rc)) { | 2021 | switch (errno(rc)) { |
| 2043 | 0 => return @intCast(i32, rc), | 2022 | 0 => return @intCast(i32, rc), |
| 2044 | EACCES => return error.AccessDenied, | 2023 | EACCES => return error.AccessDenied, |
| 2045 | EBADF => unreachable, | 2024 | EBADF => unreachable, |
| ... | @@ -2055,7 +2034,7 @@ pub fn inotify_add_watchC(inotify_fd: i32, pathname: [*]const u8, mask: u32) INo | ... | @@ -2055,7 +2034,7 @@ pub fn inotify_add_watchC(inotify_fd: i32, pathname: [*]const u8, mask: u32) INo |
| 2055 | 2034 | ||
| 2056 | /// remove an existing watch from an inotify instance | 2035 | /// remove an existing watch from an inotify instance |
| 2057 | pub fn inotify_rm_watch(inotify_fd: i32, wd: i32) void { | 2036 | pub fn inotify_rm_watch(inotify_fd: i32, wd: i32) void { |
| 2058 | switch (system.getErrno(system.inotify_rm_watch(inotify_fd, wd))) { | 2037 | switch (errno(system.inotify_rm_watch(inotify_fd, wd))) { |
| 2059 | 0 => return, | 2038 | 0 => return, |
| 2060 | EBADF => unreachable, | 2039 | EBADF => unreachable, |
| 2061 | EINVAL => unreachable, | 2040 | EINVAL => unreachable, |
| ... | @@ -2071,12 +2050,12 @@ pub const MProtectError = error{ | ... | @@ -2071,12 +2050,12 @@ pub const MProtectError = error{ |
| 2071 | 2050 | ||
| 2072 | /// address and length must be page-aligned | 2051 | /// address and length must be page-aligned |
| 2073 | pub fn mprotect(address: usize, length: usize, protection: u32) MProtectError!void { | 2052 | pub fn mprotect(address: usize, length: usize, protection: u32) MProtectError!void { |
| 2074 | const negative_page_size = @bitCast(usize, -isize(page_size)); | 2053 | const negative_page_size = @bitCast(usize, -isize(os.page_size)); |
| 2075 | const aligned_address = address & negative_page_size; | 2054 | const aligned_address = address & negative_page_size; |
| 2076 | const aligned_end = (address + length + page_size - 1) & negative_page_size; | 2055 | const aligned_end = (address + length + os.page_size - 1) & negative_page_size; |
| 2077 | assert(address == aligned_address); | 2056 | assert(address == aligned_address); |
| 2078 | assert(length == aligned_end - aligned_address); | 2057 | assert(length == aligned_end - aligned_address); |
| 2079 | switch (system.getErrno(system.mprotect(address, length, protection))) { | 2058 | switch (errno(system.mprotect(address, length, protection))) { |
| 2080 | 0 => return, | 2059 | 0 => return, |
| 2081 | EINVAL => unreachable, | 2060 | EINVAL => unreachable, |
| 2082 | EACCES => return error.AccessDenied, | 2061 | EACCES => return error.AccessDenied, |
| ... | @@ -2085,6 +2064,238 @@ pub fn mprotect(address: usize, length: usize, protection: u32) MProtectError!vo | ... | @@ -2085,6 +2064,238 @@ pub fn mprotect(address: usize, length: usize, protection: u32) MProtectError!vo |
| 2085 | } | 2064 | } |
| 2086 | } | 2065 | } |
| 2087 | 2066 | ||
| 2067 | pub const ForkError = error{ | ||
| 2068 | SystemResources, | ||
| 2069 | Unexpected, | ||
| 2070 | }; | ||
| 2071 | |||
| 2072 | pub fn fork() ForkError!pid_t { | ||
| 2073 | if (builtin.link_libc) { | ||
| 2074 | return system.fork(); | ||
| 2075 | } | ||
| 2076 | if (linux.is_the_target) { | ||
| 2077 | const rc = if (@hasDecl(system, "SYS_fork")) system.fork() else system.clone2(SIGCHLD, 0); | ||
| 2078 | switch (errno(rc)) { | ||
| 2079 | 0 => return rc, | ||
| 2080 | EAGAIN => return error.SystemResources, | ||
| 2081 | ENOMEM => return error.SystemResources, | ||
| 2082 | else => |err| return unexpectedErrno(err), | ||
| 2083 | } | ||
| 2084 | } | ||
| 2085 | } | ||
| 2086 | |||
| 2087 | pub const MMapError = error{ | ||
| 2088 | AccessDenied, | ||
| 2089 | PermissionDenied, | ||
| 2090 | LockedMemoryLimitExceeded, | ||
| 2091 | SystemFdQuotaExceeded, | ||
| 2092 | MemoryMappingNotSupported, | ||
| 2093 | OutOfMemory, | ||
| 2094 | }; | ||
| 2095 | |||
| 2096 | /// Map files or devices into memory. | ||
| 2097 | /// Use of a mapped region can result in these signals: | ||
| 2098 | /// * SIGSEGV - Attempted write into a region mapped as read-only. | ||
| 2099 | /// * SIGBUS - Attempted access to a portion of the buffer that does not correspond to the file | ||
| 2100 | pub fn mmap(address: ?[*]u8, length: usize, prot: u32, flags: u32, fd: fd_t, offset: isize) MMapError!usize { | ||
| 2101 | const err = if (builtin.link_libc) blk: { | ||
| 2102 | const rc = system.mmap(address, length, prot, flags, fd, offset); | ||
| 2103 | if (rc != system.MMAP_FAILED) return rc; | ||
| 2104 | break :blk system._errno().*; | ||
| 2105 | } else blk: { | ||
| 2106 | const rc = system.mmap(address, length, prot, flags, fd, offset); | ||
| 2107 | const err = errno(rc); | ||
| 2108 | if (err == 0) return rc; | ||
| 2109 | break :blk err; | ||
| 2110 | }; | ||
| 2111 | switch (err) { | ||
| 2112 | ETXTBSY => return error.AccessDenied, | ||
| 2113 | EACCES => return error.AccessDenied, | ||
| 2114 | EPERM => return error.PermissionDenied, | ||
| 2115 | EAGAIN => return error.LockedMemoryLimitExceeded, | ||
| 2116 | EBADF => unreachable, // Always a race condition. | ||
| 2117 | EOVERFLOW => unreachable, // The number of pages used for length + offset would overflow. | ||
| 2118 | ENFILE => return error.SystemFdQuotaExceeded, | ||
| 2119 | ENODEV => return error.MemoryMappingNotSupported, | ||
| 2120 | EINVAL => unreachable, // Invalid parameters to mmap() | ||
| 2121 | ENOMEM => return error.OutOfMemory, | ||
| 2122 | else => return unexpectedErrno(err), | ||
| 2123 | } | ||
| 2124 | } | ||
| 2125 | |||
| 2126 | /// Deletes the mappings for the specified address range, causing | ||
| 2127 | /// further references to addresses within the range to generate invalid memory references. | ||
| 2128 | /// Note that while POSIX allows unmapping a region in the middle of an existing mapping, | ||
| 2129 | /// Zig's munmap function does not, for two reasons: | ||
| 2130 | /// * It violates the Zig principle that resource deallocation must succeed. | ||
| 2131 | /// * The Windows function, VirtualFree, has this restriction. | ||
| 2132 | pub fn munmap(address: usize, length: usize) void { | ||
| 2133 | switch (errno(system.munmap(address, length))) { | ||
| 2134 | 0 => return, | ||
| 2135 | EINVAL => unreachable, // Invalid parameters. | ||
| 2136 | ENOMEM => unreachable, // Attempted to unmap a region in the middle of an existing mapping. | ||
| 2137 | else => unreachable, | ||
| 2138 | } | ||
| 2139 | } | ||
| 2140 | |||
| 2141 | pub const AccessError = error{ | ||
| 2142 | PermissionDenied, | ||
| 2143 | FileNotFound, | ||
| 2144 | NameTooLong, | ||
| 2145 | InputOutput, | ||
| 2146 | SystemResources, | ||
| 2147 | BadPathName, | ||
| 2148 | |||
| 2149 | /// On Windows, file paths must be valid Unicode. | ||
| 2150 | InvalidUtf8, | ||
| 2151 | |||
| 2152 | Unexpected, | ||
| 2153 | }; | ||
| 2154 | |||
| 2155 | /// check user's permissions for a file | ||
| 2156 | pub fn access(path: []const u8, mode: u32) AccessError!void { | ||
| 2157 | if (windows.is_the_target and !builtin.link_libc) { | ||
| 2158 | const path_w = try sliceToPrefixedFileW(path); | ||
| 2159 | return accessW(&path_w, mode); | ||
| 2160 | } | ||
| 2161 | const path_c = try toPosixPath(path); | ||
| 2162 | return accessC(&path_c, mode); | ||
| 2163 | } | ||
| 2164 | |||
| 2165 | /// Call from Windows-specific code if you already have a UTF-16LE encoded, null terminated string. | ||
| 2166 | /// Otherwise use `access` or `accessC`. | ||
| 2167 | /// TODO currently this ignores `mode`. | ||
| 2168 | pub fn accessW(path: [*]const u16, mode: u32) AccessError!void { | ||
| 2169 | if (windows.GetFileAttributesW(path) != windows.INVALID_FILE_ATTRIBUTES) { | ||
| 2170 | return; | ||
| 2171 | } | ||
| 2172 | switch (windows.GetLastError()) { | ||
| 2173 | windows.ERROR.FILE_NOT_FOUND => return error.FileNotFound, | ||
| 2174 | windows.ERROR.PATH_NOT_FOUND => return error.FileNotFound, | ||
| 2175 | windows.ERROR.ACCESS_DENIED => return error.PermissionDenied, | ||
| 2176 | else => |err| return unexpectedErrorWindows(err), | ||
| 2177 | } | ||
| 2178 | } | ||
| 2179 | |||
| 2180 | /// Call if you have a UTF-8 encoded, null-terminated string. | ||
| 2181 | /// Otherwise use `access` or `accessW`. | ||
| 2182 | pub fn accessC(path: [*]const u8, mode: u32) AccessError!void { | ||
| 2183 | if (windows.is_the_target) { | ||
| 2184 | const path_w = try cStrToPrefixedFileW(path); | ||
| 2185 | return accessW(&path_w, mode); | ||
| 2186 | } | ||
| 2187 | switch (errno(system.access(path, mode))) { | ||
| 2188 | 0 => return, | ||
| 2189 | EACCES => return error.PermissionDenied, | ||
| 2190 | EROFS => return error.PermissionDenied, | ||
| 2191 | ELOOP => return error.PermissionDenied, | ||
| 2192 | ETXTBSY => return error.PermissionDenied, | ||
| 2193 | ENOTDIR => return error.FileNotFound, | ||
| 2194 | ENOENT => return error.FileNotFound, | ||
| 2195 | |||
| 2196 | ENAMETOOLONG => return error.NameTooLong, | ||
| 2197 | EINVAL => unreachable, | ||
| 2198 | EFAULT => unreachable, | ||
| 2199 | EIO => return error.InputOutput, | ||
| 2200 | ENOMEM => return error.SystemResources, | ||
| 2201 | else => |err| return unexpectedErrno(err), | ||
| 2202 | } | ||
| 2203 | } | ||
| 2204 | |||
| 2205 | pub const PipeError = error{ | ||
| 2206 | SystemFdQuotaExceeded, | ||
| 2207 | ProcessFdQuotaExceeded, | ||
| 2208 | }; | ||
| 2209 | |||
| 2210 | /// Creates a unidirectional data channel that can be used for interprocess communication. | ||
| 2211 | pub fn pipe(fds: *[2]fd_t) PipeError!void { | ||
| 2212 | const rc = if (builtin.link_libc or @hasDecl(system, SYS_pipe)) | ||
| 2213 | system.pipe(fds) | ||
| 2214 | else | ||
| 2215 | system.pipe2(fds, 0); | ||
| 2216 | switch (errno(rc)) { | ||
| 2217 | 0 => return, | ||
| 2218 | EINVAL => unreachable, // Invalid parameters to pipe() | ||
| 2219 | EFAULT => unreachable, // Invalid fds pointer | ||
| 2220 | ENFILE => return error.SystemFdQuotaExceeded, | ||
| 2221 | EMFILE => return error.ProcessFdQuotaExceeded, | ||
| 2222 | else => |err| return unexpectedErrno(err), | ||
| 2223 | } | ||
| 2224 | } | ||
| 2225 | |||
| 2226 | pub fn pipe2(fds: *[2]fd_t, flags: u32) PipeError!void { | ||
| 2227 | switch (errno(system.pipe2(fds, flags))) { | ||
| 2228 | 0 => return, | ||
| 2229 | EINVAL => unreachable, // Invalid flags | ||
| 2230 | EFAULT => unreachable, // Invalid fds pointer | ||
| 2231 | ENFILE => return error.SystemFdQuotaExceeded, | ||
| 2232 | EMFILE => return error.ProcessFdQuotaExceeded, | ||
| 2233 | else => |err| return unexpectedErrno(err), | ||
| 2234 | } | ||
| 2235 | } | ||
| 2236 | |||
| 2237 | pub const SysCtlError = error{ | ||
| 2238 | PermissionDenied, | ||
| 2239 | SystemResources, | ||
| 2240 | Unexpected, | ||
| 2241 | }; | ||
| 2242 | |||
| 2243 | pub fn sysctl( | ||
| 2244 | name: []const c_int, | ||
| 2245 | oldp: ?*c_void, | ||
| 2246 | oldlenp: ?*usize, | ||
| 2247 | newp: ?*c_void, | ||
| 2248 | newlen: usize, | ||
| 2249 | ) SysCtlError!void { | ||
| 2250 | switch (errno(system.sysctl(name.ptr, name.len, oldp, oldlenp, newp, newlen))) { | ||
| 2251 | 0 => return, | ||
| 2252 | EFAULT => unreachable, | ||
| 2253 | EPERM => return error.PermissionDenied, | ||
| 2254 | ENOMEM => return error.SystemResources, | ||
| 2255 | else => |err| return unexpectedErrno(err), | ||
| 2256 | } | ||
| 2257 | } | ||
| 2258 | |||
| 2259 | pub fn sysctlbynameC( | ||
| 2260 | name: [*]const u8, | ||
| 2261 | oldp: ?*c_void, | ||
| 2262 | oldlenp: ?*usize, | ||
| 2263 | newp: ?*c_void, | ||
| 2264 | newlen: usize, | ||
| 2265 | ) SysCtlError!void { | ||
| 2266 | switch (errno(system.sysctlbyname(name, oldp, oldlenp, newp, newlen))) { | ||
| 2267 | 0 => return, | ||
| 2268 | EFAULT => unreachable, | ||
| 2269 | EPERM => return error.PermissionDenied, | ||
| 2270 | ENOMEM => return error.SystemResources, | ||
| 2271 | else => |err| return unexpectedErrno(err), | ||
| 2272 | } | ||
| 2273 | } | ||
| 2274 | |||
| 2275 | pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void { | ||
| 2276 | switch (errno(system.gettimeofday(tv, tz))) { | ||
| 2277 | 0 => return, | ||
| 2278 | EINVAL => unreachable, | ||
| 2279 | else => unreachable, | ||
| 2280 | } | ||
| 2281 | } | ||
| 2282 | |||
| 2283 | pub fn nanosleep(req: timespec) void { | ||
| 2284 | var rem = req; | ||
| 2285 | while (true) { | ||
| 2286 | switch (errno(system.nanosleep(&rem, &rem))) { | ||
| 2287 | 0 => return, | ||
| 2288 | EINVAL => unreachable, // Invalid parameters. | ||
| 2289 | EFAULT => unreachable, | ||
| 2290 | EINTR => continue, | ||
| 2291 | } | ||
| 2292 | } | ||
| 2293 | } | ||
| 2294 | |||
| 2295 | pub const realpath = std.os.path.real; | ||
| 2296 | pub const realpathC = std.os.path.realC; | ||
| 2297 | pub const realpathW = std.os.path.realW; | ||
| 2298 | |||
| 2088 | /// Used to convert a slice to a null terminated slice on the stack. | 2299 | /// Used to convert a slice to a null terminated slice on the stack. |
| 2089 | /// TODO https://github.com/ziglang/zig/issues/287 | 2300 | /// TODO https://github.com/ziglang/zig/issues/287 |
| 2090 | pub fn toPosixPath(file_path: []const u8) ![PATH_MAX]u8 { | 2301 | pub fn toPosixPath(file_path: []const u8) ![PATH_MAX]u8 { |
std/os/wasi.zig+2-318| ... | @@ -4,10 +4,8 @@ const std = @import("std"); | ... | @@ -4,10 +4,8 @@ const std = @import("std"); |
| 4 | const assert = std.debug.assert; | 4 | const assert = std.debug.assert; |
| 5 | 5 | ||
| 6 | pub const is_the_target = @import("builtin").os == .wasi; | 6 | pub const is_the_target = @import("builtin").os == .wasi; |
| 7 | 7 | pub const posix = @import("wasi/posix.zig"); | |
| 8 | pub const STDIN_FILENO = 0; | 8 | pub use posix; |
| 9 | pub const STDOUT_FILENO = 1; | ||
| 10 | pub const STDERR_FILENO = 2; | ||
| 11 | 9 | ||
| 12 | comptime { | 10 | comptime { |
| 13 | assert(@alignOf(i8) == 1); | 11 | assert(@alignOf(i8) == 1); |
| ... | @@ -20,320 +18,6 @@ comptime { | ... | @@ -20,320 +18,6 @@ comptime { |
| 20 | assert(@alignOf(u64) == 8); | 18 | assert(@alignOf(u64) == 8); |
| 21 | } | 19 | } |
| 22 | 20 | ||
| 23 | pub const advice_t = u8; | ||
| 24 | pub const ADVICE_NORMAL: advice_t = 0; | ||
| 25 | pub const ADVICE_SEQUENTIAL: advice_t = 1; | ||
| 26 | pub const ADVICE_RANDOM: advice_t = 2; | ||
| 27 | pub const ADVICE_WILLNEED: advice_t = 3; | ||
| 28 | pub const ADVICE_DONTNEED: advice_t = 4; | ||
| 29 | pub const ADVICE_NOREUSE: advice_t = 5; | ||
| 30 | |||
| 31 | pub const ciovec_t = extern struct { | ||
| 32 | buf: [*]const u8, | ||
| 33 | buf_len: usize, | ||
| 34 | }; | ||
| 35 | |||
| 36 | pub const clockid_t = u32; | ||
| 37 | pub const CLOCK_REALTIME: clockid_t = 0; | ||
| 38 | pub const CLOCK_MONOTONIC: clockid_t = 1; | ||
| 39 | pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2; | ||
| 40 | pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3; | ||
| 41 | |||
| 42 | pub const device_t = u64; | ||
| 43 | |||
| 44 | pub const dircookie_t = u64; | ||
| 45 | pub const DIRCOOKIE_START: dircookie_t = 0; | ||
| 46 | |||
| 47 | pub const dirent_t = extern struct { | ||
| 48 | d_next: dircookie_t, | ||
| 49 | d_ino: inode_t, | ||
| 50 | d_namlen: u32, | ||
| 51 | d_type: filetype_t, | ||
| 52 | }; | ||
| 53 | |||
| 54 | pub const errno_t = u16; | ||
| 55 | pub const ESUCCESS: errno_t = 0; | ||
| 56 | pub const E2BIG: errno_t = 1; | ||
| 57 | pub const EACCES: errno_t = 2; | ||
| 58 | pub const EADDRINUSE: errno_t = 3; | ||
| 59 | pub const EADDRNOTAVAIL: errno_t = 4; | ||
| 60 | pub const EAFNOSUPPORT: errno_t = 5; | ||
| 61 | pub const EAGAIN: errno_t = 6; | ||
| 62 | pub const EALREADY: errno_t = 7; | ||
| 63 | pub const EBADF: errno_t = 8; | ||
| 64 | pub const EBADMSG: errno_t = 9; | ||
| 65 | pub const EBUSY: errno_t = 10; | ||
| 66 | pub const ECANCELED: errno_t = 11; | ||
| 67 | pub const ECHILD: errno_t = 12; | ||
| 68 | pub const ECONNABORTED: errno_t = 13; | ||
| 69 | pub const ECONNREFUSED: errno_t = 14; | ||
| 70 | pub const ECONNRESET: errno_t = 15; | ||
| 71 | pub const EDEADLK: errno_t = 16; | ||
| 72 | pub const EDESTADDRREQ: errno_t = 17; | ||
| 73 | pub const EDOM: errno_t = 18; | ||
| 74 | pub const EDQUOT: errno_t = 19; | ||
| 75 | pub const EEXIST: errno_t = 20; | ||
| 76 | pub const EFAULT: errno_t = 21; | ||
| 77 | pub const EFBIG: errno_t = 22; | ||
| 78 | pub const EHOSTUNREACH: errno_t = 23; | ||
| 79 | pub const EIDRM: errno_t = 24; | ||
| 80 | pub const EILSEQ: errno_t = 25; | ||
| 81 | pub const EINPROGRESS: errno_t = 26; | ||
| 82 | pub const EINTR: errno_t = 27; | ||
| 83 | pub const EINVAL: errno_t = 28; | ||
| 84 | pub const EIO: errno_t = 29; | ||
| 85 | pub const EISCONN: errno_t = 30; | ||
| 86 | pub const EISDIR: errno_t = 31; | ||
| 87 | pub const ELOOP: errno_t = 32; | ||
| 88 | pub const EMFILE: errno_t = 33; | ||
| 89 | pub const EMLINK: errno_t = 34; | ||
| 90 | pub const EMSGSIZE: errno_t = 35; | ||
| 91 | pub const EMULTIHOP: errno_t = 36; | ||
| 92 | pub const ENAMETOOLONG: errno_t = 37; | ||
| 93 | pub const ENETDOWN: errno_t = 38; | ||
| 94 | pub const ENETRESET: errno_t = 39; | ||
| 95 | pub const ENETUNREACH: errno_t = 40; | ||
| 96 | pub const ENFILE: errno_t = 41; | ||
| 97 | pub const ENOBUFS: errno_t = 42; | ||
| 98 | pub const ENODEV: errno_t = 43; | ||
| 99 | pub const ENOENT: errno_t = 44; | ||
| 100 | pub const ENOEXEC: errno_t = 45; | ||
| 101 | pub const ENOLCK: errno_t = 46; | ||
| 102 | pub const ENOLINK: errno_t = 47; | ||
| 103 | pub const ENOMEM: errno_t = 48; | ||
| 104 | pub const ENOMSG: errno_t = 49; | ||
| 105 | pub const ENOPROTOOPT: errno_t = 50; | ||
| 106 | pub const ENOSPC: errno_t = 51; | ||
| 107 | pub const ENOSYS: errno_t = 52; | ||
| 108 | pub const ENOTCONN: errno_t = 53; | ||
| 109 | pub const ENOTDIR: errno_t = 54; | ||
| 110 | pub const ENOTEMPTY: errno_t = 55; | ||
| 111 | pub const ENOTRECOVERABLE: errno_t = 56; | ||
| 112 | pub const ENOTSOCK: errno_t = 57; | ||
| 113 | pub const ENOTSUP: errno_t = 58; | ||
| 114 | pub const ENOTTY: errno_t = 59; | ||
| 115 | pub const ENXIO: errno_t = 60; | ||
| 116 | pub const EOVERFLOW: errno_t = 61; | ||
| 117 | pub const EOWNERDEAD: errno_t = 62; | ||
| 118 | pub const EPERM: errno_t = 63; | ||
| 119 | pub const EPIPE: errno_t = 64; | ||
| 120 | pub const EPROTO: errno_t = 65; | ||
| 121 | pub const EPROTONOSUPPORT: errno_t = 66; | ||
| 122 | pub const EPROTOTYPE: errno_t = 67; | ||
| 123 | pub const ERANGE: errno_t = 68; | ||
| 124 | pub const EROFS: errno_t = 69; | ||
| 125 | pub const ESPIPE: errno_t = 70; | ||
| 126 | pub const ESRCH: errno_t = 71; | ||
| 127 | pub const ESTALE: errno_t = 72; | ||
| 128 | pub const ETIMEDOUT: errno_t = 73; | ||
| 129 | pub const ETXTBSY: errno_t = 74; | ||
| 130 | pub const EXDEV: errno_t = 75; | ||
| 131 | pub const ENOTCAPABLE: errno_t = 76; | ||
| 132 | |||
| 133 | pub const event_t = extern struct { | ||
| 134 | userdata: userdata_t, | ||
| 135 | @"error": errno_t, | ||
| 136 | @"type": eventtype_t, | ||
| 137 | u: extern union { | ||
| 138 | fd_readwrite: extern struct { | ||
| 139 | nbytes: filesize_t, | ||
| 140 | flags: eventrwflags_t, | ||
| 141 | }, | ||
| 142 | }, | ||
| 143 | }; | ||
| 144 | |||
| 145 | pub const eventrwflags_t = u16; | ||
| 146 | pub const EVENT_FD_READWRITE_HANGUP: eventrwflags_t = 0x0001; | ||
| 147 | |||
| 148 | pub const eventtype_t = u8; | ||
| 149 | pub const EVENTTYPE_CLOCK: eventtype_t = 0; | ||
| 150 | pub const EVENTTYPE_FD_READ: eventtype_t = 1; | ||
| 151 | pub const EVENTTYPE_FD_WRITE: eventtype_t = 2; | ||
| 152 | |||
| 153 | pub const exitcode_t = u32; | ||
| 154 | |||
| 155 | pub const fd_t = u32; | ||
| 156 | |||
| 157 | pub const fdflags_t = u16; | ||
| 158 | pub const FDFLAG_APPEND: fdflags_t = 0x0001; | ||
| 159 | pub const FDFLAG_DSYNC: fdflags_t = 0x0002; | ||
| 160 | pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004; | ||
| 161 | pub const FDFLAG_RSYNC: fdflags_t = 0x0008; | ||
| 162 | pub const FDFLAG_SYNC: fdflags_t = 0x0010; | ||
| 163 | |||
| 164 | const fdstat_t = extern struct { | ||
| 165 | fs_filetype: filetype_t, | ||
| 166 | fs_flags: fdflags_t, | ||
| 167 | fs_rights_base: rights_t, | ||
| 168 | fs_rights_inheriting: rights_t, | ||
| 169 | }; | ||
| 170 | |||
| 171 | pub const filedelta_t = i64; | ||
| 172 | |||
| 173 | pub const filesize_t = u64; | ||
| 174 | |||
| 175 | pub const filestat_t = extern struct { | ||
| 176 | st_dev: device_t, | ||
| 177 | st_ino: inode_t, | ||
| 178 | st_filetype: filetype_t, | ||
| 179 | st_nlink: linkcount_t, | ||
| 180 | st_size: filesize_t, | ||
| 181 | st_atim: timestamp_t, | ||
| 182 | st_mtim: timestamp_t, | ||
| 183 | st_ctim: timestamp_t, | ||
| 184 | }; | ||
| 185 | |||
| 186 | pub const filetype_t = u8; | ||
| 187 | pub const FILETYPE_UNKNOWN: filetype_t = 0; | ||
| 188 | pub const FILETYPE_BLOCK_DEVICE: filetype_t = 1; | ||
| 189 | pub const FILETYPE_CHARACTER_DEVICE: filetype_t = 2; | ||
| 190 | pub const FILETYPE_DIRECTORY: filetype_t = 3; | ||
| 191 | pub const FILETYPE_REGULAR_FILE: filetype_t = 4; | ||
| 192 | pub const FILETYPE_SOCKET_DGRAM: filetype_t = 5; | ||
| 193 | pub const FILETYPE_SOCKET_STREAM: filetype_t = 6; | ||
| 194 | pub const FILETYPE_SYMBOLIC_LINK: filetype_t = 7; | ||
| 195 | |||
| 196 | pub const fstflags_t = u16; | ||
| 197 | pub const FILESTAT_SET_ATIM: fstflags_t = 0x0001; | ||
| 198 | pub const FILESTAT_SET_ATIM_NOW: fstflags_t = 0x0002; | ||
| 199 | pub const FILESTAT_SET_MTIM: fstflags_t = 0x0004; | ||
| 200 | pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008; | ||
| 201 | |||
| 202 | pub const inode_t = u64; | ||
| 203 | |||
| 204 | pub const iovec_t = extern struct { | ||
| 205 | buf: [*]u8, | ||
| 206 | buf_len: usize, | ||
| 207 | }; | ||
| 208 | |||
| 209 | pub const linkcount_t = u32; | ||
| 210 | |||
| 211 | pub const lookupflags_t = u32; | ||
| 212 | pub const LOOKUP_SYMLINK_FOLLOW: lookupflags_t = 0x00000001; | ||
| 213 | |||
| 214 | pub const oflags_t = u16; | ||
| 215 | pub const O_CREAT: oflags_t = 0x0001; | ||
| 216 | pub const O_DIRECTORY: oflags_t = 0x0002; | ||
| 217 | pub const O_EXCL: oflags_t = 0x0004; | ||
| 218 | pub const O_TRUNC: oflags_t = 0x0008; | ||
| 219 | |||
| 220 | pub const preopentype_t = u8; | ||
| 221 | pub const PREOPENTYPE_DIR: preopentype_t = 0; | ||
| 222 | |||
| 223 | pub const prestat_t = extern struct { | ||
| 224 | pr_type: preopentype_t, | ||
| 225 | u: extern union { | ||
| 226 | dir: extern struct { | ||
| 227 | pr_name_len: usize, | ||
| 228 | }, | ||
| 229 | }, | ||
| 230 | }; | ||
| 231 | |||
| 232 | pub const riflags_t = u16; | ||
| 233 | pub const SOCK_RECV_PEEK: riflags_t = 0x0001; | ||
| 234 | pub const SOCK_RECV_WAITALL: riflags_t = 0x0002; | ||
| 235 | |||
| 236 | pub const rights_t = u64; | ||
| 237 | pub const RIGHT_FD_DATASYNC: rights_t = 0x0000000000000001; | ||
| 238 | pub const RIGHT_FD_READ: rights_t = 0x0000000000000002; | ||
| 239 | pub const RIGHT_FD_SEEK: rights_t = 0x0000000000000004; | ||
| 240 | pub const RIGHT_FD_FDSTAT_SET_FLAGS: rights_t = 0x0000000000000008; | ||
| 241 | pub const RIGHT_FD_SYNC: rights_t = 0x0000000000000010; | ||
| 242 | pub const RIGHT_FD_TELL: rights_t = 0x0000000000000020; | ||
| 243 | pub const RIGHT_FD_WRITE: rights_t = 0x0000000000000040; | ||
| 244 | pub const RIGHT_FD_ADVISE: rights_t = 0x0000000000000080; | ||
| 245 | pub const RIGHT_FD_ALLOCATE: rights_t = 0x0000000000000100; | ||
| 246 | pub const RIGHT_PATH_CREATE_DIRECTORY: rights_t = 0x0000000000000200; | ||
| 247 | pub const RIGHT_PATH_CREATE_FILE: rights_t = 0x0000000000000400; | ||
| 248 | pub const RIGHT_PATH_LINK_SOURCE: rights_t = 0x0000000000000800; | ||
| 249 | pub const RIGHT_PATH_LINK_TARGET: rights_t = 0x0000000000001000; | ||
| 250 | pub const RIGHT_PATH_OPEN: rights_t = 0x0000000000002000; | ||
| 251 | pub const RIGHT_FD_READDIR: rights_t = 0x0000000000004000; | ||
| 252 | pub const RIGHT_PATH_READLINK: rights_t = 0x0000000000008000; | ||
| 253 | pub const RIGHT_PATH_RENAME_SOURCE: rights_t = 0x0000000000010000; | ||
| 254 | pub const RIGHT_PATH_RENAME_TARGET: rights_t = 0x0000000000020000; | ||
| 255 | pub const RIGHT_PATH_FILESTAT_GET: rights_t = 0x0000000000040000; | ||
| 256 | pub const RIGHT_PATH_FILESTAT_SET_SIZE: rights_t = 0x0000000000080000; | ||
| 257 | pub const RIGHT_PATH_FILESTAT_SET_TIMES: rights_t = 0x0000000000100000; | ||
| 258 | pub const RIGHT_FD_FILESTAT_GET: rights_t = 0x0000000000200000; | ||
| 259 | pub const RIGHT_FD_FILESTAT_SET_SIZE: rights_t = 0x0000000000400000; | ||
| 260 | pub const RIGHT_FD_FILESTAT_SET_TIMES: rights_t = 0x0000000000800000; | ||
| 261 | pub const RIGHT_PATH_SYMLINK: rights_t = 0x0000000001000000; | ||
| 262 | pub const RIGHT_PATH_REMOVE_DIRECTORY: rights_t = 0x0000000002000000; | ||
| 263 | pub const RIGHT_PATH_UNLINK_FILE: rights_t = 0x0000000004000000; | ||
| 264 | pub const RIGHT_POLL_FD_READWRITE: rights_t = 0x0000000008000000; | ||
| 265 | pub const RIGHT_SOCK_SHUTDOWN: rights_t = 0x0000000010000000; | ||
| 266 | |||
| 267 | pub const roflags_t = u16; | ||
| 268 | pub const SOCK_RECV_DATA_TRUNCATED: roflags_t = 0x0001; | ||
| 269 | |||
| 270 | pub const sdflags_t = u8; | ||
| 271 | pub const SHUT_RD: sdflags_t = 0x01; | ||
| 272 | pub const SHUT_WR: sdflags_t = 0x02; | ||
| 273 | |||
| 274 | pub const siflags_t = u16; | ||
| 275 | |||
| 276 | pub const signal_t = u8; | ||
| 277 | pub const SIGHUP: signal_t = 1; | ||
| 278 | pub const SIGINT: signal_t = 2; | ||
| 279 | pub const SIGQUIT: signal_t = 3; | ||
| 280 | pub const SIGILL: signal_t = 4; | ||
| 281 | pub const SIGTRAP: signal_t = 5; | ||
| 282 | pub const SIGABRT: signal_t = 6; | ||
| 283 | pub const SIGBUS: signal_t = 7; | ||
| 284 | pub const SIGFPE: signal_t = 8; | ||
| 285 | pub const SIGKILL: signal_t = 9; | ||
| 286 | pub const SIGUSR1: signal_t = 10; | ||
| 287 | pub const SIGSEGV: signal_t = 11; | ||
| 288 | pub const SIGUSR2: signal_t = 12; | ||
| 289 | pub const SIGPIPE: signal_t = 13; | ||
| 290 | pub const SIGALRM: signal_t = 14; | ||
| 291 | pub const SIGTERM: signal_t = 15; | ||
| 292 | pub const SIGCHLD: signal_t = 16; | ||
| 293 | pub const SIGCONT: signal_t = 17; | ||
| 294 | pub const SIGSTOP: signal_t = 18; | ||
| 295 | pub const SIGTSTP: signal_t = 19; | ||
| 296 | pub const SIGTTIN: signal_t = 20; | ||
| 297 | pub const SIGTTOU: signal_t = 21; | ||
| 298 | pub const SIGURG: signal_t = 22; | ||
| 299 | pub const SIGXCPU: signal_t = 23; | ||
| 300 | pub const SIGXFSZ: signal_t = 24; | ||
| 301 | pub const SIGVTALRM: signal_t = 25; | ||
| 302 | pub const SIGPROF: signal_t = 26; | ||
| 303 | pub const SIGWINCH: signal_t = 27; | ||
| 304 | pub const SIGPOLL: signal_t = 28; | ||
| 305 | pub const SIGPWR: signal_t = 29; | ||
| 306 | pub const SIGSYS: signal_t = 30; | ||
| 307 | |||
| 308 | pub const subclockflags_t = u16; | ||
| 309 | pub const SUBSCRIPTION_CLOCK_ABSTIME: subclockflags_t = 0x0001; | ||
| 310 | |||
| 311 | pub const subscription_t = extern struct { | ||
| 312 | userdata: userdata_t, | ||
| 313 | @"type": eventtype_t, | ||
| 314 | u: extern union { | ||
| 315 | clock: extern struct { | ||
| 316 | identifier: userdata_t, | ||
| 317 | clock_id: clockid_t, | ||
| 318 | timeout: timestamp_t, | ||
| 319 | precision: timestamp_t, | ||
| 320 | flags: subclockflags_t, | ||
| 321 | }, | ||
| 322 | fd_readwrite: extern struct { | ||
| 323 | fd: fd_t, | ||
| 324 | }, | ||
| 325 | }, | ||
| 326 | }; | ||
| 327 | |||
| 328 | pub const timestamp_t = u64; | ||
| 329 | |||
| 330 | pub const userdata_t = u64; | ||
| 331 | |||
| 332 | pub const whence_t = u8; | ||
| 333 | pub const WHENCE_CUR: whence_t = 0; | ||
| 334 | pub const WHENCE_END: whence_t = 1; | ||
| 335 | pub const WHENCE_SET: whence_t = 2; | ||
| 336 | |||
| 337 | pub extern "wasi_unstable" fn args_get(argv: [*][*]u8, argv_buf: [*]u8) errno_t; | 21 | pub extern "wasi_unstable" fn args_get(argv: [*][*]u8, argv_buf: [*]u8) errno_t; |
| 338 | pub extern "wasi_unstable" fn args_sizes_get(argc: *usize, argv_buf_size: *usize) errno_t; | 22 | pub extern "wasi_unstable" fn args_sizes_get(argc: *usize, argv_buf_size: *usize) errno_t; |
| 339 | 23 |
std/os/wasi/posix.zig created+320| ... | @@ -0,0 +1,320 @@ | ||
| 1 | // Declarations that are intended to be imported into the POSIX namespace. | ||
| 2 | // This includes WASI-only APIs. | ||
| 3 | |||
| 4 | pub const STDIN_FILENO = 0; | ||
| 5 | pub const STDOUT_FILENO = 1; | ||
| 6 | pub const STDERR_FILENO = 2; | ||
| 7 | |||
| 8 | pub const advice_t = u8; | ||
| 9 | pub const ADVICE_NORMAL: advice_t = 0; | ||
| 10 | pub const ADVICE_SEQUENTIAL: advice_t = 1; | ||
| 11 | pub const ADVICE_RANDOM: advice_t = 2; | ||
| 12 | pub const ADVICE_WILLNEED: advice_t = 3; | ||
| 13 | pub const ADVICE_DONTNEED: advice_t = 4; | ||
| 14 | pub const ADVICE_NOREUSE: advice_t = 5; | ||
| 15 | |||
| 16 | pub const ciovec_t = extern struct { | ||
| 17 | buf: [*]const u8, | ||
| 18 | buf_len: usize, | ||
| 19 | }; | ||
| 20 | |||
| 21 | pub const clockid_t = u32; | ||
| 22 | pub const CLOCK_REALTIME: clockid_t = 0; | ||
| 23 | pub const CLOCK_MONOTONIC: clockid_t = 1; | ||
| 24 | pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2; | ||
| 25 | pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3; | ||
| 26 | |||
| 27 | pub const device_t = u64; | ||
| 28 | |||
| 29 | pub const dircookie_t = u64; | ||
| 30 | pub const DIRCOOKIE_START: dircookie_t = 0; | ||
| 31 | |||
| 32 | pub const dirent_t = extern struct { | ||
| 33 | d_next: dircookie_t, | ||
| 34 | d_ino: inode_t, | ||
| 35 | d_namlen: u32, | ||
| 36 | d_type: filetype_t, | ||
| 37 | }; | ||
| 38 | |||
| 39 | pub const errno_t = u16; | ||
| 40 | pub const ESUCCESS: errno_t = 0; | ||
| 41 | pub const E2BIG: errno_t = 1; | ||
| 42 | pub const EACCES: errno_t = 2; | ||
| 43 | pub const EADDRINUSE: errno_t = 3; | ||
| 44 | pub const EADDRNOTAVAIL: errno_t = 4; | ||
| 45 | pub const EAFNOSUPPORT: errno_t = 5; | ||
| 46 | pub const EAGAIN: errno_t = 6; | ||
| 47 | pub const EALREADY: errno_t = 7; | ||
| 48 | pub const EBADF: errno_t = 8; | ||
| 49 | pub const EBADMSG: errno_t = 9; | ||
| 50 | pub const EBUSY: errno_t = 10; | ||
| 51 | pub const ECANCELED: errno_t = 11; | ||
| 52 | pub const ECHILD: errno_t = 12; | ||
| 53 | pub const ECONNABORTED: errno_t = 13; | ||
| 54 | pub const ECONNREFUSED: errno_t = 14; | ||
| 55 | pub const ECONNRESET: errno_t = 15; | ||
| 56 | pub const EDEADLK: errno_t = 16; | ||
| 57 | pub const EDESTADDRREQ: errno_t = 17; | ||
| 58 | pub const EDOM: errno_t = 18; | ||
| 59 | pub const EDQUOT: errno_t = 19; | ||
| 60 | pub const EEXIST: errno_t = 20; | ||
| 61 | pub const EFAULT: errno_t = 21; | ||
| 62 | pub const EFBIG: errno_t = 22; | ||
| 63 | pub const EHOSTUNREACH: errno_t = 23; | ||
| 64 | pub const EIDRM: errno_t = 24; | ||
| 65 | pub const EILSEQ: errno_t = 25; | ||
| 66 | pub const EINPROGRESS: errno_t = 26; | ||
| 67 | pub const EINTR: errno_t = 27; | ||
| 68 | pub const EINVAL: errno_t = 28; | ||
| 69 | pub const EIO: errno_t = 29; | ||
| 70 | pub const EISCONN: errno_t = 30; | ||
| 71 | pub const EISDIR: errno_t = 31; | ||
| 72 | pub const ELOOP: errno_t = 32; | ||
| 73 | pub const EMFILE: errno_t = 33; | ||
| 74 | pub const EMLINK: errno_t = 34; | ||
| 75 | pub const EMSGSIZE: errno_t = 35; | ||
| 76 | pub const EMULTIHOP: errno_t = 36; | ||
| 77 | pub const ENAMETOOLONG: errno_t = 37; | ||
| 78 | pub const ENETDOWN: errno_t = 38; | ||
| 79 | pub const ENETRESET: errno_t = 39; | ||
| 80 | pub const ENETUNREACH: errno_t = 40; | ||
| 81 | pub const ENFILE: errno_t = 41; | ||
| 82 | pub const ENOBUFS: errno_t = 42; | ||
| 83 | pub const ENODEV: errno_t = 43; | ||
| 84 | pub const ENOENT: errno_t = 44; | ||
| 85 | pub const ENOEXEC: errno_t = 45; | ||
| 86 | pub const ENOLCK: errno_t = 46; | ||
| 87 | pub const ENOLINK: errno_t = 47; | ||
| 88 | pub const ENOMEM: errno_t = 48; | ||
| 89 | pub const ENOMSG: errno_t = 49; | ||
| 90 | pub const ENOPROTOOPT: errno_t = 50; | ||
| 91 | pub const ENOSPC: errno_t = 51; | ||
| 92 | pub const ENOSYS: errno_t = 52; | ||
| 93 | pub const ENOTCONN: errno_t = 53; | ||
| 94 | pub const ENOTDIR: errno_t = 54; | ||
| 95 | pub const ENOTEMPTY: errno_t = 55; | ||
| 96 | pub const ENOTRECOVERABLE: errno_t = 56; | ||
| 97 | pub const ENOTSOCK: errno_t = 57; | ||
| 98 | pub const ENOTSUP: errno_t = 58; | ||
| 99 | pub const ENOTTY: errno_t = 59; | ||
| 100 | pub const ENXIO: errno_t = 60; | ||
| 101 | pub const EOVERFLOW: errno_t = 61; | ||
| 102 | pub const EOWNERDEAD: errno_t = 62; | ||
| 103 | pub const EPERM: errno_t = 63; | ||
| 104 | pub const EPIPE: errno_t = 64; | ||
| 105 | pub const EPROTO: errno_t = 65; | ||
| 106 | pub const EPROTONOSUPPORT: errno_t = 66; | ||
| 107 | pub const EPROTOTYPE: errno_t = 67; | ||
| 108 | pub const ERANGE: errno_t = 68; | ||
| 109 | pub const EROFS: errno_t = 69; | ||
| 110 | pub const ESPIPE: errno_t = 70; | ||
| 111 | pub const ESRCH: errno_t = 71; | ||
| 112 | pub const ESTALE: errno_t = 72; | ||
| 113 | pub const ETIMEDOUT: errno_t = 73; | ||
| 114 | pub const ETXTBSY: errno_t = 74; | ||
| 115 | pub const EXDEV: errno_t = 75; | ||
| 116 | pub const ENOTCAPABLE: errno_t = 76; | ||
| 117 | |||
| 118 | pub const event_t = extern struct { | ||
| 119 | userdata: userdata_t, | ||
| 120 | @"error": errno_t, | ||
| 121 | @"type": eventtype_t, | ||
| 122 | u: extern union { | ||
| 123 | fd_readwrite: extern struct { | ||
| 124 | nbytes: filesize_t, | ||
| 125 | flags: eventrwflags_t, | ||
| 126 | }, | ||
| 127 | }, | ||
| 128 | }; | ||
| 129 | |||
| 130 | pub const eventrwflags_t = u16; | ||
| 131 | pub const EVENT_FD_READWRITE_HANGUP: eventrwflags_t = 0x0001; | ||
| 132 | |||
| 133 | pub const eventtype_t = u8; | ||
| 134 | pub const EVENTTYPE_CLOCK: eventtype_t = 0; | ||
| 135 | pub const EVENTTYPE_FD_READ: eventtype_t = 1; | ||
| 136 | pub const EVENTTYPE_FD_WRITE: eventtype_t = 2; | ||
| 137 | |||
| 138 | pub const exitcode_t = u32; | ||
| 139 | |||
| 140 | pub const fd_t = u32; | ||
| 141 | |||
| 142 | pub const fdflags_t = u16; | ||
| 143 | pub const FDFLAG_APPEND: fdflags_t = 0x0001; | ||
| 144 | pub const FDFLAG_DSYNC: fdflags_t = 0x0002; | ||
| 145 | pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004; | ||
| 146 | pub const FDFLAG_RSYNC: fdflags_t = 0x0008; | ||
| 147 | pub const FDFLAG_SYNC: fdflags_t = 0x0010; | ||
| 148 | |||
| 149 | const fdstat_t = extern struct { | ||
| 150 | fs_filetype: filetype_t, | ||
| 151 | fs_flags: fdflags_t, | ||
| 152 | fs_rights_base: rights_t, | ||
| 153 | fs_rights_inheriting: rights_t, | ||
| 154 | }; | ||
| 155 | |||
| 156 | pub const filedelta_t = i64; | ||
| 157 | |||
| 158 | pub const filesize_t = u64; | ||
| 159 | |||
| 160 | pub const filestat_t = extern struct { | ||
| 161 | st_dev: device_t, | ||
| 162 | st_ino: inode_t, | ||
| 163 | st_filetype: filetype_t, | ||
| 164 | st_nlink: linkcount_t, | ||
| 165 | st_size: filesize_t, | ||
| 166 | st_atim: timestamp_t, | ||
| 167 | st_mtim: timestamp_t, | ||
| 168 | st_ctim: timestamp_t, | ||
| 169 | }; | ||
| 170 | |||
| 171 | pub const filetype_t = u8; | ||
| 172 | pub const FILETYPE_UNKNOWN: filetype_t = 0; | ||
| 173 | pub const FILETYPE_BLOCK_DEVICE: filetype_t = 1; | ||
| 174 | pub const FILETYPE_CHARACTER_DEVICE: filetype_t = 2; | ||
| 175 | pub const FILETYPE_DIRECTORY: filetype_t = 3; | ||
| 176 | pub const FILETYPE_REGULAR_FILE: filetype_t = 4; | ||
| 177 | pub const FILETYPE_SOCKET_DGRAM: filetype_t = 5; | ||
| 178 | pub const FILETYPE_SOCKET_STREAM: filetype_t = 6; | ||
| 179 | pub const FILETYPE_SYMBOLIC_LINK: filetype_t = 7; | ||
| 180 | |||
| 181 | pub const fstflags_t = u16; | ||
| 182 | pub const FILESTAT_SET_ATIM: fstflags_t = 0x0001; | ||
| 183 | pub const FILESTAT_SET_ATIM_NOW: fstflags_t = 0x0002; | ||
| 184 | pub const FILESTAT_SET_MTIM: fstflags_t = 0x0004; | ||
| 185 | pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008; | ||
| 186 | |||
| 187 | pub const inode_t = u64; | ||
| 188 | |||
| 189 | pub const iovec_t = extern struct { | ||
| 190 | buf: [*]u8, | ||
| 191 | buf_len: usize, | ||
| 192 | }; | ||
| 193 | |||
| 194 | pub const linkcount_t = u32; | ||
| 195 | |||
| 196 | pub const lookupflags_t = u32; | ||
| 197 | pub const LOOKUP_SYMLINK_FOLLOW: lookupflags_t = 0x00000001; | ||
| 198 | |||
| 199 | pub const oflags_t = u16; | ||
| 200 | pub const O_CREAT: oflags_t = 0x0001; | ||
| 201 | pub const O_DIRECTORY: oflags_t = 0x0002; | ||
| 202 | pub const O_EXCL: oflags_t = 0x0004; | ||
| 203 | pub const O_TRUNC: oflags_t = 0x0008; | ||
| 204 | |||
| 205 | pub const preopentype_t = u8; | ||
| 206 | pub const PREOPENTYPE_DIR: preopentype_t = 0; | ||
| 207 | |||
| 208 | pub const prestat_t = extern struct { | ||
| 209 | pr_type: preopentype_t, | ||
| 210 | u: extern union { | ||
| 211 | dir: extern struct { | ||
| 212 | pr_name_len: usize, | ||
| 213 | }, | ||
| 214 | }, | ||
| 215 | }; | ||
| 216 | |||
| 217 | pub const riflags_t = u16; | ||
| 218 | pub const SOCK_RECV_PEEK: riflags_t = 0x0001; | ||
| 219 | pub const SOCK_RECV_WAITALL: riflags_t = 0x0002; | ||
| 220 | |||
| 221 | pub const rights_t = u64; | ||
| 222 | pub const RIGHT_FD_DATASYNC: rights_t = 0x0000000000000001; | ||
| 223 | pub const RIGHT_FD_READ: rights_t = 0x0000000000000002; | ||
| 224 | pub const RIGHT_FD_SEEK: rights_t = 0x0000000000000004; | ||
| 225 | pub const RIGHT_FD_FDSTAT_SET_FLAGS: rights_t = 0x0000000000000008; | ||
| 226 | pub const RIGHT_FD_SYNC: rights_t = 0x0000000000000010; | ||
| 227 | pub const RIGHT_FD_TELL: rights_t = 0x0000000000000020; | ||
| 228 | pub const RIGHT_FD_WRITE: rights_t = 0x0000000000000040; | ||
| 229 | pub const RIGHT_FD_ADVISE: rights_t = 0x0000000000000080; | ||
| 230 | pub const RIGHT_FD_ALLOCATE: rights_t = 0x0000000000000100; | ||
| 231 | pub const RIGHT_PATH_CREATE_DIRECTORY: rights_t = 0x0000000000000200; | ||
| 232 | pub const RIGHT_PATH_CREATE_FILE: rights_t = 0x0000000000000400; | ||
| 233 | pub const RIGHT_PATH_LINK_SOURCE: rights_t = 0x0000000000000800; | ||
| 234 | pub const RIGHT_PATH_LINK_TARGET: rights_t = 0x0000000000001000; | ||
| 235 | pub const RIGHT_PATH_OPEN: rights_t = 0x0000000000002000; | ||
| 236 | pub const RIGHT_FD_READDIR: rights_t = 0x0000000000004000; | ||
| 237 | pub const RIGHT_PATH_READLINK: rights_t = 0x0000000000008000; | ||
| 238 | pub const RIGHT_PATH_RENAME_SOURCE: rights_t = 0x0000000000010000; | ||
| 239 | pub const RIGHT_PATH_RENAME_TARGET: rights_t = 0x0000000000020000; | ||
| 240 | pub const RIGHT_PATH_FILESTAT_GET: rights_t = 0x0000000000040000; | ||
| 241 | pub const RIGHT_PATH_FILESTAT_SET_SIZE: rights_t = 0x0000000000080000; | ||
| 242 | pub const RIGHT_PATH_FILESTAT_SET_TIMES: rights_t = 0x0000000000100000; | ||
| 243 | pub const RIGHT_FD_FILESTAT_GET: rights_t = 0x0000000000200000; | ||
| 244 | pub const RIGHT_FD_FILESTAT_SET_SIZE: rights_t = 0x0000000000400000; | ||
| 245 | pub const RIGHT_FD_FILESTAT_SET_TIMES: rights_t = 0x0000000000800000; | ||
| 246 | pub const RIGHT_PATH_SYMLINK: rights_t = 0x0000000001000000; | ||
| 247 | pub const RIGHT_PATH_REMOVE_DIRECTORY: rights_t = 0x0000000002000000; | ||
| 248 | pub const RIGHT_PATH_UNLINK_FILE: rights_t = 0x0000000004000000; | ||
| 249 | pub const RIGHT_POLL_FD_READWRITE: rights_t = 0x0000000008000000; | ||
| 250 | pub const RIGHT_SOCK_SHUTDOWN: rights_t = 0x0000000010000000; | ||
| 251 | |||
| 252 | pub const roflags_t = u16; | ||
| 253 | pub const SOCK_RECV_DATA_TRUNCATED: roflags_t = 0x0001; | ||
| 254 | |||
| 255 | pub const sdflags_t = u8; | ||
| 256 | pub const SHUT_RD: sdflags_t = 0x01; | ||
| 257 | pub const SHUT_WR: sdflags_t = 0x02; | ||
| 258 | |||
| 259 | pub const siflags_t = u16; | ||
| 260 | |||
| 261 | pub const signal_t = u8; | ||
| 262 | pub const SIGHUP: signal_t = 1; | ||
| 263 | pub const SIGINT: signal_t = 2; | ||
| 264 | pub const SIGQUIT: signal_t = 3; | ||
| 265 | pub const SIGILL: signal_t = 4; | ||
| 266 | pub const SIGTRAP: signal_t = 5; | ||
| 267 | pub const SIGABRT: signal_t = 6; | ||
| 268 | pub const SIGBUS: signal_t = 7; | ||
| 269 | pub const SIGFPE: signal_t = 8; | ||
| 270 | pub const SIGKILL: signal_t = 9; | ||
| 271 | pub const SIGUSR1: signal_t = 10; | ||
| 272 | pub const SIGSEGV: signal_t = 11; | ||
| 273 | pub const SIGUSR2: signal_t = 12; | ||
| 274 | pub const SIGPIPE: signal_t = 13; | ||
| 275 | pub const SIGALRM: signal_t = 14; | ||
| 276 | pub const SIGTERM: signal_t = 15; | ||
| 277 | pub const SIGCHLD: signal_t = 16; | ||
| 278 | pub const SIGCONT: signal_t = 17; | ||
| 279 | pub const SIGSTOP: signal_t = 18; | ||
| 280 | pub const SIGTSTP: signal_t = 19; | ||
| 281 | pub const SIGTTIN: signal_t = 20; | ||
| 282 | pub const SIGTTOU: signal_t = 21; | ||
| 283 | pub const SIGURG: signal_t = 22; | ||
| 284 | pub const SIGXCPU: signal_t = 23; | ||
| 285 | pub const SIGXFSZ: signal_t = 24; | ||
| 286 | pub const SIGVTALRM: signal_t = 25; | ||
| 287 | pub const SIGPROF: signal_t = 26; | ||
| 288 | pub const SIGWINCH: signal_t = 27; | ||
| 289 | pub const SIGPOLL: signal_t = 28; | ||
| 290 | pub const SIGPWR: signal_t = 29; | ||
| 291 | pub const SIGSYS: signal_t = 30; | ||
| 292 | |||
| 293 | pub const subclockflags_t = u16; | ||
| 294 | pub const SUBSCRIPTION_CLOCK_ABSTIME: subclockflags_t = 0x0001; | ||
| 295 | |||
| 296 | pub const subscription_t = extern struct { | ||
| 297 | userdata: userdata_t, | ||
| 298 | @"type": eventtype_t, | ||
| 299 | u: extern union { | ||
| 300 | clock: extern struct { | ||
| 301 | identifier: userdata_t, | ||
| 302 | clock_id: clockid_t, | ||
| 303 | timeout: timestamp_t, | ||
| 304 | precision: timestamp_t, | ||
| 305 | flags: subclockflags_t, | ||
| 306 | }, | ||
| 307 | fd_readwrite: extern struct { | ||
| 308 | fd: fd_t, | ||
| 309 | }, | ||
| 310 | }, | ||
| 311 | }; | ||
| 312 | |||
| 313 | pub const timestamp_t = u64; | ||
| 314 | |||
| 315 | pub const userdata_t = u64; | ||
| 316 | |||
| 317 | pub const whence_t = u8; | ||
| 318 | pub const WHENCE_CUR: whence_t = 0; | ||
| 319 | pub const WHENCE_END: whence_t = 1; | ||
| 320 | pub const WHENCE_SET: whence_t = 2; | ||
std/os/windows.zig+2-10| ... | @@ -6,6 +6,8 @@ pub const is_the_target = switch (builtin.os) { | ... | @@ -6,6 +6,8 @@ pub const is_the_target = switch (builtin.os) { |
| 6 | .windows => true, | 6 | .windows => true, |
| 7 | else => false, | 7 | else => false, |
| 8 | }; | 8 | }; |
| 9 | pub const posix = @import("windows/posix.zig"); | ||
| 10 | pub use posix; | ||
| 9 | 11 | ||
| 10 | pub use @import("windows/advapi32.zig"); | 12 | pub use @import("windows/advapi32.zig"); |
| 11 | pub use @import("windows/kernel32.zig"); | 13 | pub use @import("windows/kernel32.zig"); |
| ... | @@ -20,7 +22,6 @@ test "import" { | ... | @@ -20,7 +22,6 @@ test "import" { |
| 20 | } | 22 | } |
| 21 | 23 | ||
| 22 | pub const ERROR = @import("windows/error.zig"); | 24 | pub const ERROR = @import("windows/error.zig"); |
| 23 | pub const errno_codes = @import("windows/errno.zig"); | ||
| 24 | 25 | ||
| 25 | pub const SHORT = c_short; | 26 | pub const SHORT = c_short; |
| 26 | pub const BOOL = c_int; | 27 | pub const BOOL = c_int; |
| ... | @@ -65,15 +66,6 @@ pub const LONGLONG = i64; | ... | @@ -65,15 +66,6 @@ pub const LONGLONG = i64; |
| 65 | pub const TRUE = 1; | 66 | pub const TRUE = 1; |
| 66 | pub const FALSE = 0; | 67 | pub const FALSE = 0; |
| 67 | 68 | ||
| 68 | /// The standard input device. Initially, this is the console input buffer, CONIN$. | ||
| 69 | pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1; | ||
| 70 | |||
| 71 | /// The standard output device. Initially, this is the active console screen buffer, CONOUT$. | ||
| 72 | pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1; | ||
| 73 | |||
| 74 | /// The standard error device. Initially, this is the active console screen buffer, CONOUT$. | ||
| 75 | pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1; | ||
| 76 | |||
| 77 | pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize)); | 69 | pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize)); |
| 78 | 70 | ||
| 79 | pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD)); | 71 | pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD)); |
std/os/windows/errno.zig deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | // TODO get these values from msvcrt | ||
std/os/windows/posix.zig created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | // Declarations that are intended to be imported into the POSIX namespace. | ||
| 2 | const std = @import("../../std.zig"); | ||
| 3 | const maxInt = std.math.maxInt; | ||
| 4 | use std.os.windows; | ||
| 5 | |||
| 6 | pub const fd_t = HANDLE; | ||
| 7 | |||
| 8 | /// The standard input device. Initially, this is the console input buffer, CONIN$. | ||
| 9 | pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1; | ||
| 10 | |||
| 11 | /// The standard output device. Initially, this is the active console screen buffer, CONOUT$. | ||
| 12 | pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1; | ||
| 13 | |||
| 14 | /// The standard error device. Initially, this is the active console screen buffer, CONOUT$. | ||
| 15 | pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1; | ||
std/os/windows/util.zig-2| ... | @@ -11,8 +11,6 @@ const cstr = std.cstr; | ... | @@ -11,8 +11,6 @@ const cstr = std.cstr; |
| 11 | pub const WaitError = error{ | 11 | pub const WaitError = error{ |
| 12 | WaitAbandoned, | 12 | WaitAbandoned, |
| 13 | WaitTimeOut, | 13 | WaitTimeOut, |
| 14 | |||
| 15 | /// See https://github.com/ziglang/zig/issues/1396 | ||
| 16 | Unexpected, | 14 | Unexpected, |
| 17 | }; | 15 | }; |
| 18 | 16 |