authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-20 01:15:23-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-26 18:32:43-04:00
logdaae7e1f5aa5aac02a342c9a60d703c2a0cba579
treef3b2bca3e6b0d1088aa2d570bb029d076c5f3abe
parent67726e36b02d26343398ed8ede460622d706c539
signaturelock-open Commit is signed but in an unrecognized format.

more progress on posix API layer

see #2380

36 files changed, 5430 insertions(+), 5948 deletions(-)

CMakeLists.txt+9
......@@ -474,6 +474,10 @@ set(ZIG_STD_FILES
474474 "c/linux.zig"
475475 "c/netbsd.zig"
476476 "c/windows.zig"
477 "c/posix.zig"
478 "c/posix/darwin.zig"
479 "c/posix/freebsd.zig"
480 "c/posix/windows.zig"
477481 "coff.zig"
478482 "crypto.zig"
479483 "crypto/blake2.zig"
......@@ -612,15 +616,20 @@ set(ZIG_STD_FILES
612616 "os/linux.zig"
613617 "os/linux/arm64.zig"
614618 "os/linux/errno.zig"
619 "os/linux/posix.zig"
620 "os/linux/posix/arm64.zig"
621 "os/linux/posix/x86_64.zig"
615622 "os/linux/tls.zig"
616623 "os/linux/vdso.zig"
617624 "os/linux/x86_64.zig"
618625 "os/netbsd.zig"
619626 "os/netbsd/errno.zig"
620627 "os/path.zig"
628 "os/posix.zig"
621629 "os/time.zig"
622630 "os/uefi.zig"
623631 "os/wasi.zig"
632 "os/wasi/posix.zig"
624633 "os/windows.zig"
625634 "os/windows/advapi32.zig"
626635 "os/windows/errno.zig"
doc/langref.html.in+1
......@@ -9923,6 +9923,7 @@ keyword &lt;- KEYWORD_align / KEYWORD_and / KEYWORD_allowzero / KEYWORD_anyerror
99239923 <li>Avoid local maximums.</li>
99249924 <li>Reduce the amount one must remember.</li>
99259925 <li>Minimize energy spent on coding style.</li>
9926 <li>Resource deallocation must succeed.</li>
99269927 <li>Together we serve end users.</li>
99279928 </ul>
99289929 {#header_close#}
std/c.zig+47-23
......@@ -1,9 +1,10 @@
11const builtin = @import("builtin");
22
3pub const is_the_target = builtin.link_libc;
3pub const posix = @import("c/posix.zig");
4pub use posix;
45
56pub use switch (builtin.os) {
6 .linux => @import("c/linux.zig"),
7 .linux => @import("os/linux/posix.zig"),
78 .windows => @import("c/windows.zig"),
89 .macosx, .ios, .tvos, .watchos => @import("c/darwin.zig"),
910 .freebsd => @import("c/freebsd.zig"),
......@@ -21,7 +22,6 @@ pub fn getErrno(rc: var) u12 {
2122
2223// TODO https://github.com/ziglang/zig/issues/265 on this whole file
2324
24pub const FILE = @OpaqueType();
2525pub extern "c" fn fopen(filename: [*]const u8, modes: [*]const u8) ?*FILE;
2626pub extern "c" fn fclose(stream: *FILE) c_int;
2727pub 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
2929
3030pub extern "c" fn abort() noreturn;
3131pub extern "c" fn exit(code: c_int) noreturn;
32pub extern "c" fn isatty(fd: c_int) c_int;
33pub extern "c" fn close(fd: c_int) c_int;
34pub extern "c" fn fstat(fd: c_int, buf: *Stat) c_int;
35pub extern "c" fn @"fstat$INODE64"(fd: c_int, buf: *Stat) c_int;
36pub extern "c" fn lseek(fd: c_int, offset: isize, whence: c_int) isize;
32pub extern "c" fn isatty(fd: fd_t) c_int;
33pub extern "c" fn close(fd: fd_t) c_int;
34pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
35pub extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;
36pub extern "c" fn lseek(fd: fd_t, offset: isize, whence: c_int) isize;
3737pub extern "c" fn open(path: [*]const u8, oflag: c_int, ...) c_int;
3838pub extern "c" fn raise(sig: c_int) c_int;
39pub extern "c" fn read(fd: c_int, buf: *c_void, nbyte: usize) isize;
40pub extern "c" fn pread(fd: c_int, buf: *c_void, nbyte: usize, offset: u64) isize;
39pub extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize;
40pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: u64) isize;
41pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_int, offset: usize) isize;
42pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec, iovcnt: c_int, offset: usize) isize;
4143pub extern "c" fn stat(noalias path: [*]const u8, noalias buf: *Stat) c_int;
42pub extern "c" fn write(fd: c_int, buf: *const c_void, nbyte: usize) isize;
43pub extern "c" fn pwrite(fd: c_int, buf: *const c_void, nbyte: usize, offset: u64) isize;
44pub extern "c" fn mmap(addr: ?*c_void, len: usize, prot: c_int, flags: c_int, fd: c_int, offset: isize) ?*c_void;
44pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize;
45pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: u64) isize;
46pub extern "c" fn mmap(addr: ?*c_void, len: usize, prot: c_int, flags: c_int, fd: fd_t, offset: isize) usize;
4547pub extern "c" fn munmap(addr: ?*c_void, len: usize) c_int;
4648pub extern "c" fn unlink(path: [*]const u8) c_int;
4749pub extern "c" fn getcwd(buf: [*]u8, size: usize) ?[*]u8;
4850pub extern "c" fn waitpid(pid: c_int, stat_loc: *c_int, options: c_int) c_int;
4951pub extern "c" fn fork() c_int;
5052pub extern "c" fn access(path: [*]const u8, mode: c_uint) c_int;
51pub extern "c" fn pipe(fds: *[2]c_int) c_int;
53pub extern "c" fn pipe(fds: *[2]fd_t) c_int;
54pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;
5255pub extern "c" fn mkdir(path: [*]const u8, mode: c_uint) c_int;
5356pub extern "c" fn symlink(existing: [*]const u8, new: [*]const u8) c_int;
5457pub extern "c" fn rename(old: [*]const u8, new: [*]const u8) c_int;
5558pub extern "c" fn chdir(path: [*]const u8) c_int;
5659pub extern "c" fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) c_int;
57pub extern "c" fn dup(fd: c_int) c_int;
58pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int;
60pub extern "c" fn dup(fd: fd_t) c_int;
61pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int;
5962pub extern "c" fn readlink(noalias path: [*]const u8, noalias buf: [*]u8, bufsize: usize) isize;
6063pub extern "c" fn realpath(noalias file_name: [*]const u8, noalias resolved_name: [*]u8) ?[*]u8;
6164pub 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;
6669pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;
6770pub extern "c" fn rmdir(path: [*]const u8) c_int;
6871pub extern "c" fn getenv(name: [*]const u8) ?[*]u8;
72pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
73pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
74pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
75
76pub extern "c" fn bind(socket: fd_t, address: ?*const sockaddr, address_len: socklen_t) c_int;
77pub extern "c" fn socket(domain: c_int, sock_type: c_int, protocol: c_int) c_int;
78pub extern "c" fn kill(pid: pid_t, sig: c_int) c_int;
79pub extern "c" fn getdirentries(fd: fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) usize;
80pub extern "c" fn openat(fd: c_int, path: [*]const u8, flags: c_int) c_int;
81pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int;
82pub extern "c" fn setuid(uid: c_uint) c_int;
83pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
84pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
6985
7086pub extern "c" fn aligned_alloc(alignment: usize, size: usize) ?*c_void;
7187pub extern "c" fn malloc(usize) ?*c_void;
......@@ -73,11 +89,19 @@ pub extern "c" fn realloc(?*c_void, usize) ?*c_void;
7389pub extern "c" fn free(*c_void) void;
7490pub extern "c" fn posix_memalign(memptr: **c_void, alignment: usize, size: usize) c_int;
7591
76pub 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;
77pub extern "pthread" fn pthread_attr_init(attr: *pthread_attr_t) c_int;
78pub extern "pthread" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int;
79pub extern "pthread" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int;
80pub extern "pthread" fn pthread_self() pthread_t;
81pub extern "pthread" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int;
92pub 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;
93pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) c_int;
94pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int;
95pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int;
96pub extern "c" fn pthread_self() pthread_t;
97pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int;
8298
83pub const pthread_t = *@OpaqueType();
99pub extern "c" fn kqueue() c_int;
100pub 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 @@
1const macho = @import("../macho.zig");
1const std = @import("../std.zig");
2const assert = std.debug.assert;
3const builtin = @import("builtin");
4const macho = std.macho;
5
6use @import("posix/darwin.zig");
27
38extern "c" fn __error() *c_int;
49pub extern "c" fn _NSGetExecutablePath(buf: [*]u8, bufsize: *u32) c_int;
510pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header;
611
7pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) usize;
12pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
813
914pub extern "c" fn mach_absolute_time() u64;
1015pub extern "c" fn mach_timebase_info(tinfo: ?*mach_timebase_info_data) void;
1116
12pub extern "c" fn kqueue() c_int;
13pub 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
2217pub extern "c" fn kevent64(
2318 kq: c_int,
2419 changelist: [*]const kevent64_s,
......@@ -29,13 +24,6 @@ pub extern "c" fn kevent64(
2924 timeout: ?*const timespec,
3025) c_int;
3126
32pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
33pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
34pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
35
36pub extern "c" fn bind(socket: c_int, address: ?*const sockaddr, address_len: socklen_t) c_int;
37pub extern "c" fn socket(domain: c_int, type: c_int, protocol: c_int) c_int;
38
3927const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header;
4028
4129/// 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;
4836/// export a weak symbol here, to be overridden by the real one.
4937pub extern "c" var _mh_execute_header: mach_hdr = undefined;
5038comptime {
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 }
5242}
5343
5444pub const mach_header_64 = macho.mach_header_64;
5545pub const mach_header = macho.mach_header;
5646
57pub use @import("../os/darwin/errno.zig");
58
5947pub const _errno = __error;
6048
61pub const in_port_t = u16;
62pub const sa_family_t = u8;
63pub const socklen_t = u32;
64pub const sockaddr = extern union {
65 in: sockaddr_in,
66 in6: sockaddr_in6,
67};
68pub 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};
75pub 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
84pub const timeval = extern struct {
85 tv_sec: c_long,
86 tv_usec: i32,
87};
88
89pub const timezone = extern struct {
90 tz_minuteswest: i32,
91 tz_dsttime: i32,
92};
93
94pub 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.
100pub 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};
49pub extern "c" fn mach_host_self() mach_port_t;
50pub extern "c" fn clock_get_time(clock_serv: clock_serv_t, cur_time: *mach_timespec_t) kern_return_t;
51pub extern "c" fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clock_serv: ?[*]clock_serv_t) kern_return_t;
52pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t;
12453
125pub const timespec = extern struct {
126 tv_sec: isize,
127 tv_nsec: isize,
128};
129
130pub const sigset_t = u32;
131
132/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
133pub const Sigaction = extern struct {
134 handler: extern fn (c_int) void,
135 sa_mask: sigset_t,
136 sa_flags: c_int,
137};
138
139pub 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
148pub 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.
154pub 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.
166const std = @import("../std.zig");
167const assert = std.debug.assert;
168
169comptime {
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
178pub 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
188pub const mach_port_t = c_uint;
189pub const clock_serv_t = mach_port_t;
190pub const clock_res_t = c_int;
191pub const mach_port_name_t = natural_t;
192pub const natural_t = c_uint;
193pub const mach_timespec_t = extern struct {
194 tv_sec: c_uint,
195 tv_nsec: clock_res_t,
196};
197pub const kern_return_t = c_int;
198pub const host_t = mach_port_t;
199pub const CALENDAR_CLOCK = 1;
200
201pub extern fn mach_host_self() mach_port_t;
202pub extern fn clock_get_time(clock_serv: clock_serv_t, cur_time: *mach_timespec_t) kern_return_t;
203pub extern fn host_get_clock_service(host: host_t, clock_id: clock_id_t, clock_serv: ?[*]clock_serv_t) kern_return_t;
204pub 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.
209comptime {
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);
54pub fn sigaddset(set: *sigset_t, signo: u5) void {
55 set.* |= u32(1) << (signo - 1);
21756}
std/c/freebsd.zig-150
......@@ -1,154 +1,4 @@
11extern "c" fn __error() *c_int;
22pub const _errno = __error;
33
4pub extern "c" fn kqueue() c_int;
5pub 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;
13pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
14pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
15pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
16pub extern "c" fn getdirentries(fd: c_int, buf_ptr: [*]u8, nbytes: usize, basep: *i64) usize;
174pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
18pub extern "c" fn pipe2(arg0: *[2]c_int, arg1: u32) c_int;
19pub extern "c" fn preadv(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize;
20pub extern "c" fn pwritev(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize;
21pub extern "c" fn openat(fd: c_int, path: ?[*]const u8, flags: c_int) c_int;
22pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int;
23pub extern "c" fn setuid(uid: c_uint) c_int;
24pub extern "c" fn kill(pid: c_int, sig: c_int) c_int;
25pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
26pub 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.
29pub 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
39pub const pthread_attr_t = extern struct {
40 __size: [56]u8,
41 __align: c_long,
42};
43
44pub 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
67pub 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
90pub 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
115pub const timespec = extern struct {
116 tv_sec: isize,
117 tv_nsec: isize,
118};
119
120pub 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
131pub const in_port_t = u16;
132pub const sa_family_t = u16;
133
134pub const sockaddr = extern union {
135 in: sockaddr_in,
136 in6: sockaddr_in6,
137};
138
139pub 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
147pub 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 @@
11extern "c" fn __errno() *c_int;
22pub const _errno = __errno;
33
4pub extern "c" fn kqueue() c_int;
5pub 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;
13pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
14pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
15pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
16pub extern "c" fn getdirentries(fd: c_int, buf_ptr: [*]u8, nbytes: usize, basep: *i64) usize;
174pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
18pub extern "c" fn pipe2(arg0: *[2]c_int, arg1: u32) c_int;
19pub extern "c" fn preadv(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize;
20pub extern "c" fn pwritev(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize;
21pub extern "c" fn openat(fd: c_int, path: ?[*]const u8, flags: c_int) c_int;
22pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int;
23pub extern "c" fn setuid(uid: c_uint) c_int;
24pub extern "c" fn kill(pid: c_int, sig: c_int) c_int;
25pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
26pub 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.
29pub const Kevent = extern struct {
30 ident: usize,
31 filter: i32,
32 flags: u32,
33 fflags: u32,
34 data: i64,
35 udata: usize,
36};
37
38pub const pthread_attr_t = extern struct {
39 pta_magic: u32,
40 pta_flags: c_int,
41 pta_private: *c_void,
42};
43
44pub 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
67pub 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
90pub 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
113pub const timespec = extern struct {
114 tv_sec: i64,
115 tv_nsec: isize,
116};
117
118pub 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
127pub const in_port_t = u16;
128pub const sa_family_t = u8;
129
130pub const sockaddr = extern union {
131 in: sockaddr_in,
132 in6: sockaddr_in6,
133};
134
135pub 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
143pub 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
3const builtin = @import("builtin");
4
5pub 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
13pub const fd_t = c_int;
14pub const pid_t = c_int;
15pub const pthread_t = *@OpaqueType();
16pub const FILE = @OpaqueType();
17
18pub const iovec = extern struct {
19 iov_base: [*]u8,
20 iov_len: usize,
21};
22
23pub 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 @@
1const std = @import("../std.zig");
2const assert = std.debug.assert;
3
4pub 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
27pub const in_port_t = u16;
28pub const sa_family_t = u8;
29pub const socklen_t = u32;
30pub const sockaddr = extern union {
31 in: sockaddr_in,
32 in6: sockaddr_in6,
33};
34pub 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};
41pub 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
50pub const timeval = extern struct {
51 tv_sec: c_long,
52 tv_usec: i32,
53};
54
55pub const timezone = extern struct {
56 tz_minuteswest: i32,
57 tz_dsttime: i32,
58};
59
60pub 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.
66pub 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
91pub const timespec = extern struct {
92 tv_sec: isize,
93 tv_nsec: isize,
94};
95
96pub const sigset_t = u32;
97pub const empty_sigset = sigset_t(0);
98
99/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
100pub const Sigaction = extern struct {
101 handler: extern fn (c_int) void,
102 sa_mask: sigset_t,
103 sa_flags: c_int,
104};
105
106pub 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
115pub 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.
121pub 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.
133comptime {
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
142pub 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.
155comptime {
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
165pub const mach_port_t = c_uint;
166pub const clock_serv_t = mach_port_t;
167pub const clock_res_t = c_int;
168pub const mach_port_name_t = natural_t;
169pub const natural_t = c_uint;
170pub const mach_timespec_t = extern struct {
171 tv_sec: c_uint,
172 tv_nsec: clock_res_t,
173};
174pub const kern_return_t = c_int;
175pub const host_t = mach_port_t;
176pub const CALENDAR_CLOCK = 1;
177
178pub const PATH_MAX = 1024;
179
180pub const STDIN_FILENO = 0;
181pub const STDOUT_FILENO = 1;
182pub const STDERR_FILENO = 2;
183
184/// [MC2] no permissions
185pub const PROT_NONE = 0x00;
186
187/// [MC2] pages can be read
188pub const PROT_READ = 0x01;
189
190/// [MC2] pages can be written
191pub const PROT_WRITE = 0x02;
192
193/// [MC2] pages can be executed
194pub const PROT_EXEC = 0x04;
195
196/// allocated from memory, swap space
197pub const MAP_ANONYMOUS = 0x1000;
198
199/// map from file (default)
200pub const MAP_FILE = 0x0000;
201
202/// interpret addr exactly
203pub const MAP_FIXED = 0x0010;
204
205/// region may contain semaphores
206pub const MAP_HASSEMAPHORE = 0x0200;
207
208/// changes are private
209pub const MAP_PRIVATE = 0x0002;
210
211/// share changes
212pub const MAP_SHARED = 0x0001;
213
214/// don't cache pages for this mapping
215pub const MAP_NOCACHE = 0x0400;
216
217/// don't reserve needed swap area
218pub const MAP_NORESERVE = 0x0040;
219pub const MAP_FAILED = maxInt(usize);
220
221/// [XSI] no hang in wait/no child to reap
222pub const WNOHANG = 0x00000001;
223
224/// [XSI] notify on stop, untraced child
225pub const WUNTRACED = 0x00000002;
226
227/// take signal on signal stack
228pub const SA_ONSTACK = 0x0001;
229
230/// restart system on signal return
231pub const SA_RESTART = 0x0002;
232
233/// reset to SIG_DFL when taking signal
234pub const SA_RESETHAND = 0x0004;
235
236/// do not generate SIGCHLD on child stop
237pub const SA_NOCLDSTOP = 0x0008;
238
239/// don't mask the signal we're delivering
240pub const SA_NODEFER = 0x0010;
241
242/// don't keep zombies around
243pub const SA_NOCLDWAIT = 0x0020;
244
245/// signal handler with SA_SIGINFO args
246pub const SA_SIGINFO = 0x0040;
247
248/// do not bounce off kernel's sigtramp
249pub const SA_USERTRAMP = 0x0100;
250
251/// signal handler with SA_SIGINFO args with 64bit regs information
252pub const SA_64REGSET = 0x0200;
253
254pub const O_LARGEFILE = 0x0000;
255pub const O_PATH = 0x0000;
256
257pub const F_OK = 0;
258pub const X_OK = 1;
259pub const W_OK = 2;
260pub const R_OK = 4;
261
262/// open for reading only
263pub const O_RDONLY = 0x0000;
264
265/// open for writing only
266pub const O_WRONLY = 0x0001;
267
268/// open for reading and writing
269pub const O_RDWR = 0x0002;
270
271/// do not block on open or for data to become available
272pub const O_NONBLOCK = 0x0004;
273
274/// append on each write
275pub const O_APPEND = 0x0008;
276
277/// create file if it does not exist
278pub const O_CREAT = 0x0200;
279
280/// truncate size to 0
281pub const O_TRUNC = 0x0400;
282
283/// error if O_CREAT and the file exists
284pub const O_EXCL = 0x0800;
285
286/// atomically obtain a shared lock
287pub const O_SHLOCK = 0x0010;
288
289/// atomically obtain an exclusive lock
290pub const O_EXLOCK = 0x0020;
291
292/// do not follow symlinks
293pub const O_NOFOLLOW = 0x0100;
294
295/// allow open of symlinks
296pub const O_SYMLINK = 0x200000;
297
298/// descriptor requested for event notifications only
299pub const O_EVTONLY = 0x8000;
300
301/// mark as close-on-exec
302pub const O_CLOEXEC = 0x1000000;
303
304pub const O_ACCMODE = 3;
305pub const O_ALERT = 536870912;
306pub const O_ASYNC = 64;
307pub const O_DIRECTORY = 1048576;
308pub const O_DP_GETRAWENCRYPTED = 1;
309pub const O_DP_GETRAWUNENCRYPTED = 2;
310pub const O_DSYNC = 4194304;
311pub const O_FSYNC = O_SYNC;
312pub const O_NOCTTY = 131072;
313pub const O_POPUP = 2147483648;
314pub const O_SYNC = 128;
315
316pub const SEEK_SET = 0x0;
317pub const SEEK_CUR = 0x1;
318pub const SEEK_END = 0x2;
319
320pub const DT_UNKNOWN = 0;
321pub const DT_FIFO = 1;
322pub const DT_CHR = 2;
323pub const DT_DIR = 4;
324pub const DT_BLK = 6;
325pub const DT_REG = 8;
326pub const DT_LNK = 10;
327pub const DT_SOCK = 12;
328pub const DT_WHT = 14;
329
330/// block specified signal set
331pub const SIG_BLOCK = 1;
332
333/// unblock specified signal set
334pub const SIG_UNBLOCK = 2;
335
336/// set specified signal set
337pub const SIG_SETMASK = 3;
338
339/// hangup
340pub const SIGHUP = 1;
341
342/// interrupt
343pub const SIGINT = 2;
344
345/// quit
346pub const SIGQUIT = 3;
347
348/// illegal instruction (not reset when caught)
349pub const SIGILL = 4;
350
351/// trace trap (not reset when caught)
352pub const SIGTRAP = 5;
353
354/// abort()
355pub const SIGABRT = 6;
356
357/// pollable event ([XSR] generated, not supported)
358pub const SIGPOLL = 7;
359
360/// compatibility
361pub const SIGIOT = SIGABRT;
362
363/// EMT instruction
364pub const SIGEMT = 7;
365
366/// floating point exception
367pub const SIGFPE = 8;
368
369/// kill (cannot be caught or ignored)
370pub const SIGKILL = 9;
371
372/// bus error
373pub const SIGBUS = 10;
374
375/// segmentation violation
376pub const SIGSEGV = 11;
377
378/// bad argument to system call
379pub const SIGSYS = 12;
380
381/// write on a pipe with no one to read it
382pub const SIGPIPE = 13;
383
384/// alarm clock
385pub const SIGALRM = 14;
386
387/// software termination signal from kill
388pub const SIGTERM = 15;
389
390/// urgent condition on IO channel
391pub const SIGURG = 16;
392
393/// sendable stop signal not from tty
394pub const SIGSTOP = 17;
395
396/// stop signal from tty
397pub const SIGTSTP = 18;
398
399/// continue a stopped process
400pub const SIGCONT = 19;
401
402/// to parent on child stop or exit
403pub const SIGCHLD = 20;
404
405/// to readers pgrp upon background tty read
406pub const SIGTTIN = 21;
407
408/// like TTIN for output if (tp->t_local&LTOSTOP)
409pub const SIGTTOU = 22;
410
411/// input/output possible signal
412pub const SIGIO = 23;
413
414/// exceeded CPU time limit
415pub const SIGXCPU = 24;
416
417/// exceeded file size limit
418pub const SIGXFSZ = 25;
419
420/// virtual time alarm
421pub const SIGVTALRM = 26;
422
423/// profiling time alarm
424pub const SIGPROF = 27;
425
426/// window size changes
427pub const SIGWINCH = 28;
428
429/// information request
430pub const SIGINFO = 29;
431
432/// user defined signal 1
433pub const SIGUSR1 = 30;
434
435/// user defined signal 2
436pub const SIGUSR2 = 31;
437
438/// no flag value
439pub const KEVENT_FLAG_NONE = 0x000;
440
441/// immediate timeout
442pub const KEVENT_FLAG_IMMEDIATE = 0x001;
443
444/// output events only include change
445pub const KEVENT_FLAG_ERROR_EVENTS = 0x002;
446
447/// add event to kq (implies enable)
448pub const EV_ADD = 0x0001;
449
450/// delete event from kq
451pub const EV_DELETE = 0x0002;
452
453/// enable event
454pub const EV_ENABLE = 0x0004;
455
456/// disable event (not reported)
457pub const EV_DISABLE = 0x0008;
458
459/// only report one occurrence
460pub const EV_ONESHOT = 0x0010;
461
462/// clear event state after reporting
463pub 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
469pub const EV_RECEIPT = 0x0040;
470
471/// disable event after reporting
472pub const EV_DISPATCH = 0x0080;
473
474/// unique kevent per udata value
475pub 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
481pub const EV_DISPATCH2 = EV_DISPATCH | EV_UDATA_SPECIFIC;
482
483/// report that source has vanished
484/// ... only valid with EV_DISPATCH2
485pub const EV_VANISHED = 0x0200;
486
487/// reserved by system
488pub const EV_SYSFLAGS = 0xF000;
489
490/// filter-specific flag
491pub const EV_FLAG0 = 0x1000;
492
493/// filter-specific flag
494pub const EV_FLAG1 = 0x2000;
495
496/// EOF detected
497pub const EV_EOF = 0x8000;
498
499/// error, data contains errno
500pub const EV_ERROR = 0x4000;
501
502pub const EV_POLL = EV_FLAG0;
503pub const EV_OOBAND = EV_FLAG1;
504
505pub const EVFILT_READ = -1;
506pub const EVFILT_WRITE = -2;
507
508/// attached to aio requests
509pub const EVFILT_AIO = -3;
510
511/// attached to vnodes
512pub const EVFILT_VNODE = -4;
513
514/// attached to struct proc
515pub const EVFILT_PROC = -5;
516
517/// attached to struct proc
518pub const EVFILT_SIGNAL = -6;
519
520/// timers
521pub const EVFILT_TIMER = -7;
522
523/// Mach portsets
524pub const EVFILT_MACHPORT = -8;
525
526/// Filesystem events
527pub const EVFILT_FS = -9;
528
529/// User events
530pub const EVFILT_USER = -10;
531
532/// Virtual memory events
533pub const EVFILT_VM = -12;
534
535/// Exception events
536pub const EVFILT_EXCEPT = -15;
537
538pub const EVFILT_SYSCOUNT = 17;
539
540/// On input, NOTE_TRIGGER causes the event to be triggered for output.
541pub const NOTE_TRIGGER = 0x01000000;
542
543/// ignore input fflags
544pub const NOTE_FFNOP = 0x00000000;
545
546/// and fflags
547pub const NOTE_FFAND = 0x40000000;
548
549/// or fflags
550pub const NOTE_FFOR = 0x80000000;
551
552/// copy fflags
553pub const NOTE_FFCOPY = 0xc0000000;
554
555/// mask for operations
556pub const NOTE_FFCTRLMASK = 0xc0000000;
557pub const NOTE_FFLAGSMASK = 0x00ffffff;
558
559/// low water mark
560pub const NOTE_LOWAT = 0x00000001;
561
562/// OOB data
563pub const NOTE_OOB = 0x00000002;
564
565/// vnode was removed
566pub const NOTE_DELETE = 0x00000001;
567
568/// data contents changed
569pub const NOTE_WRITE = 0x00000002;
570
571/// size increased
572pub const NOTE_EXTEND = 0x00000004;
573
574/// attributes changed
575pub const NOTE_ATTRIB = 0x00000008;
576
577/// link count changed
578pub const NOTE_LINK = 0x00000010;
579
580/// vnode was renamed
581pub const NOTE_RENAME = 0x00000020;
582
583/// vnode access was revoked
584pub const NOTE_REVOKE = 0x00000040;
585
586/// No specific vnode event: to test for EVFILT_READ activation
587pub const NOTE_NONE = 0x00000080;
588
589/// vnode was unlocked by flock(2)
590pub const NOTE_FUNLOCK = 0x00000100;
591
592/// process exited
593pub const NOTE_EXIT = 0x80000000;
594
595/// process forked
596pub const NOTE_FORK = 0x40000000;
597
598/// process exec'd
599pub const NOTE_EXEC = 0x20000000;
600
601/// shared with EVFILT_SIGNAL
602pub const NOTE_SIGNAL = 0x08000000;
603
604/// exit status to be returned, valid for child process only
605pub const NOTE_EXITSTATUS = 0x04000000;
606
607/// provide details on reasons for exit
608pub const NOTE_EXIT_DETAIL = 0x02000000;
609
610/// mask for signal & exit status
611pub const NOTE_PDATAMASK = 0x000fffff;
612pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
613
614pub const NOTE_EXIT_DETAIL_MASK = 0x00070000;
615pub const NOTE_EXIT_DECRYPTFAIL = 0x00010000;
616pub const NOTE_EXIT_MEMORY = 0x00020000;
617pub const NOTE_EXIT_CSERROR = 0x00040000;
618
619/// will react on memory pressure
620pub const NOTE_VM_PRESSURE = 0x80000000;
621
622/// will quit on memory pressure, possibly after cleaning up dirty state
623pub const NOTE_VM_PRESSURE_TERMINATE = 0x40000000;
624
625/// will quit immediately on memory pressure
626pub const NOTE_VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000;
627
628/// there was an error
629pub const NOTE_VM_ERROR = 0x10000000;
630
631/// data is seconds
632pub const NOTE_SECONDS = 0x00000001;
633
634/// data is microseconds
635pub const NOTE_USECONDS = 0x00000002;
636
637/// data is nanoseconds
638pub const NOTE_NSECONDS = 0x00000004;
639
640/// absolute timeout
641pub const NOTE_ABSOLUTE = 0x00000008;
642
643/// ext[1] holds leeway for power aware timers
644pub const NOTE_LEEWAY = 0x00000010;
645
646/// system does minimal timer coalescing
647pub const NOTE_CRITICAL = 0x00000020;
648
649/// system does maximum timer coalescing
650pub const NOTE_BACKGROUND = 0x00000040;
651pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080;
652
653/// data is mach absolute time units
654pub const NOTE_MACHTIME = 0x00000100;
655
656pub const AF_UNSPEC = 0;
657pub const AF_LOCAL = 1;
658pub const AF_UNIX = AF_LOCAL;
659pub const AF_INET = 2;
660pub const AF_SYS_CONTROL = 2;
661pub const AF_IMPLINK = 3;
662pub const AF_PUP = 4;
663pub const AF_CHAOS = 5;
664pub const AF_NS = 6;
665pub const AF_ISO = 7;
666pub const AF_OSI = AF_ISO;
667pub const AF_ECMA = 8;
668pub const AF_DATAKIT = 9;
669pub const AF_CCITT = 10;
670pub const AF_SNA = 11;
671pub const AF_DECnet = 12;
672pub const AF_DLI = 13;
673pub const AF_LAT = 14;
674pub const AF_HYLINK = 15;
675pub const AF_APPLETALK = 16;
676pub const AF_ROUTE = 17;
677pub const AF_LINK = 18;
678pub const AF_XTP = 19;
679pub const AF_COIP = 20;
680pub const AF_CNT = 21;
681pub const AF_RTIP = 22;
682pub const AF_IPX = 23;
683pub const AF_SIP = 24;
684pub const AF_PIP = 25;
685pub const AF_ISDN = 28;
686pub const AF_E164 = AF_ISDN;
687pub const AF_KEY = 29;
688pub const AF_INET6 = 30;
689pub const AF_NATM = 31;
690pub const AF_SYSTEM = 32;
691pub const AF_NETBIOS = 33;
692pub const AF_PPP = 34;
693pub const AF_MAX = 40;
694
695pub const PF_UNSPEC = AF_UNSPEC;
696pub const PF_LOCAL = AF_LOCAL;
697pub const PF_UNIX = PF_LOCAL;
698pub const PF_INET = AF_INET;
699pub const PF_IMPLINK = AF_IMPLINK;
700pub const PF_PUP = AF_PUP;
701pub const PF_CHAOS = AF_CHAOS;
702pub const PF_NS = AF_NS;
703pub const PF_ISO = AF_ISO;
704pub const PF_OSI = AF_ISO;
705pub const PF_ECMA = AF_ECMA;
706pub const PF_DATAKIT = AF_DATAKIT;
707pub const PF_CCITT = AF_CCITT;
708pub const PF_SNA = AF_SNA;
709pub const PF_DECnet = AF_DECnet;
710pub const PF_DLI = AF_DLI;
711pub const PF_LAT = AF_LAT;
712pub const PF_HYLINK = AF_HYLINK;
713pub const PF_APPLETALK = AF_APPLETALK;
714pub const PF_ROUTE = AF_ROUTE;
715pub const PF_LINK = AF_LINK;
716pub const PF_XTP = AF_XTP;
717pub const PF_COIP = AF_COIP;
718pub const PF_CNT = AF_CNT;
719pub const PF_SIP = AF_SIP;
720pub const PF_IPX = AF_IPX;
721pub const PF_RTIP = AF_RTIP;
722pub const PF_PIP = AF_PIP;
723pub const PF_ISDN = AF_ISDN;
724pub const PF_KEY = AF_KEY;
725pub const PF_INET6 = AF_INET6;
726pub const PF_NATM = AF_NATM;
727pub const PF_SYSTEM = AF_SYSTEM;
728pub const PF_NETBIOS = AF_NETBIOS;
729pub const PF_PPP = AF_PPP;
730pub const PF_MAX = AF_MAX;
731
732pub const SYSPROTO_EVENT = 1;
733pub const SYSPROTO_CONTROL = 2;
734
735pub const SOCK_STREAM = 1;
736pub const SOCK_DGRAM = 2;
737pub const SOCK_RAW = 3;
738pub const SOCK_RDM = 4;
739pub const SOCK_SEQPACKET = 5;
740pub const SOCK_MAXADDRLEN = 255;
741
742pub const IPPROTO_ICMP = 1;
743pub const IPPROTO_ICMPV6 = 58;
744pub const IPPROTO_TCP = 6;
745pub const IPPROTO_UDP = 17;
746pub const IPPROTO_IP = 0;
747pub const IPPROTO_IPV6 = 41;
748
749fn wstatus(x: i32) i32 {
750 return x & 0o177;
751}
752const wstopped = 0o177;
753pub fn WEXITSTATUS(x: i32) i32 {
754 return x >> 8;
755}
756pub fn WTERMSIG(x: i32) i32 {
757 return wstatus(x);
758}
759pub fn WSTOPSIG(x: i32) i32 {
760 return x >> 8;
761}
762pub fn WIFEXITED(x: i32) bool {
763 return wstatus(x) == 0;
764}
765pub fn WIFSTOPPED(x: i32) bool {
766 return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13;
767}
768pub fn WIFSIGNALED(x: i32) bool {
769 return wstatus(x) != wstopped and wstatus(x) != 0;
770}
771
772/// Operation not permitted
773pub const EPERM = 1;
774
775/// No such file or directory
776pub const ENOENT = 2;
777
778/// No such process
779pub const ESRCH = 3;
780
781/// Interrupted system call
782pub const EINTR = 4;
783
784/// Input/output error
785pub const EIO = 5;
786
787/// Device not configured
788pub const ENXIO = 6;
789
790/// Argument list too long
791pub const E2BIG = 7;
792
793/// Exec format error
794pub const ENOEXEC = 8;
795
796/// Bad file descriptor
797pub const EBADF = 9;
798
799/// No child processes
800pub const ECHILD = 10;
801
802/// Resource deadlock avoided
803pub const EDEADLK = 11;
804
805/// Cannot allocate memory
806pub const ENOMEM = 12;
807
808/// Permission denied
809pub const EACCES = 13;
810
811/// Bad address
812pub const EFAULT = 14;
813
814/// Block device required
815pub const ENOTBLK = 15;
816
817/// Device / Resource busy
818pub const EBUSY = 16;
819
820/// File exists
821pub const EEXIST = 17;
822
823/// Cross-device link
824pub const EXDEV = 18;
825
826/// Operation not supported by device
827pub const ENODEV = 19;
828
829/// Not a directory
830pub const ENOTDIR = 20;
831
832/// Is a directory
833pub const EISDIR = 21;
834
835/// Invalid argument
836pub const EINVAL = 22;
837
838/// Too many open files in system
839pub const ENFILE = 23;
840
841/// Too many open files
842pub const EMFILE = 24;
843
844/// Inappropriate ioctl for device
845pub const ENOTTY = 25;
846
847/// Text file busy
848pub const ETXTBSY = 26;
849
850/// File too large
851pub const EFBIG = 27;
852
853/// No space left on device
854pub const ENOSPC = 28;
855
856/// Illegal seek
857pub const ESPIPE = 29;
858
859/// Read-only file system
860pub const EROFS = 30;
861
862/// Too many links
863pub const EMLINK = 31;
864/// Broken pipe
865
866// math software
867pub const EPIPE = 32;
868
869/// Numerical argument out of domain
870pub const EDOM = 33;
871/// Result too large
872
873// non-blocking and interrupt i/o
874pub const ERANGE = 34;
875
876/// Resource temporarily unavailable
877pub const EAGAIN = 35;
878
879/// Operation would block
880pub const EWOULDBLOCK = EAGAIN;
881
882/// Operation now in progress
883pub const EINPROGRESS = 36;
884/// Operation already in progress
885
886// ipc/network software -- argument errors
887pub const EALREADY = 37;
888
889/// Socket operation on non-socket
890pub const ENOTSOCK = 38;
891
892/// Destination address required
893pub const EDESTADDRREQ = 39;
894
895/// Message too long
896pub const EMSGSIZE = 40;
897
898/// Protocol wrong type for socket
899pub const EPROTOTYPE = 41;
900
901/// Protocol not available
902pub const ENOPROTOOPT = 42;
903
904/// Protocol not supported
905pub const EPROTONOSUPPORT = 43;
906
907/// Socket type not supported
908pub const ESOCKTNOSUPPORT = 44;
909
910/// Operation not supported
911pub const ENOTSUP = 45;
912
913/// Protocol family not supported
914pub const EPFNOSUPPORT = 46;
915
916/// Address family not supported by protocol family
917pub const EAFNOSUPPORT = 47;
918
919/// Address already in use
920pub const EADDRINUSE = 48;
921/// Can't assign requested address
922
923// ipc/network software -- operational errors
924pub const EADDRNOTAVAIL = 49;
925
926/// Network is down
927pub const ENETDOWN = 50;
928
929/// Network is unreachable
930pub const ENETUNREACH = 51;
931
932/// Network dropped connection on reset
933pub const ENETRESET = 52;
934
935/// Software caused connection abort
936pub const ECONNABORTED = 53;
937
938/// Connection reset by peer
939pub const ECONNRESET = 54;
940
941/// No buffer space available
942pub const ENOBUFS = 55;
943
944/// Socket is already connected
945pub const EISCONN = 56;
946
947/// Socket is not connected
948pub const ENOTCONN = 57;
949
950/// Can't send after socket shutdown
951pub const ESHUTDOWN = 58;
952
953/// Too many references: can't splice
954pub const ETOOMANYREFS = 59;
955
956/// Operation timed out
957pub const ETIMEDOUT = 60;
958
959/// Connection refused
960pub const ECONNREFUSED = 61;
961
962/// Too many levels of symbolic links
963pub const ELOOP = 62;
964
965/// File name too long
966pub const ENAMETOOLONG = 63;
967
968/// Host is down
969pub const EHOSTDOWN = 64;
970
971/// No route to host
972pub const EHOSTUNREACH = 65;
973/// Directory not empty
974
975// quotas & mush
976pub const ENOTEMPTY = 66;
977
978/// Too many processes
979pub const EPROCLIM = 67;
980
981/// Too many users
982pub const EUSERS = 68;
983/// Disc quota exceeded
984
985// Network File System
986pub const EDQUOT = 69;
987
988/// Stale NFS file handle
989pub const ESTALE = 70;
990
991/// Too many levels of remote in path
992pub const EREMOTE = 71;
993
994/// RPC struct is bad
995pub const EBADRPC = 72;
996
997/// RPC version wrong
998pub const ERPCMISMATCH = 73;
999
1000/// RPC prog. not avail
1001pub const EPROGUNAVAIL = 74;
1002
1003/// Program version wrong
1004pub const EPROGMISMATCH = 75;
1005
1006/// Bad procedure for program
1007pub const EPROCUNAVAIL = 76;
1008
1009/// No locks available
1010pub const ENOLCK = 77;
1011
1012/// Function not implemented
1013pub const ENOSYS = 78;
1014
1015/// Inappropriate file type or format
1016pub const EFTYPE = 79;
1017
1018/// Authentication error
1019pub const EAUTH = 80;
1020/// Need authenticator
1021
1022// Intelligent device errors
1023pub const ENEEDAUTH = 81;
1024
1025/// Device power is off
1026pub const EPWROFF = 82;
1027
1028/// Device error, e.g. paper out
1029pub const EDEVERR = 83;
1030/// Value too large to be stored in data type
1031
1032// Program loading errors
1033pub const EOVERFLOW = 84;
1034
1035/// Bad executable
1036pub const EBADEXEC = 85;
1037
1038/// Bad CPU type in executable
1039pub const EBADARCH = 86;
1040
1041/// Shared library version mismatch
1042pub const ESHLIBVERS = 87;
1043
1044/// Malformed Macho file
1045pub const EBADMACHO = 88;
1046
1047/// Operation canceled
1048pub const ECANCELED = 89;
1049
1050/// Identifier removed
1051pub const EIDRM = 90;
1052
1053/// No message of desired type
1054pub const ENOMSG = 91;
1055
1056/// Illegal byte sequence
1057pub const EILSEQ = 92;
1058
1059/// Attribute not found
1060pub const ENOATTR = 93;
1061
1062/// Bad message
1063pub const EBADMSG = 94;
1064
1065/// Reserved
1066pub const EMULTIHOP = 95;
1067
1068/// No message available on STREAM
1069pub const ENODATA = 96;
1070
1071/// Reserved
1072pub const ENOLINK = 97;
1073
1074/// No STREAM resources
1075pub const ENOSR = 98;
1076
1077/// Not a STREAM
1078pub const ENOSTR = 99;
1079
1080/// Protocol error
1081pub const EPROTO = 100;
1082
1083/// STREAM ioctl timeout
1084pub const ETIME = 101;
1085
1086/// No such policy registered
1087pub const ENOPOLICY = 103;
1088
1089/// State not recoverable
1090pub const ENOTRECOVERABLE = 104;
1091
1092/// Previous owner died
1093pub const EOWNERDEAD = 105;
1094
1095/// Interface output queue is full
1096pub const EQFULL = 106;
1097
1098/// Must be equal largest errno
1099pub const ELAST = 106;
std/c/posix/freebsd.zig created+839
......@@ -0,0 +1,839 @@
1const std = @import("../std.zig");
2
3/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
4pub 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
14pub const pthread_attr_t = extern struct {
15 __size: [56]u8,
16 __align: c_long,
17};
18
19pub 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
42pub 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
65pub 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
90pub const timespec = extern struct {
91 tv_sec: isize,
92 tv_nsec: isize,
93};
94
95pub 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
106pub const in_port_t = u16;
107pub const sa_family_t = u16;
108
109pub const sockaddr = extern union {
110 in: sockaddr_in,
111 in6: sockaddr_in6,
112};
113
114pub 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
122pub 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
131pub const CTL_KERN = 1;
132pub const CTL_DEBUG = 5;
133
134pub const KERN_PROC = 14; // struct: process entries
135pub const KERN_PROC_PATHNAME = 12; // path to executable
136
137pub const PATH_MAX = 1024;
138
139pub const STDIN_FILENO = 0;
140pub const STDOUT_FILENO = 1;
141pub const STDERR_FILENO = 2;
142
143pub const PROT_NONE = 0;
144pub const PROT_READ = 1;
145pub const PROT_WRITE = 2;
146pub const PROT_EXEC = 4;
147
148pub const CLOCK_REALTIME = 0;
149pub const CLOCK_VIRTUAL = 1;
150pub const CLOCK_PROF = 2;
151pub const CLOCK_MONOTONIC = 4;
152pub const CLOCK_UPTIME = 5;
153pub const CLOCK_UPTIME_PRECISE = 7;
154pub const CLOCK_UPTIME_FAST = 8;
155pub const CLOCK_REALTIME_PRECISE = 9;
156pub const CLOCK_REALTIME_FAST = 10;
157pub const CLOCK_MONOTONIC_PRECISE = 11;
158pub const CLOCK_MONOTONIC_FAST = 12;
159pub const CLOCK_SECOND = 13;
160pub const CLOCK_THREAD_CPUTIME_ID = 14;
161pub const CLOCK_PROCESS_CPUTIME_ID = 15;
162
163pub const MAP_FAILED = maxInt(usize);
164pub const MAP_SHARED = 0x0001;
165pub const MAP_PRIVATE = 0x0002;
166pub const MAP_FIXED = 0x0010;
167pub const MAP_STACK = 0x0400;
168pub const MAP_NOSYNC = 0x0800;
169pub const MAP_ANON = 0x1000;
170pub const MAP_ANONYMOUS = MAP_ANON;
171pub const MAP_FILE = 0;
172pub const MAP_NORESERVE = 0;
173
174pub const MAP_GUARD = 0x00002000;
175pub const MAP_EXCL = 0x00004000;
176pub const MAP_NOCORE = 0x00020000;
177pub const MAP_PREFAULT_READ = 0x00040000;
178pub const MAP_32BIT = 0x00080000;
179
180pub const WNOHANG = 1;
181pub const WUNTRACED = 2;
182pub const WSTOPPED = WUNTRACED;
183pub const WCONTINUED = 4;
184pub const WNOWAIT = 8;
185pub const WEXITED = 16;
186pub const WTRAPPED = 32;
187
188pub const SA_ONSTACK = 0x0001;
189pub const SA_RESTART = 0x0002;
190pub const SA_RESETHAND = 0x0004;
191pub const SA_NOCLDSTOP = 0x0008;
192pub const SA_NODEFER = 0x0010;
193pub const SA_NOCLDWAIT = 0x0020;
194pub const SA_SIGINFO = 0x0040;
195
196pub const SIGHUP = 1;
197pub const SIGINT = 2;
198pub const SIGQUIT = 3;
199pub const SIGILL = 4;
200pub const SIGTRAP = 5;
201pub const SIGABRT = 6;
202pub const SIGIOT = SIGABRT;
203pub const SIGEMT = 7;
204pub const SIGFPE = 8;
205pub const SIGKILL = 9;
206pub const SIGBUS = 10;
207pub const SIGSEGV = 11;
208pub const SIGSYS = 12;
209pub const SIGPIPE = 13;
210pub const SIGALRM = 14;
211pub const SIGTERM = 15;
212pub const SIGURG = 16;
213pub const SIGSTOP = 17;
214pub const SIGTSTP = 18;
215pub const SIGCONT = 19;
216pub const SIGCHLD = 20;
217pub const SIGTTIN = 21;
218pub const SIGTTOU = 22;
219pub const SIGIO = 23;
220pub const SIGXCPU = 24;
221pub const SIGXFSZ = 25;
222pub const SIGVTALRM = 26;
223pub const SIGPROF = 27;
224pub const SIGWINCH = 28;
225pub const SIGINFO = 29;
226pub const SIGUSR1 = 30;
227pub const SIGUSR2 = 31;
228pub const SIGTHR = 32;
229pub const SIGLWP = SIGTHR;
230pub const SIGLIBRT = 33;
231
232pub const SIGRTMIN = 65;
233pub const SIGRTMAX = 126;
234
235// access function
236pub const F_OK = 0; // test for existence of file
237pub const X_OK = 1; // test for execute or search permission
238pub const W_OK = 2; // test for write permission
239pub const R_OK = 4; // test for read permission
240
241pub const O_RDONLY = 0x0000;
242pub const O_WRONLY = 0x0001;
243pub const O_RDWR = 0x0002;
244pub const O_ACCMODE = 0x0003;
245
246pub const O_CREAT = 0x0200;
247pub const O_EXCL = 0x0800;
248pub const O_NOCTTY = 0x8000;
249pub const O_TRUNC = 0x0400;
250pub const O_APPEND = 0x0008;
251pub const O_NONBLOCK = 0x0004;
252pub const O_DSYNC = 0o10000;
253pub const O_SYNC = 0x0080;
254pub const O_RSYNC = 0o4010000;
255pub const O_DIRECTORY = 0o200000;
256pub const O_NOFOLLOW = 0x0100;
257pub const O_CLOEXEC = 0x00100000;
258
259pub const O_ASYNC = 0x0040;
260pub const O_DIRECT = 0x00010000;
261pub const O_LARGEFILE = 0;
262pub const O_NOATIME = 0o1000000;
263pub const O_PATH = 0o10000000;
264pub const O_TMPFILE = 0o20200000;
265pub const O_NDELAY = O_NONBLOCK;
266
267pub const F_DUPFD = 0;
268pub const F_GETFD = 1;
269pub const F_SETFD = 2;
270pub const F_GETFL = 3;
271pub const F_SETFL = 4;
272
273pub const F_SETOWN = 8;
274pub const F_GETOWN = 9;
275pub const F_SETSIG = 10;
276pub const F_GETSIG = 11;
277
278pub const F_GETLK = 5;
279pub const F_SETLK = 6;
280pub const F_SETLKW = 7;
281
282pub const F_SETOWN_EX = 15;
283pub const F_GETOWN_EX = 16;
284
285pub const F_GETOWNER_UIDS = 17;
286
287pub const SEEK_SET = 0;
288pub const SEEK_CUR = 1;
289pub const SEEK_END = 2;
290
291pub const SIG_BLOCK = 1;
292pub const SIG_UNBLOCK = 2;
293pub const SIG_SETMASK = 3;
294
295pub const SOCK_STREAM = 1;
296pub const SOCK_DGRAM = 2;
297pub const SOCK_RAW = 3;
298pub const SOCK_RDM = 4;
299pub const SOCK_SEQPACKET = 5;
300
301pub const SOCK_CLOEXEC = 0x10000000;
302pub const SOCK_NONBLOCK = 0x20000000;
303
304pub const PROTO_ip = 0o000;
305pub const PROTO_icmp = 0o001;
306pub const PROTO_igmp = 0o002;
307pub const PROTO_ggp = 0o003;
308pub const PROTO_ipencap = 0o004;
309pub const PROTO_st = 0o005;
310pub const PROTO_tcp = 0o006;
311pub const PROTO_egp = 0o010;
312pub const PROTO_pup = 0o014;
313pub const PROTO_udp = 0o021;
314pub const PROTO_hmp = 0o024;
315pub const PROTO_xns_idp = 0o026;
316pub const PROTO_rdp = 0o033;
317pub const PROTO_iso_tp4 = 0o035;
318pub const PROTO_xtp = 0o044;
319pub const PROTO_ddp = 0o045;
320pub const PROTO_idpr_cmtp = 0o046;
321pub const PROTO_ipv6 = 0o051;
322pub const PROTO_ipv6_route = 0o053;
323pub const PROTO_ipv6_frag = 0o054;
324pub const PROTO_idrp = 0o055;
325pub const PROTO_rsvp = 0o056;
326pub const PROTO_gre = 0o057;
327pub const PROTO_esp = 0o062;
328pub const PROTO_ah = 0o063;
329pub const PROTO_skip = 0o071;
330pub const PROTO_ipv6_icmp = 0o072;
331pub const PROTO_ipv6_nonxt = 0o073;
332pub const PROTO_ipv6_opts = 0o074;
333pub const PROTO_rspf = 0o111;
334pub const PROTO_vmtp = 0o121;
335pub const PROTO_ospf = 0o131;
336pub const PROTO_ipip = 0o136;
337pub const PROTO_encap = 0o142;
338pub const PROTO_pim = 0o147;
339pub const PROTO_raw = 0o377;
340
341pub const PF_UNSPEC = 0;
342pub const PF_LOCAL = 1;
343pub const PF_UNIX = PF_LOCAL;
344pub const PF_FILE = PF_LOCAL;
345pub const PF_INET = 2;
346pub const PF_AX25 = 3;
347pub const PF_IPX = 4;
348pub const PF_APPLETALK = 5;
349pub const PF_NETROM = 6;
350pub const PF_BRIDGE = 7;
351pub const PF_ATMPVC = 8;
352pub const PF_X25 = 9;
353pub const PF_INET6 = 10;
354pub const PF_ROSE = 11;
355pub const PF_DECnet = 12;
356pub const PF_NETBEUI = 13;
357pub const PF_SECURITY = 14;
358pub const PF_KEY = 15;
359pub const PF_NETLINK = 16;
360pub const PF_ROUTE = PF_NETLINK;
361pub const PF_PACKET = 17;
362pub const PF_ASH = 18;
363pub const PF_ECONET = 19;
364pub const PF_ATMSVC = 20;
365pub const PF_RDS = 21;
366pub const PF_SNA = 22;
367pub const PF_IRDA = 23;
368pub const PF_PPPOX = 24;
369pub const PF_WANPIPE = 25;
370pub const PF_LLC = 26;
371pub const PF_IB = 27;
372pub const PF_MPLS = 28;
373pub const PF_CAN = 29;
374pub const PF_TIPC = 30;
375pub const PF_BLUETOOTH = 31;
376pub const PF_IUCV = 32;
377pub const PF_RXRPC = 33;
378pub const PF_ISDN = 34;
379pub const PF_PHONET = 35;
380pub const PF_IEEE802154 = 36;
381pub const PF_CAIF = 37;
382pub const PF_ALG = 38;
383pub const PF_NFC = 39;
384pub const PF_VSOCK = 40;
385pub const PF_MAX = 41;
386
387pub const AF_UNSPEC = PF_UNSPEC;
388pub const AF_LOCAL = PF_LOCAL;
389pub const AF_UNIX = AF_LOCAL;
390pub const AF_FILE = AF_LOCAL;
391pub const AF_INET = PF_INET;
392pub const AF_AX25 = PF_AX25;
393pub const AF_IPX = PF_IPX;
394pub const AF_APPLETALK = PF_APPLETALK;
395pub const AF_NETROM = PF_NETROM;
396pub const AF_BRIDGE = PF_BRIDGE;
397pub const AF_ATMPVC = PF_ATMPVC;
398pub const AF_X25 = PF_X25;
399pub const AF_INET6 = PF_INET6;
400pub const AF_ROSE = PF_ROSE;
401pub const AF_DECnet = PF_DECnet;
402pub const AF_NETBEUI = PF_NETBEUI;
403pub const AF_SECURITY = PF_SECURITY;
404pub const AF_KEY = PF_KEY;
405pub const AF_NETLINK = PF_NETLINK;
406pub const AF_ROUTE = PF_ROUTE;
407pub const AF_PACKET = PF_PACKET;
408pub const AF_ASH = PF_ASH;
409pub const AF_ECONET = PF_ECONET;
410pub const AF_ATMSVC = PF_ATMSVC;
411pub const AF_RDS = PF_RDS;
412pub const AF_SNA = PF_SNA;
413pub const AF_IRDA = PF_IRDA;
414pub const AF_PPPOX = PF_PPPOX;
415pub const AF_WANPIPE = PF_WANPIPE;
416pub const AF_LLC = PF_LLC;
417pub const AF_IB = PF_IB;
418pub const AF_MPLS = PF_MPLS;
419pub const AF_CAN = PF_CAN;
420pub const AF_TIPC = PF_TIPC;
421pub const AF_BLUETOOTH = PF_BLUETOOTH;
422pub const AF_IUCV = PF_IUCV;
423pub const AF_RXRPC = PF_RXRPC;
424pub const AF_ISDN = PF_ISDN;
425pub const AF_PHONET = PF_PHONET;
426pub const AF_IEEE802154 = PF_IEEE802154;
427pub const AF_CAIF = PF_CAIF;
428pub const AF_ALG = PF_ALG;
429pub const AF_NFC = PF_NFC;
430pub const AF_VSOCK = PF_VSOCK;
431pub const AF_MAX = PF_MAX;
432
433pub const DT_UNKNOWN = 0;
434pub const DT_FIFO = 1;
435pub const DT_CHR = 2;
436pub const DT_DIR = 4;
437pub const DT_BLK = 6;
438pub const DT_REG = 8;
439pub const DT_LNK = 10;
440pub const DT_SOCK = 12;
441pub const DT_WHT = 14;
442
443/// add event to kq (implies enable)
444pub const EV_ADD = 0x0001;
445
446/// delete event from kq
447pub const EV_DELETE = 0x0002;
448
449/// enable event
450pub const EV_ENABLE = 0x0004;
451
452/// disable event (not reported)
453pub const EV_DISABLE = 0x0008;
454
455/// only report one occurrence
456pub const EV_ONESHOT = 0x0010;
457
458/// clear event state after reporting
459pub 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
465pub const EV_RECEIPT = 0x0040;
466
467/// disable event after reporting
468pub const EV_DISPATCH = 0x0080;
469
470pub const EVFILT_READ = -1;
471pub const EVFILT_WRITE = -2;
472
473/// attached to aio requests
474pub const EVFILT_AIO = -3;
475
476/// attached to vnodes
477pub const EVFILT_VNODE = -4;
478
479/// attached to struct proc
480pub const EVFILT_PROC = -5;
481
482/// attached to struct proc
483pub const EVFILT_SIGNAL = -6;
484
485/// timers
486pub const EVFILT_TIMER = -7;
487
488/// Process descriptors
489pub const EVFILT_PROCDESC = -8;
490
491/// Filesystem events
492pub const EVFILT_FS = -9;
493
494pub const EVFILT_LIO = -10;
495
496/// User events
497pub const EVFILT_USER = -11;
498
499/// Sendfile events
500pub const EVFILT_SENDFILE = -12;
501
502pub const EVFILT_EMPTY = -13;
503
504/// On input, NOTE_TRIGGER causes the event to be triggered for output.
505pub const NOTE_TRIGGER = 0x01000000;
506
507/// ignore input fflags
508pub const NOTE_FFNOP = 0x00000000;
509
510/// and fflags
511pub const NOTE_FFAND = 0x40000000;
512
513/// or fflags
514pub const NOTE_FFOR = 0x80000000;
515
516/// copy fflags
517pub const NOTE_FFCOPY = 0xc0000000;
518
519/// mask for operations
520pub const NOTE_FFCTRLMASK = 0xc0000000;
521pub const NOTE_FFLAGSMASK = 0x00ffffff;
522
523/// low water mark
524pub const NOTE_LOWAT = 0x00000001;
525
526/// behave like poll()
527pub const NOTE_FILE_POLL = 0x00000002;
528
529/// vnode was removed
530pub const NOTE_DELETE = 0x00000001;
531
532/// data contents changed
533pub const NOTE_WRITE = 0x00000002;
534
535/// size increased
536pub const NOTE_EXTEND = 0x00000004;
537
538/// attributes changed
539pub const NOTE_ATTRIB = 0x00000008;
540
541/// link count changed
542pub const NOTE_LINK = 0x00000010;
543
544/// vnode was renamed
545pub const NOTE_RENAME = 0x00000020;
546
547/// vnode access was revoked
548pub const NOTE_REVOKE = 0x00000040;
549
550/// vnode was opened
551pub const NOTE_OPEN = 0x00000080;
552
553/// file closed, fd did not allow write
554pub const NOTE_CLOSE = 0x00000100;
555
556/// file closed, fd did allow write
557pub const NOTE_CLOSE_WRITE = 0x00000200;
558
559/// file was read
560pub const NOTE_READ = 0x00000400;
561
562/// process exited
563pub const NOTE_EXIT = 0x80000000;
564
565/// process forked
566pub const NOTE_FORK = 0x40000000;
567
568/// process exec'd
569pub const NOTE_EXEC = 0x20000000;
570
571/// mask for signal & exit status
572pub const NOTE_PDATAMASK = 0x000fffff;
573pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
574
575/// data is seconds
576pub const NOTE_SECONDS = 0x00000001;
577
578/// data is milliseconds
579pub const NOTE_MSECONDS = 0x00000002;
580
581/// data is microseconds
582pub const NOTE_USECONDS = 0x00000004;
583
584/// data is nanoseconds
585pub const NOTE_NSECONDS = 0x00000008;
586
587/// timeout is absolute
588pub const NOTE_ABSTIME = 0x00000010;
589
590pub const TCGETS = 0x5401;
591pub const TCSETS = 0x5402;
592pub const TCSETSW = 0x5403;
593pub const TCSETSF = 0x5404;
594pub const TCGETA = 0x5405;
595pub const TCSETA = 0x5406;
596pub const TCSETAW = 0x5407;
597pub const TCSETAF = 0x5408;
598pub const TCSBRK = 0x5409;
599pub const TCXONC = 0x540A;
600pub const TCFLSH = 0x540B;
601pub const TIOCEXCL = 0x540C;
602pub const TIOCNXCL = 0x540D;
603pub const TIOCSCTTY = 0x540E;
604pub const TIOCGPGRP = 0x540F;
605pub const TIOCSPGRP = 0x5410;
606pub const TIOCOUTQ = 0x5411;
607pub const TIOCSTI = 0x5412;
608pub const TIOCGWINSZ = 0x5413;
609pub const TIOCSWINSZ = 0x5414;
610pub const TIOCMGET = 0x5415;
611pub const TIOCMBIS = 0x5416;
612pub const TIOCMBIC = 0x5417;
613pub const TIOCMSET = 0x5418;
614pub const TIOCGSOFTCAR = 0x5419;
615pub const TIOCSSOFTCAR = 0x541A;
616pub const FIONREAD = 0x541B;
617pub const TIOCINQ = FIONREAD;
618pub const TIOCLINUX = 0x541C;
619pub const TIOCCONS = 0x541D;
620pub const TIOCGSERIAL = 0x541E;
621pub const TIOCSSERIAL = 0x541F;
622pub const TIOCPKT = 0x5420;
623pub const FIONBIO = 0x5421;
624pub const TIOCNOTTY = 0x5422;
625pub const TIOCSETD = 0x5423;
626pub const TIOCGETD = 0x5424;
627pub const TCSBRKP = 0x5425;
628pub const TIOCSBRK = 0x5427;
629pub const TIOCCBRK = 0x5428;
630pub const TIOCGSID = 0x5429;
631pub const TIOCGRS485 = 0x542E;
632pub const TIOCSRS485 = 0x542F;
633pub const TIOCGPTN = 0x80045430;
634pub const TIOCSPTLCK = 0x40045431;
635pub const TIOCGDEV = 0x80045432;
636pub const TCGETX = 0x5432;
637pub const TCSETX = 0x5433;
638pub const TCSETXF = 0x5434;
639pub const TCSETXW = 0x5435;
640pub const TIOCSIG = 0x40045436;
641pub const TIOCVHANGUP = 0x5437;
642pub const TIOCGPKT = 0x80045438;
643pub const TIOCGPTLCK = 0x80045439;
644pub const TIOCGEXCL = 0x80045440;
645
646fn unsigned(s: i32) u32 {
647 return @bitCast(u32, s);
648}
649fn signed(s: u32) i32 {
650 return @bitCast(i32, s);
651}
652pub fn WEXITSTATUS(s: i32) i32 {
653 return signed((unsigned(s) & 0xff00) >> 8);
654}
655pub fn WTERMSIG(s: i32) i32 {
656 return signed(unsigned(s) & 0x7f);
657}
658pub fn WSTOPSIG(s: i32) i32 {
659 return WEXITSTATUS(s);
660}
661pub fn WIFEXITED(s: i32) bool {
662 return WTERMSIG(s) == 0;
663}
664pub fn WIFSTOPPED(s: i32) bool {
665 return @intCast(u16, (((unsigned(s) & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
666}
667pub fn WIFSIGNALED(s: i32) bool {
668 return (unsigned(s) & 0xffff) -% 1 < 0xff;
669}
670
671pub const winsize = extern struct {
672 ws_row: u16,
673 ws_col: u16,
674 ws_xpixel: u16,
675 ws_ypixel: u16,
676};
677
678const NSIG = 32;
679
680pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
681pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
682pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
683
684/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
685pub 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
699pub const _SIG_WORDS = 4;
700pub const _SIG_MAXSIG = 128;
701
702pub inline fn _SIG_IDX(sig: usize) usize {
703 return sig - 1;
704}
705pub inline fn _SIG_WORD(sig: usize) usize {
706 return_SIG_IDX(sig) >> 5;
707}
708pub inline fn _SIG_BIT(sig: usize) usize {
709 return 1 << (_SIG_IDX(sig) & 31);
710}
711pub inline fn _SIG_VALID(sig: usize) usize {
712 return sig <= _SIG_MAXSIG and sig > 0;
713}
714
715pub const sigset_t = extern struct {
716 __bits: [_SIG_WORDS]u32,
717};
718
719pub const EPERM = 1; // Operation not permitted
720pub const ENOENT = 2; // No such file or directory
721pub const ESRCH = 3; // No such process
722pub const EINTR = 4; // Interrupted system call
723pub const EIO = 5; // Input/output error
724pub const ENXIO = 6; // Device not configured
725pub const E2BIG = 7; // Argument list too long
726pub const ENOEXEC = 8; // Exec format error
727pub const EBADF = 9; // Bad file descriptor
728pub const ECHILD = 10; // No child processes
729pub const EDEADLK = 11; // Resource deadlock avoided
730// 11 was EAGAIN
731pub const ENOMEM = 12; // Cannot allocate memory
732pub const EACCES = 13; // Permission denied
733pub const EFAULT = 14; // Bad address
734pub const ENOTBLK = 15; // Block device required
735pub const EBUSY = 16; // Device busy
736pub const EEXIST = 17; // File exists
737pub const EXDEV = 18; // Cross-device link
738pub const ENODEV = 19; // Operation not supported by device
739pub const ENOTDIR = 20; // Not a directory
740pub const EISDIR = 21; // Is a directory
741pub const EINVAL = 22; // Invalid argument
742pub const ENFILE = 23; // Too many open files in system
743pub const EMFILE = 24; // Too many open files
744pub const ENOTTY = 25; // Inappropriate ioctl for device
745pub const ETXTBSY = 26; // Text file busy
746pub const EFBIG = 27; // File too large
747pub const ENOSPC = 28; // No space left on device
748pub const ESPIPE = 29; // Illegal seek
749pub const EROFS = 30; // Read-only filesystem
750pub const EMLINK = 31; // Too many links
751pub const EPIPE = 32; // Broken pipe
752
753// math software
754pub const EDOM = 33; // Numerical argument out of domain
755pub const ERANGE = 34; // Result too large
756
757// non-blocking and interrupt i/o
758pub const EAGAIN = 35; // Resource temporarily unavailable
759pub const EWOULDBLOCK = EAGAIN; // Operation would block
760pub const EINPROGRESS = 36; // Operation now in progress
761pub const EALREADY = 37; // Operation already in progress
762
763// ipc/network software -- argument errors
764pub const ENOTSOCK = 38; // Socket operation on non-socket
765pub const EDESTADDRREQ = 39; // Destination address required
766pub const EMSGSIZE = 40; // Message too long
767pub const EPROTOTYPE = 41; // Protocol wrong type for socket
768pub const ENOPROTOOPT = 42; // Protocol not available
769pub const EPROTONOSUPPORT = 43; // Protocol not supported
770pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
771pub const EOPNOTSUPP = 45; // Operation not supported
772pub const ENOTSUP = EOPNOTSUPP; // Operation not supported
773pub const EPFNOSUPPORT = 46; // Protocol family not supported
774pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
775pub const EADDRINUSE = 48; // Address already in use
776pub const EADDRNOTAVAIL = 49; // Can't assign requested address
777
778// ipc/network software -- operational errors
779pub const ENETDOWN = 50; // Network is down
780pub const ENETUNREACH = 51; // Network is unreachable
781pub const ENETRESET = 52; // Network dropped connection on reset
782pub const ECONNABORTED = 53; // Software caused connection abort
783pub const ECONNRESET = 54; // Connection reset by peer
784pub const ENOBUFS = 55; // No buffer space available
785pub const EISCONN = 56; // Socket is already connected
786pub const ENOTCONN = 57; // Socket is not connected
787pub const ESHUTDOWN = 58; // Can't send after socket shutdown
788pub const ETOOMANYREFS = 59; // Too many references: can't splice
789pub const ETIMEDOUT = 60; // Operation timed out
790pub const ECONNREFUSED = 61; // Connection refused
791
792pub const ELOOP = 62; // Too many levels of symbolic links
793pub const ENAMETOOLONG = 63; // File name too long
794
795// should be rearranged
796pub const EHOSTDOWN = 64; // Host is down
797pub const EHOSTUNREACH = 65; // No route to host
798pub const ENOTEMPTY = 66; // Directory not empty
799
800// quotas & mush
801pub const EPROCLIM = 67; // Too many processes
802pub const EUSERS = 68; // Too many users
803pub const EDQUOT = 69; // Disc quota exceeded
804
805// Network File System
806pub const ESTALE = 70; // Stale NFS file handle
807pub const EREMOTE = 71; // Too many levels of remote in path
808pub const EBADRPC = 72; // RPC struct is bad
809pub const ERPCMISMATCH = 73; // RPC version wrong
810pub const EPROGUNAVAIL = 74; // RPC prog. not avail
811pub const EPROGMISMATCH = 75; // Program version wrong
812pub const EPROCUNAVAIL = 76; // Bad procedure for program
813
814pub const ENOLCK = 77; // No locks available
815pub const ENOSYS = 78; // Function not implemented
816
817pub const EFTYPE = 79; // Inappropriate file type or format
818pub const EAUTH = 80; // Authentication error
819pub const ENEEDAUTH = 81; // Need authenticator
820pub const EIDRM = 82; // Identifier removed
821pub const ENOMSG = 83; // No message of desired type
822pub const EOVERFLOW = 84; // Value too large to be stored in data type
823pub const ECANCELED = 85; // Operation canceled
824pub const EILSEQ = 86; // Illegal byte sequence
825pub const ENOATTR = 87; // Attribute not found
826
827pub const EDOOFUS = 88; // Programming error
828
829pub const EBADMSG = 89; // Bad message
830pub const EMULTIHOP = 90; // Multihop attempted
831pub const ENOLINK = 91; // Link has been severed
832pub const EPROTO = 92; // Protocol error
833
834pub const ENOTCAPABLE = 93; // Capabilities insufficient
835pub const ECAPMODE = 94; // Not permitted in capability mode
836pub const ENOTRECOVERABLE = 95; // State not recoverable
837pub const EOWNERDEAD = 96; // Previous owner died
838
839pub const ELAST = 96; // Must be equal largest errno
std/c/posix/netbsd.zig created+728
......@@ -0,0 +1,728 @@
1const std = @import("../../std.zig");
2const maxInt = std.math.maxInt;
3
4/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
5pub const Kevent = extern struct {
6 ident: usize,
7 filter: i32,
8 flags: u32,
9 fflags: u32,
10 data: i64,
11 udata: usize,
12};
13
14pub const pthread_attr_t = extern struct {
15 pta_magic: u32,
16 pta_flags: c_int,
17 pta_private: *c_void,
18};
19
20pub 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
43pub 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
66pub 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
89pub const timespec = extern struct {
90 tv_sec: i64,
91 tv_nsec: isize,
92};
93
94pub 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
103pub const in_port_t = u16;
104pub const sa_family_t = u8;
105
106pub const sockaddr = extern union {
107 in: sockaddr_in,
108 in6: sockaddr_in6,
109};
110
111pub 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
119pub 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
128pub const CTL_KERN = 1;
129pub const CTL_DEBUG = 5;
130
131pub const KERN_PROC_ARGS = 48; // struct: process argv/env
132pub const KERN_PROC_PATHNAME = 5; // path to executable
133
134pub const PATH_MAX = 1024;
135
136pub const STDIN_FILENO = 0;
137pub const STDOUT_FILENO = 1;
138pub const STDERR_FILENO = 2;
139
140pub const PROT_NONE = 0;
141pub const PROT_READ = 1;
142pub const PROT_WRITE = 2;
143pub const PROT_EXEC = 4;
144
145pub const CLOCK_REALTIME = 0;
146pub const CLOCK_VIRTUAL = 1;
147pub const CLOCK_PROF = 2;
148pub const CLOCK_MONOTONIC = 3;
149pub const CLOCK_THREAD_CPUTIME_ID = 0x20000000;
150pub const CLOCK_PROCESS_CPUTIME_ID = 0x40000000;
151
152pub const MAP_FAILED = maxInt(usize);
153pub const MAP_SHARED = 0x0001;
154pub const MAP_PRIVATE = 0x0002;
155pub const MAP_REMAPDUP = 0x0004;
156pub const MAP_FIXED = 0x0010;
157pub const MAP_RENAME = 0x0020;
158pub const MAP_NORESERVE = 0x0040;
159pub const MAP_INHERIT = 0x0080;
160pub const MAP_HASSEMAPHORE = 0x0200;
161pub const MAP_TRYFIXED = 0x0400;
162pub const MAP_WIRED = 0x0800;
163
164pub const MAP_FILE = 0x0000;
165pub const MAP_NOSYNC = 0x0800;
166pub const MAP_ANON = 0x1000;
167pub const MAP_ANONYMOUS = MAP_ANON;
168pub const MAP_STACK = 0x2000;
169
170pub const WNOHANG = 0x00000001;
171pub const WUNTRACED = 0x00000002;
172pub const WSTOPPED = WUNTRACED;
173pub const WCONTINUED = 0x00000010;
174pub const WNOWAIT = 0x00010000;
175pub const WEXITED = 0x00000020;
176pub const WTRAPPED = 0x00000040;
177
178pub const SA_ONSTACK = 0x0001;
179pub const SA_RESTART = 0x0002;
180pub const SA_RESETHAND = 0x0004;
181pub const SA_NOCLDSTOP = 0x0008;
182pub const SA_NODEFER = 0x0010;
183pub const SA_NOCLDWAIT = 0x0020;
184pub const SA_SIGINFO = 0x0040;
185
186pub const SIGHUP = 1;
187pub const SIGINT = 2;
188pub const SIGQUIT = 3;
189pub const SIGILL = 4;
190pub const SIGTRAP = 5;
191pub const SIGABRT = 6;
192pub const SIGIOT = SIGABRT;
193pub const SIGEMT = 7;
194pub const SIGFPE = 8;
195pub const SIGKILL = 9;
196pub const SIGBUS = 10;
197pub const SIGSEGV = 11;
198pub const SIGSYS = 12;
199pub const SIGPIPE = 13;
200pub const SIGALRM = 14;
201pub const SIGTERM = 15;
202pub const SIGURG = 16;
203pub const SIGSTOP = 17;
204pub const SIGTSTP = 18;
205pub const SIGCONT = 19;
206pub const SIGCHLD = 20;
207pub const SIGTTIN = 21;
208pub const SIGTTOU = 22;
209pub const SIGIO = 23;
210pub const SIGXCPU = 24;
211pub const SIGXFSZ = 25;
212pub const SIGVTALRM = 26;
213pub const SIGPROF = 27;
214pub const SIGWINCH = 28;
215pub const SIGINFO = 29;
216pub const SIGUSR1 = 30;
217pub const SIGUSR2 = 31;
218pub const SIGPWR = 32;
219
220pub const SIGRTMIN = 33;
221pub const SIGRTMAX = 63;
222
223// access function
224pub const F_OK = 0; // test for existence of file
225pub const X_OK = 1; // test for execute or search permission
226pub const W_OK = 2; // test for write permission
227pub const R_OK = 4; // test for read permission
228
229pub const O_RDONLY = 0x0000;
230pub const O_WRONLY = 0x0001;
231pub const O_RDWR = 0x0002;
232pub const O_ACCMODE = 0x0003;
233
234pub const O_CREAT = 0x0200;
235pub const O_EXCL = 0x0800;
236pub const O_NOCTTY = 0x8000;
237pub const O_TRUNC = 0x0400;
238pub const O_APPEND = 0x0008;
239pub const O_NONBLOCK = 0x0004;
240pub const O_DSYNC = 0x00010000;
241pub const O_SYNC = 0x0080;
242pub const O_RSYNC = 0x00020000;
243pub const O_DIRECTORY = 0x00080000;
244pub const O_NOFOLLOW = 0x00000100;
245pub const O_CLOEXEC = 0x00400000;
246
247pub const O_ASYNC = 0x0040;
248pub const O_DIRECT = 0x00080000;
249pub const O_LARGEFILE = 0;
250pub const O_NOATIME = 0;
251pub const O_PATH = 0;
252pub const O_TMPFILE = 0;
253pub const O_NDELAY = O_NONBLOCK;
254
255pub const F_DUPFD = 0;
256pub const F_GETFD = 1;
257pub const F_SETFD = 2;
258pub const F_GETFL = 3;
259pub const F_SETFL = 4;
260
261pub const F_GETOWN = 5;
262pub const F_SETOWN = 6;
263
264pub const F_GETLK = 7;
265pub const F_SETLK = 8;
266pub const F_SETLKW = 9;
267
268pub const SEEK_SET = 0;
269pub const SEEK_CUR = 1;
270pub const SEEK_END = 2;
271
272pub const SIG_BLOCK = 1;
273pub const SIG_UNBLOCK = 2;
274pub const SIG_SETMASK = 3;
275
276pub const SOCK_STREAM = 1;
277pub const SOCK_DGRAM = 2;
278pub const SOCK_RAW = 3;
279pub const SOCK_RDM = 4;
280pub const SOCK_SEQPACKET = 5;
281
282pub const SOCK_CLOEXEC = 0x10000000;
283pub const SOCK_NONBLOCK = 0x20000000;
284
285pub const PROTO_ip = 0;
286pub const PROTO_icmp = 1;
287pub const PROTO_igmp = 2;
288pub const PROTO_ggp = 3;
289pub const PROTO_ipencap = 4;
290pub const PROTO_tcp = 6;
291pub const PROTO_egp = 8;
292pub const PROTO_pup = 12;
293pub const PROTO_udp = 17;
294pub const PROTO_xns_idp = 22;
295pub const PROTO_iso_tp4 = 29;
296pub const PROTO_ipv6 = 41;
297pub const PROTO_ipv6_route = 43;
298pub const PROTO_ipv6_frag = 44;
299pub const PROTO_rsvp = 46;
300pub const PROTO_gre = 47;
301pub const PROTO_esp = 50;
302pub const PROTO_ah = 51;
303pub const PROTO_ipv6_icmp = 58;
304pub const PROTO_ipv6_nonxt = 59;
305pub const PROTO_ipv6_opts = 60;
306pub const PROTO_encap = 98;
307pub const PROTO_pim = 103;
308pub const PROTO_raw = 255;
309
310pub const PF_UNSPEC = 0;
311pub const PF_LOCAL = 1;
312pub const PF_UNIX = PF_LOCAL;
313pub const PF_FILE = PF_LOCAL;
314pub const PF_INET = 2;
315pub const PF_APPLETALK = 16;
316pub const PF_INET6 = 24;
317pub const PF_DECnet = 12;
318pub const PF_KEY = 29;
319pub const PF_ROUTE = 34;
320pub const PF_SNA = 11;
321pub const PF_MPLS = 33;
322pub const PF_CAN = 35;
323pub const PF_BLUETOOTH = 31;
324pub const PF_ISDN = 26;
325pub const PF_MAX = 37;
326
327pub const AF_UNSPEC = PF_UNSPEC;
328pub const AF_LOCAL = PF_LOCAL;
329pub const AF_UNIX = AF_LOCAL;
330pub const AF_FILE = AF_LOCAL;
331pub const AF_INET = PF_INET;
332pub const AF_APPLETALK = PF_APPLETALK;
333pub const AF_INET6 = PF_INET6;
334pub const AF_KEY = PF_KEY;
335pub const AF_ROUTE = PF_ROUTE;
336pub const AF_SNA = PF_SNA;
337pub const AF_MPLS = PF_MPLS;
338pub const AF_CAN = PF_CAN;
339pub const AF_BLUETOOTH = PF_BLUETOOTH;
340pub const AF_ISDN = PF_ISDN;
341pub const AF_MAX = PF_MAX;
342
343pub const DT_UNKNOWN = 0;
344pub const DT_FIFO = 1;
345pub const DT_CHR = 2;
346pub const DT_DIR = 4;
347pub const DT_BLK = 6;
348pub const DT_REG = 8;
349pub const DT_LNK = 10;
350pub const DT_SOCK = 12;
351pub const DT_WHT = 14;
352
353/// add event to kq (implies enable)
354pub const EV_ADD = 0x0001;
355
356/// delete event from kq
357pub const EV_DELETE = 0x0002;
358
359/// enable event
360pub const EV_ENABLE = 0x0004;
361
362/// disable event (not reported)
363pub const EV_DISABLE = 0x0008;
364
365/// only report one occurrence
366pub const EV_ONESHOT = 0x0010;
367
368/// clear event state after reporting
369pub 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
375pub const EV_RECEIPT = 0x0040;
376
377/// disable event after reporting
378pub const EV_DISPATCH = 0x0080;
379
380pub const EVFILT_READ = 0;
381pub const EVFILT_WRITE = 1;
382
383/// attached to aio requests
384pub const EVFILT_AIO = 2;
385
386/// attached to vnodes
387pub const EVFILT_VNODE = 3;
388
389/// attached to struct proc
390pub const EVFILT_PROC = 4;
391
392/// attached to struct proc
393pub const EVFILT_SIGNAL = 5;
394
395/// timers
396pub const EVFILT_TIMER = 6;
397
398/// Filesystem events
399pub const EVFILT_FS = 7;
400
401/// On input, NOTE_TRIGGER causes the event to be triggered for output.
402pub const NOTE_TRIGGER = 0x08000000;
403
404/// low water mark
405pub const NOTE_LOWAT = 0x00000001;
406
407/// vnode was removed
408pub const NOTE_DELETE = 0x00000001;
409
410/// data contents changed
411pub const NOTE_WRITE = 0x00000002;
412
413/// size increased
414pub const NOTE_EXTEND = 0x00000004;
415
416/// attributes changed
417pub const NOTE_ATTRIB = 0x00000008;
418
419/// link count changed
420pub const NOTE_LINK = 0x00000010;
421
422/// vnode was renamed
423pub const NOTE_RENAME = 0x00000020;
424
425/// vnode access was revoked
426pub const NOTE_REVOKE = 0x00000040;
427
428/// process exited
429pub const NOTE_EXIT = 0x80000000;
430
431/// process forked
432pub const NOTE_FORK = 0x40000000;
433
434/// process exec'd
435pub const NOTE_EXEC = 0x20000000;
436
437/// mask for signal & exit status
438pub const NOTE_PDATAMASK = 0x000fffff;
439pub const NOTE_PCTRLMASK = 0xf0000000;
440
441pub const TIOCCBRK = 0x2000747a;
442pub const TIOCCDTR = 0x20007478;
443pub const TIOCCONS = 0x80047462;
444pub const TIOCDCDTIMESTAMP = 0x40107458;
445pub const TIOCDRAIN = 0x2000745e;
446pub const TIOCEXCL = 0x2000740d;
447pub const TIOCEXT = 0x80047460;
448pub const TIOCFLAG_CDTRCTS = 0x10;
449pub const TIOCFLAG_CLOCAL = 0x2;
450pub const TIOCFLAG_CRTSCTS = 0x4;
451pub const TIOCFLAG_MDMBUF = 0x8;
452pub const TIOCFLAG_SOFTCAR = 0x1;
453pub const TIOCFLUSH = 0x80047410;
454pub const TIOCGETA = 0x402c7413;
455pub const TIOCGETD = 0x4004741a;
456pub const TIOCGFLAGS = 0x4004745d;
457pub const TIOCGLINED = 0x40207442;
458pub const TIOCGPGRP = 0x40047477;
459pub const TIOCGQSIZE = 0x40047481;
460pub const TIOCGRANTPT = 0x20007447;
461pub const TIOCGSID = 0x40047463;
462pub const TIOCGSIZE = 0x40087468;
463pub const TIOCGWINSZ = 0x40087468;
464pub const TIOCMBIC = 0x8004746b;
465pub const TIOCMBIS = 0x8004746c;
466pub const TIOCMGET = 0x4004746a;
467pub const TIOCMSET = 0x8004746d;
468pub const TIOCM_CAR = 0x40;
469pub const TIOCM_CD = 0x40;
470pub const TIOCM_CTS = 0x20;
471pub const TIOCM_DSR = 0x100;
472pub const TIOCM_DTR = 0x2;
473pub const TIOCM_LE = 0x1;
474pub const TIOCM_RI = 0x80;
475pub const TIOCM_RNG = 0x80;
476pub const TIOCM_RTS = 0x4;
477pub const TIOCM_SR = 0x10;
478pub const TIOCM_ST = 0x8;
479pub const TIOCNOTTY = 0x20007471;
480pub const TIOCNXCL = 0x2000740e;
481pub const TIOCOUTQ = 0x40047473;
482pub const TIOCPKT = 0x80047470;
483pub const TIOCPKT_DATA = 0x0;
484pub const TIOCPKT_DOSTOP = 0x20;
485pub const TIOCPKT_FLUSHREAD = 0x1;
486pub const TIOCPKT_FLUSHWRITE = 0x2;
487pub const TIOCPKT_IOCTL = 0x40;
488pub const TIOCPKT_NOSTOP = 0x10;
489pub const TIOCPKT_START = 0x8;
490pub const TIOCPKT_STOP = 0x4;
491pub const TIOCPTMGET = 0x40287446;
492pub const TIOCPTSNAME = 0x40287448;
493pub const TIOCRCVFRAME = 0x80087445;
494pub const TIOCREMOTE = 0x80047469;
495pub const TIOCSBRK = 0x2000747b;
496pub const TIOCSCTTY = 0x20007461;
497pub const TIOCSDTR = 0x20007479;
498pub const TIOCSETA = 0x802c7414;
499pub const TIOCSETAF = 0x802c7416;
500pub const TIOCSETAW = 0x802c7415;
501pub const TIOCSETD = 0x8004741b;
502pub const TIOCSFLAGS = 0x8004745c;
503pub const TIOCSIG = 0x2000745f;
504pub const TIOCSLINED = 0x80207443;
505pub const TIOCSPGRP = 0x80047476;
506pub const TIOCSQSIZE = 0x80047480;
507pub const TIOCSSIZE = 0x80087467;
508pub const TIOCSTART = 0x2000746e;
509pub const TIOCSTAT = 0x80047465;
510pub const TIOCSTI = 0x80017472;
511pub const TIOCSTOP = 0x2000746f;
512pub const TIOCSWINSZ = 0x80087467;
513pub const TIOCUCNTL = 0x80047466;
514pub const TIOCXMTFRAME = 0x80087444;
515
516fn unsigned(s: i32) u32 {
517 return @bitCast(u32, s);
518}
519fn signed(s: u32) i32 {
520 return @bitCast(i32, s);
521}
522pub fn WEXITSTATUS(s: i32) i32 {
523 return signed((unsigned(s) >> 8) & 0xff);
524}
525pub fn WTERMSIG(s: i32) i32 {
526 return signed(unsigned(s) & 0x7f);
527}
528pub fn WSTOPSIG(s: i32) i32 {
529 return WEXITSTATUS(s);
530}
531pub fn WIFEXITED(s: i32) bool {
532 return WTERMSIG(s) == 0;
533}
534
535pub fn WIFCONTINUED(s: i32) bool {
536 return ((s & 0x7f) == 0xffff);
537}
538
539pub fn WIFSTOPPED(s: i32) bool {
540 return ((s & 0x7f != 0x7f) and !WIFCONTINUED(s));
541}
542
543pub fn WIFSIGNALED(s: i32) bool {
544 return !WIFSTOPPED(s) and !WIFCONTINUED(s) and !WIFEXITED(s);
545}
546
547pub const winsize = extern struct {
548 ws_row: u16,
549 ws_col: u16,
550 ws_xpixel: u16,
551 ws_ypixel: u16,
552};
553
554const NSIG = 32;
555
556pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
557pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
558pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
559
560/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
561pub 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
575pub const _SIG_WORDS = 4;
576pub const _SIG_MAXSIG = 128;
577
578pub inline fn _SIG_IDX(sig: usize) usize {
579 return sig - 1;
580}
581pub inline fn _SIG_WORD(sig: usize) usize {
582 return_SIG_IDX(sig) >> 5;
583}
584pub inline fn _SIG_BIT(sig: usize) usize {
585 return 1 << (_SIG_IDX(sig) & 31);
586}
587pub inline fn _SIG_VALID(sig: usize) usize {
588 return sig <= _SIG_MAXSIG and sig > 0;
589}
590
591pub const sigset_t = extern struct {
592 __bits: [_SIG_WORDS]u32,
593};
594
595pub const EPERM = 1; // Operation not permitted
596pub const ENOENT = 2; // No such file or directory
597pub const ESRCH = 3; // No such process
598pub const EINTR = 4; // Interrupted system call
599pub const EIO = 5; // Input/output error
600pub const ENXIO = 6; // Device not configured
601pub const E2BIG = 7; // Argument list too long
602pub const ENOEXEC = 8; // Exec format error
603pub const EBADF = 9; // Bad file descriptor
604pub const ECHILD = 10; // No child processes
605pub const EDEADLK = 11; // Resource deadlock avoided
606// 11 was EAGAIN
607pub const ENOMEM = 12; // Cannot allocate memory
608pub const EACCES = 13; // Permission denied
609pub const EFAULT = 14; // Bad address
610pub const ENOTBLK = 15; // Block device required
611pub const EBUSY = 16; // Device busy
612pub const EEXIST = 17; // File exists
613pub const EXDEV = 18; // Cross-device link
614pub const ENODEV = 19; // Operation not supported by device
615pub const ENOTDIR = 20; // Not a directory
616pub const EISDIR = 21; // Is a directory
617pub const EINVAL = 22; // Invalid argument
618pub const ENFILE = 23; // Too many open files in system
619pub const EMFILE = 24; // Too many open files
620pub const ENOTTY = 25; // Inappropriate ioctl for device
621pub const ETXTBSY = 26; // Text file busy
622pub const EFBIG = 27; // File too large
623pub const ENOSPC = 28; // No space left on device
624pub const ESPIPE = 29; // Illegal seek
625pub const EROFS = 30; // Read-only file system
626pub const EMLINK = 31; // Too many links
627pub const EPIPE = 32; // Broken pipe
628
629// math software
630pub const EDOM = 33; // Numerical argument out of domain
631pub const ERANGE = 34; // Result too large or too small
632
633// non-blocking and interrupt i/o
634pub const EAGAIN = 35; // Resource temporarily unavailable
635pub const EWOULDBLOCK = EAGAIN; // Operation would block
636pub const EINPROGRESS = 36; // Operation now in progress
637pub const EALREADY = 37; // Operation already in progress
638
639// ipc/network software -- argument errors
640pub const ENOTSOCK = 38; // Socket operation on non-socket
641pub const EDESTADDRREQ = 39; // Destination address required
642pub const EMSGSIZE = 40; // Message too long
643pub const EPROTOTYPE = 41; // Protocol wrong type for socket
644pub const ENOPROTOOPT = 42; // Protocol option not available
645pub const EPROTONOSUPPORT = 43; // Protocol not supported
646pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
647pub const EOPNOTSUPP = 45; // Operation not supported
648pub const EPFNOSUPPORT = 46; // Protocol family not supported
649pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
650pub const EADDRINUSE = 48; // Address already in use
651pub const EADDRNOTAVAIL = 49; // Can't assign requested address
652
653// ipc/network software -- operational errors
654pub const ENETDOWN = 50; // Network is down
655pub const ENETUNREACH = 51; // Network is unreachable
656pub const ENETRESET = 52; // Network dropped connection on reset
657pub const ECONNABORTED = 53; // Software caused connection abort
658pub const ECONNRESET = 54; // Connection reset by peer
659pub const ENOBUFS = 55; // No buffer space available
660pub const EISCONN = 56; // Socket is already connected
661pub const ENOTCONN = 57; // Socket is not connected
662pub const ESHUTDOWN = 58; // Can't send after socket shutdown
663pub const ETOOMANYREFS = 59; // Too many references: can't splice
664pub const ETIMEDOUT = 60; // Operation timed out
665pub const ECONNREFUSED = 61; // Connection refused
666
667pub const ELOOP = 62; // Too many levels of symbolic links
668pub const ENAMETOOLONG = 63; // File name too long
669
670// should be rearranged
671pub const EHOSTDOWN = 64; // Host is down
672pub const EHOSTUNREACH = 65; // No route to host
673pub const ENOTEMPTY = 66; // Directory not empty
674
675// quotas & mush
676pub const EPROCLIM = 67; // Too many processes
677pub const EUSERS = 68; // Too many users
678pub const EDQUOT = 69; // Disc quota exceeded
679
680// Network File System
681pub const ESTALE = 70; // Stale NFS file handle
682pub const EREMOTE = 71; // Too many levels of remote in path
683pub const EBADRPC = 72; // RPC struct is bad
684pub const ERPCMISMATCH = 73; // RPC version wrong
685pub const EPROGUNAVAIL = 74; // RPC prog. not avail
686pub const EPROGMISMATCH = 75; // Program version wrong
687pub const EPROCUNAVAIL = 76; // Bad procedure for program
688
689pub const ENOLCK = 77; // No locks available
690pub const ENOSYS = 78; // Function not implemented
691
692pub const EFTYPE = 79; // Inappropriate file type or format
693pub const EAUTH = 80; // Authentication error
694pub const ENEEDAUTH = 81; // Need authenticator
695
696// SystemV IPC
697pub const EIDRM = 82; // Identifier removed
698pub const ENOMSG = 83; // No message of desired type
699pub const EOVERFLOW = 84; // Value too large to be stored in data type
700
701// Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
702pub const EILSEQ = 85; // Illegal byte sequence
703
704// From IEEE Std 1003.1-2001
705// Base, Realtime, Threads or Thread Priority Scheduling option errors
706pub const ENOTSUP = 86; // Not supported
707
708// Realtime option errors
709pub const ECANCELED = 87; // Operation canceled
710
711// Realtime, XSI STREAMS option errors
712pub const EBADMSG = 88; // Bad or Corrupt message
713
714// XSI STREAMS option errors
715pub const ENODATA = 89; // No message available
716pub const ENOSR = 90; // No STREAM resources
717pub const ENOSTR = 91; // Not a STREAM
718pub const ETIME = 92; // STREAM ioctl timeout
719
720// File system extended attribute errors
721pub const ENOATTR = 93; // Attribute not found
722
723// Realtime, XSI STREAMS option errors
724pub const EMULTIHOP = 94; // Multihop attempted
725pub const ENOLINK = 95; // Link has been severed
726pub const EPROTO = 96; // Protocol error
727
728pub const ELAST = 96; // Must equal largest errno
std/c/posix/windows.zig created+86
......@@ -0,0 +1,86 @@
1pub const EPERM = 1;
2pub const ENOENT = 2;
3pub const ESRCH = 3;
4pub const EINTR = 4;
5pub const EIO = 5;
6pub const ENXIO = 6;
7pub const E2BIG = 7;
8pub const ENOEXEC = 8;
9pub const EBADF = 9;
10pub const ECHILD = 10;
11pub const EAGAIN = 11;
12pub const ENOMEM = 12;
13pub const EACCES = 13;
14pub const EFAULT = 14;
15pub const EBUSY = 16;
16pub const EEXIST = 17;
17pub const EXDEV = 18;
18pub const ENODEV = 19;
19pub const ENOTDIR = 20;
20pub const EISDIR = 21;
21pub const ENFILE = 23;
22pub const EMFILE = 24;
23pub const ENOTTY = 25;
24pub const EFBIG = 27;
25pub const ENOSPC = 28;
26pub const ESPIPE = 29;
27pub const EROFS = 30;
28pub const EMLINK = 31;
29pub const EPIPE = 32;
30pub const EDOM = 33;
31pub const EDEADLK = 36;
32pub const ENAMETOOLONG = 38;
33pub const ENOLCK = 39;
34pub const ENOSYS = 40;
35pub const ENOTEMPTY = 41;
36
37pub const EINVAL = 22;
38pub const ERANGE = 34;
39pub const EILSEQ = 42;
40pub const STRUNCATE = 80;
41
42// Support EDEADLOCK for compatibility with older Microsoft C versions
43pub const EDEADLOCK = EDEADLK;
44
45// POSIX Supplement
46pub const EADDRINUSE = 100;
47pub const EADDRNOTAVAIL = 101;
48pub const EAFNOSUPPORT = 102;
49pub const EALREADY = 103;
50pub const EBADMSG = 104;
51pub const ECANCELED = 105;
52pub const ECONNABORTED = 106;
53pub const ECONNREFUSED = 107;
54pub const ECONNRESET = 108;
55pub const EDESTADDRREQ = 109;
56pub const EHOSTUNREACH = 110;
57pub const EIDRM = 111;
58pub const EINPROGRESS = 112;
59pub const EISCONN = 113;
60pub const ELOOP = 114;
61pub const EMSGSIZE = 115;
62pub const ENETDOWN = 116;
63pub const ENETRESET = 117;
64pub const ENETUNREACH = 118;
65pub const ENOBUFS = 119;
66pub const ENODATA = 120;
67pub const ENOLINK = 121;
68pub const ENOMSG = 122;
69pub const ENOPROTOOPT = 123;
70pub const ENOSR = 124;
71pub const ENOSTR = 125;
72pub const ENOTCONN = 126;
73pub const ENOTRECOVERABLE = 127;
74pub const ENOTSOCK = 128;
75pub const ENOTSUP = 129;
76pub const EOPNOTSUPP = 130;
77pub const EOTHER = 131;
78pub const EOVERFLOW = 132;
79pub const EOWNERDEAD = 133;
80pub const EPROTO = 134;
81pub const EPROTONOSUPPORT = 135;
82pub const EPROTOTYPE = 136;
83pub const ETIME = 137;
84pub const ETIMEDOUT = 138;
85pub const ETXTBSY = 139;
86pub const EWOULDBLOCK = 140;
std/event/fs.zig+25-24
......@@ -8,6 +8,7 @@ const mem = std.mem;
88const posix = os.posix;
99const windows = os.windows;
1010const Loop = event.Loop;
11const fd_t = posix.fd_t;
1112
1213pub const RequestNode = std.atomic.Queue(Request).Node;
1314
......@@ -30,7 +31,7 @@ pub const Request = struct {
3031 End, // special - means the fs thread should exit
3132
3233 pub const PWriteV = struct {
33 fd: os.FileHandle,
34 fd: fd_t,
3435 iov: []const os.posix.iovec_const,
3536 offset: usize,
3637 result: Error!void,
......@@ -39,7 +40,7 @@ pub const Request = struct {
3940 };
4041
4142 pub const PReadV = struct {
42 fd: os.FileHandle,
43 fd: fd_t,
4344 iov: []const os.posix.iovec,
4445 offset: usize,
4546 result: Error!usize,
......@@ -52,7 +53,7 @@ pub const Request = struct {
5253 path: []const u8,
5354 flags: u32,
5455 mode: os.File.Mode,
55 result: Error!os.FileHandle,
56 result: Error!fd_t,
5657
5758 pub const Error = os.File.OpenError;
5859 };
......@@ -68,7 +69,7 @@ pub const Request = struct {
6869 };
6970
7071 pub const Close = struct {
71 fd: os.FileHandle,
72 fd: fd_t,
7273 };
7374 };
7475};
......@@ -76,7 +77,7 @@ pub const Request = struct {
7677pub const PWriteVError = error{OutOfMemory} || os.File.WriteError;
7778
7879/// data - just the inner references - must live until pwritev promise completes.
79pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, offset: usize) PWriteVError!void {
80pub async fn pwritev(loop: *Loop, fd: fd_t, data: []const []const u8, offset: usize) PWriteVError!void {
8081 // workaround for https://github.com/ziglang/zig/issues/1194
8182 suspend {
8283 resume @handle();
......@@ -109,7 +110,7 @@ pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, o
109110}
110111
111112/// data must outlive the returned promise
112pub async fn pwritevWindows(loop: *Loop, fd: os.FileHandle, data: []const []const u8, offset: usize) os.WindowsWriteError!void {
113pub async fn pwritevWindows(loop: *Loop, fd: fd_t, data: []const []const u8, offset: usize) os.WindowsWriteError!void {
113114 if (data.len == 0) return;
114115 if (data.len == 1) return await (async pwriteWindows(loop, fd, data[0], offset) catch unreachable);
115116
......@@ -121,7 +122,7 @@ pub async fn pwritevWindows(loop: *Loop, fd: os.FileHandle, data: []const []cons
121122 }
122123}
123124
124pub async fn pwriteWindows(loop: *Loop, fd: os.FileHandle, data: []const u8, offset: u64) os.WindowsWriteError!void {
125pub async fn pwriteWindows(loop: *Loop, fd: fd_t, data: []const u8, offset: u64) os.WindowsWriteError!void {
125126 // workaround for https://github.com/ziglang/zig/issues/1194
126127 suspend {
127128 resume @handle();
......@@ -169,7 +170,7 @@ pub async fn pwriteWindows(loop: *Loop, fd: os.FileHandle, data: []const u8, off
169170/// iovecs must live until pwritev promise completes.
170171pub async fn pwritevPosix(
171172 loop: *Loop,
172 fd: os.FileHandle,
173 fd: fd_t,
173174 iovecs: []const posix.iovec_const,
174175 offset: usize,
175176) os.PosixWriteError!void {
......@@ -212,7 +213,7 @@ pub async fn pwritevPosix(
212213pub const PReadVError = error{OutOfMemory} || os.File.ReadError;
213214
214215/// data - just the inner references - must live until preadv promise completes.
215pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset: usize) PReadVError!usize {
216pub async fn preadv(loop: *Loop, fd: fd_t, data: []const []u8, offset: usize) PReadVError!usize {
216217 // workaround for https://github.com/ziglang/zig/issues/1194
217218 suspend {
218219 resume @handle();
......@@ -247,7 +248,7 @@ pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset:
247248}
248249
249250/// data must outlive the returned promise
250pub async fn preadvWindows(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset: u64) os.WindowsReadError!usize {
251pub async fn preadvWindows(loop: *Loop, fd: fd_t, data: []const []u8, offset: u64) os.WindowsReadError!usize {
251252 assert(data.len != 0);
252253 if (data.len == 1) return await (async preadWindows(loop, fd, data[0], offset) catch unreachable);
253254
......@@ -271,7 +272,7 @@ pub async fn preadvWindows(loop: *Loop, fd: os.FileHandle, data: []const []u8, o
271272 }
272273}
273274
274pub async fn preadWindows(loop: *Loop, fd: os.FileHandle, data: []u8, offset: u64) !usize {
275pub async fn preadWindows(loop: *Loop, fd: fd_t, data: []u8, offset: u64) !usize {
275276 // workaround for https://github.com/ziglang/zig/issues/1194
276277 suspend {
277278 resume @handle();
......@@ -318,7 +319,7 @@ pub async fn preadWindows(loop: *Loop, fd: os.FileHandle, data: []u8, offset: u6
318319/// iovecs must live until preadv promise completes
319320pub async fn preadvPosix(
320321 loop: *Loop,
321 fd: os.FileHandle,
322 fd: fd_t,
322323 iovecs: []const posix.iovec,
323324 offset: usize,
324325) os.PosixReadError!usize {
......@@ -363,7 +364,7 @@ pub async fn openPosix(
363364 path: []const u8,
364365 flags: u32,
365366 mode: os.File.Mode,
366) os.File.OpenError!os.FileHandle {
367) os.File.OpenError!fd_t {
367368 // workaround for https://github.com/ziglang/zig/issues/1194
368369 suspend {
369370 resume @handle();
......@@ -402,7 +403,7 @@ pub async fn openPosix(
402403 return req_node.data.msg.Open.result;
403404}
404405
405pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle {
406pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!fd_t {
406407 switch (builtin.os) {
407408 builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => {
408409 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
423424
424425/// Creates if does not exist. Truncates the file if it exists.
425426/// Uses the default mode.
426pub async fn openWrite(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle {
427pub async fn openWrite(loop: *Loop, path: []const u8) os.File.OpenError!fd_t {
427428 return await (async openWriteMode(loop, path, os.File.default_mode) catch unreachable);
428429}
429430
430431/// Creates if does not exist. Truncates the file if it exists.
431pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: os.File.Mode) os.File.OpenError!os.FileHandle {
432pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: os.File.Mode) os.File.OpenError!fd_t {
432433 switch (builtin.os) {
433434 builtin.Os.macosx,
434435 builtin.Os.linux,
......@@ -454,7 +455,7 @@ pub async fn openReadWrite(
454455 loop: *Loop,
455456 path: []const u8,
456457 mode: os.File.Mode,
457) os.File.OpenError!os.FileHandle {
458) os.File.OpenError!fd_t {
458459 switch (builtin.os) {
459460 builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => {
460461 const flags = posix.O_LARGEFILE | posix.O_RDWR | posix.O_CREAT | posix.O_CLOEXEC;
......@@ -487,7 +488,7 @@ pub const CloseOperation = struct {
487488 builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => OsDataPosix,
488489
489490 builtin.Os.windows => struct {
490 handle: ?os.FileHandle,
491 handle: ?fd_t,
491492 },
492493
493494 else => @compileError("Unsupported OS"),
......@@ -551,7 +552,7 @@ pub const CloseOperation = struct {
551552 }
552553 }
553554
554 pub fn setHandle(self: *CloseOperation, handle: os.FileHandle) void {
555 pub fn setHandle(self: *CloseOperation, handle: fd_t) void {
555556 switch (builtin.os) {
556557 builtin.Os.linux,
557558 builtin.Os.macosx,
......@@ -585,7 +586,7 @@ pub const CloseOperation = struct {
585586 }
586587 }
587588
588 pub fn getHandle(self: *CloseOperation) os.FileHandle {
589 pub fn getHandle(self: *CloseOperation) fd_t {
589590 switch (builtin.os) {
590591 builtin.Os.linux,
591592 builtin.Os.macosx,
......@@ -1388,7 +1389,7 @@ async fn testFsWatch(loop: *Loop) !void {
13881389}
13891390
13901391pub const OutStream = struct {
1391 fd: os.FileHandle,
1392 fd: fd_t,
13921393 stream: Stream,
13931394 loop: *Loop,
13941395 offset: usize,
......@@ -1396,7 +1397,7 @@ pub const OutStream = struct {
13961397 pub const Error = os.File.WriteError;
13971398 pub const Stream = event.io.OutStream(Error);
13981399
1399 pub fn init(loop: *Loop, fd: os.FileHandle, offset: usize) OutStream {
1400 pub fn init(loop: *Loop, fd: fd_t, offset: usize) OutStream {
14001401 return OutStream{
14011402 .fd = fd,
14021403 .loop = loop,
......@@ -1414,7 +1415,7 @@ pub const OutStream = struct {
14141415};
14151416
14161417pub const InStream = struct {
1417 fd: os.FileHandle,
1418 fd: fd_t,
14181419 stream: Stream,
14191420 loop: *Loop,
14201421 offset: usize,
......@@ -1422,7 +1423,7 @@ pub const InStream = struct {
14221423 pub const Error = PReadVError; // TODO make this not have OutOfMemory
14231424 pub const Stream = event.io.InStream(Error);
14241425
1425 pub fn init(loop: *Loop, fd: os.FileHandle, offset: usize) InStream {
1426 pub fn init(loop: *Loop, fd: fd_t, offset: usize) InStream {
14261427 return InStream{
14271428 .fd = fd,
14281429 .loop = loop,
std/event/net.zig+10-8
......@@ -7,6 +7,8 @@ const os = std.os;
77const posix = os.posix;
88const Loop = std.event.Loop;
99
10const fd_t = posix.fd_t;
11
1012pub const Server = struct {
1113 handleRequestFn: async<*mem.Allocator> fn (*Server, *const std.net.Address, os.File) void,
1214
......@@ -139,7 +141,7 @@ pub const ReadError = error{
139141};
140142
141143/// returns number of bytes read. 0 means EOF.
142pub async fn read(loop: *std.event.Loop, fd: os.FileHandle, buffer: []u8) ReadError!usize {
144pub async fn read(loop: *std.event.Loop, fd: fd_t, buffer: []u8) ReadError!usize {
143145 const iov = posix.iovec{
144146 .iov_base = buffer.ptr,
145147 .iov_len = buffer.len,
......@@ -150,7 +152,7 @@ pub async fn read(loop: *std.event.Loop, fd: os.FileHandle, buffer: []u8) ReadEr
150152
151153pub const WriteError = error{};
152154
153pub async fn write(loop: *std.event.Loop, fd: os.FileHandle, buffer: []const u8) WriteError!void {
155pub async fn write(loop: *std.event.Loop, fd: fd_t, buffer: []const u8) WriteError!void {
154156 const iov = posix.iovec_const{
155157 .iov_base = buffer.ptr,
156158 .iov_len = buffer.len,
......@@ -220,7 +222,7 @@ pub async fn readvPosix(loop: *std.event.Loop, fd: i32, iov: [*]posix.iovec, cou
220222 }
221223}
222224
223pub async fn writev(loop: *Loop, fd: os.FileHandle, data: []const []const u8) !void {
225pub async fn writev(loop: *Loop, fd: fd_t, data: []const []const u8) !void {
224226 const iovecs = try loop.allocator.alloc(os.posix.iovec_const, data.len);
225227 defer loop.allocator.free(iovecs);
226228
......@@ -234,7 +236,7 @@ pub async fn writev(loop: *Loop, fd: os.FileHandle, data: []const []const u8) !v
234236 return await (async writevPosix(loop, fd, iovecs.ptr, data.len) catch unreachable);
235237}
236238
237pub async fn readv(loop: *Loop, fd: os.FileHandle, data: []const []u8) !usize {
239pub async fn readv(loop: *Loop, fd: fd_t, data: []const []u8) !usize {
238240 const iovecs = try loop.allocator.alloc(os.posix.iovec, data.len);
239241 defer loop.allocator.free(iovecs);
240242
......@@ -324,14 +326,14 @@ async fn doAsyncTest(loop: *Loop, address: *const std.net.Address, server: *Serv
324326}
325327
326328pub const OutStream = struct {
327 fd: os.FileHandle,
329 fd: fd_t,
328330 stream: Stream,
329331 loop: *Loop,
330332
331333 pub const Error = WriteError;
332334 pub const Stream = event.io.OutStream(Error);
333335
334 pub fn init(loop: *Loop, fd: os.FileHandle) OutStream {
336 pub fn init(loop: *Loop, fd: fd_t) OutStream {
335337 return OutStream{
336338 .fd = fd,
337339 .loop = loop,
......@@ -346,14 +348,14 @@ pub const OutStream = struct {
346348};
347349
348350pub const InStream = struct {
349 fd: os.FileHandle,
351 fd: fd_t,
350352 stream: Stream,
351353 loop: *Loop,
352354
353355 pub const Error = ReadError;
354356 pub const Stream = event.io.InStream(Error);
355357
356 pub fn init(loop: *Loop, fd: os.FileHandle) InStream {
358 pub fn init(loop: *Loop, fd: fd_t) InStream {
357359 return InStream{
358360 .fd = fd,
359361 .loop = loop,
std/os.zig+20-44
......@@ -11,7 +11,6 @@ comptime {
1111test "std.os" {
1212 _ = @import("os/child_process.zig");
1313 _ = @import("os/darwin.zig");
14 _ = @import("os/darwin/errno.zig");
1514 _ = @import("os/get_user_id.zig");
1615 _ = @import("os/linux.zig");
1716 _ = @import("os/path.zig");
......@@ -32,14 +31,14 @@ pub const zen = @import("os/zen.zig");
3231pub const uefi = @import("os/uefi.zig");
3332pub const wasi = @import("os/wasi.zig");
3433
35pub const system = if (builtin.link_libc) c else switch (builtin.os) {
34pub const system = switch (builtin.os) {
3635 .linux => linux,
3736 .macosx, .ios, .watchos, .tvos => darwin,
3837 .freebsd => freebsd,
3938 .netbsd => netbsd,
4039 .zen => zen,
4140 .wasi => wasi,
42 else => @compileError("Unsupported OS"),
41 else => struct {},
4342};
4443
4544pub const net = @import("net.zig");
......@@ -93,8 +92,6 @@ pub const WindowsOpenError = windows_util.OpenError;
9392pub const WindowsWriteError = windows_util.WriteError;
9493pub const WindowsReadError = windows_util.ReadError;
9594
96pub const FileHandle = if (is_windows) windows.HANDLE else i32;
97
9895pub const getAppDataDir = @import("os/get_app_data_dir.zig").getAppDataDir;
9996pub const GetAppDataDirError = @import("os/get_app_data_dir.zig").GetAppDataDirError;
10097
......@@ -776,11 +773,13 @@ pub const Dir = struct {
776773 }
777774
778775 while (true) {
779 const result = posix.getdirentries64(self.handle.fd, self.handle.buf.ptr, self.handle.buf.len, &self.handle.seek);
780 const err = posix.getErrno(result);
781 if (err > 0) {
782 switch (err) {
783 posix.EBADF, posix.EFAULT, posix.ENOTDIR => unreachable,
776 const result = system.__getdirentries64(self.handle.fd, self.handle.buf.ptr, self.handle.buf.len, &self.handle.seek);
777 if (result == 0) return null;
778 if (result < 0) {
779 switch (system.getErrno(result)) {
780 posix.EBADF => unreachable,
781 posix.EFAULT => unreachable,
782 posix.ENOTDIR => unreachable,
784783 posix.EINVAL => {
785784 self.handle.buf = try self.allocator.realloc(self.handle.buf, self.handle.buf.len * 2);
786785 continue;
......@@ -788,9 +787,8 @@ pub const Dir = struct {
788787 else => return unexpectedErrorPosix(err),
789788 }
790789 }
791 if (result == 0) return null;
792790 self.handle.index = 0;
793 self.handle.end_index = result;
791 self.handle.end_index = @intCast(usize, result);
794792 break;
795793 }
796794 }
......@@ -1357,28 +1355,16 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
13571355 Os.freebsd => {
13581356 var mib = [4]c_int{ posix.CTL_KERN, posix.KERN_PROC, posix.KERN_PROC_PATHNAME, -1 };
13591357 var out_len: usize = out_buffer.len;
1360 const err = posix.getErrno(posix.sysctl(&mib, 4, out_buffer, &out_len, null, 0));
1361
1362 if (err == 0) 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 };
1358 try posix.sysctl(&mib, out_buffer, &out_len, null, 0);
1359 // TODO could this slice from 0 to out_len instead?
1360 return mem.toSlice(u8, out_buffer);
13691361 },
13701362 Os.netbsd => {
13711363 var mib = [4]c_int{ posix.CTL_KERN, posix.KERN_PROC_ARGS, -1, posix.KERN_PROC_PATHNAME };
13721364 var out_len: usize = out_buffer.len;
1373 const err = posix.getErrno(posix.sysctl(&mib, 4, out_buffer, &out_len, null, 0));
1374
1375 if (err == 0) 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 };
1365 try posix.sysctl(&mib, out_buffer, &out_len, null, 0);
1366 // TODO could this slice from 0 to out_len instead?
1367 return mem.toSlice(u8, out_buffer);
13821368 },
13831369 Os.windows => {
13841370 var utf16le_buf: [posix.PATH_MAX_WIDE]u16 = undefined;
......@@ -1744,22 +1730,12 @@ pub fn cpuCount(fallback_allocator: *mem.Allocator) CpuCountError!usize {
17441730 .macosx, .freebsd, .netbsd => {
17451731 var count: c_int = undefined;
17461732 var count_len: usize = @sizeOf(c_int);
1747 const rc = posix.sysctlbyname(switch (builtin.os) {
1733 const name = switch (builtin.os) {
17481734 builtin.Os.macosx => c"hw.logicalcpu",
17491735 else => c"hw.ncpu",
1750 }, @ptrCast(*c_void, &count), &count_len, null, 0);
1751 const err = posix.getErrno(rc);
1752 switch (err) {
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 }
1736 };
1737 try posix.sysctlbyname(name, @ptrCast(*c_void, &count), &count_len, null, 0);
1738 return @intCast(usize, count);
17631739 },
17641740 .linux => {
17651741 const usize_count = 16;
std/os/child_process.zig+1-8
......@@ -376,14 +376,7 @@ pub const ChildProcess = struct {
376376 const err_pipe = try makePipe();
377377 errdefer destroyPipe(err_pipe);
378378
379 const pid_result = 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 }
379 const pid_result = try posix.fork();
387380 if (pid_result == 0) {
388381 // we are the child
389382 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 @@
11const builtin = @import("builtin");
22const std = @import("../std.zig");
3const c = std.c;
4const assert = std.debug.assert;
5const maxInt = std.math.maxInt;
6
73pub const is_the_target = switch (builtin.os) {
8 .ios, .macosx, .watchos, .tvos => true,
4 .macosx, .tvos, .watchos, .ios => true,
95 else => false,
106};
11
12pub const errno_codes = @import("darwin/errno.zig");
13pub use errno_codes;
14
15pub const PATH_MAX = 1024;
16
17pub const STDIN_FILENO = 0;
18pub const STDOUT_FILENO = 1;
19pub const STDERR_FILENO = 2;
20
21/// [MC2] no permissions
22pub const PROT_NONE = 0x00;
23
24/// [MC2] pages can be read
25pub const PROT_READ = 0x01;
26
27/// [MC2] pages can be written
28pub const PROT_WRITE = 0x02;
29
30/// [MC2] pages can be executed
31pub const PROT_EXEC = 0x04;
32
33/// allocated from memory, swap space
34pub const MAP_ANONYMOUS = 0x1000;
35
36/// map from file (default)
37pub const MAP_FILE = 0x0000;
38
39/// interpret addr exactly
40pub const MAP_FIXED = 0x0010;
41
42/// region may contain semaphores
43pub const MAP_HASSEMAPHORE = 0x0200;
44
45/// changes are private
46pub const MAP_PRIVATE = 0x0002;
47
48/// share changes
49pub const MAP_SHARED = 0x0001;
50
51/// don't cache pages for this mapping
52pub const MAP_NOCACHE = 0x0400;
53
54/// don't reserve needed swap area
55pub const MAP_NORESERVE = 0x0040;
56pub const MAP_FAILED = maxInt(usize);
57
58/// [XSI] no hang in wait/no child to reap
59pub const WNOHANG = 0x00000001;
60
61/// [XSI] notify on stop, untraced child
62pub const WUNTRACED = 0x00000002;
63
64/// take signal on signal stack
65pub const SA_ONSTACK = 0x0001;
66
67/// restart system on signal return
68pub const SA_RESTART = 0x0002;
69
70/// reset to SIG_DFL when taking signal
71pub const SA_RESETHAND = 0x0004;
72
73/// do not generate SIGCHLD on child stop
74pub const SA_NOCLDSTOP = 0x0008;
75
76/// don't mask the signal we're delivering
77pub const SA_NODEFER = 0x0010;
78
79/// don't keep zombies around
80pub const SA_NOCLDWAIT = 0x0020;
81
82/// signal handler with SA_SIGINFO args
83pub const SA_SIGINFO = 0x0040;
84
85/// do not bounce off kernel's sigtramp
86pub const SA_USERTRAMP = 0x0100;
87
88/// signal handler with SA_SIGINFO args with 64bit regs information
89pub const SA_64REGSET = 0x0200;
90
91pub const O_LARGEFILE = 0x0000;
92pub const O_PATH = 0x0000;
93
94pub const F_OK = 0;
95pub const X_OK = 1;
96pub const W_OK = 2;
97pub const R_OK = 4;
98
99/// open for reading only
100pub const O_RDONLY = 0x0000;
101
102/// open for writing only
103pub const O_WRONLY = 0x0001;
104
105/// open for reading and writing
106pub const O_RDWR = 0x0002;
107
108/// do not block on open or for data to become available
109pub const O_NONBLOCK = 0x0004;
110
111/// append on each write
112pub const O_APPEND = 0x0008;
113
114/// create file if it does not exist
115pub const O_CREAT = 0x0200;
116
117/// truncate size to 0
118pub const O_TRUNC = 0x0400;
119
120/// error if O_CREAT and the file exists
121pub const O_EXCL = 0x0800;
122
123/// atomically obtain a shared lock
124pub const O_SHLOCK = 0x0010;
125
126/// atomically obtain an exclusive lock
127pub const O_EXLOCK = 0x0020;
128
129/// do not follow symlinks
130pub const O_NOFOLLOW = 0x0100;
131
132/// allow open of symlinks
133pub const O_SYMLINK = 0x200000;
134
135/// descriptor requested for event notifications only
136pub const O_EVTONLY = 0x8000;
137
138/// mark as close-on-exec
139pub const O_CLOEXEC = 0x1000000;
140
141pub const O_ACCMODE = 3;
142pub const O_ALERT = 536870912;
143pub const O_ASYNC = 64;
144pub const O_DIRECTORY = 1048576;
145pub const O_DP_GETRAWENCRYPTED = 1;
146pub const O_DP_GETRAWUNENCRYPTED = 2;
147pub const O_DSYNC = 4194304;
148pub const O_FSYNC = O_SYNC;
149pub const O_NOCTTY = 131072;
150pub const O_POPUP = 2147483648;
151pub const O_SYNC = 128;
152
153pub const SEEK_SET = 0x0;
154pub const SEEK_CUR = 0x1;
155pub const SEEK_END = 0x2;
156
157pub const DT_UNKNOWN = 0;
158pub const DT_FIFO = 1;
159pub const DT_CHR = 2;
160pub const DT_DIR = 4;
161pub const DT_BLK = 6;
162pub const DT_REG = 8;
163pub const DT_LNK = 10;
164pub const DT_SOCK = 12;
165pub const DT_WHT = 14;
166
167/// block specified signal set
168pub const SIG_BLOCK = 1;
169
170/// unblock specified signal set
171pub const SIG_UNBLOCK = 2;
172
173/// set specified signal set
174pub const SIG_SETMASK = 3;
175
176/// hangup
177pub const SIGHUP = 1;
178
179/// interrupt
180pub const SIGINT = 2;
181
182/// quit
183pub const SIGQUIT = 3;
184
185/// illegal instruction (not reset when caught)
186pub const SIGILL = 4;
187
188/// trace trap (not reset when caught)
189pub const SIGTRAP = 5;
190
191/// abort()
192pub const SIGABRT = 6;
193
194/// pollable event ([XSR] generated, not supported)
195pub const SIGPOLL = 7;
196
197/// compatibility
198pub const SIGIOT = SIGABRT;
199
200/// EMT instruction
201pub const SIGEMT = 7;
202
203/// floating point exception
204pub const SIGFPE = 8;
205
206/// kill (cannot be caught or ignored)
207pub const SIGKILL = 9;
208
209/// bus error
210pub const SIGBUS = 10;
211
212/// segmentation violation
213pub const SIGSEGV = 11;
214
215/// bad argument to system call
216pub const SIGSYS = 12;
217
218/// write on a pipe with no one to read it
219pub const SIGPIPE = 13;
220
221/// alarm clock
222pub const SIGALRM = 14;
223
224/// software termination signal from kill
225pub const SIGTERM = 15;
226
227/// urgent condition on IO channel
228pub const SIGURG = 16;
229
230/// sendable stop signal not from tty
231pub const SIGSTOP = 17;
232
233/// stop signal from tty
234pub const SIGTSTP = 18;
235
236/// continue a stopped process
237pub const SIGCONT = 19;
238
239/// to parent on child stop or exit
240pub const SIGCHLD = 20;
241
242/// to readers pgrp upon background tty read
243pub const SIGTTIN = 21;
244
245/// like TTIN for output if (tp->t_local&LTOSTOP)
246pub const SIGTTOU = 22;
247
248/// input/output possible signal
249pub const SIGIO = 23;
250
251/// exceeded CPU time limit
252pub const SIGXCPU = 24;
253
254/// exceeded file size limit
255pub const SIGXFSZ = 25;
256
257/// virtual time alarm
258pub const SIGVTALRM = 26;
259
260/// profiling time alarm
261pub const SIGPROF = 27;
262
263/// window size changes
264pub const SIGWINCH = 28;
265
266/// information request
267pub const SIGINFO = 29;
268
269/// user defined signal 1
270pub const SIGUSR1 = 30;
271
272/// user defined signal 2
273pub const SIGUSR2 = 31;
274
275/// no flag value
276pub const KEVENT_FLAG_NONE = 0x000;
277
278/// immediate timeout
279pub const KEVENT_FLAG_IMMEDIATE = 0x001;
280
281/// output events only include change
282pub const KEVENT_FLAG_ERROR_EVENTS = 0x002;
283
284/// add event to kq (implies enable)
285pub const EV_ADD = 0x0001;
286
287/// delete event from kq
288pub const EV_DELETE = 0x0002;
289
290/// enable event
291pub const EV_ENABLE = 0x0004;
292
293/// disable event (not reported)
294pub const EV_DISABLE = 0x0008;
295
296/// only report one occurrence
297pub const EV_ONESHOT = 0x0010;
298
299/// clear event state after reporting
300pub 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
306pub const EV_RECEIPT = 0x0040;
307
308/// disable event after reporting
309pub const EV_DISPATCH = 0x0080;
310
311/// unique kevent per udata value
312pub 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
318pub const EV_DISPATCH2 = EV_DISPATCH | EV_UDATA_SPECIFIC;
319
320/// report that source has vanished
321/// ... only valid with EV_DISPATCH2
322pub const EV_VANISHED = 0x0200;
323
324/// reserved by system
325pub const EV_SYSFLAGS = 0xF000;
326
327/// filter-specific flag
328pub const EV_FLAG0 = 0x1000;
329
330/// filter-specific flag
331pub const EV_FLAG1 = 0x2000;
332
333/// EOF detected
334pub const EV_EOF = 0x8000;
335
336/// error, data contains errno
337pub const EV_ERROR = 0x4000;
338
339pub const EV_POLL = EV_FLAG0;
340pub const EV_OOBAND = EV_FLAG1;
341
342pub const EVFILT_READ = -1;
343pub const EVFILT_WRITE = -2;
344
345/// attached to aio requests
346pub const EVFILT_AIO = -3;
347
348/// attached to vnodes
349pub const EVFILT_VNODE = -4;
350
351/// attached to struct proc
352pub const EVFILT_PROC = -5;
353
354/// attached to struct proc
355pub const EVFILT_SIGNAL = -6;
356
357/// timers
358pub const EVFILT_TIMER = -7;
359
360/// Mach portsets
361pub const EVFILT_MACHPORT = -8;
362
363/// Filesystem events
364pub const EVFILT_FS = -9;
365
366/// User events
367pub const EVFILT_USER = -10;
368
369/// Virtual memory events
370pub const EVFILT_VM = -12;
371
372/// Exception events
373pub const EVFILT_EXCEPT = -15;
374
375pub const EVFILT_SYSCOUNT = 17;
376
377/// On input, NOTE_TRIGGER causes the event to be triggered for output.
378pub const NOTE_TRIGGER = 0x01000000;
379
380/// ignore input fflags
381pub const NOTE_FFNOP = 0x00000000;
382
383/// and fflags
384pub const NOTE_FFAND = 0x40000000;
385
386/// or fflags
387pub const NOTE_FFOR = 0x80000000;
388
389/// copy fflags
390pub const NOTE_FFCOPY = 0xc0000000;
391
392/// mask for operations
393pub const NOTE_FFCTRLMASK = 0xc0000000;
394pub const NOTE_FFLAGSMASK = 0x00ffffff;
395
396/// low water mark
397pub const NOTE_LOWAT = 0x00000001;
398
399/// OOB data
400pub const NOTE_OOB = 0x00000002;
401
402/// vnode was removed
403pub const NOTE_DELETE = 0x00000001;
404
405/// data contents changed
406pub const NOTE_WRITE = 0x00000002;
407
408/// size increased
409pub const NOTE_EXTEND = 0x00000004;
410
411/// attributes changed
412pub const NOTE_ATTRIB = 0x00000008;
413
414/// link count changed
415pub const NOTE_LINK = 0x00000010;
416
417/// vnode was renamed
418pub const NOTE_RENAME = 0x00000020;
419
420/// vnode access was revoked
421pub const NOTE_REVOKE = 0x00000040;
422
423/// No specific vnode event: to test for EVFILT_READ activation
424pub const NOTE_NONE = 0x00000080;
425
426/// vnode was unlocked by flock(2)
427pub const NOTE_FUNLOCK = 0x00000100;
428
429/// process exited
430pub const NOTE_EXIT = 0x80000000;
431
432/// process forked
433pub const NOTE_FORK = 0x40000000;
434
435/// process exec'd
436pub const NOTE_EXEC = 0x20000000;
437
438/// shared with EVFILT_SIGNAL
439pub const NOTE_SIGNAL = 0x08000000;
440
441/// exit status to be returned, valid for child process only
442pub const NOTE_EXITSTATUS = 0x04000000;
443
444/// provide details on reasons for exit
445pub const NOTE_EXIT_DETAIL = 0x02000000;
446
447/// mask for signal & exit status
448pub const NOTE_PDATAMASK = 0x000fffff;
449pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
450
451pub const NOTE_EXIT_DETAIL_MASK = 0x00070000;
452pub const NOTE_EXIT_DECRYPTFAIL = 0x00010000;
453pub const NOTE_EXIT_MEMORY = 0x00020000;
454pub const NOTE_EXIT_CSERROR = 0x00040000;
455
456/// will react on memory pressure
457pub const NOTE_VM_PRESSURE = 0x80000000;
458
459/// will quit on memory pressure, possibly after cleaning up dirty state
460pub const NOTE_VM_PRESSURE_TERMINATE = 0x40000000;
461
462/// will quit immediately on memory pressure
463pub const NOTE_VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000;
464
465/// there was an error
466pub const NOTE_VM_ERROR = 0x10000000;
467
468/// data is seconds
469pub const NOTE_SECONDS = 0x00000001;
470
471/// data is microseconds
472pub const NOTE_USECONDS = 0x00000002;
473
474/// data is nanoseconds
475pub const NOTE_NSECONDS = 0x00000004;
476
477/// absolute timeout
478pub const NOTE_ABSOLUTE = 0x00000008;
479
480/// ext[1] holds leeway for power aware timers
481pub const NOTE_LEEWAY = 0x00000010;
482
483/// system does minimal timer coalescing
484pub const NOTE_CRITICAL = 0x00000020;
485
486/// system does maximum timer coalescing
487pub const NOTE_BACKGROUND = 0x00000040;
488pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080;
489
490/// data is mach absolute time units
491pub const NOTE_MACHTIME = 0x00000100;
492
493pub const AF_UNSPEC = 0;
494pub const AF_LOCAL = 1;
495pub const AF_UNIX = AF_LOCAL;
496pub const AF_INET = 2;
497pub const AF_SYS_CONTROL = 2;
498pub const AF_IMPLINK = 3;
499pub const AF_PUP = 4;
500pub const AF_CHAOS = 5;
501pub const AF_NS = 6;
502pub const AF_ISO = 7;
503pub const AF_OSI = AF_ISO;
504pub const AF_ECMA = 8;
505pub const AF_DATAKIT = 9;
506pub const AF_CCITT = 10;
507pub const AF_SNA = 11;
508pub const AF_DECnet = 12;
509pub const AF_DLI = 13;
510pub const AF_LAT = 14;
511pub const AF_HYLINK = 15;
512pub const AF_APPLETALK = 16;
513pub const AF_ROUTE = 17;
514pub const AF_LINK = 18;
515pub const AF_XTP = 19;
516pub const AF_COIP = 20;
517pub const AF_CNT = 21;
518pub const AF_RTIP = 22;
519pub const AF_IPX = 23;
520pub const AF_SIP = 24;
521pub const AF_PIP = 25;
522pub const AF_ISDN = 28;
523pub const AF_E164 = AF_ISDN;
524pub const AF_KEY = 29;
525pub const AF_INET6 = 30;
526pub const AF_NATM = 31;
527pub const AF_SYSTEM = 32;
528pub const AF_NETBIOS = 33;
529pub const AF_PPP = 34;
530pub const AF_MAX = 40;
531
532pub const PF_UNSPEC = AF_UNSPEC;
533pub const PF_LOCAL = AF_LOCAL;
534pub const PF_UNIX = PF_LOCAL;
535pub const PF_INET = AF_INET;
536pub const PF_IMPLINK = AF_IMPLINK;
537pub const PF_PUP = AF_PUP;
538pub const PF_CHAOS = AF_CHAOS;
539pub const PF_NS = AF_NS;
540pub const PF_ISO = AF_ISO;
541pub const PF_OSI = AF_ISO;
542pub const PF_ECMA = AF_ECMA;
543pub const PF_DATAKIT = AF_DATAKIT;
544pub const PF_CCITT = AF_CCITT;
545pub const PF_SNA = AF_SNA;
546pub const PF_DECnet = AF_DECnet;
547pub const PF_DLI = AF_DLI;
548pub const PF_LAT = AF_LAT;
549pub const PF_HYLINK = AF_HYLINK;
550pub const PF_APPLETALK = AF_APPLETALK;
551pub const PF_ROUTE = AF_ROUTE;
552pub const PF_LINK = AF_LINK;
553pub const PF_XTP = AF_XTP;
554pub const PF_COIP = AF_COIP;
555pub const PF_CNT = AF_CNT;
556pub const PF_SIP = AF_SIP;
557pub const PF_IPX = AF_IPX;
558pub const PF_RTIP = AF_RTIP;
559pub const PF_PIP = AF_PIP;
560pub const PF_ISDN = AF_ISDN;
561pub const PF_KEY = AF_KEY;
562pub const PF_INET6 = AF_INET6;
563pub const PF_NATM = AF_NATM;
564pub const PF_SYSTEM = AF_SYSTEM;
565pub const PF_NETBIOS = AF_NETBIOS;
566pub const PF_PPP = AF_PPP;
567pub const PF_MAX = AF_MAX;
568
569pub const SYSPROTO_EVENT = 1;
570pub const SYSPROTO_CONTROL = 2;
571
572pub const SOCK_STREAM = 1;
573pub const SOCK_DGRAM = 2;
574pub const SOCK_RAW = 3;
575pub const SOCK_RDM = 4;
576pub const SOCK_SEQPACKET = 5;
577pub const SOCK_MAXADDRLEN = 255;
578
579pub const IPPROTO_ICMP = 1;
580pub const IPPROTO_ICMPV6 = 58;
581pub const IPPROTO_TCP = 6;
582pub const IPPROTO_UDP = 17;
583pub const IPPROTO_IP = 0;
584pub const IPPROTO_IPV6 = 41;
585
586fn wstatus(x: i32) i32 {
587 return x & 0o177;
588}
589const wstopped = 0o177;
590pub fn WEXITSTATUS(x: i32) i32 {
591 return x >> 8;
592}
593pub fn WTERMSIG(x: i32) i32 {
594 return wstatus(x);
595}
596pub fn WSTOPSIG(x: i32) i32 {
597 return x >> 8;
598}
599pub fn WIFEXITED(x: i32) bool {
600 return wstatus(x) == 0;
601}
602pub fn WIFSTOPPED(x: i32) bool {
603 return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13;
604}
605pub 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.
610pub 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
615pub fn close(fd: i32) usize {
616 return errnoWrap(c.close(fd));
617}
618
619pub fn abort() noreturn {
620 c.abort();
621}
622
623// bind(int socket, const struct sockaddr *address, socklen_t address_len)
624pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
625 return errnoWrap(c.bind(@bitCast(c_int, fd), addr, len));
626}
627
628pub fn exit(code: i32) noreturn {
629 c.exit(code);
630}
631
632pub fn isatty(fd: i32) bool {
633 return c.isatty(fd) != 0;
634}
635
636pub fn fstat(fd: i32, buf: *c.Stat) usize {
637 return errnoWrap(c.@"fstat$INODE64"(fd, buf));
638}
639
640pub 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
645pub fn open(path: [*]const u8, flags: u32, mode: usize) usize {
646 return errnoWrap(c.open(path, @bitCast(c_int, flags), mode));
647}
648
649pub fn raise(sig: i32) usize {
650 return errnoWrap(c.raise(sig));
651}
652
653pub fn read(fd: i32, buf: [*]u8, nbyte: usize) usize {
654 return errnoWrap(c.read(fd, @ptrCast(*c_void, buf), nbyte));
655}
656
657pub 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
661pub fn stat(noalias path: [*]const u8, noalias buf: *stat) usize {
662 return errnoWrap(c.stat(path, buf));
663}
664
665pub fn write(fd: i32, buf: [*]const u8, nbyte: usize) usize {
666 return errnoWrap(c.write(fd, @ptrCast(*const c_void, buf), nbyte));
667}
668
669pub 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
673pub 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
686pub fn munmap(address: usize, length: usize) usize {
687 return errnoWrap(c.munmap(@intToPtr(?*c_void, address), length));
688}
689
690pub fn unlink(path: [*]const u8) usize {
691 return errnoWrap(c.unlink(path));
692}
693
694pub fn getcwd(buf: [*]u8, size: usize) usize {
695 return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
696}
697
698pub 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
703pub fn fork() usize {
704 return errnoWrap(c.fork());
705}
706
707pub fn access(path: [*]const u8, mode: u32) usize {
708 return errnoWrap(c.access(path, mode));
709}
710
711pub 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
716pub 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
720pub fn kqueue() usize {
721 return errnoWrap(c.kqueue());
722}
723
724pub 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
735pub 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
745pub fn mkdir(path: [*]const u8, mode: u32) usize {
746 return errnoWrap(c.mkdir(path, mode));
747}
748
749pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
750 return errnoWrap(c.symlink(existing, new));
751}
752
753pub 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
757pub 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
761pub fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) usize {
762 return errnoWrap(c.sysctlnametomib(name, wibp, sizep));
763}
764
765pub fn rename(old: [*]const u8, new: [*]const u8) usize {
766 return errnoWrap(c.rename(old, new));
767}
768
769pub fn rmdir(path: [*]const u8) usize {
770 return errnoWrap(c.rmdir(path));
771}
772
773pub fn chdir(path: [*]const u8) usize {
774 return errnoWrap(c.chdir(path));
775}
776
777pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {
778 return errnoWrap(c.execve(path, argv, envp));
779}
780
781pub fn dup2(old: i32, new: i32) usize {
782 return errnoWrap(c.dup2(old, new));
783}
784
785pub 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
789pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) usize {
790 return errnoWrap(c.gettimeofday(tv, tz));
791}
792
793pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
794 return errnoWrap(c.nanosleep(req, rem));
795}
796
797pub 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
801pub fn setreuid(ruid: u32, euid: u32) usize {
802 return errnoWrap(c.setreuid(ruid, euid));
803}
804
805pub fn setregid(rgid: u32, egid: u32) usize {
806 return errnoWrap(c.setregid(rgid, egid));
807}
808
809pub 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
813pub 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
836pub 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
840pub const iovec = extern struct {
841 iov_base: [*]u8,
842 iov_len: usize,
843};
844
845pub const iovec_const = extern struct {
846 iov_base: [*]const u8,
847 iov_len: usize,
848};
849
850pub const sigset_t = c.sigset_t;
851pub const empty_sigset = sigset_t(0);
852
853pub const timespec = c.timespec;
854pub const Stat = c.Stat;
855pub const dirent = c.dirent;
856
857pub const in_port_t = c.in_port_t;
858pub const sa_family_t = c.sa_family_t;
859pub const socklen_t = c.socklen_t;
860
861pub const sockaddr = c.sockaddr;
862pub const sockaddr_in = c.sockaddr_in;
863pub const sockaddr_in6 = c.sockaddr_in6;
864
865/// Renamed from `kevent` to `Kevent` to avoid conflict with the syscall.
866pub const Kevent = c.Kevent;
867pub const kevent64_s = c.kevent64_s;
868
869/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
870pub const Sigaction = struct {
871 handler: extern fn (i32) void,
872 mask: sigset_t,
873 flags: u32,
874};
875
876pub 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.
883fn errnoWrap(value: isize) usize {
884 return @bitCast(usize, if (value == -1) -isize(c._errno().*) else value);
885}
886
887pub const timezone = c.timezone;
888pub const timeval = c.timeval;
889pub const mach_timebase_info_data = c.mach_timebase_info_data;
890
891pub const mach_absolute_time = c.mach_absolute_time;
892pub const mach_timebase_info = c.mach_timebase_info;
7pub use std.c;
std/os/darwin/errno.zig deleted-328
......@@ -1,328 +0,0 @@
1/// Operation not permitted
2pub const EPERM = 1;
3
4/// No such file or directory
5pub const ENOENT = 2;
6
7/// No such process
8pub const ESRCH = 3;
9
10/// Interrupted system call
11pub const EINTR = 4;
12
13/// Input/output error
14pub const EIO = 5;
15
16/// Device not configured
17pub const ENXIO = 6;
18
19/// Argument list too long
20pub const E2BIG = 7;
21
22/// Exec format error
23pub const ENOEXEC = 8;
24
25/// Bad file descriptor
26pub const EBADF = 9;
27
28/// No child processes
29pub const ECHILD = 10;
30
31/// Resource deadlock avoided
32pub const EDEADLK = 11;
33
34/// Cannot allocate memory
35pub const ENOMEM = 12;
36
37/// Permission denied
38pub const EACCES = 13;
39
40/// Bad address
41pub const EFAULT = 14;
42
43/// Block device required
44pub const ENOTBLK = 15;
45
46/// Device / Resource busy
47pub const EBUSY = 16;
48
49/// File exists
50pub const EEXIST = 17;
51
52/// Cross-device link
53pub const EXDEV = 18;
54
55/// Operation not supported by device
56pub const ENODEV = 19;
57
58/// Not a directory
59pub const ENOTDIR = 20;
60
61/// Is a directory
62pub const EISDIR = 21;
63
64/// Invalid argument
65pub const EINVAL = 22;
66
67/// Too many open files in system
68pub const ENFILE = 23;
69
70/// Too many open files
71pub const EMFILE = 24;
72
73/// Inappropriate ioctl for device
74pub const ENOTTY = 25;
75
76/// Text file busy
77pub const ETXTBSY = 26;
78
79/// File too large
80pub const EFBIG = 27;
81
82/// No space left on device
83pub const ENOSPC = 28;
84
85/// Illegal seek
86pub const ESPIPE = 29;
87
88/// Read-only file system
89pub const EROFS = 30;
90
91/// Too many links
92pub const EMLINK = 31;
93/// Broken pipe
94
95// math software
96pub const EPIPE = 32;
97
98/// Numerical argument out of domain
99pub const EDOM = 33;
100/// Result too large
101
102// non-blocking and interrupt i/o
103pub const ERANGE = 34;
104
105/// Resource temporarily unavailable
106pub const EAGAIN = 35;
107
108/// Operation would block
109pub const EWOULDBLOCK = EAGAIN;
110
111/// Operation now in progress
112pub const EINPROGRESS = 36;
113/// Operation already in progress
114
115// ipc/network software -- argument errors
116pub const EALREADY = 37;
117
118/// Socket operation on non-socket
119pub const ENOTSOCK = 38;
120
121/// Destination address required
122pub const EDESTADDRREQ = 39;
123
124/// Message too long
125pub const EMSGSIZE = 40;
126
127/// Protocol wrong type for socket
128pub const EPROTOTYPE = 41;
129
130/// Protocol not available
131pub const ENOPROTOOPT = 42;
132
133/// Protocol not supported
134pub const EPROTONOSUPPORT = 43;
135
136/// Socket type not supported
137pub const ESOCKTNOSUPPORT = 44;
138
139/// Operation not supported
140pub const ENOTSUP = 45;
141
142/// Protocol family not supported
143pub const EPFNOSUPPORT = 46;
144
145/// Address family not supported by protocol family
146pub const EAFNOSUPPORT = 47;
147
148/// Address already in use
149pub const EADDRINUSE = 48;
150/// Can't assign requested address
151
152// ipc/network software -- operational errors
153pub const EADDRNOTAVAIL = 49;
154
155/// Network is down
156pub const ENETDOWN = 50;
157
158/// Network is unreachable
159pub const ENETUNREACH = 51;
160
161/// Network dropped connection on reset
162pub const ENETRESET = 52;
163
164/// Software caused connection abort
165pub const ECONNABORTED = 53;
166
167/// Connection reset by peer
168pub const ECONNRESET = 54;
169
170/// No buffer space available
171pub const ENOBUFS = 55;
172
173/// Socket is already connected
174pub const EISCONN = 56;
175
176/// Socket is not connected
177pub const ENOTCONN = 57;
178
179/// Can't send after socket shutdown
180pub const ESHUTDOWN = 58;
181
182/// Too many references: can't splice
183pub const ETOOMANYREFS = 59;
184
185/// Operation timed out
186pub const ETIMEDOUT = 60;
187
188/// Connection refused
189pub const ECONNREFUSED = 61;
190
191/// Too many levels of symbolic links
192pub const ELOOP = 62;
193
194/// File name too long
195pub const ENAMETOOLONG = 63;
196
197/// Host is down
198pub const EHOSTDOWN = 64;
199
200/// No route to host
201pub const EHOSTUNREACH = 65;
202/// Directory not empty
203
204// quotas & mush
205pub const ENOTEMPTY = 66;
206
207/// Too many processes
208pub const EPROCLIM = 67;
209
210/// Too many users
211pub const EUSERS = 68;
212/// Disc quota exceeded
213
214// Network File System
215pub const EDQUOT = 69;
216
217/// Stale NFS file handle
218pub const ESTALE = 70;
219
220/// Too many levels of remote in path
221pub const EREMOTE = 71;
222
223/// RPC struct is bad
224pub const EBADRPC = 72;
225
226/// RPC version wrong
227pub const ERPCMISMATCH = 73;
228
229/// RPC prog. not avail
230pub const EPROGUNAVAIL = 74;
231
232/// Program version wrong
233pub const EPROGMISMATCH = 75;
234
235/// Bad procedure for program
236pub const EPROCUNAVAIL = 76;
237
238/// No locks available
239pub const ENOLCK = 77;
240
241/// Function not implemented
242pub const ENOSYS = 78;
243
244/// Inappropriate file type or format
245pub const EFTYPE = 79;
246
247/// Authentication error
248pub const EAUTH = 80;
249/// Need authenticator
250
251// Intelligent device errors
252pub const ENEEDAUTH = 81;
253
254/// Device power is off
255pub const EPWROFF = 82;
256
257/// Device error, e.g. paper out
258pub const EDEVERR = 83;
259/// Value too large to be stored in data type
260
261// Program loading errors
262pub const EOVERFLOW = 84;
263
264/// Bad executable
265pub const EBADEXEC = 85;
266
267/// Bad CPU type in executable
268pub const EBADARCH = 86;
269
270/// Shared library version mismatch
271pub const ESHLIBVERS = 87;
272
273/// Malformed Macho file
274pub const EBADMACHO = 88;
275
276/// Operation canceled
277pub const ECANCELED = 89;
278
279/// Identifier removed
280pub const EIDRM = 90;
281
282/// No message of desired type
283pub const ENOMSG = 91;
284
285/// Illegal byte sequence
286pub const EILSEQ = 92;
287
288/// Attribute not found
289pub const ENOATTR = 93;
290
291/// Bad message
292pub const EBADMSG = 94;
293
294/// Reserved
295pub const EMULTIHOP = 95;
296
297/// No message available on STREAM
298pub const ENODATA = 96;
299
300/// Reserved
301pub const ENOLINK = 97;
302
303/// No STREAM resources
304pub const ENOSR = 98;
305
306/// Not a STREAM
307pub const ENOSTR = 99;
308
309/// Protocol error
310pub const EPROTO = 100;
311
312/// STREAM ioctl timeout
313pub const ETIME = 101;
314
315/// No such policy registered
316pub const ENOPOLICY = 103;
317
318/// State not recoverable
319pub const ENOTRECOVERABLE = 104;
320
321/// Previous owner died
322pub const EOWNERDEAD = 105;
323
324/// Interface output queue is full
325pub const EQFULL = 106;
326
327/// Must be equal largest errno
328pub const ELAST = 106;
std/os/file.zig+12-71
......@@ -16,7 +16,7 @@ const is_windows = builtin.os == builtin.Os.windows;
1616
1717pub const File = struct {
1818 /// The OS-specific file descriptor or file handle.
19 handle: os.FileHandle,
19 handle: posix.fd_t,
2020
2121 pub const Mode = switch (builtin.os) {
2222 Os.windows => void,
......@@ -138,83 +138,24 @@ pub const File = struct {
138138 return openHandle(handle);
139139 }
140140
141 pub fn openHandle(handle: os.FileHandle) File {
141 pub fn openHandle(handle: posix.fd_t) File {
142142 return File{ .handle = handle };
143143 }
144144
145 pub const AccessError = error{
146 PermissionDenied,
147 FileNotFound,
148 NameTooLong,
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 }
145 /// Test for the existence of `path`.
146 /// `path` is UTF8-encoded.
147 pub fn exists(path: []const u8) AccessError!void {
148 return posix.access(path, posix.F_OK);
173149 }
174150
175 /// Call if you have a UTF-8 encoded, null-terminated string.
176 /// Otherwise use `access` or `accessW`.
177 pub fn accessC(path: [*]const u8) AccessError!void {
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");
151 /// Same as `exists` except the parameter is null-terminated UTF16LE-encoded.
152 pub fn existsW(path: [*]const u16) AccessError!void {
153 return posix.accessW(path, posix.F_OK);
203154 }
204155
205 pub fn access(path: []const u8) AccessError!void {
206 if (is_windows) {
207 const path_w = try windows_util.sliceToPrefixedFileW(path);
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");
156 /// Same as `exists` except the parameter is null-terminated.
157 pub fn existsC(path: [*]const u8) AccessError!void {
158 return posix.accessC(path, posix.F_OK);
218159 }
219160
220161 /// Upon success, the stream is in an uninitialized state. To continue using it,
std/os/freebsd.zig+3-844
......@@ -1,845 +1,4 @@
1const builtin = @import("builtin");
2
3pub use @import("freebsd/errno.zig");
4
51const std = @import("../std.zig");
6const c = std.c;
7
8const assert = std.debug.assert;
9const maxInt = std.math.maxInt;
10pub const Kevent = c.Kevent;
11
12pub const CTL_KERN = 1;
13pub const CTL_DEBUG = 5;
14
15pub const KERN_PROC = 14; // struct: process entries
16pub const KERN_PROC_PATHNAME = 12; // path to executable
17
18pub const PATH_MAX = 1024;
19
20pub const STDIN_FILENO = 0;
21pub const STDOUT_FILENO = 1;
22pub const STDERR_FILENO = 2;
23
24pub const PROT_NONE = 0;
25pub const PROT_READ = 1;
26pub const PROT_WRITE = 2;
27pub const PROT_EXEC = 4;
28
29pub const CLOCK_REALTIME = 0;
30pub const CLOCK_VIRTUAL = 1;
31pub const CLOCK_PROF = 2;
32pub const CLOCK_MONOTONIC = 4;
33pub const CLOCK_UPTIME = 5;
34pub const CLOCK_UPTIME_PRECISE = 7;
35pub const CLOCK_UPTIME_FAST = 8;
36pub const CLOCK_REALTIME_PRECISE = 9;
37pub const CLOCK_REALTIME_FAST = 10;
38pub const CLOCK_MONOTONIC_PRECISE = 11;
39pub const CLOCK_MONOTONIC_FAST = 12;
40pub const CLOCK_SECOND = 13;
41pub const CLOCK_THREAD_CPUTIME_ID = 14;
42pub const CLOCK_PROCESS_CPUTIME_ID = 15;
43
44pub const MAP_FAILED = maxInt(usize);
45pub const MAP_SHARED = 0x0001;
46pub const MAP_PRIVATE = 0x0002;
47pub const MAP_FIXED = 0x0010;
48pub const MAP_STACK = 0x0400;
49pub const MAP_NOSYNC = 0x0800;
50pub const MAP_ANON = 0x1000;
51pub const MAP_ANONYMOUS = MAP_ANON;
52pub const MAP_FILE = 0;
53pub const MAP_NORESERVE = 0;
54
55pub const MAP_GUARD = 0x00002000;
56pub const MAP_EXCL = 0x00004000;
57pub const MAP_NOCORE = 0x00020000;
58pub const MAP_PREFAULT_READ = 0x00040000;
59pub const MAP_32BIT = 0x00080000;
60
61pub const WNOHANG = 1;
62pub const WUNTRACED = 2;
63pub const WSTOPPED = WUNTRACED;
64pub const WCONTINUED = 4;
65pub const WNOWAIT = 8;
66pub const WEXITED = 16;
67pub const WTRAPPED = 32;
68
69pub const SA_ONSTACK = 0x0001;
70pub const SA_RESTART = 0x0002;
71pub const SA_RESETHAND = 0x0004;
72pub const SA_NOCLDSTOP = 0x0008;
73pub const SA_NODEFER = 0x0010;
74pub const SA_NOCLDWAIT = 0x0020;
75pub const SA_SIGINFO = 0x0040;
76
77pub const SIGHUP = 1;
78pub const SIGINT = 2;
79pub const SIGQUIT = 3;
80pub const SIGILL = 4;
81pub const SIGTRAP = 5;
82pub const SIGABRT = 6;
83pub const SIGIOT = SIGABRT;
84pub const SIGEMT = 7;
85pub const SIGFPE = 8;
86pub const SIGKILL = 9;
87pub const SIGBUS = 10;
88pub const SIGSEGV = 11;
89pub const SIGSYS = 12;
90pub const SIGPIPE = 13;
91pub const SIGALRM = 14;
92pub const SIGTERM = 15;
93pub const SIGURG = 16;
94pub const SIGSTOP = 17;
95pub const SIGTSTP = 18;
96pub const SIGCONT = 19;
97pub const SIGCHLD = 20;
98pub const SIGTTIN = 21;
99pub const SIGTTOU = 22;
100pub const SIGIO = 23;
101pub const SIGXCPU = 24;
102pub const SIGXFSZ = 25;
103pub const SIGVTALRM = 26;
104pub const SIGPROF = 27;
105pub const SIGWINCH = 28;
106pub const SIGINFO = 29;
107pub const SIGUSR1 = 30;
108pub const SIGUSR2 = 31;
109pub const SIGTHR = 32;
110pub const SIGLWP = SIGTHR;
111pub const SIGLIBRT = 33;
112
113pub const SIGRTMIN = 65;
114pub const SIGRTMAX = 126;
115
116// access function
117pub const F_OK = 0; // test for existence of file
118pub const X_OK = 1; // test for execute or search permission
119pub const W_OK = 2; // test for write permission
120pub const R_OK = 4; // test for read permission
121
122pub const O_RDONLY = 0x0000;
123pub const O_WRONLY = 0x0001;
124pub const O_RDWR = 0x0002;
125pub const O_ACCMODE = 0x0003;
126
127pub const O_CREAT = 0x0200;
128pub const O_EXCL = 0x0800;
129pub const O_NOCTTY = 0x8000;
130pub const O_TRUNC = 0x0400;
131pub const O_APPEND = 0x0008;
132pub const O_NONBLOCK = 0x0004;
133pub const O_DSYNC = 0o10000;
134pub const O_SYNC = 0x0080;
135pub const O_RSYNC = 0o4010000;
136pub const O_DIRECTORY = 0o200000;
137pub const O_NOFOLLOW = 0x0100;
138pub const O_CLOEXEC = 0x00100000;
139
140pub const O_ASYNC = 0x0040;
141pub const O_DIRECT = 0x00010000;
142pub const O_LARGEFILE = 0;
143pub const O_NOATIME = 0o1000000;
144pub const O_PATH = 0o10000000;
145pub const O_TMPFILE = 0o20200000;
146pub const O_NDELAY = O_NONBLOCK;
147
148pub const F_DUPFD = 0;
149pub const F_GETFD = 1;
150pub const F_SETFD = 2;
151pub const F_GETFL = 3;
152pub const F_SETFL = 4;
153
154pub const F_SETOWN = 8;
155pub const F_GETOWN = 9;
156pub const F_SETSIG = 10;
157pub const F_GETSIG = 11;
158
159pub const F_GETLK = 5;
160pub const F_SETLK = 6;
161pub const F_SETLKW = 7;
162
163pub const F_SETOWN_EX = 15;
164pub const F_GETOWN_EX = 16;
165
166pub const F_GETOWNER_UIDS = 17;
167
168pub const SEEK_SET = 0;
169pub const SEEK_CUR = 1;
170pub const SEEK_END = 2;
171
172pub const SIG_BLOCK = 1;
173pub const SIG_UNBLOCK = 2;
174pub const SIG_SETMASK = 3;
175
176pub const SOCK_STREAM = 1;
177pub const SOCK_DGRAM = 2;
178pub const SOCK_RAW = 3;
179pub const SOCK_RDM = 4;
180pub const SOCK_SEQPACKET = 5;
181
182pub const SOCK_CLOEXEC = 0x10000000;
183pub const SOCK_NONBLOCK = 0x20000000;
184
185pub const PROTO_ip = 0o000;
186pub const PROTO_icmp = 0o001;
187pub const PROTO_igmp = 0o002;
188pub const PROTO_ggp = 0o003;
189pub const PROTO_ipencap = 0o004;
190pub const PROTO_st = 0o005;
191pub const PROTO_tcp = 0o006;
192pub const PROTO_egp = 0o010;
193pub const PROTO_pup = 0o014;
194pub const PROTO_udp = 0o021;
195pub const PROTO_hmp = 0o024;
196pub const PROTO_xns_idp = 0o026;
197pub const PROTO_rdp = 0o033;
198pub const PROTO_iso_tp4 = 0o035;
199pub const PROTO_xtp = 0o044;
200pub const PROTO_ddp = 0o045;
201pub const PROTO_idpr_cmtp = 0o046;
202pub const PROTO_ipv6 = 0o051;
203pub const PROTO_ipv6_route = 0o053;
204pub const PROTO_ipv6_frag = 0o054;
205pub const PROTO_idrp = 0o055;
206pub const PROTO_rsvp = 0o056;
207pub const PROTO_gre = 0o057;
208pub const PROTO_esp = 0o062;
209pub const PROTO_ah = 0o063;
210pub const PROTO_skip = 0o071;
211pub const PROTO_ipv6_icmp = 0o072;
212pub const PROTO_ipv6_nonxt = 0o073;
213pub const PROTO_ipv6_opts = 0o074;
214pub const PROTO_rspf = 0o111;
215pub const PROTO_vmtp = 0o121;
216pub const PROTO_ospf = 0o131;
217pub const PROTO_ipip = 0o136;
218pub const PROTO_encap = 0o142;
219pub const PROTO_pim = 0o147;
220pub const PROTO_raw = 0o377;
221
222pub const PF_UNSPEC = 0;
223pub const PF_LOCAL = 1;
224pub const PF_UNIX = PF_LOCAL;
225pub const PF_FILE = PF_LOCAL;
226pub const PF_INET = 2;
227pub const PF_AX25 = 3;
228pub const PF_IPX = 4;
229pub const PF_APPLETALK = 5;
230pub const PF_NETROM = 6;
231pub const PF_BRIDGE = 7;
232pub const PF_ATMPVC = 8;
233pub const PF_X25 = 9;
234pub const PF_INET6 = 10;
235pub const PF_ROSE = 11;
236pub const PF_DECnet = 12;
237pub const PF_NETBEUI = 13;
238pub const PF_SECURITY = 14;
239pub const PF_KEY = 15;
240pub const PF_NETLINK = 16;
241pub const PF_ROUTE = PF_NETLINK;
242pub const PF_PACKET = 17;
243pub const PF_ASH = 18;
244pub const PF_ECONET = 19;
245pub const PF_ATMSVC = 20;
246pub const PF_RDS = 21;
247pub const PF_SNA = 22;
248pub const PF_IRDA = 23;
249pub const PF_PPPOX = 24;
250pub const PF_WANPIPE = 25;
251pub const PF_LLC = 26;
252pub const PF_IB = 27;
253pub const PF_MPLS = 28;
254pub const PF_CAN = 29;
255pub const PF_TIPC = 30;
256pub const PF_BLUETOOTH = 31;
257pub const PF_IUCV = 32;
258pub const PF_RXRPC = 33;
259pub const PF_ISDN = 34;
260pub const PF_PHONET = 35;
261pub const PF_IEEE802154 = 36;
262pub const PF_CAIF = 37;
263pub const PF_ALG = 38;
264pub const PF_NFC = 39;
265pub const PF_VSOCK = 40;
266pub const PF_MAX = 41;
267
268pub const AF_UNSPEC = PF_UNSPEC;
269pub const AF_LOCAL = PF_LOCAL;
270pub const AF_UNIX = AF_LOCAL;
271pub const AF_FILE = AF_LOCAL;
272pub const AF_INET = PF_INET;
273pub const AF_AX25 = PF_AX25;
274pub const AF_IPX = PF_IPX;
275pub const AF_APPLETALK = PF_APPLETALK;
276pub const AF_NETROM = PF_NETROM;
277pub const AF_BRIDGE = PF_BRIDGE;
278pub const AF_ATMPVC = PF_ATMPVC;
279pub const AF_X25 = PF_X25;
280pub const AF_INET6 = PF_INET6;
281pub const AF_ROSE = PF_ROSE;
282pub const AF_DECnet = PF_DECnet;
283pub const AF_NETBEUI = PF_NETBEUI;
284pub const AF_SECURITY = PF_SECURITY;
285pub const AF_KEY = PF_KEY;
286pub const AF_NETLINK = PF_NETLINK;
287pub const AF_ROUTE = PF_ROUTE;
288pub const AF_PACKET = PF_PACKET;
289pub const AF_ASH = PF_ASH;
290pub const AF_ECONET = PF_ECONET;
291pub const AF_ATMSVC = PF_ATMSVC;
292pub const AF_RDS = PF_RDS;
293pub const AF_SNA = PF_SNA;
294pub const AF_IRDA = PF_IRDA;
295pub const AF_PPPOX = PF_PPPOX;
296pub const AF_WANPIPE = PF_WANPIPE;
297pub const AF_LLC = PF_LLC;
298pub const AF_IB = PF_IB;
299pub const AF_MPLS = PF_MPLS;
300pub const AF_CAN = PF_CAN;
301pub const AF_TIPC = PF_TIPC;
302pub const AF_BLUETOOTH = PF_BLUETOOTH;
303pub const AF_IUCV = PF_IUCV;
304pub const AF_RXRPC = PF_RXRPC;
305pub const AF_ISDN = PF_ISDN;
306pub const AF_PHONET = PF_PHONET;
307pub const AF_IEEE802154 = PF_IEEE802154;
308pub const AF_CAIF = PF_CAIF;
309pub const AF_ALG = PF_ALG;
310pub const AF_NFC = PF_NFC;
311pub const AF_VSOCK = PF_VSOCK;
312pub const AF_MAX = PF_MAX;
313
314pub const DT_UNKNOWN = 0;
315pub const DT_FIFO = 1;
316pub const DT_CHR = 2;
317pub const DT_DIR = 4;
318pub const DT_BLK = 6;
319pub const DT_REG = 8;
320pub const DT_LNK = 10;
321pub const DT_SOCK = 12;
322pub const DT_WHT = 14;
323
324/// add event to kq (implies enable)
325pub const EV_ADD = 0x0001;
326
327/// delete event from kq
328pub const EV_DELETE = 0x0002;
329
330/// enable event
331pub const EV_ENABLE = 0x0004;
332
333/// disable event (not reported)
334pub const EV_DISABLE = 0x0008;
335
336/// only report one occurrence
337pub const EV_ONESHOT = 0x0010;
338
339/// clear event state after reporting
340pub 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
346pub const EV_RECEIPT = 0x0040;
347
348/// disable event after reporting
349pub const EV_DISPATCH = 0x0080;
350
351pub const EVFILT_READ = -1;
352pub const EVFILT_WRITE = -2;
353
354/// attached to aio requests
355pub const EVFILT_AIO = -3;
356
357/// attached to vnodes
358pub const EVFILT_VNODE = -4;
359
360/// attached to struct proc
361pub const EVFILT_PROC = -5;
362
363/// attached to struct proc
364pub const EVFILT_SIGNAL = -6;
365
366/// timers
367pub const EVFILT_TIMER = -7;
368
369/// Process descriptors
370pub const EVFILT_PROCDESC = -8;
371
372/// Filesystem events
373pub const EVFILT_FS = -9;
374
375pub const EVFILT_LIO = -10;
376
377/// User events
378pub const EVFILT_USER = -11;
379
380/// Sendfile events
381pub const EVFILT_SENDFILE = -12;
382
383pub const EVFILT_EMPTY = -13;
384
385/// On input, NOTE_TRIGGER causes the event to be triggered for output.
386pub const NOTE_TRIGGER = 0x01000000;
387
388/// ignore input fflags
389pub const NOTE_FFNOP = 0x00000000;
390
391/// and fflags
392pub const NOTE_FFAND = 0x40000000;
393
394/// or fflags
395pub const NOTE_FFOR = 0x80000000;
396
397/// copy fflags
398pub const NOTE_FFCOPY = 0xc0000000;
399
400/// mask for operations
401pub const NOTE_FFCTRLMASK = 0xc0000000;
402pub const NOTE_FFLAGSMASK = 0x00ffffff;
403
404/// low water mark
405pub const NOTE_LOWAT = 0x00000001;
406
407/// behave like poll()
408pub const NOTE_FILE_POLL = 0x00000002;
409
410/// vnode was removed
411pub const NOTE_DELETE = 0x00000001;
412
413/// data contents changed
414pub const NOTE_WRITE = 0x00000002;
415
416/// size increased
417pub const NOTE_EXTEND = 0x00000004;
418
419/// attributes changed
420pub const NOTE_ATTRIB = 0x00000008;
421
422/// link count changed
423pub const NOTE_LINK = 0x00000010;
424
425/// vnode was renamed
426pub const NOTE_RENAME = 0x00000020;
427
428/// vnode access was revoked
429pub const NOTE_REVOKE = 0x00000040;
430
431/// vnode was opened
432pub const NOTE_OPEN = 0x00000080;
433
434/// file closed, fd did not allow write
435pub const NOTE_CLOSE = 0x00000100;
436
437/// file closed, fd did allow write
438pub const NOTE_CLOSE_WRITE = 0x00000200;
439
440/// file was read
441pub const NOTE_READ = 0x00000400;
442
443/// process exited
444pub const NOTE_EXIT = 0x80000000;
445
446/// process forked
447pub const NOTE_FORK = 0x40000000;
448
449/// process exec'd
450pub const NOTE_EXEC = 0x20000000;
451
452/// mask for signal & exit status
453pub const NOTE_PDATAMASK = 0x000fffff;
454pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
455
456/// data is seconds
457pub const NOTE_SECONDS = 0x00000001;
458
459/// data is milliseconds
460pub const NOTE_MSECONDS = 0x00000002;
461
462/// data is microseconds
463pub const NOTE_USECONDS = 0x00000004;
464
465/// data is nanoseconds
466pub const NOTE_NSECONDS = 0x00000008;
467
468/// timeout is absolute
469pub const NOTE_ABSTIME = 0x00000010;
470
471pub const TCGETS = 0x5401;
472pub const TCSETS = 0x5402;
473pub const TCSETSW = 0x5403;
474pub const TCSETSF = 0x5404;
475pub const TCGETA = 0x5405;
476pub const TCSETA = 0x5406;
477pub const TCSETAW = 0x5407;
478pub const TCSETAF = 0x5408;
479pub const TCSBRK = 0x5409;
480pub const TCXONC = 0x540A;
481pub const TCFLSH = 0x540B;
482pub const TIOCEXCL = 0x540C;
483pub const TIOCNXCL = 0x540D;
484pub const TIOCSCTTY = 0x540E;
485pub const TIOCGPGRP = 0x540F;
486pub const TIOCSPGRP = 0x5410;
487pub const TIOCOUTQ = 0x5411;
488pub const TIOCSTI = 0x5412;
489pub const TIOCGWINSZ = 0x5413;
490pub const TIOCSWINSZ = 0x5414;
491pub const TIOCMGET = 0x5415;
492pub const TIOCMBIS = 0x5416;
493pub const TIOCMBIC = 0x5417;
494pub const TIOCMSET = 0x5418;
495pub const TIOCGSOFTCAR = 0x5419;
496pub const TIOCSSOFTCAR = 0x541A;
497pub const FIONREAD = 0x541B;
498pub const TIOCINQ = FIONREAD;
499pub const TIOCLINUX = 0x541C;
500pub const TIOCCONS = 0x541D;
501pub const TIOCGSERIAL = 0x541E;
502pub const TIOCSSERIAL = 0x541F;
503pub const TIOCPKT = 0x5420;
504pub const FIONBIO = 0x5421;
505pub const TIOCNOTTY = 0x5422;
506pub const TIOCSETD = 0x5423;
507pub const TIOCGETD = 0x5424;
508pub const TCSBRKP = 0x5425;
509pub const TIOCSBRK = 0x5427;
510pub const TIOCCBRK = 0x5428;
511pub const TIOCGSID = 0x5429;
512pub const TIOCGRS485 = 0x542E;
513pub const TIOCSRS485 = 0x542F;
514pub const TIOCGPTN = 0x80045430;
515pub const TIOCSPTLCK = 0x40045431;
516pub const TIOCGDEV = 0x80045432;
517pub const TCGETX = 0x5432;
518pub const TCSETX = 0x5433;
519pub const TCSETXF = 0x5434;
520pub const TCSETXW = 0x5435;
521pub const TIOCSIG = 0x40045436;
522pub const TIOCVHANGUP = 0x5437;
523pub const TIOCGPKT = 0x80045438;
524pub const TIOCGPTLCK = 0x80045439;
525pub const TIOCGEXCL = 0x80045440;
526
527pub const sockaddr = c.sockaddr;
528pub const sockaddr_in = c.sockaddr_in;
529pub const sockaddr_in6 = c.sockaddr_in6;
530
531fn unsigned(s: i32) u32 {
532 return @bitCast(u32, s);
533}
534fn signed(s: u32) i32 {
535 return @bitCast(i32, s);
536}
537pub fn WEXITSTATUS(s: i32) i32 {
538 return signed((unsigned(s) & 0xff00) >> 8);
539}
540pub fn WTERMSIG(s: i32) i32 {
541 return signed(unsigned(s) & 0x7f);
542}
543pub fn WSTOPSIG(s: i32) i32 {
544 return WEXITSTATUS(s);
545}
546pub fn WIFEXITED(s: i32) bool {
547 return WTERMSIG(s) == 0;
548}
549pub fn WIFSTOPPED(s: i32) bool {
550 return @intCast(u16, (((unsigned(s) & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
551}
552pub fn WIFSIGNALED(s: i32) bool {
553 return (unsigned(s) & 0xffff) -% 1 < 0xff;
554}
555
556pub 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.
564pub 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
569pub fn dup2(old: i32, new: i32) usize {
570 return errnoWrap(c.dup2(old, new));
571}
572
573pub fn chdir(path: [*]const u8) usize {
574 return errnoWrap(c.chdir(path));
575}
576
577pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {
578 return errnoWrap(c.execve(path, argv, envp));
579}
580
581pub fn fork() usize {
582 return errnoWrap(c.fork());
583}
584
585pub fn access(path: [*]const u8, mode: u32) usize {
586 return errnoWrap(c.access(path, mode));
587}
588
589pub fn getcwd(buf: [*]u8, size: usize) usize {
590 return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
591}
592
593pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
594 return errnoWrap(@bitCast(isize, c.getdents(fd, drip, count)));
595}
596
597pub 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
601pub 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
605pub fn isatty(fd: i32) bool {
606 return c.isatty(fd) != 0;
607}
608
609pub 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
613pub fn mkdir(path: [*]const u8, mode: u32) usize {
614 return errnoWrap(c.mkdir(path, mode));
615}
616
617pub 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
630pub fn munmap(address: usize, length: usize) usize {
631 return errnoWrap(c.munmap(@intToPtr(?*c_void, address), length));
632}
633
634pub fn read(fd: i32, buf: [*]u8, nbyte: usize) usize {
635 return errnoWrap(c.read(fd, @ptrCast(*c_void, buf), nbyte));
636}
637
638pub fn rmdir(path: [*]const u8) usize {
639 return errnoWrap(c.rmdir(path));
640}
641
642pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
643 return errnoWrap(c.symlink(existing, new));
644}
645
646pub 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
650pub 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
654pub fn pipe(fd: *[2]i32) usize {
655 return pipe2(fd, 0);
656}
657
658pub 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
663pub fn write(fd: i32, buf: [*]const u8, nbyte: usize) usize {
664 return errnoWrap(c.write(fd, @ptrCast(*const c_void, buf), nbyte));
665}
666
667pub 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
671pub 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
675pub fn rename(old: [*]const u8, new: [*]const u8) usize {
676 return errnoWrap(c.rename(old, new));
677}
678
679pub fn open(path: [*]const u8, flags: u32, mode: usize) usize {
680 return errnoWrap(c.open(path, @bitCast(c_int, flags), mode));
681}
682
683pub fn create(path: [*]const u8, perm: usize) usize {
684 return arch.syscall2(SYS_creat, @ptrToInt(path), perm);
685}
686
687pub 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
691pub fn close(fd: i32) usize {
692 return errnoWrap(c.close(fd));
693}
694
695pub fn lseek(fd: i32, offset: isize, whence: c_int) usize {
696 return errnoWrap(c.lseek(fd, offset, whence));
697}
698
699pub fn exit(code: i32) noreturn {
700 c.exit(code);
701}
702
703pub fn kill(pid: i32, sig: i32) usize {
704 return errnoWrap(c.kill(pid, sig));
705}
706
707pub fn unlink(path: [*]const u8) usize {
708 return errnoWrap(c.unlink(path));
709}
710
711pub 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
716pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
717 return errnoWrap(c.nanosleep(req, rem));
718}
719
720pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
721 return errnoWrap(c.clock_gettime(clk_id, tp));
722}
723
724pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
725 return errnoWrap(c.clock_getres(clk_id, tp));
726}
727
728pub fn setuid(uid: u32) usize {
729 return errnoWrap(c.setuid(uid));
730}
731
732pub fn setgid(gid: u32) usize {
733 return errnoWrap(c.setgid(gid));
734}
735
736pub fn setreuid(ruid: u32, euid: u32) usize {
737 return errnoWrap(c.setreuid(ruid, euid));
738}
739
740pub fn setregid(rgid: u32, egid: u32) usize {
741 return errnoWrap(c.setregid(rgid, egid));
742}
743
744const NSIG = 32;
745
746pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
747pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
748pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
749
750/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
751pub 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
765pub const _SIG_WORDS = 4;
766pub const _SIG_MAXSIG = 128;
767
768pub inline fn _SIG_IDX(sig: usize) usize {
769 return sig - 1;
770}
771pub inline fn _SIG_WORD(sig: usize) usize {
772 return_SIG_IDX(sig) >> 5;
773}
774pub inline fn _SIG_BIT(sig: usize) usize {
775 return 1 << (_SIG_IDX(sig) & 31);
776}
777pub inline fn _SIG_VALID(sig: usize) usize {
778 return sig <= _SIG_MAXSIG and sig > 0;
779}
780
781pub const sigset_t = extern struct {
782 __bits: [_SIG_WORDS]u32,
783};
784
785pub fn raise(sig: i32) usize {
786 return errnoWrap(c.raise(sig));
787}
788
789pub const Stat = c.Stat;
790pub const dirent = c.dirent;
791pub const timespec = c.timespec;
792
793pub fn fstat(fd: i32, buf: *c.Stat) usize {
794 return errnoWrap(c.fstat(fd, buf));
795}
796pub const iovec = extern struct {
797 iov_base: [*]u8,
798 iov_len: usize,
799};
800
801pub const iovec_const = extern struct {
802 iov_base: [*]const u8,
803 iov_len: usize,
804};
805
806// TODO avoid libc dependency
807pub fn kqueue() usize {
808 return errnoWrap(c.kqueue());
809}
810
811// TODO avoid libc dependency
812pub 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
824pub 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
829pub 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
834pub 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.
843fn errnoWrap(value: isize) usize {
844 return @bitCast(usize, if (value == -1) -isize(c._errno().*) else value);
845}
2const builtin = @import("builtin");
3pub const is_the_target = builtin.os == .freebsd;
4pub use std.c;
std/os/freebsd/errno.zig deleted-121
......@@ -1,121 +0,0 @@
1pub const EPERM = 1; // Operation not permitted
2pub const ENOENT = 2; // No such file or directory
3pub const ESRCH = 3; // No such process
4pub const EINTR = 4; // Interrupted system call
5pub const EIO = 5; // Input/output error
6pub const ENXIO = 6; // Device not configured
7pub const E2BIG = 7; // Argument list too long
8pub const ENOEXEC = 8; // Exec format error
9pub const EBADF = 9; // Bad file descriptor
10pub const ECHILD = 10; // No child processes
11pub const EDEADLK = 11; // Resource deadlock avoided
12// 11 was EAGAIN
13pub const ENOMEM = 12; // Cannot allocate memory
14pub const EACCES = 13; // Permission denied
15pub const EFAULT = 14; // Bad address
16pub const ENOTBLK = 15; // Block device required
17pub const EBUSY = 16; // Device busy
18pub const EEXIST = 17; // File exists
19pub const EXDEV = 18; // Cross-device link
20pub const ENODEV = 19; // Operation not supported by device
21pub const ENOTDIR = 20; // Not a directory
22pub const EISDIR = 21; // Is a directory
23pub const EINVAL = 22; // Invalid argument
24pub const ENFILE = 23; // Too many open files in system
25pub const EMFILE = 24; // Too many open files
26pub const ENOTTY = 25; // Inappropriate ioctl for device
27pub const ETXTBSY = 26; // Text file busy
28pub const EFBIG = 27; // File too large
29pub const ENOSPC = 28; // No space left on device
30pub const ESPIPE = 29; // Illegal seek
31pub const EROFS = 30; // Read-only filesystem
32pub const EMLINK = 31; // Too many links
33pub const EPIPE = 32; // Broken pipe
34
35// math software
36pub const EDOM = 33; // Numerical argument out of domain
37pub const ERANGE = 34; // Result too large
38
39// non-blocking and interrupt i/o
40pub const EAGAIN = 35; // Resource temporarily unavailable
41pub const EWOULDBLOCK = EAGAIN; // Operation would block
42pub const EINPROGRESS = 36; // Operation now in progress
43pub const EALREADY = 37; // Operation already in progress
44
45// ipc/network software -- argument errors
46pub const ENOTSOCK = 38; // Socket operation on non-socket
47pub const EDESTADDRREQ = 39; // Destination address required
48pub const EMSGSIZE = 40; // Message too long
49pub const EPROTOTYPE = 41; // Protocol wrong type for socket
50pub const ENOPROTOOPT = 42; // Protocol not available
51pub const EPROTONOSUPPORT = 43; // Protocol not supported
52pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
53pub const EOPNOTSUPP = 45; // Operation not supported
54pub const ENOTSUP = EOPNOTSUPP; // Operation not supported
55pub const EPFNOSUPPORT = 46; // Protocol family not supported
56pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
57pub const EADDRINUSE = 48; // Address already in use
58pub const EADDRNOTAVAIL = 49; // Can't assign requested address
59
60// ipc/network software -- operational errors
61pub const ENETDOWN = 50; // Network is down
62pub const ENETUNREACH = 51; // Network is unreachable
63pub const ENETRESET = 52; // Network dropped connection on reset
64pub const ECONNABORTED = 53; // Software caused connection abort
65pub const ECONNRESET = 54; // Connection reset by peer
66pub const ENOBUFS = 55; // No buffer space available
67pub const EISCONN = 56; // Socket is already connected
68pub const ENOTCONN = 57; // Socket is not connected
69pub const ESHUTDOWN = 58; // Can't send after socket shutdown
70pub const ETOOMANYREFS = 59; // Too many references: can't splice
71pub const ETIMEDOUT = 60; // Operation timed out
72pub const ECONNREFUSED = 61; // Connection refused
73
74pub const ELOOP = 62; // Too many levels of symbolic links
75pub const ENAMETOOLONG = 63; // File name too long
76
77// should be rearranged
78pub const EHOSTDOWN = 64; // Host is down
79pub const EHOSTUNREACH = 65; // No route to host
80pub const ENOTEMPTY = 66; // Directory not empty
81
82// quotas & mush
83pub const EPROCLIM = 67; // Too many processes
84pub const EUSERS = 68; // Too many users
85pub const EDQUOT = 69; // Disc quota exceeded
86
87// Network File System
88pub const ESTALE = 70; // Stale NFS file handle
89pub const EREMOTE = 71; // Too many levels of remote in path
90pub const EBADRPC = 72; // RPC struct is bad
91pub const ERPCMISMATCH = 73; // RPC version wrong
92pub const EPROGUNAVAIL = 74; // RPC prog. not avail
93pub const EPROGMISMATCH = 75; // Program version wrong
94pub const EPROCUNAVAIL = 76; // Bad procedure for program
95
96pub const ENOLCK = 77; // No locks available
97pub const ENOSYS = 78; // Function not implemented
98
99pub const EFTYPE = 79; // Inappropriate file type or format
100pub const EAUTH = 80; // Authentication error
101pub const ENEEDAUTH = 81; // Need authenticator
102pub const EIDRM = 82; // Identifier removed
103pub const ENOMSG = 83; // No message of desired type
104pub const EOVERFLOW = 84; // Value too large to be stored in data type
105pub const ECANCELED = 85; // Operation canceled
106pub const EILSEQ = 86; // Illegal byte sequence
107pub const ENOATTR = 87; // Attribute not found
108
109pub const EDOOFUS = 88; // Programming error
110
111pub const EBADMSG = 89; // Bad message
112pub const EMULTIHOP = 90; // Multihop attempted
113pub const ENOLINK = 91; // Link has been severed
114pub const EPROTO = 92; // Protocol error
115
116pub const ENOTCAPABLE = 93; // Capabilities insufficient
117pub const ECAPMODE = 94; // Not permitted in capability mode
118pub const ENOTRECOVERABLE = 95; // State not recoverable
119pub const EOWNERDEAD = 96; // Previous owner died
120
121pub 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");
77const vdso = @import("linux/vdso.zig");
88const dl = @import("../dynamic_library.zig");
99pub use switch (builtin.arch) {
10 builtin.Arch.x86_64 => @import("linux/x86_64.zig"),
11 builtin.Arch.i386 => @import("linux/i386.zig"),
12 builtin.Arch.aarch64 => @import("linux/arm64.zig"),
13 else => @compileError("unsupported arch"),
10 .x86_64 => @import("linux/x86_64.zig"),
11 .aarch64 => @import("linux/arm64.zig"),
12 else => struct {},
1413};
1514pub const is_the_target = builtin.os == .linux;
16pub const errno_codes = @import("linux/errno.zig");
17pub use errno_codes;
15pub const posix = @import("linux/posix.zig");
16pub use posix;
1817
1918/// See `std.os.posix.getauxval`.
2019pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;
2120
22pub const PATH_MAX = 4096;
23pub const IOV_MAX = 1024;
24
25pub const STDIN_FILENO = 0;
26pub const STDOUT_FILENO = 1;
27pub const STDERR_FILENO = 2;
28
29pub const FUTEX_WAIT = 0;
30pub const FUTEX_WAKE = 1;
31pub const FUTEX_FD = 2;
32pub const FUTEX_REQUEUE = 3;
33pub const FUTEX_CMP_REQUEUE = 4;
34pub const FUTEX_WAKE_OP = 5;
35pub const FUTEX_LOCK_PI = 6;
36pub const FUTEX_UNLOCK_PI = 7;
37pub const FUTEX_TRYLOCK_PI = 8;
38pub const FUTEX_WAIT_BITSET = 9;
39
40pub const FUTEX_PRIVATE_FLAG = 128;
41
42pub const FUTEX_CLOCK_REALTIME = 256;
43
44pub const PROT_NONE = 0;
45pub const PROT_READ = 1;
46pub const PROT_WRITE = 2;
47pub const PROT_EXEC = 4;
48pub const PROT_GROWSDOWN = 0x01000000;
49pub const PROT_GROWSUP = 0x02000000;
50
51pub const MAP_FAILED = maxInt(usize);
52pub const MAP_SHARED = 0x01;
53pub const MAP_PRIVATE = 0x02;
54pub const MAP_TYPE = 0x0f;
55pub const MAP_FIXED = 0x10;
56pub const MAP_ANONYMOUS = 0x20;
57pub const MAP_NORESERVE = 0x4000;
58pub const MAP_GROWSDOWN = 0x0100;
59pub const MAP_DENYWRITE = 0x0800;
60pub const MAP_EXECUTABLE = 0x1000;
61pub const MAP_LOCKED = 0x2000;
62pub const MAP_POPULATE = 0x8000;
63pub const MAP_NONBLOCK = 0x10000;
64pub const MAP_STACK = 0x20000;
65pub const MAP_HUGETLB = 0x40000;
66pub const MAP_FILE = 0;
67
68pub const F_OK = 0;
69pub const X_OK = 1;
70pub const W_OK = 2;
71pub const R_OK = 4;
72
73pub const WNOHANG = 1;
74pub const WUNTRACED = 2;
75pub const WSTOPPED = 2;
76pub const WEXITED = 4;
77pub const WCONTINUED = 8;
78pub const WNOWAIT = 0x1000000;
79
80pub const SA_NOCLDSTOP = 1;
81pub const SA_NOCLDWAIT = 2;
82pub const SA_SIGINFO = 4;
83pub const SA_ONSTACK = 0x08000000;
84pub const SA_RESTART = 0x10000000;
85pub const SA_NODEFER = 0x40000000;
86pub const SA_RESETHAND = 0x80000000;
87pub const SA_RESTORER = 0x04000000;
88
89pub const SIGHUP = 1;
90pub const SIGINT = 2;
91pub const SIGQUIT = 3;
92pub const SIGILL = 4;
93pub const SIGTRAP = 5;
94pub const SIGABRT = 6;
95pub const SIGIOT = SIGABRT;
96pub const SIGBUS = 7;
97pub const SIGFPE = 8;
98pub const SIGKILL = 9;
99pub const SIGUSR1 = 10;
100pub const SIGSEGV = 11;
101pub const SIGUSR2 = 12;
102pub const SIGPIPE = 13;
103pub const SIGALRM = 14;
104pub const SIGTERM = 15;
105pub const SIGSTKFLT = 16;
106pub const SIGCHLD = 17;
107pub const SIGCONT = 18;
108pub const SIGSTOP = 19;
109pub const SIGTSTP = 20;
110pub const SIGTTIN = 21;
111pub const SIGTTOU = 22;
112pub const SIGURG = 23;
113pub const SIGXCPU = 24;
114pub const SIGXFSZ = 25;
115pub const SIGVTALRM = 26;
116pub const SIGPROF = 27;
117pub const SIGWINCH = 28;
118pub const SIGIO = 29;
119pub const SIGPOLL = 29;
120pub const SIGPWR = 30;
121pub const SIGSYS = 31;
122pub const SIGUNUSED = SIGSYS;
123
124pub const O_RDONLY = 0o0;
125pub const O_WRONLY = 0o1;
126pub const O_RDWR = 0o2;
127
128pub const SEEK_SET = 0;
129pub const SEEK_CUR = 1;
130pub const SEEK_END = 2;
131
132pub const SIG_BLOCK = 0;
133pub const SIG_UNBLOCK = 1;
134pub const SIG_SETMASK = 2;
135
136pub const PROTO_ip = 0o000;
137pub const PROTO_icmp = 0o001;
138pub const PROTO_igmp = 0o002;
139pub const PROTO_ggp = 0o003;
140pub const PROTO_ipencap = 0o004;
141pub const PROTO_st = 0o005;
142pub const PROTO_tcp = 0o006;
143pub const PROTO_egp = 0o010;
144pub const PROTO_pup = 0o014;
145pub const PROTO_udp = 0o021;
146pub const PROTO_hmp = 0o024;
147pub const PROTO_xns_idp = 0o026;
148pub const PROTO_rdp = 0o033;
149pub const PROTO_iso_tp4 = 0o035;
150pub const PROTO_xtp = 0o044;
151pub const PROTO_ddp = 0o045;
152pub const PROTO_idpr_cmtp = 0o046;
153pub const PROTO_ipv6 = 0o051;
154pub const PROTO_ipv6_route = 0o053;
155pub const PROTO_ipv6_frag = 0o054;
156pub const PROTO_idrp = 0o055;
157pub const PROTO_rsvp = 0o056;
158pub const PROTO_gre = 0o057;
159pub const PROTO_esp = 0o062;
160pub const PROTO_ah = 0o063;
161pub const PROTO_skip = 0o071;
162pub const PROTO_ipv6_icmp = 0o072;
163pub const PROTO_ipv6_nonxt = 0o073;
164pub const PROTO_ipv6_opts = 0o074;
165pub const PROTO_rspf = 0o111;
166pub const PROTO_vmtp = 0o121;
167pub const PROTO_ospf = 0o131;
168pub const PROTO_ipip = 0o136;
169pub const PROTO_encap = 0o142;
170pub const PROTO_pim = 0o147;
171pub const PROTO_raw = 0o377;
172
173pub const SHUT_RD = 0;
174pub const SHUT_WR = 1;
175pub const SHUT_RDWR = 2;
176
177pub const SOCK_STREAM = 1;
178pub const SOCK_DGRAM = 2;
179pub const SOCK_RAW = 3;
180pub const SOCK_RDM = 4;
181pub const SOCK_SEQPACKET = 5;
182pub const SOCK_DCCP = 6;
183pub const SOCK_PACKET = 10;
184pub const SOCK_CLOEXEC = 0o2000000;
185pub const SOCK_NONBLOCK = 0o4000;
186
187pub const PF_UNSPEC = 0;
188pub const PF_LOCAL = 1;
189pub const PF_UNIX = PF_LOCAL;
190pub const PF_FILE = PF_LOCAL;
191pub const PF_INET = 2;
192pub const PF_AX25 = 3;
193pub const PF_IPX = 4;
194pub const PF_APPLETALK = 5;
195pub const PF_NETROM = 6;
196pub const PF_BRIDGE = 7;
197pub const PF_ATMPVC = 8;
198pub const PF_X25 = 9;
199pub const PF_INET6 = 10;
200pub const PF_ROSE = 11;
201pub const PF_DECnet = 12;
202pub const PF_NETBEUI = 13;
203pub const PF_SECURITY = 14;
204pub const PF_KEY = 15;
205pub const PF_NETLINK = 16;
206pub const PF_ROUTE = PF_NETLINK;
207pub const PF_PACKET = 17;
208pub const PF_ASH = 18;
209pub const PF_ECONET = 19;
210pub const PF_ATMSVC = 20;
211pub const PF_RDS = 21;
212pub const PF_SNA = 22;
213pub const PF_IRDA = 23;
214pub const PF_PPPOX = 24;
215pub const PF_WANPIPE = 25;
216pub const PF_LLC = 26;
217pub const PF_IB = 27;
218pub const PF_MPLS = 28;
219pub const PF_CAN = 29;
220pub const PF_TIPC = 30;
221pub const PF_BLUETOOTH = 31;
222pub const PF_IUCV = 32;
223pub const PF_RXRPC = 33;
224pub const PF_ISDN = 34;
225pub const PF_PHONET = 35;
226pub const PF_IEEE802154 = 36;
227pub const PF_CAIF = 37;
228pub const PF_ALG = 38;
229pub const PF_NFC = 39;
230pub const PF_VSOCK = 40;
231pub const PF_KCM = 41;
232pub const PF_QIPCRTR = 42;
233pub const PF_SMC = 43;
234pub const PF_MAX = 44;
235
236pub const AF_UNSPEC = PF_UNSPEC;
237pub const AF_LOCAL = PF_LOCAL;
238pub const AF_UNIX = AF_LOCAL;
239pub const AF_FILE = AF_LOCAL;
240pub const AF_INET = PF_INET;
241pub const AF_AX25 = PF_AX25;
242pub const AF_IPX = PF_IPX;
243pub const AF_APPLETALK = PF_APPLETALK;
244pub const AF_NETROM = PF_NETROM;
245pub const AF_BRIDGE = PF_BRIDGE;
246pub const AF_ATMPVC = PF_ATMPVC;
247pub const AF_X25 = PF_X25;
248pub const AF_INET6 = PF_INET6;
249pub const AF_ROSE = PF_ROSE;
250pub const AF_DECnet = PF_DECnet;
251pub const AF_NETBEUI = PF_NETBEUI;
252pub const AF_SECURITY = PF_SECURITY;
253pub const AF_KEY = PF_KEY;
254pub const AF_NETLINK = PF_NETLINK;
255pub const AF_ROUTE = PF_ROUTE;
256pub const AF_PACKET = PF_PACKET;
257pub const AF_ASH = PF_ASH;
258pub const AF_ECONET = PF_ECONET;
259pub const AF_ATMSVC = PF_ATMSVC;
260pub const AF_RDS = PF_RDS;
261pub const AF_SNA = PF_SNA;
262pub const AF_IRDA = PF_IRDA;
263pub const AF_PPPOX = PF_PPPOX;
264pub const AF_WANPIPE = PF_WANPIPE;
265pub const AF_LLC = PF_LLC;
266pub const AF_IB = PF_IB;
267pub const AF_MPLS = PF_MPLS;
268pub const AF_CAN = PF_CAN;
269pub const AF_TIPC = PF_TIPC;
270pub const AF_BLUETOOTH = PF_BLUETOOTH;
271pub const AF_IUCV = PF_IUCV;
272pub const AF_RXRPC = PF_RXRPC;
273pub const AF_ISDN = PF_ISDN;
274pub const AF_PHONET = PF_PHONET;
275pub const AF_IEEE802154 = PF_IEEE802154;
276pub const AF_CAIF = PF_CAIF;
277pub const AF_ALG = PF_ALG;
278pub const AF_NFC = PF_NFC;
279pub const AF_VSOCK = PF_VSOCK;
280pub const AF_KCM = PF_KCM;
281pub const AF_QIPCRTR = PF_QIPCRTR;
282pub const AF_SMC = PF_SMC;
283pub const AF_MAX = PF_MAX;
284
285pub const SO_DEBUG = 1;
286pub const SO_REUSEADDR = 2;
287pub const SO_TYPE = 3;
288pub const SO_ERROR = 4;
289pub const SO_DONTROUTE = 5;
290pub const SO_BROADCAST = 6;
291pub const SO_SNDBUF = 7;
292pub const SO_RCVBUF = 8;
293pub const SO_KEEPALIVE = 9;
294pub const SO_OOBINLINE = 10;
295pub const SO_NO_CHECK = 11;
296pub const SO_PRIORITY = 12;
297pub const SO_LINGER = 13;
298pub const SO_BSDCOMPAT = 14;
299pub const SO_REUSEPORT = 15;
300pub const SO_PASSCRED = 16;
301pub const SO_PEERCRED = 17;
302pub const SO_RCVLOWAT = 18;
303pub const SO_SNDLOWAT = 19;
304pub const SO_RCVTIMEO = 20;
305pub const SO_SNDTIMEO = 21;
306pub const SO_ACCEPTCONN = 30;
307pub const SO_SNDBUFFORCE = 32;
308pub const SO_RCVBUFFORCE = 33;
309pub const SO_PROTOCOL = 38;
310pub const SO_DOMAIN = 39;
311
312pub const SO_SECURITY_AUTHENTICATION = 22;
313pub const SO_SECURITY_ENCRYPTION_TRANSPORT = 23;
314pub const SO_SECURITY_ENCRYPTION_NETWORK = 24;
315
316pub const SO_BINDTODEVICE = 25;
317
318pub const SO_ATTACH_FILTER = 26;
319pub const SO_DETACH_FILTER = 27;
320pub const SO_GET_FILTER = SO_ATTACH_FILTER;
321
322pub const SO_PEERNAME = 28;
323pub const SO_TIMESTAMP = 29;
324pub const SCM_TIMESTAMP = SO_TIMESTAMP;
325
326pub const SO_PEERSEC = 31;
327pub const SO_PASSSEC = 34;
328pub const SO_TIMESTAMPNS = 35;
329pub const SCM_TIMESTAMPNS = SO_TIMESTAMPNS;
330pub const SO_MARK = 36;
331pub const SO_TIMESTAMPING = 37;
332pub const SCM_TIMESTAMPING = SO_TIMESTAMPING;
333pub const SO_RXQ_OVFL = 40;
334pub const SO_WIFI_STATUS = 41;
335pub const SCM_WIFI_STATUS = SO_WIFI_STATUS;
336pub const SO_PEEK_OFF = 42;
337pub const SO_NOFCS = 43;
338pub const SO_LOCK_FILTER = 44;
339pub const SO_SELECT_ERR_QUEUE = 45;
340pub const SO_BUSY_POLL = 46;
341pub const SO_MAX_PACING_RATE = 47;
342pub const SO_BPF_EXTENSIONS = 48;
343pub const SO_INCOMING_CPU = 49;
344pub const SO_ATTACH_BPF = 50;
345pub const SO_DETACH_BPF = SO_DETACH_FILTER;
346pub const SO_ATTACH_REUSEPORT_CBPF = 51;
347pub const SO_ATTACH_REUSEPORT_EBPF = 52;
348pub const SO_CNX_ADVICE = 53;
349pub const SCM_TIMESTAMPING_OPT_STATS = 54;
350pub const SO_MEMINFO = 55;
351pub const SO_INCOMING_NAPI_ID = 56;
352pub const SO_COOKIE = 57;
353pub const SCM_TIMESTAMPING_PKTINFO = 58;
354pub const SO_PEERGROUPS = 59;
355pub const SO_ZEROCOPY = 60;
356
357pub const SOL_SOCKET = 1;
358
359pub const SOL_IP = 0;
360pub const SOL_IPV6 = 41;
361pub const SOL_ICMPV6 = 58;
362
363pub const SOL_RAW = 255;
364pub const SOL_DECNET = 261;
365pub const SOL_X25 = 262;
366pub const SOL_PACKET = 263;
367pub const SOL_ATM = 264;
368pub const SOL_AAL = 265;
369pub const SOL_IRDA = 266;
370pub const SOL_NETBEUI = 267;
371pub const SOL_LLC = 268;
372pub const SOL_DCCP = 269;
373pub const SOL_NETLINK = 270;
374pub const SOL_TIPC = 271;
375pub const SOL_RXRPC = 272;
376pub const SOL_PPPOL2TP = 273;
377pub const SOL_BLUETOOTH = 274;
378pub const SOL_PNPIPE = 275;
379pub const SOL_RDS = 276;
380pub const SOL_IUCV = 277;
381pub const SOL_CAIF = 278;
382pub const SOL_ALG = 279;
383pub const SOL_NFC = 280;
384pub const SOL_KCM = 281;
385pub const SOL_TLS = 282;
386
387pub const SOMAXCONN = 128;
388
389pub const MSG_OOB = 0x0001;
390pub const MSG_PEEK = 0x0002;
391pub const MSG_DONTROUTE = 0x0004;
392pub const MSG_CTRUNC = 0x0008;
393pub const MSG_PROXY = 0x0010;
394pub const MSG_TRUNC = 0x0020;
395pub const MSG_DONTWAIT = 0x0040;
396pub const MSG_EOR = 0x0080;
397pub const MSG_WAITALL = 0x0100;
398pub const MSG_FIN = 0x0200;
399pub const MSG_SYN = 0x0400;
400pub const MSG_CONFIRM = 0x0800;
401pub const MSG_RST = 0x1000;
402pub const MSG_ERRQUEUE = 0x2000;
403pub const MSG_NOSIGNAL = 0x4000;
404pub const MSG_MORE = 0x8000;
405pub const MSG_WAITFORONE = 0x10000;
406pub const MSG_BATCH = 0x40000;
407pub const MSG_ZEROCOPY = 0x4000000;
408pub const MSG_FASTOPEN = 0x20000000;
409pub const MSG_CMSG_CLOEXEC = 0x40000000;
410
411pub const DT_UNKNOWN = 0;
412pub const DT_FIFO = 1;
413pub const DT_CHR = 2;
414pub const DT_DIR = 4;
415pub const DT_BLK = 6;
416pub const DT_REG = 8;
417pub const DT_LNK = 10;
418pub const DT_SOCK = 12;
419pub const DT_WHT = 14;
420
421pub const TCGETS = 0x5401;
422pub const TCSETS = 0x5402;
423pub const TCSETSW = 0x5403;
424pub const TCSETSF = 0x5404;
425pub const TCGETA = 0x5405;
426pub const TCSETA = 0x5406;
427pub const TCSETAW = 0x5407;
428pub const TCSETAF = 0x5408;
429pub const TCSBRK = 0x5409;
430pub const TCXONC = 0x540A;
431pub const TCFLSH = 0x540B;
432pub const TIOCEXCL = 0x540C;
433pub const TIOCNXCL = 0x540D;
434pub const TIOCSCTTY = 0x540E;
435pub const TIOCGPGRP = 0x540F;
436pub const TIOCSPGRP = 0x5410;
437pub const TIOCOUTQ = 0x5411;
438pub const TIOCSTI = 0x5412;
439pub const TIOCGWINSZ = 0x5413;
440pub const TIOCSWINSZ = 0x5414;
441pub const TIOCMGET = 0x5415;
442pub const TIOCMBIS = 0x5416;
443pub const TIOCMBIC = 0x5417;
444pub const TIOCMSET = 0x5418;
445pub const TIOCGSOFTCAR = 0x5419;
446pub const TIOCSSOFTCAR = 0x541A;
447pub const FIONREAD = 0x541B;
448pub const TIOCINQ = FIONREAD;
449pub const TIOCLINUX = 0x541C;
450pub const TIOCCONS = 0x541D;
451pub const TIOCGSERIAL = 0x541E;
452pub const TIOCSSERIAL = 0x541F;
453pub const TIOCPKT = 0x5420;
454pub const FIONBIO = 0x5421;
455pub const TIOCNOTTY = 0x5422;
456pub const TIOCSETD = 0x5423;
457pub const TIOCGETD = 0x5424;
458pub const TCSBRKP = 0x5425;
459pub const TIOCSBRK = 0x5427;
460pub const TIOCCBRK = 0x5428;
461pub const TIOCGSID = 0x5429;
462pub const TIOCGRS485 = 0x542E;
463pub const TIOCSRS485 = 0x542F;
464pub const TIOCGPTN = 0x80045430;
465pub const TIOCSPTLCK = 0x40045431;
466pub const TIOCGDEV = 0x80045432;
467pub const TCGETX = 0x5432;
468pub const TCSETX = 0x5433;
469pub const TCSETXF = 0x5434;
470pub const TCSETXW = 0x5435;
471pub const TIOCSIG = 0x40045436;
472pub const TIOCVHANGUP = 0x5437;
473pub const TIOCGPKT = 0x80045438;
474pub const TIOCGPTLCK = 0x80045439;
475pub const TIOCGEXCL = 0x80045440;
476
477pub const EPOLL_CLOEXEC = O_CLOEXEC;
478
479pub const EPOLL_CTL_ADD = 1;
480pub const EPOLL_CTL_DEL = 2;
481pub const EPOLL_CTL_MOD = 3;
482
483pub const EPOLLIN = 0x001;
484pub const EPOLLPRI = 0x002;
485pub const EPOLLOUT = 0x004;
486pub const EPOLLRDNORM = 0x040;
487pub const EPOLLRDBAND = 0x080;
488pub const EPOLLWRNORM = 0x100;
489pub const EPOLLWRBAND = 0x200;
490pub const EPOLLMSG = 0x400;
491pub const EPOLLERR = 0x008;
492pub const EPOLLHUP = 0x010;
493pub const EPOLLRDHUP = 0x2000;
494pub const EPOLLEXCLUSIVE = (u32(1) << 28);
495pub const EPOLLWAKEUP = (u32(1) << 29);
496pub const EPOLLONESHOT = (u32(1) << 30);
497pub const EPOLLET = (u32(1) << 31);
498
499pub const CLOCK_REALTIME = 0;
500pub const CLOCK_MONOTONIC = 1;
501pub const CLOCK_PROCESS_CPUTIME_ID = 2;
502pub const CLOCK_THREAD_CPUTIME_ID = 3;
503pub const CLOCK_MONOTONIC_RAW = 4;
504pub const CLOCK_REALTIME_COARSE = 5;
505pub const CLOCK_MONOTONIC_COARSE = 6;
506pub const CLOCK_BOOTTIME = 7;
507pub const CLOCK_REALTIME_ALARM = 8;
508pub const CLOCK_BOOTTIME_ALARM = 9;
509pub const CLOCK_SGI_CYCLE = 10;
510pub const CLOCK_TAI = 11;
511
512pub const CSIGNAL = 0x000000ff;
513pub const CLONE_VM = 0x00000100;
514pub const CLONE_FS = 0x00000200;
515pub const CLONE_FILES = 0x00000400;
516pub const CLONE_SIGHAND = 0x00000800;
517pub const CLONE_PTRACE = 0x00002000;
518pub const CLONE_VFORK = 0x00004000;
519pub const CLONE_PARENT = 0x00008000;
520pub const CLONE_THREAD = 0x00010000;
521pub const CLONE_NEWNS = 0x00020000;
522pub const CLONE_SYSVSEM = 0x00040000;
523pub const CLONE_SETTLS = 0x00080000;
524pub const CLONE_PARENT_SETTID = 0x00100000;
525pub const CLONE_CHILD_CLEARTID = 0x00200000;
526pub const CLONE_DETACHED = 0x00400000;
527pub const CLONE_UNTRACED = 0x00800000;
528pub const CLONE_CHILD_SETTID = 0x01000000;
529pub const CLONE_NEWCGROUP = 0x02000000;
530pub const CLONE_NEWUTS = 0x04000000;
531pub const CLONE_NEWIPC = 0x08000000;
532pub const CLONE_NEWUSER = 0x10000000;
533pub const CLONE_NEWPID = 0x20000000;
534pub const CLONE_NEWNET = 0x40000000;
535pub const CLONE_IO = 0x80000000;
536
537pub const EFD_SEMAPHORE = 1;
538pub const EFD_CLOEXEC = O_CLOEXEC;
539pub const EFD_NONBLOCK = O_NONBLOCK;
540
541pub const MS_RDONLY = 1;
542pub const MS_NOSUID = 2;
543pub const MS_NODEV = 4;
544pub const MS_NOEXEC = 8;
545pub const MS_SYNCHRONOUS = 16;
546pub const MS_REMOUNT = 32;
547pub const MS_MANDLOCK = 64;
548pub const MS_DIRSYNC = 128;
549pub const MS_NOATIME = 1024;
550pub const MS_NODIRATIME = 2048;
551pub const MS_BIND = 4096;
552pub const MS_MOVE = 8192;
553pub const MS_REC = 16384;
554pub const MS_SILENT = 32768;
555pub const MS_POSIXACL = (1 << 16);
556pub const MS_UNBINDABLE = (1 << 17);
557pub const MS_PRIVATE = (1 << 18);
558pub const MS_SLAVE = (1 << 19);
559pub const MS_SHARED = (1 << 20);
560pub const MS_RELATIME = (1 << 21);
561pub const MS_KERNMOUNT = (1 << 22);
562pub const MS_I_VERSION = (1 << 23);
563pub const MS_STRICTATIME = (1 << 24);
564pub const MS_LAZYTIME = (1 << 25);
565pub const MS_NOREMOTELOCK = (1 << 27);
566pub const MS_NOSEC = (1 << 28);
567pub const MS_BORN = (1 << 29);
568pub const MS_ACTIVE = (1 << 30);
569pub const MS_NOUSER = (1 << 31);
570
571pub const MS_RMT_MASK = (MS_RDONLY | MS_SYNCHRONOUS | MS_MANDLOCK | MS_I_VERSION | MS_LAZYTIME);
572
573pub const MS_MGC_VAL = 0xc0ed0000;
574pub const MS_MGC_MSK = 0xffff0000;
575
576pub const MNT_FORCE = 1;
577pub const MNT_DETACH = 2;
578pub const MNT_EXPIRE = 4;
579pub const UMOUNT_NOFOLLOW = 8;
580
581pub const IN_CLOEXEC = O_CLOEXEC;
582pub const IN_NONBLOCK = O_NONBLOCK;
583
584pub const IN_ACCESS = 0x00000001;
585pub const IN_MODIFY = 0x00000002;
586pub const IN_ATTRIB = 0x00000004;
587pub const IN_CLOSE_WRITE = 0x00000008;
588pub const IN_CLOSE_NOWRITE = 0x00000010;
589pub const IN_CLOSE = IN_CLOSE_WRITE | IN_CLOSE_NOWRITE;
590pub const IN_OPEN = 0x00000020;
591pub const IN_MOVED_FROM = 0x00000040;
592pub const IN_MOVED_TO = 0x00000080;
593pub const IN_MOVE = IN_MOVED_FROM | IN_MOVED_TO;
594pub const IN_CREATE = 0x00000100;
595pub const IN_DELETE = 0x00000200;
596pub const IN_DELETE_SELF = 0x00000400;
597pub const IN_MOVE_SELF = 0x00000800;
598pub const IN_ALL_EVENTS = 0x00000fff;
599
600pub const IN_UNMOUNT = 0x00002000;
601pub const IN_Q_OVERFLOW = 0x00004000;
602pub const IN_IGNORED = 0x00008000;
603
604pub const IN_ONLYDIR = 0x01000000;
605pub const IN_DONT_FOLLOW = 0x02000000;
606pub const IN_EXCL_UNLINK = 0x04000000;
607pub const IN_MASK_ADD = 0x20000000;
608
609pub const IN_ISDIR = 0x40000000;
610pub const IN_ONESHOT = 0x80000000;
611
612pub const S_IFMT = 0o170000;
613
614pub const S_IFDIR = 0o040000;
615pub const S_IFCHR = 0o020000;
616pub const S_IFBLK = 0o060000;
617pub const S_IFREG = 0o100000;
618pub const S_IFIFO = 0o010000;
619pub const S_IFLNK = 0o120000;
620pub const S_IFSOCK = 0o140000;
621
622pub const S_ISUID = 0o4000;
623pub const S_ISGID = 0o2000;
624pub const S_ISVTX = 0o1000;
625pub const S_IRUSR = 0o400;
626pub const S_IWUSR = 0o200;
627pub const S_IXUSR = 0o100;
628pub const S_IRWXU = 0o700;
629pub const S_IRGRP = 0o040;
630pub const S_IWGRP = 0o020;
631pub const S_IXGRP = 0o010;
632pub const S_IRWXG = 0o070;
633pub const S_IROTH = 0o004;
634pub const S_IWOTH = 0o002;
635pub const S_IXOTH = 0o001;
636pub const S_IRWXO = 0o007;
637
638pub fn S_ISREG(m: u32) bool {
639 return m & S_IFMT == S_IFREG;
640}
641
642pub fn S_ISDIR(m: u32) bool {
643 return m & S_IFMT == S_IFDIR;
644}
645
646pub fn S_ISCHR(m: u32) bool {
647 return m & S_IFMT == S_IFCHR;
648}
649
650pub fn S_ISBLK(m: u32) bool {
651 return m & S_IFMT == S_IFBLK;
652}
653
654pub fn S_ISFIFO(m: u32) bool {
655 return m & S_IFMT == S_IFIFO;
656}
657
658pub fn S_ISLNK(m: u32) bool {
659 return m & S_IFMT == S_IFLNK;
660}
661
662pub fn S_ISSOCK(m: u32) bool {
663 return m & S_IFMT == S_IFSOCK;
664}
665
666pub const TFD_NONBLOCK = O_NONBLOCK;
667pub const TFD_CLOEXEC = O_CLOEXEC;
668
669pub const TFD_TIMER_ABSTIME = 1;
670pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1);
671
672fn unsigned(s: i32) u32 {
673 return @bitCast(u32, s);
674}
675fn signed(s: u32) i32 {
676 return @bitCast(i32, s);
677}
678pub fn WEXITSTATUS(s: i32) i32 {
679 return signed((unsigned(s) & 0xff00) >> 8);
680}
681pub fn WTERMSIG(s: i32) i32 {
682 return signed(unsigned(s) & 0x7f);
683}
684pub fn WSTOPSIG(s: i32) i32 {
685 return WEXITSTATUS(s);
686}
687pub fn WIFEXITED(s: i32) bool {
688 return WTERMSIG(s) == 0;
689}
690pub fn WIFSTOPPED(s: i32) bool {
691 return @intCast(u16, ((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00;
692}
693pub fn WIFSIGNALED(s: i32) bool {
694 return (unsigned(s) & 0xffff) -% 1 < 0xff;
695}
696
697pub const winsize = extern struct {
698 ws_row: u16,
699 ws_col: u16,
700 ws_xpixel: u16,
701 ws_ypixel: u16,
702};
703
70421/// Get the errno from a syscall return value, or 0 for no error.
70522pub fn getErrno(r: usize) u12 {
70623 const signed_r = @bitCast(isize, r);
......@@ -708,7 +25,7 @@ pub fn getErrno(r: usize) u12 {
70825}
70926
71027pub 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)));
71229}
71330
71431pub 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 ?[*
73148}
73249
73350pub fn fork() usize {
734 return clone2(SIGCHLD, 0);
51 return syscall0(SYS_fork);
73552}
73653
73754/// 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 {
75572 return syscall2(SYS_getcwd, @ptrToInt(buf), size);
75673}
75774
75pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
76 return syscall3(SYS_getdents, @bitCast(usize, isize(fd)), @ptrToInt(dirp), count);
77}
78
75879pub fn getdents64(fd: i32, dirp: [*]u8, count: usize) usize {
75980 return syscall3(SYS_getdents64, @bitCast(usize, isize(fd)), @ptrToInt(dirp), count);
76081}
......@@ -773,7 +94,7 @@ pub fn inotify_rm_watch(fd: i32, wd: i32) usize {
77394
77495// TODO https://github.com/ziglang/zig/issues/265
77596pub 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);
77798}
77899
779100// 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,
783104
784105// TODO https://github.com/ziglang/zig/issues/265
785106pub fn mkdir(path: [*]const u8, mode: u32) usize {
786 return mkdirat(AT_FDCWD, path, mode);
107 return syscall2(SYS_mkdir, @ptrToInt(path), mode);
787108}
788109
789110// 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
840161
841162// TODO https://github.com/ziglang/zig/issues/265
842163pub fn rmdir(path: [*]const u8) usize {
843 return unlinkat(AT_FDCWD, path, AT_REMOVEDIR);
164 return syscall1(SYS_rmdir, @ptrToInt(path));
844165}
845166
846167// TODO https://github.com/ziglang/zig/issues/265
847168pub 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));
849170}
850171
851172// TODO https://github.com/ziglang/zig/issues/265
......@@ -860,9 +181,10 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
860181
861182// TODO https://github.com/ziglang/zig/issues/265
862183pub fn access(path: [*]const u8, mode: u32) usize {
863 return faccessat(AT_FDCWD, path, mode);
184 return syscall2(SYS_access, @ptrToInt(path), mode);
864185}
865186
187// TODO https://github.com/ziglang/zig/issues/265
866188pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32) usize {
867189 return syscall3(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode);
868190}
......@@ -885,7 +207,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
885207
886208// TODO https://github.com/ziglang/zig/issues/265
887209pub 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));
889211}
890212
891213// TODO https://github.com/ziglang/zig/issues/265
......@@ -895,7 +217,7 @@ pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
895217
896218// TODO https://github.com/ziglang/zig/issues/265
897219pub 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);
899221}
900222
901223// TODO https://github.com/ziglang/zig/issues/265
......@@ -947,7 +269,7 @@ pub fn kill(pid: i32, sig: i32) usize {
947269
948270// TODO https://github.com/ziglang/zig/issues/265
949271pub fn unlink(path: [*]const u8) usize {
950 return unlinkat(AT_FDCWD, path, 0);
272 return syscall1(SYS_unlink, @ptrToInt(path));
951273}
952274
953275// TODO https://github.com/ziglang/zig/issues/265
......@@ -1113,30 +435,6 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti
1113435 return 0;
1114436}
1115437
1116const NSIG = 65;
1117const sigset_t = [128 / @sizeOf(usize)]usize;
1118const all_mask = []u32{ 0xffffffff, 0xffffffff };
1119const app_mask = []u32{ 0xfffffffc, 0x7fffffff };
1120
1121const 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.
1129pub const Sigaction = struct {
1130 handler: extern fn (i32) void,
1131 mask: sigset_t,
1132 flags: u32,
1133};
1134
1135pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
1136pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
1137pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
1138pub const empty_sigset = []usize{0} ** sigset_t.len;
1139
1140438fn blockAllSignals(set: *sigset_t) void {
1141439 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG / 8);
1142440}
......@@ -1159,56 +457,6 @@ pub fn sigismember(set: *const sigset_t, sig: u6) bool {
1159457 return ((set.*)[@intCast(usize, s) / usize.bit_count] & (@intCast(usize, 1) << (s & (usize.bit_count - 1)))) != 0;
1160458}
1161459
1162pub const in_port_t = u16;
1163pub const sa_family_t = u16;
1164pub const socklen_t = u32;
1165
1166/// This intentionally only has ip4 and ip6
1167pub const sockaddr = extern union {
1168 in: sockaddr_in,
1169 in6: sockaddr_in6,
1170};
1171
1172pub const sockaddr_in = extern struct {
1173 family: sa_family_t,
1174 port: in_port_t,
1175 addr: u32,
1176 zero: [8]u8,
1177};
1178
1179pub 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
1187pub const sockaddr_un = extern struct {
1188 family: sa_family_t,
1189 path: [108]u8,
1190};
1191
1192pub const iovec = extern struct {
1193 iov_base: [*]u8,
1194 iov_len: usize,
1195};
1196
1197pub const iovec_const = extern struct {
1198 iov_base: [*]const u8,
1199 iov_len: usize,
1200};
1201
1202pub const mmsghdr = extern struct {
1203 msg_hdr: msghdr,
1204 msg_len: u32,
1205};
1206
1207pub const mmsghdr_const = extern struct {
1208 msg_hdr: msghdr_const,
1209 msg_len: u32,
1210};
1211
1212460pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
1213461 return syscall3(SYS_getsockname, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len));
1214462}
......@@ -1319,12 +567,12 @@ pub fn fstat(fd: i32, stat_buf: *Stat) usize {
1319567
1320568// TODO https://github.com/ziglang/zig/issues/265
1321569pub 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));
1323571}
1324572
1325573// TODO https://github.com/ziglang/zig/issues/265
1326574pub 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));
1328576}
1329577
1330578// TODO https://github.com/ziglang/zig/issues/265
......@@ -1395,26 +643,6 @@ pub fn sched_getaffinity(pid: i32, set: []usize) usize {
1395643 return syscall3(SYS_sched_getaffinity, @bitCast(usize, isize(pid)), set.len * @sizeOf(usize), @ptrToInt(set.ptr));
1396644}
1397645
1398pub 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
1407pub const epoll_event = if (builtin.arch != .x86_64)
1408 extern struct {
1409 events: u32,
1410 data: epoll_data,
1411 }
1412else
1413 packed struct {
1414 events: u32,
1415 data: epoll_data,
1416 };
1417
1418646pub fn epoll_create() usize {
1419647 return epoll_create1(0);
1420648}
......@@ -1428,7 +656,13 @@ pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: *epoll_event) usize {
1428656}
1429657
1430658pub 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 );
1432666}
1433667
1434668pub 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
1464698 return syscall4(SYS_timerfd_settime, @bitCast(usize, isize(fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value));
1465699}
1466700
1467pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330;
1468pub const _LINUX_CAPABILITY_U32S_1 = 1;
1469
1470pub const _LINUX_CAPABILITY_VERSION_2 = 0x20071026;
1471pub const _LINUX_CAPABILITY_U32S_2 = 2;
1472
1473pub const _LINUX_CAPABILITY_VERSION_3 = 0x20080522;
1474pub const _LINUX_CAPABILITY_U32S_3 = 2;
1475
1476pub const VFS_CAP_REVISION_MASK = 0xFF000000;
1477pub const VFS_CAP_REVISION_SHIFT = 24;
1478pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK;
1479pub const VFS_CAP_FLAGS_EFFECTIVE = 0x000001;
1480
1481pub const VFS_CAP_REVISION_1 = 0x01000000;
1482pub const VFS_CAP_U32_1 = 1;
1483pub const XATTR_CAPS_SZ_1 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_1);
1484
1485pub const VFS_CAP_REVISION_2 = 0x02000000;
1486pub const VFS_CAP_U32_2 = 2;
1487pub const XATTR_CAPS_SZ_2 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_2);
1488
1489pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2;
1490pub const VFS_CAP_U32 = VFS_CAP_U32_2;
1491pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2;
1492
1493pub 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
1505pub const CAP_CHOWN = 0;
1506pub const CAP_DAC_OVERRIDE = 1;
1507pub const CAP_DAC_READ_SEARCH = 2;
1508pub const CAP_FOWNER = 3;
1509pub const CAP_FSETID = 4;
1510pub const CAP_KILL = 5;
1511pub const CAP_SETGID = 6;
1512pub const CAP_SETUID = 7;
1513pub const CAP_SETPCAP = 8;
1514pub const CAP_LINUX_IMMUTABLE = 9;
1515pub const CAP_NET_BIND_SERVICE = 10;
1516pub const CAP_NET_BROADCAST = 11;
1517pub const CAP_NET_ADMIN = 12;
1518pub const CAP_NET_RAW = 13;
1519pub const CAP_IPC_LOCK = 14;
1520pub const CAP_IPC_OWNER = 15;
1521pub const CAP_SYS_MODULE = 16;
1522pub const CAP_SYS_RAWIO = 17;
1523pub const CAP_SYS_CHROOT = 18;
1524pub const CAP_SYS_PTRACE = 19;
1525pub const CAP_SYS_PACCT = 20;
1526pub const CAP_SYS_ADMIN = 21;
1527pub const CAP_SYS_BOOT = 22;
1528pub const CAP_SYS_NICE = 23;
1529pub const CAP_SYS_RESOURCE = 24;
1530pub const CAP_SYS_TIME = 25;
1531pub const CAP_SYS_TTY_CONFIG = 26;
1532pub const CAP_MKNOD = 27;
1533pub const CAP_LEASE = 28;
1534pub const CAP_AUDIT_WRITE = 29;
1535pub const CAP_AUDIT_CONTROL = 30;
1536pub const CAP_SETFCAP = 31;
1537pub const CAP_MAC_OVERRIDE = 32;
1538pub const CAP_MAC_ADMIN = 33;
1539pub const CAP_SYSLOG = 34;
1540pub const CAP_WAKE_ALARM = 35;
1541pub const CAP_BLOCK_SUSPEND = 36;
1542pub const CAP_AUDIT_READ = 37;
1543pub const CAP_LAST_CAP = CAP_AUDIT_READ;
1544
1545pub fn cap_valid(u8: x) bool {
1546 return x >= 0 and x <= CAP_LAST_CAP;
1547}
1548
1549pub fn CAP_TO_MASK(cap: u8) u32 {
1550 return u32(1) << u5(cap & 31);
1551}
1552
1553pub fn CAP_TO_INDEX(cap: u8) u8 {
1554 return cap >> 5;
1555}
1556
1557pub const cap_t = extern struct {
1558 hdrp: *cap_user_header_t,
1559 datap: *cap_user_data_t,
1560};
1561
1562pub const cap_user_header_t = extern struct {
1563 version: u32,
1564 pid: usize,
1565};
1566
1567pub const cap_user_data_t = extern struct {
1568 effective: u32,
1569 permitted: u32,
1570 inheritable: u32,
1571};
1572
1573701pub fn unshare(flags: usize) usize {
1574702 return syscall1(SYS_unshare, flags);
1575703}
......@@ -1582,29 +710,6 @@ pub fn capset(hdrp: *cap_user_header_t, datap: *const cap_user_data_t) usize {
1582710 return syscall2(SYS_capset, @ptrToInt(hdrp), @ptrToInt(datap));
1583711}
1584712
1585pub const inotify_event = extern struct {
1586 wd: i32,
1587 mask: u32,
1588 cookie: u32,
1589 len: u32,
1590 //name: [?]u8,
1591};
1592
1593pub 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
1601pub 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
1608713// XXX: This should be weak
1609714extern const __ehdr_start: elf.Ehdr = undefined;
1610715
std/os/linux/arm64.zig-403
......@@ -1,344 +1,3 @@
1const std = @import("../../std.zig");
2const linux = std.os.linux;
3const socklen_t = linux.socklen_t;
4const iovec = linux.iovec;
5const iovec_const = linux.iovec_const;
6
7pub const SYS_io_setup = 0;
8pub const SYS_io_destroy = 1;
9pub const SYS_io_submit = 2;
10pub const SYS_io_cancel = 3;
11pub const SYS_io_getevents = 4;
12pub const SYS_setxattr = 5;
13pub const SYS_lsetxattr = 6;
14pub const SYS_fsetxattr = 7;
15pub const SYS_getxattr = 8;
16pub const SYS_lgetxattr = 9;
17pub const SYS_fgetxattr = 10;
18pub const SYS_listxattr = 11;
19pub const SYS_llistxattr = 12;
20pub const SYS_flistxattr = 13;
21pub const SYS_removexattr = 14;
22pub const SYS_lremovexattr = 15;
23pub const SYS_fremovexattr = 16;
24pub const SYS_getcwd = 17;
25pub const SYS_lookup_dcookie = 18;
26pub const SYS_eventfd2 = 19;
27pub const SYS_epoll_create1 = 20;
28pub const SYS_epoll_ctl = 21;
29pub const SYS_epoll_pwait = 22;
30pub const SYS_dup = 23;
31pub const SYS_dup3 = 24;
32pub const SYS_fcntl = 25;
33pub const SYS_inotify_init1 = 26;
34pub const SYS_inotify_add_watch = 27;
35pub const SYS_inotify_rm_watch = 28;
36pub const SYS_ioctl = 29;
37pub const SYS_ioprio_set = 30;
38pub const SYS_ioprio_get = 31;
39pub const SYS_flock = 32;
40pub const SYS_mknodat = 33;
41pub const SYS_mkdirat = 34;
42pub const SYS_unlinkat = 35;
43pub const SYS_symlinkat = 36;
44pub const SYS_linkat = 37;
45pub const SYS_renameat = 38;
46pub const SYS_umount2 = 39;
47pub const SYS_mount = 40;
48pub const SYS_pivot_root = 41;
49pub const SYS_nfsservctl = 42;
50pub const SYS_statfs = 43;
51pub const SYS_fstatfs = 44;
52pub const SYS_truncate = 45;
53pub const SYS_ftruncate = 46;
54pub const SYS_fallocate = 47;
55pub const SYS_faccessat = 48;
56pub const SYS_chdir = 49;
57pub const SYS_fchdir = 50;
58pub const SYS_chroot = 51;
59pub const SYS_fchmod = 52;
60pub const SYS_fchmodat = 53;
61pub const SYS_fchownat = 54;
62pub const SYS_fchown = 55;
63pub const SYS_openat = 56;
64pub const SYS_close = 57;
65pub const SYS_vhangup = 58;
66pub const SYS_pipe2 = 59;
67pub const SYS_quotactl = 60;
68pub const SYS_getdents64 = 61;
69pub const SYS_lseek = 62;
70pub const SYS_read = 63;
71pub const SYS_write = 64;
72pub const SYS_readv = 65;
73pub const SYS_writev = 66;
74pub const SYS_pread64 = 67;
75pub const SYS_pwrite64 = 68;
76pub const SYS_preadv = 69;
77pub const SYS_pwritev = 70;
78pub const SYS_pselect6 = 72;
79pub const SYS_ppoll = 73;
80pub const SYS_signalfd4 = 74;
81pub const SYS_vmsplice = 75;
82pub const SYS_splice = 76;
83pub const SYS_tee = 77;
84pub const SYS_readlinkat = 78;
85pub const SYS_fstatat = 79;
86pub const SYS_fstat = 80;
87pub const SYS_sync = 81;
88pub const SYS_fsync = 82;
89pub const SYS_fdatasync = 83;
90pub const SYS_sync_file_range2 = 84;
91pub const SYS_sync_file_range = 84;
92pub const SYS_timerfd_create = 85;
93pub const SYS_timerfd_settime = 86;
94pub const SYS_timerfd_gettime = 87;
95pub const SYS_utimensat = 88;
96pub const SYS_acct = 89;
97pub const SYS_capget = 90;
98pub const SYS_capset = 91;
99pub const SYS_personality = 92;
100pub const SYS_exit = 93;
101pub const SYS_exit_group = 94;
102pub const SYS_waitid = 95;
103pub const SYS_set_tid_address = 96;
104pub const SYS_unshare = 97;
105pub const SYS_futex = 98;
106pub const SYS_set_robust_list = 99;
107pub const SYS_get_robust_list = 100;
108pub const SYS_nanosleep = 101;
109pub const SYS_getitimer = 102;
110pub const SYS_setitimer = 103;
111pub const SYS_kexec_load = 104;
112pub const SYS_init_module = 105;
113pub const SYS_delete_module = 106;
114pub const SYS_timer_create = 107;
115pub const SYS_timer_gettime = 108;
116pub const SYS_timer_getoverrun = 109;
117pub const SYS_timer_settime = 110;
118pub const SYS_timer_delete = 111;
119pub const SYS_clock_settime = 112;
120pub const SYS_clock_gettime = 113;
121pub const SYS_clock_getres = 114;
122pub const SYS_clock_nanosleep = 115;
123pub const SYS_syslog = 116;
124pub const SYS_ptrace = 117;
125pub const SYS_sched_setparam = 118;
126pub const SYS_sched_setscheduler = 119;
127pub const SYS_sched_getscheduler = 120;
128pub const SYS_sched_getparam = 121;
129pub const SYS_sched_setaffinity = 122;
130pub const SYS_sched_getaffinity = 123;
131pub const SYS_sched_yield = 124;
132pub const SYS_sched_get_priority_max = 125;
133pub const SYS_sched_get_priority_min = 126;
134pub const SYS_sched_rr_get_interval = 127;
135pub const SYS_restart_syscall = 128;
136pub const SYS_kill = 129;
137pub const SYS_tkill = 130;
138pub const SYS_tgkill = 131;
139pub const SYS_sigaltstack = 132;
140pub const SYS_rt_sigsuspend = 133;
141pub const SYS_rt_sigaction = 134;
142pub const SYS_rt_sigprocmask = 135;
143pub const SYS_rt_sigpending = 136;
144pub const SYS_rt_sigtimedwait = 137;
145pub const SYS_rt_sigqueueinfo = 138;
146pub const SYS_rt_sigreturn = 139;
147pub const SYS_setpriority = 140;
148pub const SYS_getpriority = 141;
149pub const SYS_reboot = 142;
150pub const SYS_setregid = 143;
151pub const SYS_setgid = 144;
152pub const SYS_setreuid = 145;
153pub const SYS_setuid = 146;
154pub const SYS_setresuid = 147;
155pub const SYS_getresuid = 148;
156pub const SYS_setresgid = 149;
157pub const SYS_getresgid = 150;
158pub const SYS_setfsuid = 151;
159pub const SYS_setfsgid = 152;
160pub const SYS_times = 153;
161pub const SYS_setpgid = 154;
162pub const SYS_getpgid = 155;
163pub const SYS_getsid = 156;
164pub const SYS_setsid = 157;
165pub const SYS_getgroups = 158;
166pub const SYS_setgroups = 159;
167pub const SYS_uname = 160;
168pub const SYS_sethostname = 161;
169pub const SYS_setdomainname = 162;
170pub const SYS_getrlimit = 163;
171pub const SYS_setrlimit = 164;
172pub const SYS_getrusage = 165;
173pub const SYS_umask = 166;
174pub const SYS_prctl = 167;
175pub const SYS_getcpu = 168;
176pub const SYS_gettimeofday = 169;
177pub const SYS_settimeofday = 170;
178pub const SYS_adjtimex = 171;
179pub const SYS_getpid = 172;
180pub const SYS_getppid = 173;
181pub const SYS_getuid = 174;
182pub const SYS_geteuid = 175;
183pub const SYS_getgid = 176;
184pub const SYS_getegid = 177;
185pub const SYS_gettid = 178;
186pub const SYS_sysinfo = 179;
187pub const SYS_mq_open = 180;
188pub const SYS_mq_unlink = 181;
189pub const SYS_mq_timedsend = 182;
190pub const SYS_mq_timedreceive = 183;
191pub const SYS_mq_notify = 184;
192pub const SYS_mq_getsetattr = 185;
193pub const SYS_msgget = 186;
194pub const SYS_msgctl = 187;
195pub const SYS_msgrcv = 188;
196pub const SYS_msgsnd = 189;
197pub const SYS_semget = 190;
198pub const SYS_semctl = 191;
199pub const SYS_semtimedop = 192;
200pub const SYS_semop = 193;
201pub const SYS_shmget = 194;
202pub const SYS_shmctl = 195;
203pub const SYS_shmat = 196;
204pub const SYS_shmdt = 197;
205pub const SYS_socket = 198;
206pub const SYS_socketpair = 199;
207pub const SYS_bind = 200;
208pub const SYS_listen = 201;
209pub const SYS_accept = 202;
210pub const SYS_connect = 203;
211pub const SYS_getsockname = 204;
212pub const SYS_getpeername = 205;
213pub const SYS_sendto = 206;
214pub const SYS_recvfrom = 207;
215pub const SYS_setsockopt = 208;
216pub const SYS_getsockopt = 209;
217pub const SYS_shutdown = 210;
218pub const SYS_sendmsg = 211;
219pub const SYS_recvmsg = 212;
220pub const SYS_readahead = 213;
221pub const SYS_brk = 214;
222pub const SYS_munmap = 215;
223pub const SYS_mremap = 216;
224pub const SYS_add_key = 217;
225pub const SYS_request_key = 218;
226pub const SYS_keyctl = 219;
227pub const SYS_clone = 220;
228pub const SYS_execve = 221;
229pub const SYS_mmap = 222;
230pub const SYS_fadvise64 = 223;
231pub const SYS_swapon = 224;
232pub const SYS_swapoff = 225;
233pub const SYS_mprotect = 226;
234pub const SYS_msync = 227;
235pub const SYS_mlock = 228;
236pub const SYS_munlock = 229;
237pub const SYS_mlockall = 230;
238pub const SYS_munlockall = 231;
239pub const SYS_mincore = 232;
240pub const SYS_madvise = 233;
241pub const SYS_remap_file_pages = 234;
242pub const SYS_mbind = 235;
243pub const SYS_get_mempolicy = 236;
244pub const SYS_set_mempolicy = 237;
245pub const SYS_migrate_pages = 238;
246pub const SYS_move_pages = 239;
247pub const SYS_rt_tgsigqueueinfo = 240;
248pub const SYS_perf_event_open = 241;
249pub const SYS_accept4 = 242;
250pub const SYS_recvmmsg = 243;
251pub const SYS_arch_specific_syscall = 244;
252pub const SYS_wait4 = 260;
253pub const SYS_prlimit64 = 261;
254pub const SYS_fanotify_init = 262;
255pub const SYS_fanotify_mark = 263;
256pub const SYS_clock_adjtime = 266;
257pub const SYS_syncfs = 267;
258pub const SYS_setns = 268;
259pub const SYS_sendmmsg = 269;
260pub const SYS_process_vm_readv = 270;
261pub const SYS_process_vm_writev = 271;
262pub const SYS_kcmp = 272;
263pub const SYS_finit_module = 273;
264pub const SYS_sched_setattr = 274;
265pub const SYS_sched_getattr = 275;
266pub const SYS_renameat2 = 276;
267pub const SYS_seccomp = 277;
268pub const SYS_getrandom = 278;
269pub const SYS_memfd_create = 279;
270pub const SYS_bpf = 280;
271pub const SYS_execveat = 281;
272pub const SYS_userfaultfd = 282;
273pub const SYS_membarrier = 283;
274pub const SYS_mlock2 = 284;
275pub const SYS_copy_file_range = 285;
276pub const SYS_preadv2 = 286;
277pub const SYS_pwritev2 = 287;
278pub const SYS_pkey_mprotect = 288;
279pub const SYS_pkey_alloc = 289;
280pub const SYS_pkey_free = 290;
281pub const SYS_statx = 291;
282pub const SYS_io_pgetevents = 292;
283pub const SYS_rseq = 293;
284pub const SYS_kexec_file_load = 294;
285pub const SYS_pidfd_send_signal = 424;
286pub const SYS_io_uring_setup = 425;
287pub const SYS_io_uring_enter = 426;
288pub const SYS_io_uring_register = 427;
289
290pub const O_CREAT = 0o100;
291pub const O_EXCL = 0o200;
292pub const O_NOCTTY = 0o400;
293pub const O_TRUNC = 0o1000;
294pub const O_APPEND = 0o2000;
295pub const O_NONBLOCK = 0o4000;
296pub const O_DSYNC = 0o10000;
297pub const O_SYNC = 0o4010000;
298pub const O_RSYNC = 0o4010000;
299pub const O_DIRECTORY = 0o200000;
300pub const O_NOFOLLOW = 0o400000;
301pub const O_CLOEXEC = 0o2000000;
302
303pub const O_ASYNC = 0o20000;
304pub const O_DIRECT = 0o40000;
305pub const O_LARGEFILE = 0;
306pub const O_NOATIME = 0o1000000;
307pub const O_PATH = 0o10000000;
308pub const O_TMPFILE = 0o20200000;
309pub const O_NDELAY = O_NONBLOCK;
310
311pub const F_DUPFD = 0;
312pub const F_GETFD = 1;
313pub const F_SETFD = 2;
314pub const F_GETFL = 3;
315pub const F_SETFL = 4;
316
317pub const F_SETOWN = 8;
318pub const F_GETOWN = 9;
319pub const F_SETSIG = 10;
320pub const F_GETSIG = 11;
321
322pub const F_GETLK = 5;
323pub const F_SETLK = 6;
324pub const F_SETLKW = 7;
325
326pub const F_SETOWN_EX = 15;
327pub const F_GETOWN_EX = 16;
328
329pub const F_GETOWNER_UIDS = 17;
330
331pub const AT_FDCWD = -100;
332pub const AT_SYMLINK_NOFOLLOW = 0x100;
333pub const AT_REMOVEDIR = 0x200;
334pub const AT_SYMLINK_FOLLOW = 0x400;
335pub const AT_NO_AUTOMOUNT = 0x800;
336pub const AT_EMPTY_PATH = 0x1000;
337
338pub const VDSO_USEFUL = true;
339pub const VDSO_CGT_SYM = "__kernel_clock_gettime";
340pub const VDSO_CGT_VER = "LINUX_2.6.39";
341
3421pub fn syscall0(number: usize) usize {
3432 return asm volatile ("svc #0"
3443 : [ret] "={x0}" (-> usize)
......@@ -419,65 +78,3 @@ pub fn syscall6(
41978
42079/// This matches the libc clone function.
42180pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
422
423pub 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
435pub 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.
448pub 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
468pub const timespec = extern struct {
469 tv_sec: isize,
470 tv_nsec: isize,
471};
472
473pub const timeval = extern struct {
474 tv_sec: isize,
475 tv_usec: isize,
476};
477
478pub const timezone = extern struct {
479 tz_minuteswest: i32,
480 tz_dsttime: i32,
481};
482
483pub 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
4pub use @import("errno.zig");
5pub use switch (builtin.arch) {
6 .x86_64 => @import("posix/x86_64.zig"),
7 .aarch64 => @import("posix/arm64.zig"),
8 else => struct {},
9};
10
11pub const pid_t = i32;
12pub const fd_t = i32;
13
14pub const PATH_MAX = 4096;
15pub const IOV_MAX = 1024;
16
17pub const STDIN_FILENO = 0;
18pub const STDOUT_FILENO = 1;
19pub const STDERR_FILENO = 2;
20
21pub const FUTEX_WAIT = 0;
22pub const FUTEX_WAKE = 1;
23pub const FUTEX_FD = 2;
24pub const FUTEX_REQUEUE = 3;
25pub const FUTEX_CMP_REQUEUE = 4;
26pub const FUTEX_WAKE_OP = 5;
27pub const FUTEX_LOCK_PI = 6;
28pub const FUTEX_UNLOCK_PI = 7;
29pub const FUTEX_TRYLOCK_PI = 8;
30pub const FUTEX_WAIT_BITSET = 9;
31
32pub const FUTEX_PRIVATE_FLAG = 128;
33
34pub const FUTEX_CLOCK_REALTIME = 256;
35
36pub const PROT_NONE = 0;
37pub const PROT_READ = 1;
38pub const PROT_WRITE = 2;
39pub const PROT_EXEC = 4;
40pub const PROT_GROWSDOWN = 0x01000000;
41pub const PROT_GROWSUP = 0x02000000;
42
43pub const MAP_FAILED = maxInt(usize);
44pub const MAP_SHARED = 0x01;
45pub const MAP_PRIVATE = 0x02;
46pub const MAP_TYPE = 0x0f;
47pub const MAP_FIXED = 0x10;
48pub const MAP_ANONYMOUS = 0x20;
49pub const MAP_NORESERVE = 0x4000;
50pub const MAP_GROWSDOWN = 0x0100;
51pub const MAP_DENYWRITE = 0x0800;
52pub const MAP_EXECUTABLE = 0x1000;
53pub const MAP_LOCKED = 0x2000;
54pub const MAP_POPULATE = 0x8000;
55pub const MAP_NONBLOCK = 0x10000;
56pub const MAP_STACK = 0x20000;
57pub const MAP_HUGETLB = 0x40000;
58pub const MAP_FILE = 0;
59
60pub const F_OK = 0;
61pub const X_OK = 1;
62pub const W_OK = 2;
63pub const R_OK = 4;
64
65pub const WNOHANG = 1;
66pub const WUNTRACED = 2;
67pub const WSTOPPED = 2;
68pub const WEXITED = 4;
69pub const WCONTINUED = 8;
70pub const WNOWAIT = 0x1000000;
71
72pub const SA_NOCLDSTOP = 1;
73pub const SA_NOCLDWAIT = 2;
74pub const SA_SIGINFO = 4;
75pub const SA_ONSTACK = 0x08000000;
76pub const SA_RESTART = 0x10000000;
77pub const SA_NODEFER = 0x40000000;
78pub const SA_RESETHAND = 0x80000000;
79pub const SA_RESTORER = 0x04000000;
80
81pub const SIGHUP = 1;
82pub const SIGINT = 2;
83pub const SIGQUIT = 3;
84pub const SIGILL = 4;
85pub const SIGTRAP = 5;
86pub const SIGABRT = 6;
87pub const SIGIOT = SIGABRT;
88pub const SIGBUS = 7;
89pub const SIGFPE = 8;
90pub const SIGKILL = 9;
91pub const SIGUSR1 = 10;
92pub const SIGSEGV = 11;
93pub const SIGUSR2 = 12;
94pub const SIGPIPE = 13;
95pub const SIGALRM = 14;
96pub const SIGTERM = 15;
97pub const SIGSTKFLT = 16;
98pub const SIGCHLD = 17;
99pub const SIGCONT = 18;
100pub const SIGSTOP = 19;
101pub const SIGTSTP = 20;
102pub const SIGTTIN = 21;
103pub const SIGTTOU = 22;
104pub const SIGURG = 23;
105pub const SIGXCPU = 24;
106pub const SIGXFSZ = 25;
107pub const SIGVTALRM = 26;
108pub const SIGPROF = 27;
109pub const SIGWINCH = 28;
110pub const SIGIO = 29;
111pub const SIGPOLL = 29;
112pub const SIGPWR = 30;
113pub const SIGSYS = 31;
114pub const SIGUNUSED = SIGSYS;
115
116pub const O_RDONLY = 0o0;
117pub const O_WRONLY = 0o1;
118pub const O_RDWR = 0o2;
119
120pub const SEEK_SET = 0;
121pub const SEEK_CUR = 1;
122pub const SEEK_END = 2;
123
124pub const SIG_BLOCK = 0;
125pub const SIG_UNBLOCK = 1;
126pub const SIG_SETMASK = 2;
127
128pub const PROTO_ip = 0o000;
129pub const PROTO_icmp = 0o001;
130pub const PROTO_igmp = 0o002;
131pub const PROTO_ggp = 0o003;
132pub const PROTO_ipencap = 0o004;
133pub const PROTO_st = 0o005;
134pub const PROTO_tcp = 0o006;
135pub const PROTO_egp = 0o010;
136pub const PROTO_pup = 0o014;
137pub const PROTO_udp = 0o021;
138pub const PROTO_hmp = 0o024;
139pub const PROTO_xns_idp = 0o026;
140pub const PROTO_rdp = 0o033;
141pub const PROTO_iso_tp4 = 0o035;
142pub const PROTO_xtp = 0o044;
143pub const PROTO_ddp = 0o045;
144pub const PROTO_idpr_cmtp = 0o046;
145pub const PROTO_ipv6 = 0o051;
146pub const PROTO_ipv6_route = 0o053;
147pub const PROTO_ipv6_frag = 0o054;
148pub const PROTO_idrp = 0o055;
149pub const PROTO_rsvp = 0o056;
150pub const PROTO_gre = 0o057;
151pub const PROTO_esp = 0o062;
152pub const PROTO_ah = 0o063;
153pub const PROTO_skip = 0o071;
154pub const PROTO_ipv6_icmp = 0o072;
155pub const PROTO_ipv6_nonxt = 0o073;
156pub const PROTO_ipv6_opts = 0o074;
157pub const PROTO_rspf = 0o111;
158pub const PROTO_vmtp = 0o121;
159pub const PROTO_ospf = 0o131;
160pub const PROTO_ipip = 0o136;
161pub const PROTO_encap = 0o142;
162pub const PROTO_pim = 0o147;
163pub const PROTO_raw = 0o377;
164
165pub const SHUT_RD = 0;
166pub const SHUT_WR = 1;
167pub const SHUT_RDWR = 2;
168
169pub const SOCK_STREAM = 1;
170pub const SOCK_DGRAM = 2;
171pub const SOCK_RAW = 3;
172pub const SOCK_RDM = 4;
173pub const SOCK_SEQPACKET = 5;
174pub const SOCK_DCCP = 6;
175pub const SOCK_PACKET = 10;
176pub const SOCK_CLOEXEC = 0o2000000;
177pub const SOCK_NONBLOCK = 0o4000;
178
179pub const PF_UNSPEC = 0;
180pub const PF_LOCAL = 1;
181pub const PF_UNIX = PF_LOCAL;
182pub const PF_FILE = PF_LOCAL;
183pub const PF_INET = 2;
184pub const PF_AX25 = 3;
185pub const PF_IPX = 4;
186pub const PF_APPLETALK = 5;
187pub const PF_NETROM = 6;
188pub const PF_BRIDGE = 7;
189pub const PF_ATMPVC = 8;
190pub const PF_X25 = 9;
191pub const PF_INET6 = 10;
192pub const PF_ROSE = 11;
193pub const PF_DECnet = 12;
194pub const PF_NETBEUI = 13;
195pub const PF_SECURITY = 14;
196pub const PF_KEY = 15;
197pub const PF_NETLINK = 16;
198pub const PF_ROUTE = PF_NETLINK;
199pub const PF_PACKET = 17;
200pub const PF_ASH = 18;
201pub const PF_ECONET = 19;
202pub const PF_ATMSVC = 20;
203pub const PF_RDS = 21;
204pub const PF_SNA = 22;
205pub const PF_IRDA = 23;
206pub const PF_PPPOX = 24;
207pub const PF_WANPIPE = 25;
208pub const PF_LLC = 26;
209pub const PF_IB = 27;
210pub const PF_MPLS = 28;
211pub const PF_CAN = 29;
212pub const PF_TIPC = 30;
213pub const PF_BLUETOOTH = 31;
214pub const PF_IUCV = 32;
215pub const PF_RXRPC = 33;
216pub const PF_ISDN = 34;
217pub const PF_PHONET = 35;
218pub const PF_IEEE802154 = 36;
219pub const PF_CAIF = 37;
220pub const PF_ALG = 38;
221pub const PF_NFC = 39;
222pub const PF_VSOCK = 40;
223pub const PF_KCM = 41;
224pub const PF_QIPCRTR = 42;
225pub const PF_SMC = 43;
226pub const PF_MAX = 44;
227
228pub const AF_UNSPEC = PF_UNSPEC;
229pub const AF_LOCAL = PF_LOCAL;
230pub const AF_UNIX = AF_LOCAL;
231pub const AF_FILE = AF_LOCAL;
232pub const AF_INET = PF_INET;
233pub const AF_AX25 = PF_AX25;
234pub const AF_IPX = PF_IPX;
235pub const AF_APPLETALK = PF_APPLETALK;
236pub const AF_NETROM = PF_NETROM;
237pub const AF_BRIDGE = PF_BRIDGE;
238pub const AF_ATMPVC = PF_ATMPVC;
239pub const AF_X25 = PF_X25;
240pub const AF_INET6 = PF_INET6;
241pub const AF_ROSE = PF_ROSE;
242pub const AF_DECnet = PF_DECnet;
243pub const AF_NETBEUI = PF_NETBEUI;
244pub const AF_SECURITY = PF_SECURITY;
245pub const AF_KEY = PF_KEY;
246pub const AF_NETLINK = PF_NETLINK;
247pub const AF_ROUTE = PF_ROUTE;
248pub const AF_PACKET = PF_PACKET;
249pub const AF_ASH = PF_ASH;
250pub const AF_ECONET = PF_ECONET;
251pub const AF_ATMSVC = PF_ATMSVC;
252pub const AF_RDS = PF_RDS;
253pub const AF_SNA = PF_SNA;
254pub const AF_IRDA = PF_IRDA;
255pub const AF_PPPOX = PF_PPPOX;
256pub const AF_WANPIPE = PF_WANPIPE;
257pub const AF_LLC = PF_LLC;
258pub const AF_IB = PF_IB;
259pub const AF_MPLS = PF_MPLS;
260pub const AF_CAN = PF_CAN;
261pub const AF_TIPC = PF_TIPC;
262pub const AF_BLUETOOTH = PF_BLUETOOTH;
263pub const AF_IUCV = PF_IUCV;
264pub const AF_RXRPC = PF_RXRPC;
265pub const AF_ISDN = PF_ISDN;
266pub const AF_PHONET = PF_PHONET;
267pub const AF_IEEE802154 = PF_IEEE802154;
268pub const AF_CAIF = PF_CAIF;
269pub const AF_ALG = PF_ALG;
270pub const AF_NFC = PF_NFC;
271pub const AF_VSOCK = PF_VSOCK;
272pub const AF_KCM = PF_KCM;
273pub const AF_QIPCRTR = PF_QIPCRTR;
274pub const AF_SMC = PF_SMC;
275pub const AF_MAX = PF_MAX;
276
277pub const SO_DEBUG = 1;
278pub const SO_REUSEADDR = 2;
279pub const SO_TYPE = 3;
280pub const SO_ERROR = 4;
281pub const SO_DONTROUTE = 5;
282pub const SO_BROADCAST = 6;
283pub const SO_SNDBUF = 7;
284pub const SO_RCVBUF = 8;
285pub const SO_KEEPALIVE = 9;
286pub const SO_OOBINLINE = 10;
287pub const SO_NO_CHECK = 11;
288pub const SO_PRIORITY = 12;
289pub const SO_LINGER = 13;
290pub const SO_BSDCOMPAT = 14;
291pub const SO_REUSEPORT = 15;
292pub const SO_PASSCRED = 16;
293pub const SO_PEERCRED = 17;
294pub const SO_RCVLOWAT = 18;
295pub const SO_SNDLOWAT = 19;
296pub const SO_RCVTIMEO = 20;
297pub const SO_SNDTIMEO = 21;
298pub const SO_ACCEPTCONN = 30;
299pub const SO_SNDBUFFORCE = 32;
300pub const SO_RCVBUFFORCE = 33;
301pub const SO_PROTOCOL = 38;
302pub const SO_DOMAIN = 39;
303
304pub const SO_SECURITY_AUTHENTICATION = 22;
305pub const SO_SECURITY_ENCRYPTION_TRANSPORT = 23;
306pub const SO_SECURITY_ENCRYPTION_NETWORK = 24;
307
308pub const SO_BINDTODEVICE = 25;
309
310pub const SO_ATTACH_FILTER = 26;
311pub const SO_DETACH_FILTER = 27;
312pub const SO_GET_FILTER = SO_ATTACH_FILTER;
313
314pub const SO_PEERNAME = 28;
315pub const SO_TIMESTAMP = 29;
316pub const SCM_TIMESTAMP = SO_TIMESTAMP;
317
318pub const SO_PEERSEC = 31;
319pub const SO_PASSSEC = 34;
320pub const SO_TIMESTAMPNS = 35;
321pub const SCM_TIMESTAMPNS = SO_TIMESTAMPNS;
322pub const SO_MARK = 36;
323pub const SO_TIMESTAMPING = 37;
324pub const SCM_TIMESTAMPING = SO_TIMESTAMPING;
325pub const SO_RXQ_OVFL = 40;
326pub const SO_WIFI_STATUS = 41;
327pub const SCM_WIFI_STATUS = SO_WIFI_STATUS;
328pub const SO_PEEK_OFF = 42;
329pub const SO_NOFCS = 43;
330pub const SO_LOCK_FILTER = 44;
331pub const SO_SELECT_ERR_QUEUE = 45;
332pub const SO_BUSY_POLL = 46;
333pub const SO_MAX_PACING_RATE = 47;
334pub const SO_BPF_EXTENSIONS = 48;
335pub const SO_INCOMING_CPU = 49;
336pub const SO_ATTACH_BPF = 50;
337pub const SO_DETACH_BPF = SO_DETACH_FILTER;
338pub const SO_ATTACH_REUSEPORT_CBPF = 51;
339pub const SO_ATTACH_REUSEPORT_EBPF = 52;
340pub const SO_CNX_ADVICE = 53;
341pub const SCM_TIMESTAMPING_OPT_STATS = 54;
342pub const SO_MEMINFO = 55;
343pub const SO_INCOMING_NAPI_ID = 56;
344pub const SO_COOKIE = 57;
345pub const SCM_TIMESTAMPING_PKTINFO = 58;
346pub const SO_PEERGROUPS = 59;
347pub const SO_ZEROCOPY = 60;
348
349pub const SOL_SOCKET = 1;
350
351pub const SOL_IP = 0;
352pub const SOL_IPV6 = 41;
353pub const SOL_ICMPV6 = 58;
354
355pub const SOL_RAW = 255;
356pub const SOL_DECNET = 261;
357pub const SOL_X25 = 262;
358pub const SOL_PACKET = 263;
359pub const SOL_ATM = 264;
360pub const SOL_AAL = 265;
361pub const SOL_IRDA = 266;
362pub const SOL_NETBEUI = 267;
363pub const SOL_LLC = 268;
364pub const SOL_DCCP = 269;
365pub const SOL_NETLINK = 270;
366pub const SOL_TIPC = 271;
367pub const SOL_RXRPC = 272;
368pub const SOL_PPPOL2TP = 273;
369pub const SOL_BLUETOOTH = 274;
370pub const SOL_PNPIPE = 275;
371pub const SOL_RDS = 276;
372pub const SOL_IUCV = 277;
373pub const SOL_CAIF = 278;
374pub const SOL_ALG = 279;
375pub const SOL_NFC = 280;
376pub const SOL_KCM = 281;
377pub const SOL_TLS = 282;
378
379pub const SOMAXCONN = 128;
380
381pub const MSG_OOB = 0x0001;
382pub const MSG_PEEK = 0x0002;
383pub const MSG_DONTROUTE = 0x0004;
384pub const MSG_CTRUNC = 0x0008;
385pub const MSG_PROXY = 0x0010;
386pub const MSG_TRUNC = 0x0020;
387pub const MSG_DONTWAIT = 0x0040;
388pub const MSG_EOR = 0x0080;
389pub const MSG_WAITALL = 0x0100;
390pub const MSG_FIN = 0x0200;
391pub const MSG_SYN = 0x0400;
392pub const MSG_CONFIRM = 0x0800;
393pub const MSG_RST = 0x1000;
394pub const MSG_ERRQUEUE = 0x2000;
395pub const MSG_NOSIGNAL = 0x4000;
396pub const MSG_MORE = 0x8000;
397pub const MSG_WAITFORONE = 0x10000;
398pub const MSG_BATCH = 0x40000;
399pub const MSG_ZEROCOPY = 0x4000000;
400pub const MSG_FASTOPEN = 0x20000000;
401pub const MSG_CMSG_CLOEXEC = 0x40000000;
402
403pub const DT_UNKNOWN = 0;
404pub const DT_FIFO = 1;
405pub const DT_CHR = 2;
406pub const DT_DIR = 4;
407pub const DT_BLK = 6;
408pub const DT_REG = 8;
409pub const DT_LNK = 10;
410pub const DT_SOCK = 12;
411pub const DT_WHT = 14;
412
413pub const TCGETS = 0x5401;
414pub const TCSETS = 0x5402;
415pub const TCSETSW = 0x5403;
416pub const TCSETSF = 0x5404;
417pub const TCGETA = 0x5405;
418pub const TCSETA = 0x5406;
419pub const TCSETAW = 0x5407;
420pub const TCSETAF = 0x5408;
421pub const TCSBRK = 0x5409;
422pub const TCXONC = 0x540A;
423pub const TCFLSH = 0x540B;
424pub const TIOCEXCL = 0x540C;
425pub const TIOCNXCL = 0x540D;
426pub const TIOCSCTTY = 0x540E;
427pub const TIOCGPGRP = 0x540F;
428pub const TIOCSPGRP = 0x5410;
429pub const TIOCOUTQ = 0x5411;
430pub const TIOCSTI = 0x5412;
431pub const TIOCGWINSZ = 0x5413;
432pub const TIOCSWINSZ = 0x5414;
433pub const TIOCMGET = 0x5415;
434pub const TIOCMBIS = 0x5416;
435pub const TIOCMBIC = 0x5417;
436pub const TIOCMSET = 0x5418;
437pub const TIOCGSOFTCAR = 0x5419;
438pub const TIOCSSOFTCAR = 0x541A;
439pub const FIONREAD = 0x541B;
440pub const TIOCINQ = FIONREAD;
441pub const TIOCLINUX = 0x541C;
442pub const TIOCCONS = 0x541D;
443pub const TIOCGSERIAL = 0x541E;
444pub const TIOCSSERIAL = 0x541F;
445pub const TIOCPKT = 0x5420;
446pub const FIONBIO = 0x5421;
447pub const TIOCNOTTY = 0x5422;
448pub const TIOCSETD = 0x5423;
449pub const TIOCGETD = 0x5424;
450pub const TCSBRKP = 0x5425;
451pub const TIOCSBRK = 0x5427;
452pub const TIOCCBRK = 0x5428;
453pub const TIOCGSID = 0x5429;
454pub const TIOCGRS485 = 0x542E;
455pub const TIOCSRS485 = 0x542F;
456pub const TIOCGPTN = 0x80045430;
457pub const TIOCSPTLCK = 0x40045431;
458pub const TIOCGDEV = 0x80045432;
459pub const TCGETX = 0x5432;
460pub const TCSETX = 0x5433;
461pub const TCSETXF = 0x5434;
462pub const TCSETXW = 0x5435;
463pub const TIOCSIG = 0x40045436;
464pub const TIOCVHANGUP = 0x5437;
465pub const TIOCGPKT = 0x80045438;
466pub const TIOCGPTLCK = 0x80045439;
467pub const TIOCGEXCL = 0x80045440;
468
469pub const EPOLL_CLOEXEC = O_CLOEXEC;
470
471pub const EPOLL_CTL_ADD = 1;
472pub const EPOLL_CTL_DEL = 2;
473pub const EPOLL_CTL_MOD = 3;
474
475pub const EPOLLIN = 0x001;
476pub const EPOLLPRI = 0x002;
477pub const EPOLLOUT = 0x004;
478pub const EPOLLRDNORM = 0x040;
479pub const EPOLLRDBAND = 0x080;
480pub const EPOLLWRNORM = 0x100;
481pub const EPOLLWRBAND = 0x200;
482pub const EPOLLMSG = 0x400;
483pub const EPOLLERR = 0x008;
484pub const EPOLLHUP = 0x010;
485pub const EPOLLRDHUP = 0x2000;
486pub const EPOLLEXCLUSIVE = (u32(1) << 28);
487pub const EPOLLWAKEUP = (u32(1) << 29);
488pub const EPOLLONESHOT = (u32(1) << 30);
489pub const EPOLLET = (u32(1) << 31);
490
491pub const CLOCK_REALTIME = 0;
492pub const CLOCK_MONOTONIC = 1;
493pub const CLOCK_PROCESS_CPUTIME_ID = 2;
494pub const CLOCK_THREAD_CPUTIME_ID = 3;
495pub const CLOCK_MONOTONIC_RAW = 4;
496pub const CLOCK_REALTIME_COARSE = 5;
497pub const CLOCK_MONOTONIC_COARSE = 6;
498pub const CLOCK_BOOTTIME = 7;
499pub const CLOCK_REALTIME_ALARM = 8;
500pub const CLOCK_BOOTTIME_ALARM = 9;
501pub const CLOCK_SGI_CYCLE = 10;
502pub const CLOCK_TAI = 11;
503
504pub const CSIGNAL = 0x000000ff;
505pub const CLONE_VM = 0x00000100;
506pub const CLONE_FS = 0x00000200;
507pub const CLONE_FILES = 0x00000400;
508pub const CLONE_SIGHAND = 0x00000800;
509pub const CLONE_PTRACE = 0x00002000;
510pub const CLONE_VFORK = 0x00004000;
511pub const CLONE_PARENT = 0x00008000;
512pub const CLONE_THREAD = 0x00010000;
513pub const CLONE_NEWNS = 0x00020000;
514pub const CLONE_SYSVSEM = 0x00040000;
515pub const CLONE_SETTLS = 0x00080000;
516pub const CLONE_PARENT_SETTID = 0x00100000;
517pub const CLONE_CHILD_CLEARTID = 0x00200000;
518pub const CLONE_DETACHED = 0x00400000;
519pub const CLONE_UNTRACED = 0x00800000;
520pub const CLONE_CHILD_SETTID = 0x01000000;
521pub const CLONE_NEWCGROUP = 0x02000000;
522pub const CLONE_NEWUTS = 0x04000000;
523pub const CLONE_NEWIPC = 0x08000000;
524pub const CLONE_NEWUSER = 0x10000000;
525pub const CLONE_NEWPID = 0x20000000;
526pub const CLONE_NEWNET = 0x40000000;
527pub const CLONE_IO = 0x80000000;
528
529pub const EFD_SEMAPHORE = 1;
530pub const EFD_CLOEXEC = O_CLOEXEC;
531pub const EFD_NONBLOCK = O_NONBLOCK;
532
533pub const MS_RDONLY = 1;
534pub const MS_NOSUID = 2;
535pub const MS_NODEV = 4;
536pub const MS_NOEXEC = 8;
537pub const MS_SYNCHRONOUS = 16;
538pub const MS_REMOUNT = 32;
539pub const MS_MANDLOCK = 64;
540pub const MS_DIRSYNC = 128;
541pub const MS_NOATIME = 1024;
542pub const MS_NODIRATIME = 2048;
543pub const MS_BIND = 4096;
544pub const MS_MOVE = 8192;
545pub const MS_REC = 16384;
546pub const MS_SILENT = 32768;
547pub const MS_POSIXACL = (1 << 16);
548pub const MS_UNBINDABLE = (1 << 17);
549pub const MS_PRIVATE = (1 << 18);
550pub const MS_SLAVE = (1 << 19);
551pub const MS_SHARED = (1 << 20);
552pub const MS_RELATIME = (1 << 21);
553pub const MS_KERNMOUNT = (1 << 22);
554pub const MS_I_VERSION = (1 << 23);
555pub const MS_STRICTATIME = (1 << 24);
556pub const MS_LAZYTIME = (1 << 25);
557pub const MS_NOREMOTELOCK = (1 << 27);
558pub const MS_NOSEC = (1 << 28);
559pub const MS_BORN = (1 << 29);
560pub const MS_ACTIVE = (1 << 30);
561pub const MS_NOUSER = (1 << 31);
562
563pub const MS_RMT_MASK = (MS_RDONLY | MS_SYNCHRONOUS | MS_MANDLOCK | MS_I_VERSION | MS_LAZYTIME);
564
565pub const MS_MGC_VAL = 0xc0ed0000;
566pub const MS_MGC_MSK = 0xffff0000;
567
568pub const MNT_FORCE = 1;
569pub const MNT_DETACH = 2;
570pub const MNT_EXPIRE = 4;
571pub const UMOUNT_NOFOLLOW = 8;
572
573pub const IN_CLOEXEC = O_CLOEXEC;
574pub const IN_NONBLOCK = O_NONBLOCK;
575
576pub const IN_ACCESS = 0x00000001;
577pub const IN_MODIFY = 0x00000002;
578pub const IN_ATTRIB = 0x00000004;
579pub const IN_CLOSE_WRITE = 0x00000008;
580pub const IN_CLOSE_NOWRITE = 0x00000010;
581pub const IN_CLOSE = IN_CLOSE_WRITE | IN_CLOSE_NOWRITE;
582pub const IN_OPEN = 0x00000020;
583pub const IN_MOVED_FROM = 0x00000040;
584pub const IN_MOVED_TO = 0x00000080;
585pub const IN_MOVE = IN_MOVED_FROM | IN_MOVED_TO;
586pub const IN_CREATE = 0x00000100;
587pub const IN_DELETE = 0x00000200;
588pub const IN_DELETE_SELF = 0x00000400;
589pub const IN_MOVE_SELF = 0x00000800;
590pub const IN_ALL_EVENTS = 0x00000fff;
591
592pub const IN_UNMOUNT = 0x00002000;
593pub const IN_Q_OVERFLOW = 0x00004000;
594pub const IN_IGNORED = 0x00008000;
595
596pub const IN_ONLYDIR = 0x01000000;
597pub const IN_DONT_FOLLOW = 0x02000000;
598pub const IN_EXCL_UNLINK = 0x04000000;
599pub const IN_MASK_ADD = 0x20000000;
600
601pub const IN_ISDIR = 0x40000000;
602pub const IN_ONESHOT = 0x80000000;
603
604pub const S_IFMT = 0o170000;
605
606pub const S_IFDIR = 0o040000;
607pub const S_IFCHR = 0o020000;
608pub const S_IFBLK = 0o060000;
609pub const S_IFREG = 0o100000;
610pub const S_IFIFO = 0o010000;
611pub const S_IFLNK = 0o120000;
612pub const S_IFSOCK = 0o140000;
613
614pub const S_ISUID = 0o4000;
615pub const S_ISGID = 0o2000;
616pub const S_ISVTX = 0o1000;
617pub const S_IRUSR = 0o400;
618pub const S_IWUSR = 0o200;
619pub const S_IXUSR = 0o100;
620pub const S_IRWXU = 0o700;
621pub const S_IRGRP = 0o040;
622pub const S_IWGRP = 0o020;
623pub const S_IXGRP = 0o010;
624pub const S_IRWXG = 0o070;
625pub const S_IROTH = 0o004;
626pub const S_IWOTH = 0o002;
627pub const S_IXOTH = 0o001;
628pub const S_IRWXO = 0o007;
629
630pub fn S_ISREG(m: u32) bool {
631 return m & S_IFMT == S_IFREG;
632}
633
634pub fn S_ISDIR(m: u32) bool {
635 return m & S_IFMT == S_IFDIR;
636}
637
638pub fn S_ISCHR(m: u32) bool {
639 return m & S_IFMT == S_IFCHR;
640}
641
642pub fn S_ISBLK(m: u32) bool {
643 return m & S_IFMT == S_IFBLK;
644}
645
646pub fn S_ISFIFO(m: u32) bool {
647 return m & S_IFMT == S_IFIFO;
648}
649
650pub fn S_ISLNK(m: u32) bool {
651 return m & S_IFMT == S_IFLNK;
652}
653
654pub fn S_ISSOCK(m: u32) bool {
655 return m & S_IFMT == S_IFSOCK;
656}
657
658pub const TFD_NONBLOCK = O_NONBLOCK;
659pub const TFD_CLOEXEC = O_CLOEXEC;
660
661pub const TFD_TIMER_ABSTIME = 1;
662pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1);
663
664fn unsigned(s: i32) u32 {
665 return @bitCast(u32, s);
666}
667fn signed(s: u32) i32 {
668 return @bitCast(i32, s);
669}
670pub fn WEXITSTATUS(s: i32) i32 {
671 return signed((unsigned(s) & 0xff00) >> 8);
672}
673pub fn WTERMSIG(s: i32) i32 {
674 return signed(unsigned(s) & 0x7f);
675}
676pub fn WSTOPSIG(s: i32) i32 {
677 return WEXITSTATUS(s);
678}
679pub fn WIFEXITED(s: i32) bool {
680 return WTERMSIG(s) == 0;
681}
682pub fn WIFSTOPPED(s: i32) bool {
683 return @intCast(u16, ((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00;
684}
685pub fn WIFSIGNALED(s: i32) bool {
686 return (unsigned(s) & 0xffff) -% 1 < 0xff;
687}
688
689pub const winsize = extern struct {
690 ws_row: u16,
691 ws_col: u16,
692 ws_xpixel: u16,
693 ws_ypixel: u16,
694};
695
696const NSIG = 65;
697const sigset_t = [128 / @sizeOf(usize)]usize;
698const all_mask = []u32{ 0xffffffff, 0xffffffff };
699const app_mask = []u32{ 0xfffffffc, 0x7fffffff };
700
701const 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.
709pub const Sigaction = struct {
710 handler: extern fn (i32) void,
711 mask: sigset_t,
712 flags: u32,
713};
714
715pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
716pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
717pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
718pub const empty_sigset = []usize{0} ** sigset_t.len;
719
720pub const in_port_t = u16;
721pub const sa_family_t = u16;
722pub const socklen_t = u32;
723
724/// This intentionally only has ip4 and ip6
725pub const sockaddr = extern union {
726 in: sockaddr_in,
727 in6: sockaddr_in6,
728};
729
730pub const sockaddr_in = extern struct {
731 family: sa_family_t,
732 port: in_port_t,
733 addr: u32,
734 zero: [8]u8,
735};
736
737pub 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
745pub const sockaddr_un = extern struct {
746 family: sa_family_t,
747 path: [108]u8,
748};
749
750pub const iovec = extern struct {
751 iov_base: [*]u8,
752 iov_len: usize,
753};
754
755pub const iovec_const = extern struct {
756 iov_base: [*]const u8,
757 iov_len: usize,
758};
759
760pub const mmsghdr = extern struct {
761 msg_hdr: msghdr,
762 msg_len: u32,
763};
764
765pub const mmsghdr_const = extern struct {
766 msg_hdr: msghdr_const,
767 msg_len: u32,
768};
769
770pub 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
779pub const epoll_event = if (builtin.arch != .x86_64)
780 extern struct {
781 events: u32,
782 data: epoll_data,
783 }
784else
785 packed struct {
786 events: u32,
787 data: epoll_data,
788 };
789
790pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330;
791pub const _LINUX_CAPABILITY_U32S_1 = 1;
792
793pub const _LINUX_CAPABILITY_VERSION_2 = 0x20071026;
794pub const _LINUX_CAPABILITY_U32S_2 = 2;
795
796pub const _LINUX_CAPABILITY_VERSION_3 = 0x20080522;
797pub const _LINUX_CAPABILITY_U32S_3 = 2;
798
799pub const VFS_CAP_REVISION_MASK = 0xFF000000;
800pub const VFS_CAP_REVISION_SHIFT = 24;
801pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK;
802pub const VFS_CAP_FLAGS_EFFECTIVE = 0x000001;
803
804pub const VFS_CAP_REVISION_1 = 0x01000000;
805pub const VFS_CAP_U32_1 = 1;
806pub const XATTR_CAPS_SZ_1 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_1);
807
808pub const VFS_CAP_REVISION_2 = 0x02000000;
809pub const VFS_CAP_U32_2 = 2;
810pub const XATTR_CAPS_SZ_2 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_2);
811
812pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2;
813pub const VFS_CAP_U32 = VFS_CAP_U32_2;
814pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2;
815
816pub 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
828pub const CAP_CHOWN = 0;
829pub const CAP_DAC_OVERRIDE = 1;
830pub const CAP_DAC_READ_SEARCH = 2;
831pub const CAP_FOWNER = 3;
832pub const CAP_FSETID = 4;
833pub const CAP_KILL = 5;
834pub const CAP_SETGID = 6;
835pub const CAP_SETUID = 7;
836pub const CAP_SETPCAP = 8;
837pub const CAP_LINUX_IMMUTABLE = 9;
838pub const CAP_NET_BIND_SERVICE = 10;
839pub const CAP_NET_BROADCAST = 11;
840pub const CAP_NET_ADMIN = 12;
841pub const CAP_NET_RAW = 13;
842pub const CAP_IPC_LOCK = 14;
843pub const CAP_IPC_OWNER = 15;
844pub const CAP_SYS_MODULE = 16;
845pub const CAP_SYS_RAWIO = 17;
846pub const CAP_SYS_CHROOT = 18;
847pub const CAP_SYS_PTRACE = 19;
848pub const CAP_SYS_PACCT = 20;
849pub const CAP_SYS_ADMIN = 21;
850pub const CAP_SYS_BOOT = 22;
851pub const CAP_SYS_NICE = 23;
852pub const CAP_SYS_RESOURCE = 24;
853pub const CAP_SYS_TIME = 25;
854pub const CAP_SYS_TTY_CONFIG = 26;
855pub const CAP_MKNOD = 27;
856pub const CAP_LEASE = 28;
857pub const CAP_AUDIT_WRITE = 29;
858pub const CAP_AUDIT_CONTROL = 30;
859pub const CAP_SETFCAP = 31;
860pub const CAP_MAC_OVERRIDE = 32;
861pub const CAP_MAC_ADMIN = 33;
862pub const CAP_SYSLOG = 34;
863pub const CAP_WAKE_ALARM = 35;
864pub const CAP_BLOCK_SUSPEND = 36;
865pub const CAP_AUDIT_READ = 37;
866pub const CAP_LAST_CAP = CAP_AUDIT_READ;
867
868pub fn cap_valid(u8: x) bool {
869 return x >= 0 and x <= CAP_LAST_CAP;
870}
871
872pub fn CAP_TO_MASK(cap: u8) u32 {
873 return u32(1) << u5(cap & 31);
874}
875
876pub fn CAP_TO_INDEX(cap: u8) u8 {
877 return cap >> 5;
878}
879
880pub const cap_t = extern struct {
881 hdrp: *cap_user_header_t,
882 datap: *cap_user_data_t,
883};
884
885pub const cap_user_header_t = extern struct {
886 version: u32,
887 pid: usize,
888};
889
890pub const cap_user_data_t = extern struct {
891 effective: u32,
892 permitted: u32,
893 inheritable: u32,
894};
895
896pub const inotify_event = extern struct {
897 wd: i32,
898 mask: u32,
899 cookie: u32,
900 len: u32,
901 //name: [?]u8,
902};
903
904pub 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
912pub 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
4const std = @import("../../std.zig");
5const linux = std.os.linux;
6const socklen_t = linux.socklen_t;
7const iovec = linux.iovec;
8const iovec_const = linux.iovec_const;
9
10pub const SYS_io_setup = 0;
11pub const SYS_io_destroy = 1;
12pub const SYS_io_submit = 2;
13pub const SYS_io_cancel = 3;
14pub const SYS_io_getevents = 4;
15pub const SYS_setxattr = 5;
16pub const SYS_lsetxattr = 6;
17pub const SYS_fsetxattr = 7;
18pub const SYS_getxattr = 8;
19pub const SYS_lgetxattr = 9;
20pub const SYS_fgetxattr = 10;
21pub const SYS_listxattr = 11;
22pub const SYS_llistxattr = 12;
23pub const SYS_flistxattr = 13;
24pub const SYS_removexattr = 14;
25pub const SYS_lremovexattr = 15;
26pub const SYS_fremovexattr = 16;
27pub const SYS_getcwd = 17;
28pub const SYS_lookup_dcookie = 18;
29pub const SYS_eventfd2 = 19;
30pub const SYS_epoll_create1 = 20;
31pub const SYS_epoll_ctl = 21;
32pub const SYS_epoll_pwait = 22;
33pub const SYS_dup = 23;
34pub const SYS_dup3 = 24;
35pub const SYS_fcntl = 25;
36pub const SYS_inotify_init1 = 26;
37pub const SYS_inotify_add_watch = 27;
38pub const SYS_inotify_rm_watch = 28;
39pub const SYS_ioctl = 29;
40pub const SYS_ioprio_set = 30;
41pub const SYS_ioprio_get = 31;
42pub const SYS_flock = 32;
43pub const SYS_mknodat = 33;
44pub const SYS_mkdirat = 34;
45pub const SYS_unlinkat = 35;
46pub const SYS_symlinkat = 36;
47pub const SYS_linkat = 37;
48pub const SYS_renameat = 38;
49pub const SYS_umount2 = 39;
50pub const SYS_mount = 40;
51pub const SYS_pivot_root = 41;
52pub const SYS_nfsservctl = 42;
53pub const SYS_statfs = 43;
54pub const SYS_fstatfs = 44;
55pub const SYS_truncate = 45;
56pub const SYS_ftruncate = 46;
57pub const SYS_fallocate = 47;
58pub const SYS_faccessat = 48;
59pub const SYS_chdir = 49;
60pub const SYS_fchdir = 50;
61pub const SYS_chroot = 51;
62pub const SYS_fchmod = 52;
63pub const SYS_fchmodat = 53;
64pub const SYS_fchownat = 54;
65pub const SYS_fchown = 55;
66pub const SYS_openat = 56;
67pub const SYS_close = 57;
68pub const SYS_vhangup = 58;
69pub const SYS_pipe2 = 59;
70pub const SYS_quotactl = 60;
71pub const SYS_getdents64 = 61;
72pub const SYS_lseek = 62;
73pub const SYS_read = 63;
74pub const SYS_write = 64;
75pub const SYS_readv = 65;
76pub const SYS_writev = 66;
77pub const SYS_pread64 = 67;
78pub const SYS_pwrite64 = 68;
79pub const SYS_preadv = 69;
80pub const SYS_pwritev = 70;
81pub const SYS_pselect6 = 72;
82pub const SYS_ppoll = 73;
83pub const SYS_signalfd4 = 74;
84pub const SYS_vmsplice = 75;
85pub const SYS_splice = 76;
86pub const SYS_tee = 77;
87pub const SYS_readlinkat = 78;
88pub const SYS_fstatat = 79;
89pub const SYS_fstat = 80;
90pub const SYS_sync = 81;
91pub const SYS_fsync = 82;
92pub const SYS_fdatasync = 83;
93pub const SYS_sync_file_range2 = 84;
94pub const SYS_sync_file_range = 84;
95pub const SYS_timerfd_create = 85;
96pub const SYS_timerfd_settime = 86;
97pub const SYS_timerfd_gettime = 87;
98pub const SYS_utimensat = 88;
99pub const SYS_acct = 89;
100pub const SYS_capget = 90;
101pub const SYS_capset = 91;
102pub const SYS_personality = 92;
103pub const SYS_exit = 93;
104pub const SYS_exit_group = 94;
105pub const SYS_waitid = 95;
106pub const SYS_set_tid_address = 96;
107pub const SYS_unshare = 97;
108pub const SYS_futex = 98;
109pub const SYS_set_robust_list = 99;
110pub const SYS_get_robust_list = 100;
111pub const SYS_nanosleep = 101;
112pub const SYS_getitimer = 102;
113pub const SYS_setitimer = 103;
114pub const SYS_kexec_load = 104;
115pub const SYS_init_module = 105;
116pub const SYS_delete_module = 106;
117pub const SYS_timer_create = 107;
118pub const SYS_timer_gettime = 108;
119pub const SYS_timer_getoverrun = 109;
120pub const SYS_timer_settime = 110;
121pub const SYS_timer_delete = 111;
122pub const SYS_clock_settime = 112;
123pub const SYS_clock_gettime = 113;
124pub const SYS_clock_getres = 114;
125pub const SYS_clock_nanosleep = 115;
126pub const SYS_syslog = 116;
127pub const SYS_ptrace = 117;
128pub const SYS_sched_setparam = 118;
129pub const SYS_sched_setscheduler = 119;
130pub const SYS_sched_getscheduler = 120;
131pub const SYS_sched_getparam = 121;
132pub const SYS_sched_setaffinity = 122;
133pub const SYS_sched_getaffinity = 123;
134pub const SYS_sched_yield = 124;
135pub const SYS_sched_get_priority_max = 125;
136pub const SYS_sched_get_priority_min = 126;
137pub const SYS_sched_rr_get_interval = 127;
138pub const SYS_restart_syscall = 128;
139pub const SYS_kill = 129;
140pub const SYS_tkill = 130;
141pub const SYS_tgkill = 131;
142pub const SYS_sigaltstack = 132;
143pub const SYS_rt_sigsuspend = 133;
144pub const SYS_rt_sigaction = 134;
145pub const SYS_rt_sigprocmask = 135;
146pub const SYS_rt_sigpending = 136;
147pub const SYS_rt_sigtimedwait = 137;
148pub const SYS_rt_sigqueueinfo = 138;
149pub const SYS_rt_sigreturn = 139;
150pub const SYS_setpriority = 140;
151pub const SYS_getpriority = 141;
152pub const SYS_reboot = 142;
153pub const SYS_setregid = 143;
154pub const SYS_setgid = 144;
155pub const SYS_setreuid = 145;
156pub const SYS_setuid = 146;
157pub const SYS_setresuid = 147;
158pub const SYS_getresuid = 148;
159pub const SYS_setresgid = 149;
160pub const SYS_getresgid = 150;
161pub const SYS_setfsuid = 151;
162pub const SYS_setfsgid = 152;
163pub const SYS_times = 153;
164pub const SYS_setpgid = 154;
165pub const SYS_getpgid = 155;
166pub const SYS_getsid = 156;
167pub const SYS_setsid = 157;
168pub const SYS_getgroups = 158;
169pub const SYS_setgroups = 159;
170pub const SYS_uname = 160;
171pub const SYS_sethostname = 161;
172pub const SYS_setdomainname = 162;
173pub const SYS_getrlimit = 163;
174pub const SYS_setrlimit = 164;
175pub const SYS_getrusage = 165;
176pub const SYS_umask = 166;
177pub const SYS_prctl = 167;
178pub const SYS_getcpu = 168;
179pub const SYS_gettimeofday = 169;
180pub const SYS_settimeofday = 170;
181pub const SYS_adjtimex = 171;
182pub const SYS_getpid = 172;
183pub const SYS_getppid = 173;
184pub const SYS_getuid = 174;
185pub const SYS_geteuid = 175;
186pub const SYS_getgid = 176;
187pub const SYS_getegid = 177;
188pub const SYS_gettid = 178;
189pub const SYS_sysinfo = 179;
190pub const SYS_mq_open = 180;
191pub const SYS_mq_unlink = 181;
192pub const SYS_mq_timedsend = 182;
193pub const SYS_mq_timedreceive = 183;
194pub const SYS_mq_notify = 184;
195pub const SYS_mq_getsetattr = 185;
196pub const SYS_msgget = 186;
197pub const SYS_msgctl = 187;
198pub const SYS_msgrcv = 188;
199pub const SYS_msgsnd = 189;
200pub const SYS_semget = 190;
201pub const SYS_semctl = 191;
202pub const SYS_semtimedop = 192;
203pub const SYS_semop = 193;
204pub const SYS_shmget = 194;
205pub const SYS_shmctl = 195;
206pub const SYS_shmat = 196;
207pub const SYS_shmdt = 197;
208pub const SYS_socket = 198;
209pub const SYS_socketpair = 199;
210pub const SYS_bind = 200;
211pub const SYS_listen = 201;
212pub const SYS_accept = 202;
213pub const SYS_connect = 203;
214pub const SYS_getsockname = 204;
215pub const SYS_getpeername = 205;
216pub const SYS_sendto = 206;
217pub const SYS_recvfrom = 207;
218pub const SYS_setsockopt = 208;
219pub const SYS_getsockopt = 209;
220pub const SYS_shutdown = 210;
221pub const SYS_sendmsg = 211;
222pub const SYS_recvmsg = 212;
223pub const SYS_readahead = 213;
224pub const SYS_brk = 214;
225pub const SYS_munmap = 215;
226pub const SYS_mremap = 216;
227pub const SYS_add_key = 217;
228pub const SYS_request_key = 218;
229pub const SYS_keyctl = 219;
230pub const SYS_clone = 220;
231pub const SYS_execve = 221;
232pub const SYS_mmap = 222;
233pub const SYS_fadvise64 = 223;
234pub const SYS_swapon = 224;
235pub const SYS_swapoff = 225;
236pub const SYS_mprotect = 226;
237pub const SYS_msync = 227;
238pub const SYS_mlock = 228;
239pub const SYS_munlock = 229;
240pub const SYS_mlockall = 230;
241pub const SYS_munlockall = 231;
242pub const SYS_mincore = 232;
243pub const SYS_madvise = 233;
244pub const SYS_remap_file_pages = 234;
245pub const SYS_mbind = 235;
246pub const SYS_get_mempolicy = 236;
247pub const SYS_set_mempolicy = 237;
248pub const SYS_migrate_pages = 238;
249pub const SYS_move_pages = 239;
250pub const SYS_rt_tgsigqueueinfo = 240;
251pub const SYS_perf_event_open = 241;
252pub const SYS_accept4 = 242;
253pub const SYS_recvmmsg = 243;
254pub const SYS_arch_specific_syscall = 244;
255pub const SYS_wait4 = 260;
256pub const SYS_prlimit64 = 261;
257pub const SYS_fanotify_init = 262;
258pub const SYS_fanotify_mark = 263;
259pub const SYS_clock_adjtime = 266;
260pub const SYS_syncfs = 267;
261pub const SYS_setns = 268;
262pub const SYS_sendmmsg = 269;
263pub const SYS_process_vm_readv = 270;
264pub const SYS_process_vm_writev = 271;
265pub const SYS_kcmp = 272;
266pub const SYS_finit_module = 273;
267pub const SYS_sched_setattr = 274;
268pub const SYS_sched_getattr = 275;
269pub const SYS_renameat2 = 276;
270pub const SYS_seccomp = 277;
271pub const SYS_getrandom = 278;
272pub const SYS_memfd_create = 279;
273pub const SYS_bpf = 280;
274pub const SYS_execveat = 281;
275pub const SYS_userfaultfd = 282;
276pub const SYS_membarrier = 283;
277pub const SYS_mlock2 = 284;
278pub const SYS_copy_file_range = 285;
279pub const SYS_preadv2 = 286;
280pub const SYS_pwritev2 = 287;
281pub const SYS_pkey_mprotect = 288;
282pub const SYS_pkey_alloc = 289;
283pub const SYS_pkey_free = 290;
284pub const SYS_statx = 291;
285pub const SYS_io_pgetevents = 292;
286pub const SYS_rseq = 293;
287pub const SYS_kexec_file_load = 294;
288pub const SYS_pidfd_send_signal = 424;
289pub const SYS_io_uring_setup = 425;
290pub const SYS_io_uring_enter = 426;
291pub const SYS_io_uring_register = 427;
292
293pub const O_CREAT = 0o100;
294pub const O_EXCL = 0o200;
295pub const O_NOCTTY = 0o400;
296pub const O_TRUNC = 0o1000;
297pub const O_APPEND = 0o2000;
298pub const O_NONBLOCK = 0o4000;
299pub const O_DSYNC = 0o10000;
300pub const O_SYNC = 0o4010000;
301pub const O_RSYNC = 0o4010000;
302pub const O_DIRECTORY = 0o200000;
303pub const O_NOFOLLOW = 0o400000;
304pub const O_CLOEXEC = 0o2000000;
305
306pub const O_ASYNC = 0o20000;
307pub const O_DIRECT = 0o40000;
308pub const O_LARGEFILE = 0;
309pub const O_NOATIME = 0o1000000;
310pub const O_PATH = 0o10000000;
311pub const O_TMPFILE = 0o20200000;
312pub const O_NDELAY = O_NONBLOCK;
313
314pub const F_DUPFD = 0;
315pub const F_GETFD = 1;
316pub const F_SETFD = 2;
317pub const F_GETFL = 3;
318pub const F_SETFL = 4;
319
320pub const F_SETOWN = 8;
321pub const F_GETOWN = 9;
322pub const F_SETSIG = 10;
323pub const F_GETSIG = 11;
324
325pub const F_GETLK = 5;
326pub const F_SETLK = 6;
327pub const F_SETLKW = 7;
328
329pub const F_SETOWN_EX = 15;
330pub const F_GETOWN_EX = 16;
331
332pub const F_GETOWNER_UIDS = 17;
333
334pub const AT_FDCWD = -100;
335pub const AT_SYMLINK_NOFOLLOW = 0x100;
336pub const AT_REMOVEDIR = 0x200;
337pub const AT_SYMLINK_FOLLOW = 0x400;
338pub const AT_NO_AUTOMOUNT = 0x800;
339pub const AT_EMPTY_PATH = 0x1000;
340
341pub const VDSO_USEFUL = true;
342pub const VDSO_CGT_SYM = "__kernel_clock_gettime";
343pub const VDSO_CGT_VER = "LINUX_2.6.39";
344
345pub 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
357pub 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.
370pub 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
390pub const timespec = extern struct {
391 tv_sec: isize,
392 tv_nsec: isize,
393};
394
395pub const timeval = extern struct {
396 tv_sec: isize,
397 tv_usec: isize,
398};
399
400pub const timezone = extern struct {
401 tz_minuteswest: i32,
402 tz_dsttime: i32,
403};
404
405pub 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.
2const std = @import("../../../std.zig");
3
4const linux = std.os.linux;
5const sockaddr = linux.sockaddr;
6const socklen_t = linux.socklen_t;
7const iovec = linux.iovec;
8const iovec_const = linux.iovec_const;
9
10pub const SYS_read = 0;
11pub const SYS_write = 1;
12pub const SYS_open = 2;
13pub const SYS_close = 3;
14pub const SYS_stat = 4;
15pub const SYS_fstat = 5;
16pub const SYS_lstat = 6;
17pub const SYS_poll = 7;
18pub const SYS_lseek = 8;
19pub const SYS_mmap = 9;
20pub const SYS_mprotect = 10;
21pub const SYS_munmap = 11;
22pub const SYS_brk = 12;
23pub const SYS_rt_sigaction = 13;
24pub const SYS_rt_sigprocmask = 14;
25pub const SYS_rt_sigreturn = 15;
26pub const SYS_ioctl = 16;
27pub const SYS_pread = 17;
28pub const SYS_pwrite = 18;
29pub const SYS_readv = 19;
30pub const SYS_writev = 20;
31pub const SYS_access = 21;
32pub const SYS_pipe = 22;
33pub const SYS_select = 23;
34pub const SYS_sched_yield = 24;
35pub const SYS_mremap = 25;
36pub const SYS_msync = 26;
37pub const SYS_mincore = 27;
38pub const SYS_madvise = 28;
39pub const SYS_shmget = 29;
40pub const SYS_shmat = 30;
41pub const SYS_shmctl = 31;
42pub const SYS_dup = 32;
43pub const SYS_dup2 = 33;
44pub const SYS_pause = 34;
45pub const SYS_nanosleep = 35;
46pub const SYS_getitimer = 36;
47pub const SYS_alarm = 37;
48pub const SYS_setitimer = 38;
49pub const SYS_getpid = 39;
50pub const SYS_sendfile = 40;
51pub const SYS_socket = 41;
52pub const SYS_connect = 42;
53pub const SYS_accept = 43;
54pub const SYS_sendto = 44;
55pub const SYS_recvfrom = 45;
56pub const SYS_sendmsg = 46;
57pub const SYS_recvmsg = 47;
58pub const SYS_shutdown = 48;
59pub const SYS_bind = 49;
60pub const SYS_listen = 50;
61pub const SYS_getsockname = 51;
62pub const SYS_getpeername = 52;
63pub const SYS_socketpair = 53;
64pub const SYS_setsockopt = 54;
65pub const SYS_getsockopt = 55;
66pub const SYS_clone = 56;
67pub const SYS_fork = 57;
68pub const SYS_vfork = 58;
69pub const SYS_execve = 59;
70pub const SYS_exit = 60;
71pub const SYS_wait4 = 61;
72pub const SYS_kill = 62;
73pub const SYS_uname = 63;
74pub const SYS_semget = 64;
75pub const SYS_semop = 65;
76pub const SYS_semctl = 66;
77pub const SYS_shmdt = 67;
78pub const SYS_msgget = 68;
79pub const SYS_msgsnd = 69;
80pub const SYS_msgrcv = 70;
81pub const SYS_msgctl = 71;
82pub const SYS_fcntl = 72;
83pub const SYS_flock = 73;
84pub const SYS_fsync = 74;
85pub const SYS_fdatasync = 75;
86pub const SYS_truncate = 76;
87pub const SYS_ftruncate = 77;
88pub const SYS_getdents = 78;
89pub const SYS_getcwd = 79;
90pub const SYS_chdir = 80;
91pub const SYS_fchdir = 81;
92pub const SYS_rename = 82;
93pub const SYS_mkdir = 83;
94pub const SYS_rmdir = 84;
95pub const SYS_creat = 85;
96pub const SYS_link = 86;
97pub const SYS_unlink = 87;
98pub const SYS_symlink = 88;
99pub const SYS_readlink = 89;
100pub const SYS_chmod = 90;
101pub const SYS_fchmod = 91;
102pub const SYS_chown = 92;
103pub const SYS_fchown = 93;
104pub const SYS_lchown = 94;
105pub const SYS_umask = 95;
106pub const SYS_gettimeofday = 96;
107pub const SYS_getrlimit = 97;
108pub const SYS_getrusage = 98;
109pub const SYS_sysinfo = 99;
110pub const SYS_times = 100;
111pub const SYS_ptrace = 101;
112pub const SYS_getuid = 102;
113pub const SYS_syslog = 103;
114pub const SYS_getgid = 104;
115pub const SYS_setuid = 105;
116pub const SYS_setgid = 106;
117pub const SYS_geteuid = 107;
118pub const SYS_getegid = 108;
119pub const SYS_setpgid = 109;
120pub const SYS_getppid = 110;
121pub const SYS_getpgrp = 111;
122pub const SYS_setsid = 112;
123pub const SYS_setreuid = 113;
124pub const SYS_setregid = 114;
125pub const SYS_getgroups = 115;
126pub const SYS_setgroups = 116;
127pub const SYS_setresuid = 117;
128pub const SYS_getresuid = 118;
129pub const SYS_setresgid = 119;
130pub const SYS_getresgid = 120;
131pub const SYS_getpgid = 121;
132pub const SYS_setfsuid = 122;
133pub const SYS_setfsgid = 123;
134pub const SYS_getsid = 124;
135pub const SYS_capget = 125;
136pub const SYS_capset = 126;
137pub const SYS_rt_sigpending = 127;
138pub const SYS_rt_sigtimedwait = 128;
139pub const SYS_rt_sigqueueinfo = 129;
140pub const SYS_rt_sigsuspend = 130;
141pub const SYS_sigaltstack = 131;
142pub const SYS_utime = 132;
143pub const SYS_mknod = 133;
144pub const SYS_uselib = 134;
145pub const SYS_personality = 135;
146pub const SYS_ustat = 136;
147pub const SYS_statfs = 137;
148pub const SYS_fstatfs = 138;
149pub const SYS_sysfs = 139;
150pub const SYS_getpriority = 140;
151pub const SYS_setpriority = 141;
152pub const SYS_sched_setparam = 142;
153pub const SYS_sched_getparam = 143;
154pub const SYS_sched_setscheduler = 144;
155pub const SYS_sched_getscheduler = 145;
156pub const SYS_sched_get_priority_max = 146;
157pub const SYS_sched_get_priority_min = 147;
158pub const SYS_sched_rr_get_interval = 148;
159pub const SYS_mlock = 149;
160pub const SYS_munlock = 150;
161pub const SYS_mlockall = 151;
162pub const SYS_munlockall = 152;
163pub const SYS_vhangup = 153;
164pub const SYS_modify_ldt = 154;
165pub const SYS_pivot_root = 155;
166pub const SYS__sysctl = 156;
167pub const SYS_prctl = 157;
168pub const SYS_arch_prctl = 158;
169pub const SYS_adjtimex = 159;
170pub const SYS_setrlimit = 160;
171pub const SYS_chroot = 161;
172pub const SYS_sync = 162;
173pub const SYS_acct = 163;
174pub const SYS_settimeofday = 164;
175pub const SYS_mount = 165;
176pub const SYS_umount2 = 166;
177pub const SYS_swapon = 167;
178pub const SYS_swapoff = 168;
179pub const SYS_reboot = 169;
180pub const SYS_sethostname = 170;
181pub const SYS_setdomainname = 171;
182pub const SYS_iopl = 172;
183pub const SYS_ioperm = 173;
184pub const SYS_create_module = 174;
185pub const SYS_init_module = 175;
186pub const SYS_delete_module = 176;
187pub const SYS_get_kernel_syms = 177;
188pub const SYS_query_module = 178;
189pub const SYS_quotactl = 179;
190pub const SYS_nfsservctl = 180;
191pub const SYS_getpmsg = 181;
192pub const SYS_putpmsg = 182;
193pub const SYS_afs_syscall = 183;
194pub const SYS_tuxcall = 184;
195pub const SYS_security = 185;
196pub const SYS_gettid = 186;
197pub const SYS_readahead = 187;
198pub const SYS_setxattr = 188;
199pub const SYS_lsetxattr = 189;
200pub const SYS_fsetxattr = 190;
201pub const SYS_getxattr = 191;
202pub const SYS_lgetxattr = 192;
203pub const SYS_fgetxattr = 193;
204pub const SYS_listxattr = 194;
205pub const SYS_llistxattr = 195;
206pub const SYS_flistxattr = 196;
207pub const SYS_removexattr = 197;
208pub const SYS_lremovexattr = 198;
209pub const SYS_fremovexattr = 199;
210pub const SYS_tkill = 200;
211pub const SYS_time = 201;
212pub const SYS_futex = 202;
213pub const SYS_sched_setaffinity = 203;
214pub const SYS_sched_getaffinity = 204;
215pub const SYS_set_thread_area = 205;
216pub const SYS_io_setup = 206;
217pub const SYS_io_destroy = 207;
218pub const SYS_io_getevents = 208;
219pub const SYS_io_submit = 209;
220pub const SYS_io_cancel = 210;
221pub const SYS_get_thread_area = 211;
222pub const SYS_lookup_dcookie = 212;
223pub const SYS_epoll_create = 213;
224pub const SYS_epoll_ctl_old = 214;
225pub const SYS_epoll_wait_old = 215;
226pub const SYS_remap_file_pages = 216;
227pub const SYS_getdents64 = 217;
228pub const SYS_set_tid_address = 218;
229pub const SYS_restart_syscall = 219;
230pub const SYS_semtimedop = 220;
231pub const SYS_fadvise64 = 221;
232pub const SYS_timer_create = 222;
233pub const SYS_timer_settime = 223;
234pub const SYS_timer_gettime = 224;
235pub const SYS_timer_getoverrun = 225;
236pub const SYS_timer_delete = 226;
237pub const SYS_clock_settime = 227;
238pub const SYS_clock_gettime = 228;
239pub const SYS_clock_getres = 229;
240pub const SYS_clock_nanosleep = 230;
241pub const SYS_exit_group = 231;
242pub const SYS_epoll_wait = 232;
243pub const SYS_epoll_ctl = 233;
244pub const SYS_tgkill = 234;
245pub const SYS_utimes = 235;
246pub const SYS_vserver = 236;
247pub const SYS_mbind = 237;
248pub const SYS_set_mempolicy = 238;
249pub const SYS_get_mempolicy = 239;
250pub const SYS_mq_open = 240;
251pub const SYS_mq_unlink = 241;
252pub const SYS_mq_timedsend = 242;
253pub const SYS_mq_timedreceive = 243;
254pub const SYS_mq_notify = 244;
255pub const SYS_mq_getsetattr = 245;
256pub const SYS_kexec_load = 246;
257pub const SYS_waitid = 247;
258pub const SYS_add_key = 248;
259pub const SYS_request_key = 249;
260pub const SYS_keyctl = 250;
261pub const SYS_ioprio_set = 251;
262pub const SYS_ioprio_get = 252;
263pub const SYS_inotify_init = 253;
264pub const SYS_inotify_add_watch = 254;
265pub const SYS_inotify_rm_watch = 255;
266pub const SYS_migrate_pages = 256;
267pub const SYS_openat = 257;
268pub const SYS_mkdirat = 258;
269pub const SYS_mknodat = 259;
270pub const SYS_fchownat = 260;
271pub const SYS_futimesat = 261;
272pub const SYS_newfstatat = 262;
273pub const SYS_fstatat = 262;
274pub const SYS_unlinkat = 263;
275pub const SYS_renameat = 264;
276pub const SYS_linkat = 265;
277pub const SYS_symlinkat = 266;
278pub const SYS_readlinkat = 267;
279pub const SYS_fchmodat = 268;
280pub const SYS_faccessat = 269;
281pub const SYS_pselect6 = 270;
282pub const SYS_ppoll = 271;
283pub const SYS_unshare = 272;
284pub const SYS_set_robust_list = 273;
285pub const SYS_get_robust_list = 274;
286pub const SYS_splice = 275;
287pub const SYS_tee = 276;
288pub const SYS_sync_file_range = 277;
289pub const SYS_vmsplice = 278;
290pub const SYS_move_pages = 279;
291pub const SYS_utimensat = 280;
292pub const SYS_epoll_pwait = 281;
293pub const SYS_signalfd = 282;
294pub const SYS_timerfd_create = 283;
295pub const SYS_eventfd = 284;
296pub const SYS_fallocate = 285;
297pub const SYS_timerfd_settime = 286;
298pub const SYS_timerfd_gettime = 287;
299pub const SYS_accept4 = 288;
300pub const SYS_signalfd4 = 289;
301pub const SYS_eventfd2 = 290;
302pub const SYS_epoll_create1 = 291;
303pub const SYS_dup3 = 292;
304pub const SYS_pipe2 = 293;
305pub const SYS_inotify_init1 = 294;
306pub const SYS_preadv = 295;
307pub const SYS_pwritev = 296;
308pub const SYS_rt_tgsigqueueinfo = 297;
309pub const SYS_perf_event_open = 298;
310pub const SYS_recvmmsg = 299;
311pub const SYS_fanotify_init = 300;
312pub const SYS_fanotify_mark = 301;
313pub const SYS_prlimit64 = 302;
314pub const SYS_name_to_handle_at = 303;
315pub const SYS_open_by_handle_at = 304;
316pub const SYS_clock_adjtime = 305;
317pub const SYS_syncfs = 306;
318pub const SYS_sendmmsg = 307;
319pub const SYS_setns = 308;
320pub const SYS_getcpu = 309;
321pub const SYS_process_vm_readv = 310;
322pub const SYS_process_vm_writev = 311;
323pub const SYS_kcmp = 312;
324pub const SYS_finit_module = 313;
325pub const SYS_sched_setattr = 314;
326pub const SYS_sched_getattr = 315;
327pub const SYS_renameat2 = 316;
328pub const SYS_seccomp = 317;
329pub const SYS_getrandom = 318;
330pub const SYS_memfd_create = 319;
331pub const SYS_kexec_file_load = 320;
332pub const SYS_bpf = 321;
333pub const SYS_execveat = 322;
334pub const SYS_userfaultfd = 323;
335pub const SYS_membarrier = 324;
336pub const SYS_mlock2 = 325;
337pub const SYS_copy_file_range = 326;
338pub const SYS_preadv2 = 327;
339pub const SYS_pwritev2 = 328;
340pub const SYS_pkey_mprotect = 329;
341pub const SYS_pkey_alloc = 330;
342pub const SYS_pkey_free = 331;
343pub const SYS_statx = 332;
344pub const SYS_io_pgetevents = 333;
345pub const SYS_rseq = 334;
346pub const SYS_pidfd_send_signal = 424;
347pub const SYS_io_uring_setup = 425;
348pub const SYS_io_uring_enter = 426;
349pub const SYS_io_uring_register = 427;
350
351pub const O_CREAT = 0o100;
352pub const O_EXCL = 0o200;
353pub const O_NOCTTY = 0o400;
354pub const O_TRUNC = 0o1000;
355pub const O_APPEND = 0o2000;
356pub const O_NONBLOCK = 0o4000;
357pub const O_DSYNC = 0o10000;
358pub const O_SYNC = 0o4010000;
359pub const O_RSYNC = 0o4010000;
360pub const O_DIRECTORY = 0o200000;
361pub const O_NOFOLLOW = 0o400000;
362pub const O_CLOEXEC = 0o2000000;
363
364pub const O_ASYNC = 0o20000;
365pub const O_DIRECT = 0o40000;
366pub const O_LARGEFILE = 0;
367pub const O_NOATIME = 0o1000000;
368pub const O_PATH = 0o10000000;
369pub const O_TMPFILE = 0o20200000;
370pub const O_NDELAY = O_NONBLOCK;
371
372pub const F_DUPFD = 0;
373pub const F_GETFD = 1;
374pub const F_SETFD = 2;
375pub const F_GETFL = 3;
376pub const F_SETFL = 4;
377
378pub const F_SETOWN = 8;
379pub const F_GETOWN = 9;
380pub const F_SETSIG = 10;
381pub const F_GETSIG = 11;
382
383pub const F_GETLK = 5;
384pub const F_SETLK = 6;
385pub const F_SETLKW = 7;
386
387pub const F_SETOWN_EX = 15;
388pub const F_GETOWN_EX = 16;
389
390pub const F_GETOWNER_UIDS = 17;
391
392pub const AT_FDCWD = -100;
393pub const AT_SYMLINK_NOFOLLOW = 0x100;
394pub const AT_REMOVEDIR = 0x200;
395pub const AT_SYMLINK_FOLLOW = 0x400;
396pub const AT_NO_AUTOMOUNT = 0x800;
397pub const AT_EMPTY_PATH = 0x1000;
398
399pub const VDSO_USEFUL = true;
400pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
401pub const VDSO_CGT_VER = "LINUX_2.6";
402pub const VDSO_GETCPU_SYM = "__vdso_getcpu";
403pub const VDSO_GETCPU_VER = "LINUX_2.6";
404
405pub const ARCH_SET_GS = 0x1001;
406pub const ARCH_SET_FS = 0x1002;
407pub const ARCH_GET_FS = 0x1003;
408pub const ARCH_GET_GS = 0x1004;
409
410pub 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
422pub 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.
435pub 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
455pub const timespec = extern struct {
456 tv_sec: isize,
457 tv_nsec: isize,
458};
459
460pub const timeval = extern struct {
461 tv_sec: isize,
462 tv_usec: isize,
463};
464
465pub const timezone = extern struct {
466 tz_minuteswest: i32,
467 tz_dsttime: i32,
468};
469
470pub const Elf_Symndx = u32;
std/os/linux/x86_64.zig+1-469
......@@ -1,410 +1,4 @@
1const std = @import("../../std.zig");
2const linux = std.os.linux;
3const sockaddr = linux.sockaddr;
4const socklen_t = linux.socklen_t;
5const iovec = linux.iovec;
6const iovec_const = linux.iovec_const;
7
8pub const SYS_read = 0;
9pub const SYS_write = 1;
10pub const SYS_open = 2;
11pub const SYS_close = 3;
12pub const SYS_stat = 4;
13pub const SYS_fstat = 5;
14pub const SYS_lstat = 6;
15pub const SYS_poll = 7;
16pub const SYS_lseek = 8;
17pub const SYS_mmap = 9;
18pub const SYS_mprotect = 10;
19pub const SYS_munmap = 11;
20pub const SYS_brk = 12;
21pub const SYS_rt_sigaction = 13;
22pub const SYS_rt_sigprocmask = 14;
23pub const SYS_rt_sigreturn = 15;
24pub const SYS_ioctl = 16;
25pub const SYS_pread = 17;
26pub const SYS_pwrite = 18;
27pub const SYS_readv = 19;
28pub const SYS_writev = 20;
29pub const SYS_access = 21;
30pub const SYS_pipe = 22;
31pub const SYS_select = 23;
32pub const SYS_sched_yield = 24;
33pub const SYS_mremap = 25;
34pub const SYS_msync = 26;
35pub const SYS_mincore = 27;
36pub const SYS_madvise = 28;
37pub const SYS_shmget = 29;
38pub const SYS_shmat = 30;
39pub const SYS_shmctl = 31;
40pub const SYS_dup = 32;
41pub const SYS_dup2 = 33;
42pub const SYS_pause = 34;
43pub const SYS_nanosleep = 35;
44pub const SYS_getitimer = 36;
45pub const SYS_alarm = 37;
46pub const SYS_setitimer = 38;
47pub const SYS_getpid = 39;
48pub const SYS_sendfile = 40;
49pub const SYS_socket = 41;
50pub const SYS_connect = 42;
51pub const SYS_accept = 43;
52pub const SYS_sendto = 44;
53pub const SYS_recvfrom = 45;
54pub const SYS_sendmsg = 46;
55pub const SYS_recvmsg = 47;
56pub const SYS_shutdown = 48;
57pub const SYS_bind = 49;
58pub const SYS_listen = 50;
59pub const SYS_getsockname = 51;
60pub const SYS_getpeername = 52;
61pub const SYS_socketpair = 53;
62pub const SYS_setsockopt = 54;
63pub const SYS_getsockopt = 55;
64pub const SYS_clone = 56;
65pub const SYS_fork = 57;
66pub const SYS_vfork = 58;
67pub const SYS_execve = 59;
68pub const SYS_exit = 60;
69pub const SYS_wait4 = 61;
70pub const SYS_kill = 62;
71pub const SYS_uname = 63;
72pub const SYS_semget = 64;
73pub const SYS_semop = 65;
74pub const SYS_semctl = 66;
75pub const SYS_shmdt = 67;
76pub const SYS_msgget = 68;
77pub const SYS_msgsnd = 69;
78pub const SYS_msgrcv = 70;
79pub const SYS_msgctl = 71;
80pub const SYS_fcntl = 72;
81pub const SYS_flock = 73;
82pub const SYS_fsync = 74;
83pub const SYS_fdatasync = 75;
84pub const SYS_truncate = 76;
85pub const SYS_ftruncate = 77;
86pub const SYS_getdents = 78;
87pub const SYS_getcwd = 79;
88pub const SYS_chdir = 80;
89pub const SYS_fchdir = 81;
90pub const SYS_rename = 82;
91pub const SYS_mkdir = 83;
92pub const SYS_rmdir = 84;
93pub const SYS_creat = 85;
94pub const SYS_link = 86;
95pub const SYS_unlink = 87;
96pub const SYS_symlink = 88;
97pub const SYS_readlink = 89;
98pub const SYS_chmod = 90;
99pub const SYS_fchmod = 91;
100pub const SYS_chown = 92;
101pub const SYS_fchown = 93;
102pub const SYS_lchown = 94;
103pub const SYS_umask = 95;
104pub const SYS_gettimeofday = 96;
105pub const SYS_getrlimit = 97;
106pub const SYS_getrusage = 98;
107pub const SYS_sysinfo = 99;
108pub const SYS_times = 100;
109pub const SYS_ptrace = 101;
110pub const SYS_getuid = 102;
111pub const SYS_syslog = 103;
112pub const SYS_getgid = 104;
113pub const SYS_setuid = 105;
114pub const SYS_setgid = 106;
115pub const SYS_geteuid = 107;
116pub const SYS_getegid = 108;
117pub const SYS_setpgid = 109;
118pub const SYS_getppid = 110;
119pub const SYS_getpgrp = 111;
120pub const SYS_setsid = 112;
121pub const SYS_setreuid = 113;
122pub const SYS_setregid = 114;
123pub const SYS_getgroups = 115;
124pub const SYS_setgroups = 116;
125pub const SYS_setresuid = 117;
126pub const SYS_getresuid = 118;
127pub const SYS_setresgid = 119;
128pub const SYS_getresgid = 120;
129pub const SYS_getpgid = 121;
130pub const SYS_setfsuid = 122;
131pub const SYS_setfsgid = 123;
132pub const SYS_getsid = 124;
133pub const SYS_capget = 125;
134pub const SYS_capset = 126;
135pub const SYS_rt_sigpending = 127;
136pub const SYS_rt_sigtimedwait = 128;
137pub const SYS_rt_sigqueueinfo = 129;
138pub const SYS_rt_sigsuspend = 130;
139pub const SYS_sigaltstack = 131;
140pub const SYS_utime = 132;
141pub const SYS_mknod = 133;
142pub const SYS_uselib = 134;
143pub const SYS_personality = 135;
144pub const SYS_ustat = 136;
145pub const SYS_statfs = 137;
146pub const SYS_fstatfs = 138;
147pub const SYS_sysfs = 139;
148pub const SYS_getpriority = 140;
149pub const SYS_setpriority = 141;
150pub const SYS_sched_setparam = 142;
151pub const SYS_sched_getparam = 143;
152pub const SYS_sched_setscheduler = 144;
153pub const SYS_sched_getscheduler = 145;
154pub const SYS_sched_get_priority_max = 146;
155pub const SYS_sched_get_priority_min = 147;
156pub const SYS_sched_rr_get_interval = 148;
157pub const SYS_mlock = 149;
158pub const SYS_munlock = 150;
159pub const SYS_mlockall = 151;
160pub const SYS_munlockall = 152;
161pub const SYS_vhangup = 153;
162pub const SYS_modify_ldt = 154;
163pub const SYS_pivot_root = 155;
164pub const SYS__sysctl = 156;
165pub const SYS_prctl = 157;
166pub const SYS_arch_prctl = 158;
167pub const SYS_adjtimex = 159;
168pub const SYS_setrlimit = 160;
169pub const SYS_chroot = 161;
170pub const SYS_sync = 162;
171pub const SYS_acct = 163;
172pub const SYS_settimeofday = 164;
173pub const SYS_mount = 165;
174pub const SYS_umount2 = 166;
175pub const SYS_swapon = 167;
176pub const SYS_swapoff = 168;
177pub const SYS_reboot = 169;
178pub const SYS_sethostname = 170;
179pub const SYS_setdomainname = 171;
180pub const SYS_iopl = 172;
181pub const SYS_ioperm = 173;
182pub const SYS_create_module = 174;
183pub const SYS_init_module = 175;
184pub const SYS_delete_module = 176;
185pub const SYS_get_kernel_syms = 177;
186pub const SYS_query_module = 178;
187pub const SYS_quotactl = 179;
188pub const SYS_nfsservctl = 180;
189pub const SYS_getpmsg = 181;
190pub const SYS_putpmsg = 182;
191pub const SYS_afs_syscall = 183;
192pub const SYS_tuxcall = 184;
193pub const SYS_security = 185;
194pub const SYS_gettid = 186;
195pub const SYS_readahead = 187;
196pub const SYS_setxattr = 188;
197pub const SYS_lsetxattr = 189;
198pub const SYS_fsetxattr = 190;
199pub const SYS_getxattr = 191;
200pub const SYS_lgetxattr = 192;
201pub const SYS_fgetxattr = 193;
202pub const SYS_listxattr = 194;
203pub const SYS_llistxattr = 195;
204pub const SYS_flistxattr = 196;
205pub const SYS_removexattr = 197;
206pub const SYS_lremovexattr = 198;
207pub const SYS_fremovexattr = 199;
208pub const SYS_tkill = 200;
209pub const SYS_time = 201;
210pub const SYS_futex = 202;
211pub const SYS_sched_setaffinity = 203;
212pub const SYS_sched_getaffinity = 204;
213pub const SYS_set_thread_area = 205;
214pub const SYS_io_setup = 206;
215pub const SYS_io_destroy = 207;
216pub const SYS_io_getevents = 208;
217pub const SYS_io_submit = 209;
218pub const SYS_io_cancel = 210;
219pub const SYS_get_thread_area = 211;
220pub const SYS_lookup_dcookie = 212;
221pub const SYS_epoll_create = 213;
222pub const SYS_epoll_ctl_old = 214;
223pub const SYS_epoll_wait_old = 215;
224pub const SYS_remap_file_pages = 216;
225pub const SYS_getdents64 = 217;
226pub const SYS_set_tid_address = 218;
227pub const SYS_restart_syscall = 219;
228pub const SYS_semtimedop = 220;
229pub const SYS_fadvise64 = 221;
230pub const SYS_timer_create = 222;
231pub const SYS_timer_settime = 223;
232pub const SYS_timer_gettime = 224;
233pub const SYS_timer_getoverrun = 225;
234pub const SYS_timer_delete = 226;
235pub const SYS_clock_settime = 227;
236pub const SYS_clock_gettime = 228;
237pub const SYS_clock_getres = 229;
238pub const SYS_clock_nanosleep = 230;
239pub const SYS_exit_group = 231;
240pub const SYS_epoll_wait = 232;
241pub const SYS_epoll_ctl = 233;
242pub const SYS_tgkill = 234;
243pub const SYS_utimes = 235;
244pub const SYS_vserver = 236;
245pub const SYS_mbind = 237;
246pub const SYS_set_mempolicy = 238;
247pub const SYS_get_mempolicy = 239;
248pub const SYS_mq_open = 240;
249pub const SYS_mq_unlink = 241;
250pub const SYS_mq_timedsend = 242;
251pub const SYS_mq_timedreceive = 243;
252pub const SYS_mq_notify = 244;
253pub const SYS_mq_getsetattr = 245;
254pub const SYS_kexec_load = 246;
255pub const SYS_waitid = 247;
256pub const SYS_add_key = 248;
257pub const SYS_request_key = 249;
258pub const SYS_keyctl = 250;
259pub const SYS_ioprio_set = 251;
260pub const SYS_ioprio_get = 252;
261pub const SYS_inotify_init = 253;
262pub const SYS_inotify_add_watch = 254;
263pub const SYS_inotify_rm_watch = 255;
264pub const SYS_migrate_pages = 256;
265pub const SYS_openat = 257;
266pub const SYS_mkdirat = 258;
267pub const SYS_mknodat = 259;
268pub const SYS_fchownat = 260;
269pub const SYS_futimesat = 261;
270pub const SYS_newfstatat = 262;
271// https://github.com/ziglang/zig/issues/1439
272pub const SYS_fstatat = 262;
273pub const SYS_unlinkat = 263;
274pub const SYS_renameat = 264;
275pub const SYS_linkat = 265;
276pub const SYS_symlinkat = 266;
277pub const SYS_readlinkat = 267;
278pub const SYS_fchmodat = 268;
279pub const SYS_faccessat = 269;
280pub const SYS_pselect6 = 270;
281pub const SYS_ppoll = 271;
282pub const SYS_unshare = 272;
283pub const SYS_set_robust_list = 273;
284pub const SYS_get_robust_list = 274;
285pub const SYS_splice = 275;
286pub const SYS_tee = 276;
287pub const SYS_sync_file_range = 277;
288pub const SYS_vmsplice = 278;
289pub const SYS_move_pages = 279;
290pub const SYS_utimensat = 280;
291pub const SYS_epoll_pwait = 281;
292pub const SYS_signalfd = 282;
293pub const SYS_timerfd_create = 283;
294pub const SYS_eventfd = 284;
295pub const SYS_fallocate = 285;
296pub const SYS_timerfd_settime = 286;
297pub const SYS_timerfd_gettime = 287;
298pub const SYS_accept4 = 288;
299pub const SYS_signalfd4 = 289;
300pub const SYS_eventfd2 = 290;
301pub const SYS_epoll_create1 = 291;
302pub const SYS_dup3 = 292;
303pub const SYS_pipe2 = 293;
304pub const SYS_inotify_init1 = 294;
305pub const SYS_preadv = 295;
306pub const SYS_pwritev = 296;
307pub const SYS_rt_tgsigqueueinfo = 297;
308pub const SYS_perf_event_open = 298;
309pub const SYS_recvmmsg = 299;
310pub const SYS_fanotify_init = 300;
311pub const SYS_fanotify_mark = 301;
312pub const SYS_prlimit64 = 302;
313pub const SYS_name_to_handle_at = 303;
314pub const SYS_open_by_handle_at = 304;
315pub const SYS_clock_adjtime = 305;
316pub const SYS_syncfs = 306;
317pub const SYS_sendmmsg = 307;
318pub const SYS_setns = 308;
319pub const SYS_getcpu = 309;
320pub const SYS_process_vm_readv = 310;
321pub const SYS_process_vm_writev = 311;
322pub const SYS_kcmp = 312;
323pub const SYS_finit_module = 313;
324pub const SYS_sched_setattr = 314;
325pub const SYS_sched_getattr = 315;
326pub const SYS_renameat2 = 316;
327pub const SYS_seccomp = 317;
328pub const SYS_getrandom = 318;
329pub const SYS_memfd_create = 319;
330pub const SYS_kexec_file_load = 320;
331pub const SYS_bpf = 321;
332pub const SYS_execveat = 322;
333pub const SYS_userfaultfd = 323;
334pub const SYS_membarrier = 324;
335pub const SYS_mlock2 = 325;
336pub const SYS_copy_file_range = 326;
337pub const SYS_preadv2 = 327;
338pub const SYS_pwritev2 = 328;
339pub const SYS_pkey_mprotect = 329;
340pub const SYS_pkey_alloc = 330;
341pub const SYS_pkey_free = 331;
342pub const SYS_statx = 332;
343pub const SYS_io_pgetevents = 333;
344pub const SYS_rseq = 334;
345pub const SYS_pidfd_send_signal = 424;
346pub const SYS_io_uring_setup = 425;
347pub const SYS_io_uring_enter = 426;
348pub const SYS_io_uring_register = 427;
349
350pub const O_CREAT = 0o100;
351pub const O_EXCL = 0o200;
352pub const O_NOCTTY = 0o400;
353pub const O_TRUNC = 0o1000;
354pub const O_APPEND = 0o2000;
355pub const O_NONBLOCK = 0o4000;
356pub const O_DSYNC = 0o10000;
357pub const O_SYNC = 0o4010000;
358pub const O_RSYNC = 0o4010000;
359pub const O_DIRECTORY = 0o200000;
360pub const O_NOFOLLOW = 0o400000;
361pub const O_CLOEXEC = 0o2000000;
362
363pub const O_ASYNC = 0o20000;
364pub const O_DIRECT = 0o40000;
365pub const O_LARGEFILE = 0;
366pub const O_NOATIME = 0o1000000;
367pub const O_PATH = 0o10000000;
368pub const O_TMPFILE = 0o20200000;
369pub const O_NDELAY = O_NONBLOCK;
370
371pub const F_DUPFD = 0;
372pub const F_GETFD = 1;
373pub const F_SETFD = 2;
374pub const F_GETFL = 3;
375pub const F_SETFL = 4;
376
377pub const F_SETOWN = 8;
378pub const F_GETOWN = 9;
379pub const F_SETSIG = 10;
380pub const F_GETSIG = 11;
381
382pub const F_GETLK = 5;
383pub const F_SETLK = 6;
384pub const F_SETLKW = 7;
385
386pub const F_SETOWN_EX = 15;
387pub const F_GETOWN_EX = 16;
388
389pub const F_GETOWNER_UIDS = 17;
390
391pub const AT_FDCWD = -100;
392pub const AT_SYMLINK_NOFOLLOW = 0x100;
393pub const AT_REMOVEDIR = 0x200;
394pub const AT_SYMLINK_FOLLOW = 0x400;
395pub const AT_NO_AUTOMOUNT = 0x800;
396pub const AT_EMPTY_PATH = 0x1000;
397
398pub const VDSO_USEFUL = true;
399pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
400pub const VDSO_CGT_VER = "LINUX_2.6";
401pub const VDSO_GETCPU_SYM = "__vdso_getcpu";
402pub const VDSO_GETCPU_VER = "LINUX_2.6";
403
404pub const ARCH_SET_GS = 0x1001;
405pub const ARCH_SET_FS = 0x1002;
406pub const ARCH_GET_FS = 0x1003;
407pub const ARCH_GET_GS = 0x1004;
1use @import("posix/x86_64.zig");
4082
4093pub fn syscall0(number: usize) usize {
4104 return asm volatile ("syscall"
......@@ -501,65 +95,3 @@ pub nakedcc fn restore_rt() void {
50195 : "rcx", "r11"
50296 );
50397}
504
505pub 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
517pub 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.
530pub 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
550pub const timespec = extern struct {
551 tv_sec: isize,
552 tv_nsec: isize,
553};
554
555pub const timeval = extern struct {
556 tv_sec: isize,
557 tv_usec: isize,
558};
559
560pub const timezone = extern struct {
561 tz_minuteswest: i32,
562 tz_dsttime: i32,
563};
564
565pub const Elf_Symndx = u32;
std/os/netbsd.zig+2-722
......@@ -1,724 +1,4 @@
11const builtin = @import("builtin");
2
3pub use @import("netbsd/errno.zig");
4
52const std = @import("../std.zig");
6const c = std.c;
7
8const assert = std.debug.assert;
9const maxInt = std.math.maxInt;
10pub const Kevent = c.Kevent;
11
12pub const CTL_KERN = 1;
13pub const CTL_DEBUG = 5;
14
15pub const KERN_PROC_ARGS = 48; // struct: process argv/env
16pub const KERN_PROC_PATHNAME = 5; // path to executable
17
18pub const PATH_MAX = 1024;
19
20pub const STDIN_FILENO = 0;
21pub const STDOUT_FILENO = 1;
22pub const STDERR_FILENO = 2;
23
24pub const PROT_NONE = 0;
25pub const PROT_READ = 1;
26pub const PROT_WRITE = 2;
27pub const PROT_EXEC = 4;
28
29pub const CLOCK_REALTIME = 0;
30pub const CLOCK_VIRTUAL = 1;
31pub const CLOCK_PROF = 2;
32pub const CLOCK_MONOTONIC = 3;
33pub const CLOCK_THREAD_CPUTIME_ID = 0x20000000;
34pub const CLOCK_PROCESS_CPUTIME_ID = 0x40000000;
35
36pub const MAP_FAILED = maxInt(usize);
37pub const MAP_SHARED = 0x0001;
38pub const MAP_PRIVATE = 0x0002;
39pub const MAP_REMAPDUP = 0x0004;
40pub const MAP_FIXED = 0x0010;
41pub const MAP_RENAME = 0x0020;
42pub const MAP_NORESERVE = 0x0040;
43pub const MAP_INHERIT = 0x0080;
44pub const MAP_HASSEMAPHORE = 0x0200;
45pub const MAP_TRYFIXED = 0x0400;
46pub const MAP_WIRED = 0x0800;
47
48pub const MAP_FILE = 0x0000;
49pub const MAP_NOSYNC = 0x0800;
50pub const MAP_ANON = 0x1000;
51pub const MAP_ANONYMOUS = MAP_ANON;
52pub const MAP_STACK = 0x2000;
53
54pub const WNOHANG = 0x00000001;
55pub const WUNTRACED = 0x00000002;
56pub const WSTOPPED = WUNTRACED;
57pub const WCONTINUED = 0x00000010;
58pub const WNOWAIT = 0x00010000;
59pub const WEXITED = 0x00000020;
60pub const WTRAPPED = 0x00000040;
61
62pub const SA_ONSTACK = 0x0001;
63pub const SA_RESTART = 0x0002;
64pub const SA_RESETHAND = 0x0004;
65pub const SA_NOCLDSTOP = 0x0008;
66pub const SA_NODEFER = 0x0010;
67pub const SA_NOCLDWAIT = 0x0020;
68pub const SA_SIGINFO = 0x0040;
69
70pub const SIGHUP = 1;
71pub const SIGINT = 2;
72pub const SIGQUIT = 3;
73pub const SIGILL = 4;
74pub const SIGTRAP = 5;
75pub const SIGABRT = 6;
76pub const SIGIOT = SIGABRT;
77pub const SIGEMT = 7;
78pub const SIGFPE = 8;
79pub const SIGKILL = 9;
80pub const SIGBUS = 10;
81pub const SIGSEGV = 11;
82pub const SIGSYS = 12;
83pub const SIGPIPE = 13;
84pub const SIGALRM = 14;
85pub const SIGTERM = 15;
86pub const SIGURG = 16;
87pub const SIGSTOP = 17;
88pub const SIGTSTP = 18;
89pub const SIGCONT = 19;
90pub const SIGCHLD = 20;
91pub const SIGTTIN = 21;
92pub const SIGTTOU = 22;
93pub const SIGIO = 23;
94pub const SIGXCPU = 24;
95pub const SIGXFSZ = 25;
96pub const SIGVTALRM = 26;
97pub const SIGPROF = 27;
98pub const SIGWINCH = 28;
99pub const SIGINFO = 29;
100pub const SIGUSR1 = 30;
101pub const SIGUSR2 = 31;
102pub const SIGPWR = 32;
103
104pub const SIGRTMIN = 33;
105pub const SIGRTMAX = 63;
106
107// access function
108pub const F_OK = 0; // test for existence of file
109pub const X_OK = 1; // test for execute or search permission
110pub const W_OK = 2; // test for write permission
111pub const R_OK = 4; // test for read permission
112
113pub const O_RDONLY = 0x0000;
114pub const O_WRONLY = 0x0001;
115pub const O_RDWR = 0x0002;
116pub const O_ACCMODE = 0x0003;
117
118pub const O_CREAT = 0x0200;
119pub const O_EXCL = 0x0800;
120pub const O_NOCTTY = 0x8000;
121pub const O_TRUNC = 0x0400;
122pub const O_APPEND = 0x0008;
123pub const O_NONBLOCK = 0x0004;
124pub const O_DSYNC = 0x00010000;
125pub const O_SYNC = 0x0080;
126pub const O_RSYNC = 0x00020000;
127pub const O_DIRECTORY = 0x00080000;
128pub const O_NOFOLLOW = 0x00000100;
129pub const O_CLOEXEC = 0x00400000;
130
131pub const O_ASYNC = 0x0040;
132pub const O_DIRECT = 0x00080000;
133pub const O_LARGEFILE = 0;
134pub const O_NOATIME = 0;
135pub const O_PATH = 0;
136pub const O_TMPFILE = 0;
137pub const O_NDELAY = O_NONBLOCK;
138
139pub const F_DUPFD = 0;
140pub const F_GETFD = 1;
141pub const F_SETFD = 2;
142pub const F_GETFL = 3;
143pub const F_SETFL = 4;
144
145pub const F_GETOWN = 5;
146pub const F_SETOWN = 6;
147
148pub const F_GETLK = 7;
149pub const F_SETLK = 8;
150pub const F_SETLKW = 9;
151
152pub const SEEK_SET = 0;
153pub const SEEK_CUR = 1;
154pub const SEEK_END = 2;
155
156pub const SIG_BLOCK = 1;
157pub const SIG_UNBLOCK = 2;
158pub const SIG_SETMASK = 3;
159
160pub const SOCK_STREAM = 1;
161pub const SOCK_DGRAM = 2;
162pub const SOCK_RAW = 3;
163pub const SOCK_RDM = 4;
164pub const SOCK_SEQPACKET = 5;
165
166pub const SOCK_CLOEXEC = 0x10000000;
167pub const SOCK_NONBLOCK = 0x20000000;
168
169pub const PROTO_ip = 0;
170pub const PROTO_icmp = 1;
171pub const PROTO_igmp = 2;
172pub const PROTO_ggp = 3;
173pub const PROTO_ipencap = 4;
174pub const PROTO_tcp = 6;
175pub const PROTO_egp = 8;
176pub const PROTO_pup = 12;
177pub const PROTO_udp = 17;
178pub const PROTO_xns_idp = 22;
179pub const PROTO_iso_tp4 = 29;
180pub const PROTO_ipv6 = 41;
181pub const PROTO_ipv6_route = 43;
182pub const PROTO_ipv6_frag = 44;
183pub const PROTO_rsvp = 46;
184pub const PROTO_gre = 47;
185pub const PROTO_esp = 50;
186pub const PROTO_ah = 51;
187pub const PROTO_ipv6_icmp = 58;
188pub const PROTO_ipv6_nonxt = 59;
189pub const PROTO_ipv6_opts = 60;
190pub const PROTO_encap = 98;
191pub const PROTO_pim = 103;
192pub const PROTO_raw = 255;
193
194pub const PF_UNSPEC = 0;
195pub const PF_LOCAL = 1;
196pub const PF_UNIX = PF_LOCAL;
197pub const PF_FILE = PF_LOCAL;
198pub const PF_INET = 2;
199pub const PF_APPLETALK = 16;
200pub const PF_INET6 = 24;
201pub const PF_DECnet = 12;
202pub const PF_KEY = 29;
203pub const PF_ROUTE = 34;
204pub const PF_SNA = 11;
205pub const PF_MPLS = 33;
206pub const PF_CAN = 35;
207pub const PF_BLUETOOTH = 31;
208pub const PF_ISDN = 26;
209pub const PF_MAX = 37;
210
211pub const AF_UNSPEC = PF_UNSPEC;
212pub const AF_LOCAL = PF_LOCAL;
213pub const AF_UNIX = AF_LOCAL;
214pub const AF_FILE = AF_LOCAL;
215pub const AF_INET = PF_INET;
216pub const AF_APPLETALK = PF_APPLETALK;
217pub const AF_INET6 = PF_INET6;
218pub const AF_KEY = PF_KEY;
219pub const AF_ROUTE = PF_ROUTE;
220pub const AF_SNA = PF_SNA;
221pub const AF_MPLS = PF_MPLS;
222pub const AF_CAN = PF_CAN;
223pub const AF_BLUETOOTH = PF_BLUETOOTH;
224pub const AF_ISDN = PF_ISDN;
225pub const AF_MAX = PF_MAX;
226
227pub const DT_UNKNOWN = 0;
228pub const DT_FIFO = 1;
229pub const DT_CHR = 2;
230pub const DT_DIR = 4;
231pub const DT_BLK = 6;
232pub const DT_REG = 8;
233pub const DT_LNK = 10;
234pub const DT_SOCK = 12;
235pub const DT_WHT = 14;
236
237/// add event to kq (implies enable)
238pub const EV_ADD = 0x0001;
239
240/// delete event from kq
241pub const EV_DELETE = 0x0002;
242
243/// enable event
244pub const EV_ENABLE = 0x0004;
245
246/// disable event (not reported)
247pub const EV_DISABLE = 0x0008;
248
249/// only report one occurrence
250pub const EV_ONESHOT = 0x0010;
251
252/// clear event state after reporting
253pub 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
259pub const EV_RECEIPT = 0x0040;
260
261/// disable event after reporting
262pub const EV_DISPATCH = 0x0080;
263
264pub const EVFILT_READ = 0;
265pub const EVFILT_WRITE = 1;
266
267/// attached to aio requests
268pub const EVFILT_AIO = 2;
269
270/// attached to vnodes
271pub const EVFILT_VNODE = 3;
272
273/// attached to struct proc
274pub const EVFILT_PROC = 4;
275
276/// attached to struct proc
277pub const EVFILT_SIGNAL = 5;
278
279/// timers
280pub const EVFILT_TIMER = 6;
281
282/// Filesystem events
283pub const EVFILT_FS = 7;
284
285/// On input, NOTE_TRIGGER causes the event to be triggered for output.
286pub const NOTE_TRIGGER = 0x08000000;
287
288/// low water mark
289pub const NOTE_LOWAT = 0x00000001;
290
291/// vnode was removed
292pub const NOTE_DELETE = 0x00000001;
293
294/// data contents changed
295pub const NOTE_WRITE = 0x00000002;
296
297/// size increased
298pub const NOTE_EXTEND = 0x00000004;
299
300/// attributes changed
301pub const NOTE_ATTRIB = 0x00000008;
302
303/// link count changed
304pub const NOTE_LINK = 0x00000010;
305
306/// vnode was renamed
307pub const NOTE_RENAME = 0x00000020;
308
309/// vnode access was revoked
310pub const NOTE_REVOKE = 0x00000040;
311
312/// process exited
313pub const NOTE_EXIT = 0x80000000;
314
315/// process forked
316pub const NOTE_FORK = 0x40000000;
317
318/// process exec'd
319pub const NOTE_EXEC = 0x20000000;
320
321/// mask for signal & exit status
322pub const NOTE_PDATAMASK = 0x000fffff;
323pub const NOTE_PCTRLMASK = 0xf0000000;
324
325pub const TIOCCBRK = 0x2000747a;
326pub const TIOCCDTR = 0x20007478;
327pub const TIOCCONS = 0x80047462;
328pub const TIOCDCDTIMESTAMP = 0x40107458;
329pub const TIOCDRAIN = 0x2000745e;
330pub const TIOCEXCL = 0x2000740d;
331pub const TIOCEXT = 0x80047460;
332pub const TIOCFLAG_CDTRCTS = 0x10;
333pub const TIOCFLAG_CLOCAL = 0x2;
334pub const TIOCFLAG_CRTSCTS = 0x4;
335pub const TIOCFLAG_MDMBUF = 0x8;
336pub const TIOCFLAG_SOFTCAR = 0x1;
337pub const TIOCFLUSH = 0x80047410;
338pub const TIOCGETA = 0x402c7413;
339pub const TIOCGETD = 0x4004741a;
340pub const TIOCGFLAGS = 0x4004745d;
341pub const TIOCGLINED = 0x40207442;
342pub const TIOCGPGRP = 0x40047477;
343pub const TIOCGQSIZE = 0x40047481;
344pub const TIOCGRANTPT = 0x20007447;
345pub const TIOCGSID = 0x40047463;
346pub const TIOCGSIZE = 0x40087468;
347pub const TIOCGWINSZ = 0x40087468;
348pub const TIOCMBIC = 0x8004746b;
349pub const TIOCMBIS = 0x8004746c;
350pub const TIOCMGET = 0x4004746a;
351pub const TIOCMSET = 0x8004746d;
352pub const TIOCM_CAR = 0x40;
353pub const TIOCM_CD = 0x40;
354pub const TIOCM_CTS = 0x20;
355pub const TIOCM_DSR = 0x100;
356pub const TIOCM_DTR = 0x2;
357pub const TIOCM_LE = 0x1;
358pub const TIOCM_RI = 0x80;
359pub const TIOCM_RNG = 0x80;
360pub const TIOCM_RTS = 0x4;
361pub const TIOCM_SR = 0x10;
362pub const TIOCM_ST = 0x8;
363pub const TIOCNOTTY = 0x20007471;
364pub const TIOCNXCL = 0x2000740e;
365pub const TIOCOUTQ = 0x40047473;
366pub const TIOCPKT = 0x80047470;
367pub const TIOCPKT_DATA = 0x0;
368pub const TIOCPKT_DOSTOP = 0x20;
369pub const TIOCPKT_FLUSHREAD = 0x1;
370pub const TIOCPKT_FLUSHWRITE = 0x2;
371pub const TIOCPKT_IOCTL = 0x40;
372pub const TIOCPKT_NOSTOP = 0x10;
373pub const TIOCPKT_START = 0x8;
374pub const TIOCPKT_STOP = 0x4;
375pub const TIOCPTMGET = 0x40287446;
376pub const TIOCPTSNAME = 0x40287448;
377pub const TIOCRCVFRAME = 0x80087445;
378pub const TIOCREMOTE = 0x80047469;
379pub const TIOCSBRK = 0x2000747b;
380pub const TIOCSCTTY = 0x20007461;
381pub const TIOCSDTR = 0x20007479;
382pub const TIOCSETA = 0x802c7414;
383pub const TIOCSETAF = 0x802c7416;
384pub const TIOCSETAW = 0x802c7415;
385pub const TIOCSETD = 0x8004741b;
386pub const TIOCSFLAGS = 0x8004745c;
387pub const TIOCSIG = 0x2000745f;
388pub const TIOCSLINED = 0x80207443;
389pub const TIOCSPGRP = 0x80047476;
390pub const TIOCSQSIZE = 0x80047480;
391pub const TIOCSSIZE = 0x80087467;
392pub const TIOCSTART = 0x2000746e;
393pub const TIOCSTAT = 0x80047465;
394pub const TIOCSTI = 0x80017472;
395pub const TIOCSTOP = 0x2000746f;
396pub const TIOCSWINSZ = 0x80087467;
397pub const TIOCUCNTL = 0x80047466;
398pub const TIOCXMTFRAME = 0x80087444;
399
400pub const sockaddr = c.sockaddr;
401pub const sockaddr_in = c.sockaddr_in;
402pub const sockaddr_in6 = c.sockaddr_in6;
403
404fn unsigned(s: i32) u32 {
405 return @bitCast(u32, s);
406}
407fn signed(s: u32) i32 {
408 return @bitCast(i32, s);
409}
410pub fn WEXITSTATUS(s: i32) i32 {
411 return signed((unsigned(s) >> 8) & 0xff);
412}
413pub fn WTERMSIG(s: i32) i32 {
414 return signed(unsigned(s) & 0x7f);
415}
416pub fn WSTOPSIG(s: i32) i32 {
417 return WEXITSTATUS(s);
418}
419pub fn WIFEXITED(s: i32) bool {
420 return WTERMSIG(s) == 0;
421}
422
423pub fn WIFCONTINUED(s: i32) bool {
424 return ((s & 0x7f) == 0xffff);
425}
426
427pub fn WIFSTOPPED(s: i32) bool {
428 return ((s & 0x7f != 0x7f) and !WIFCONTINUED(s));
429}
430
431pub fn WIFSIGNALED(s: i32) bool {
432 return !WIFSTOPPED(s) and !WIFCONTINUED(s) and !WIFEXITED(s);
433}
434
435pub 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.
443pub 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
448pub fn dup2(old: i32, new: i32) usize {
449 return errnoWrap(c.dup2(old, new));
450}
451
452pub fn chdir(path: [*]const u8) usize {
453 return errnoWrap(c.chdir(path));
454}
455
456pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {
457 return errnoWrap(c.execve(path, argv, envp));
458}
459
460pub fn fork() usize {
461 return errnoWrap(c.fork());
462}
463
464pub fn access(path: [*]const u8, mode: u32) usize {
465 return errnoWrap(c.access(path, mode));
466}
467
468pub fn getcwd(buf: [*]u8, size: usize) usize {
469 return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
470}
471
472pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
473 return errnoWrap(@bitCast(isize, c.getdents(fd, drip, count)));
474}
475
476pub 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
480pub 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
484pub fn isatty(fd: i32) bool {
485 return c.isatty(fd) != 0;
486}
487
488pub 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
492pub fn mkdir(path: [*]const u8, mode: u32) usize {
493 return errnoWrap(c.mkdir(path, mode));
494}
495
496pub 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
509pub fn munmap(address: usize, length: usize) usize {
510 return errnoWrap(c.munmap(@intToPtr(*c_void, address), length));
511}
512
513pub fn read(fd: i32, buf: [*]u8, nbyte: usize) usize {
514 return errnoWrap(c.read(fd, @ptrCast(*c_void, buf), nbyte));
515}
516
517pub fn rmdir(path: [*]const u8) usize {
518 return errnoWrap(c.rmdir(path));
519}
520
521pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
522 return errnoWrap(c.symlink(existing, new));
523}
524
525pub 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
529pub 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
533pub fn pipe(fd: *[2]i32) usize {
534 return pipe2(fd, 0);
535}
536
537pub 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
542pub fn write(fd: i32, buf: [*]const u8, nbyte: usize) usize {
543 return errnoWrap(c.write(fd, @ptrCast(*const c_void, buf), nbyte));
544}
545
546pub 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
550pub 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
554pub fn rename(old: [*]const u8, new: [*]const u8) usize {
555 return errnoWrap(c.rename(old, new));
556}
557
558pub fn open(path: [*]const u8, flags: u32, mode: usize) usize {
559 return errnoWrap(c.open(path, @bitCast(c_int, flags), mode));
560}
561
562pub fn create(path: [*]const u8, perm: usize) usize {
563 return arch.syscall2(SYS_creat, @ptrToInt(path), perm);
564}
565
566pub 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
570pub fn close(fd: i32) usize {
571 return errnoWrap(c.close(fd));
572}
573
574pub fn lseek(fd: i32, offset: isize, whence: c_int) usize {
575 return errnoWrap(c.lseek(fd, offset, whence));
576}
577
578pub fn exit(code: i32) noreturn {
579 c.exit(code);
580}
581
582pub fn kill(pid: i32, sig: i32) usize {
583 return errnoWrap(c.kill(pid, sig));
584}
585
586pub fn unlink(path: [*]const u8) usize {
587 return errnoWrap(c.unlink(path));
588}
589
590pub 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
595pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
596 return errnoWrap(c.nanosleep(req, rem));
597}
598
599pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
600 return errnoWrap(c.clock_gettime(clk_id, tp));
601}
602
603pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
604 return errnoWrap(c.clock_getres(clk_id, tp));
605}
606
607pub fn setuid(uid: u32) usize {
608 return errnoWrap(c.setuid(uid));
609}
610
611pub fn setgid(gid: u32) usize {
612 return errnoWrap(c.setgid(gid));
613}
614
615pub fn setreuid(ruid: u32, euid: u32) usize {
616 return errnoWrap(c.setreuid(ruid, euid));
617}
618
619pub fn setregid(rgid: u32, egid: u32) usize {
620 return errnoWrap(c.setregid(rgid, egid));
621}
622
623const NSIG = 32;
624
625pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
626pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
627pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
628
629/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
630pub 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
644pub const _SIG_WORDS = 4;
645pub const _SIG_MAXSIG = 128;
646
647pub inline fn _SIG_IDX(sig: usize) usize {
648 return sig - 1;
649}
650pub inline fn _SIG_WORD(sig: usize) usize {
651 return_SIG_IDX(sig) >> 5;
652}
653pub inline fn _SIG_BIT(sig: usize) usize {
654 return 1 << (_SIG_IDX(sig) & 31);
655}
656pub inline fn _SIG_VALID(sig: usize) usize {
657 return sig <= _SIG_MAXSIG and sig > 0;
658}
659
660pub const sigset_t = extern struct {
661 __bits: [_SIG_WORDS]u32,
662};
663
664pub fn raise(sig: i32) usize {
665 return errnoWrap(c.raise(sig));
666}
667
668pub const Stat = c.Stat;
669pub const dirent = c.dirent;
670pub const timespec = c.timespec;
671
672pub fn fstat(fd: i32, buf: *c.Stat) usize {
673 return errnoWrap(c.fstat(fd, buf));
674}
675pub const iovec = extern struct {
676 iov_base: [*]u8,
677 iov_len: usize,
678};
679
680pub const iovec_const = extern struct {
681 iov_base: [*]const u8,
682 iov_len: usize,
683};
684
685// TODO avoid libc dependency
686pub fn kqueue() usize {
687 return errnoWrap(c.kqueue());
688}
689
690// TODO avoid libc dependency
691pub 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
703pub 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
708pub 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
713pub 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.
722fn errnoWrap(value: isize) usize {
723 return @bitCast(usize, if (value == -1) -isize(c._errno().*) else value);
724}
3pub const is_the_target = builtin.os == .netbsd;
4pub use std.c;
std/os/netbsd/errno.zig deleted-134
......@@ -1,134 +0,0 @@
1pub const EPERM = 1; // Operation not permitted
2pub const ENOENT = 2; // No such file or directory
3pub const ESRCH = 3; // No such process
4pub const EINTR = 4; // Interrupted system call
5pub const EIO = 5; // Input/output error
6pub const ENXIO = 6; // Device not configured
7pub const E2BIG = 7; // Argument list too long
8pub const ENOEXEC = 8; // Exec format error
9pub const EBADF = 9; // Bad file descriptor
10pub const ECHILD = 10; // No child processes
11pub const EDEADLK = 11; // Resource deadlock avoided
12// 11 was EAGAIN
13pub const ENOMEM = 12; // Cannot allocate memory
14pub const EACCES = 13; // Permission denied
15pub const EFAULT = 14; // Bad address
16pub const ENOTBLK = 15; // Block device required
17pub const EBUSY = 16; // Device busy
18pub const EEXIST = 17; // File exists
19pub const EXDEV = 18; // Cross-device link
20pub const ENODEV = 19; // Operation not supported by device
21pub const ENOTDIR = 20; // Not a directory
22pub const EISDIR = 21; // Is a directory
23pub const EINVAL = 22; // Invalid argument
24pub const ENFILE = 23; // Too many open files in system
25pub const EMFILE = 24; // Too many open files
26pub const ENOTTY = 25; // Inappropriate ioctl for device
27pub const ETXTBSY = 26; // Text file busy
28pub const EFBIG = 27; // File too large
29pub const ENOSPC = 28; // No space left on device
30pub const ESPIPE = 29; // Illegal seek
31pub const EROFS = 30; // Read-only file system
32pub const EMLINK = 31; // Too many links
33pub const EPIPE = 32; // Broken pipe
34
35// math software
36pub const EDOM = 33; // Numerical argument out of domain
37pub const ERANGE = 34; // Result too large or too small
38
39// non-blocking and interrupt i/o
40pub const EAGAIN = 35; // Resource temporarily unavailable
41pub const EWOULDBLOCK = EAGAIN; // Operation would block
42pub const EINPROGRESS = 36; // Operation now in progress
43pub const EALREADY = 37; // Operation already in progress
44
45// ipc/network software -- argument errors
46pub const ENOTSOCK = 38; // Socket operation on non-socket
47pub const EDESTADDRREQ = 39; // Destination address required
48pub const EMSGSIZE = 40; // Message too long
49pub const EPROTOTYPE = 41; // Protocol wrong type for socket
50pub const ENOPROTOOPT = 42; // Protocol option not available
51pub const EPROTONOSUPPORT = 43; // Protocol not supported
52pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
53pub const EOPNOTSUPP = 45; // Operation not supported
54pub const EPFNOSUPPORT = 46; // Protocol family not supported
55pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
56pub const EADDRINUSE = 48; // Address already in use
57pub const EADDRNOTAVAIL = 49; // Can't assign requested address
58
59// ipc/network software -- operational errors
60pub const ENETDOWN = 50; // Network is down
61pub const ENETUNREACH = 51; // Network is unreachable
62pub const ENETRESET = 52; // Network dropped connection on reset
63pub const ECONNABORTED = 53; // Software caused connection abort
64pub const ECONNRESET = 54; // Connection reset by peer
65pub const ENOBUFS = 55; // No buffer space available
66pub const EISCONN = 56; // Socket is already connected
67pub const ENOTCONN = 57; // Socket is not connected
68pub const ESHUTDOWN = 58; // Can't send after socket shutdown
69pub const ETOOMANYREFS = 59; // Too many references: can't splice
70pub const ETIMEDOUT = 60; // Operation timed out
71pub const ECONNREFUSED = 61; // Connection refused
72
73pub const ELOOP = 62; // Too many levels of symbolic links
74pub const ENAMETOOLONG = 63; // File name too long
75
76// should be rearranged
77pub const EHOSTDOWN = 64; // Host is down
78pub const EHOSTUNREACH = 65; // No route to host
79pub const ENOTEMPTY = 66; // Directory not empty
80
81// quotas & mush
82pub const EPROCLIM = 67; // Too many processes
83pub const EUSERS = 68; // Too many users
84pub const EDQUOT = 69; // Disc quota exceeded
85
86// Network File System
87pub const ESTALE = 70; // Stale NFS file handle
88pub const EREMOTE = 71; // Too many levels of remote in path
89pub const EBADRPC = 72; // RPC struct is bad
90pub const ERPCMISMATCH = 73; // RPC version wrong
91pub const EPROGUNAVAIL = 74; // RPC prog. not avail
92pub const EPROGMISMATCH = 75; // Program version wrong
93pub const EPROCUNAVAIL = 76; // Bad procedure for program
94
95pub const ENOLCK = 77; // No locks available
96pub const ENOSYS = 78; // Function not implemented
97
98pub const EFTYPE = 79; // Inappropriate file type or format
99pub const EAUTH = 80; // Authentication error
100pub const ENEEDAUTH = 81; // Need authenticator
101
102// SystemV IPC
103pub const EIDRM = 82; // Identifier removed
104pub const ENOMSG = 83; // No message of desired type
105pub const EOVERFLOW = 84; // Value too large to be stored in data type
106
107// Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
108pub const EILSEQ = 85; // Illegal byte sequence
109
110// From IEEE Std 1003.1-2001
111// Base, Realtime, Threads or Thread Priority Scheduling option errors
112pub const ENOTSUP = 86; // Not supported
113
114// Realtime option errors
115pub const ECANCELED = 87; // Operation canceled
116
117// Realtime, XSI STREAMS option errors
118pub const EBADMSG = 88; // Bad or Corrupt message
119
120// XSI STREAMS option errors
121pub const ENODATA = 89; // No message available
122pub const ENOSR = 90; // No STREAM resources
123pub const ENOSTR = 91; // Not a STREAM
124pub const ETIME = 92; // STREAM ioctl timeout
125
126// File system extended attribute errors
127pub const ENOATTR = 93; // Attribute not found
128
129// Realtime, XSI STREAMS option errors
130pub const EMULTIHOP = 94; // Multihop attempted
131pub const ENOLINK = 95; // Link has been severed
132pub const EPROTO = 96; // Protocol error
133
134pub const ELAST = 96; // Must equal largest errno
std/os/path.zig-2
......@@ -1162,10 +1162,8 @@ pub const RealError = error{
11621162 /// On Windows, file paths must be valid Unicode.
11631163 InvalidUtf8,
11641164
1165 /// TODO remove this possibility
11661165 PathAlreadyExists,
11671166
1168 /// TODO remove this possibility
11691167 Unexpected,
11701168};
11711169
std/os/posix.zig+343-132
......@@ -33,10 +33,7 @@ const wasi = os.wasi;
3333const linux = os.linux;
3434const testing = std.testing;
3535
36pub const FileHandle = if (windows.is_the_target) windows.HANDLE else if (wasi.is_the_target) wasi.fd_t else i32;
37pub use system.errno_codes;
38
39pub const PATH_MAX = system.PATH_MAX;
36pub use system.posix;
4037
4138/// > The maximum path of 32,767 characters is approximate, because the "\\?\"
4239/// > 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;
4441/// from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
4542pub const PATH_MAX_WIDE = 32767;
4643
47pub const iovec = system.iovec;
48pub const iovec_const = system.iovec_const;
49
5044/// See also `getenv`.
5145pub var environ: [][*]u8 = undefined;
5246
......@@ -58,23 +52,23 @@ pub var environ: [][*]u8 = undefined;
5852/// value of.
5953pub const errno = system.getErrno;
6054
61/// Closes the file handle.
55/// Closes the file descriptor.
6256/// This function is not capable of returning any indication of failure. An
6357/// application which wants to ensure writes have succeeded before closing
6458/// must call `fsync` before `close`.
6559/// Note: The Zig standard library does not support POSIX thread cancellation.
66pub fn close(handle: FileHandle) void {
60pub fn close(fd: fd_t) void {
6761 if (windows.is_the_target and !builtin.link_libc) {
68 assert(windows.CloseHandle(handle) != 0);
62 assert(windows.CloseHandle(fd) != 0);
6963 return;
7064 }
7165 if (wasi.is_the_target) {
72 switch (wasi.fd_close(handle)) {
66 switch (wasi.fd_close(fd)) {
7367 0 => return,
7468 else => |err| return unexpectedErrno(err),
7569 }
7670 }
77 switch (system.getErrno(system.close(handle))) {
71 switch (errno(system.close(fd))) {
7872 EBADF => unreachable, // Always a race condition.
7973 EINTR => return, // This is still a success. See https://github.com/ziglang/zig/issues/2425
8074 else => return,
......@@ -103,7 +97,7 @@ pub fn getrandom(buf: []u8) GetRandomError!void {
10397 }
10498 if (linux.is_the_target) {
10599 while (true) {
106 switch (system.getErrno(system.getrandom(buf.ptr, buf.len, 0))) {
100 switch (errno(system.getrandom(buf.ptr, buf.len, 0))) {
107101 0 => return,
108102 EINVAL => unreachable,
109103 EFAULT => unreachable,
......@@ -146,7 +140,7 @@ test "os.getRandomBytes" {
146140pub fn abort() noreturn {
147141 @setCold(true);
148142 if (builtin.link_libc) {
149 c.abort();
143 system.abort();
150144 }
151145 if (windows.is_the_target) {
152146 if (builtin.mode == .Debug) {
......@@ -171,7 +165,7 @@ pub const RaiseError = error{};
171165
172166pub fn raise(sig: u8) RaiseError!void {
173167 if (builtin.link_libc) {
174 switch (system.getErrno(system.raise(sig))) {
168 switch (errno(system.raise(sig))) {
175169 0 => return,
176170 else => |err| return unexpectedErrno(err),
177171 }
......@@ -193,7 +187,7 @@ pub fn raise(sig: u8) RaiseError!void {
193187 const tid = system.syscall0(system.SYS_gettid);
194188 const rc = system.syscall2(system.SYS_tkill, tid, sig);
195189 system.restoreSignals(&set);
196 switch (system.getErrno(rc)) {
190 switch (errno(rc)) {
197191 0 => return,
198192 else => |err| return unexpectedErrno(err),
199193 }
......@@ -202,7 +196,7 @@ pub fn raise(sig: u8) RaiseError!void {
202196/// Exits the program cleanly with the specified status code.
203197pub fn exit(status: u8) noreturn {
204198 if (builtin.link_libc) {
205 std.c.exit(status);
199 system.exit(status);
206200 }
207201 if (windows.is_the_target) {
208202 windows.ExitProcess(status);
......@@ -229,7 +223,7 @@ pub const ReadError = error{
229223/// buf.len. If 0 bytes were read, that means EOF.
230224/// This function is for blocking file descriptors only. For non-blocking, see
231225/// `readAsync`.
232pub fn read(fd: FileHandle, buf: []u8) ReadError!usize {
226pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
233227 if (windows.is_the_target and !builtin.link_libc) {
234228 var index: usize = 0;
235229 while (index < buffer.len) {
......@@ -270,7 +264,7 @@ pub fn read(fd: FileHandle, buf: []u8) ReadError!usize {
270264 while (index < buf.len) {
271265 const want_to_read = math.min(buf.len - index, usize(max_buf_len));
272266 const rc = system.read(fd, buf.ptr + index, want_to_read);
273 switch (system.getErrno(rc)) {
267 switch (errno(rc)) {
274268 0 => {
275269 index += rc;
276270 if (rc == want_to_read) continue;
......@@ -295,7 +289,7 @@ pub fn read(fd: FileHandle, buf: []u8) ReadError!usize {
295289/// Number of bytes read is returned. Upon reading end-of-file, zero is returned.
296290/// This function is for blocking file descriptors only. For non-blocking, see
297291/// `preadvAsync`.
298pub fn preadv(fd: FileHandle, iov: [*]const iovec, count: usize, offset: u64) ReadError!usize {
292pub fn preadv(fd: fd_t, iov: [*]const iovec, count: usize, offset: u64) ReadError!usize {
299293 if (os.darwin.is_the_target) {
300294 // Darwin does not have preadv but it does have pread.
301295 var off: usize = 0;
......@@ -335,8 +329,7 @@ pub fn preadv(fd: FileHandle, iov: [*]const iovec, count: usize, offset: u64) Re
335329 }
336330 while (true) {
337331 const rc = system.preadv(fd, iov, count, offset);
338 const err = system.getErrno(rc);
339 switch (err) {
332 switch (errno(rc)) {
340333 0 => return rc,
341334 EINTR => continue,
342335 EINVAL => unreachable,
......@@ -347,7 +340,7 @@ pub fn preadv(fd: FileHandle, iov: [*]const iovec, count: usize, offset: u64) Re
347340 EISDIR => return error.IsDir,
348341 ENOBUFS => return error.SystemResources,
349342 ENOMEM => return error.SystemResources,
350 else => return unexpectedErrno(err),
343 else => |err| return unexpectedErrno(err),
351344 }
352345 }
353346}
......@@ -367,7 +360,7 @@ pub const WriteError = error{
367360/// Write to a file descriptor. Keeps trying if it gets interrupted.
368361/// This function is for blocking file descriptors only. For non-blocking, see
369362/// `writeAsync`.
370pub fn write(fd: FileHandle, bytes: []const u8) WriteError!void {
363pub fn write(fd: fd_t, bytes: []const u8) WriteError!void {
371364 if (windows.is_the_target and !builtin.link_libc) {
372365 var bytes_written: windows.DWORD = undefined;
373366 // 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 {
404397 while (index < bytes.len) {
405398 const amt_to_write = math.min(bytes.len - index, usize(max_bytes_len));
406399 const rc = system.write(fd, bytes.ptr + index, amt_to_write);
407 const write_err = system.getErrno(rc);
408 switch (write_err) {
400 switch (errno(rc)) {
409401 0 => {
410402 index += rc;
411403 continue;
......@@ -422,7 +414,7 @@ pub fn write(fd: FileHandle, bytes: []const u8) WriteError!void {
422414 ENOSPC => return error.NoSpaceLeft,
423415 EPERM => return error.AccessDenied,
424416 EPIPE => return error.BrokenPipe,
425 else => return unexpectedErrno(write_err),
417 else => |err| return unexpectedErrno(err),
426418 }
427419 }
428420}
......@@ -430,7 +422,7 @@ pub fn write(fd: FileHandle, bytes: []const u8) WriteError!void {
430422/// Write multiple buffers to a file descriptor. Keeps trying if it gets interrupted.
431423/// This function is for blocking file descriptors only. For non-blocking, see
432424/// `pwritevAsync`.
433pub fn pwritev(fd: FileHandle, iov: [*]const iovec_const, count: usize, offset: u64) WriteError!void {
425pub fn pwritev(fd: fd_t, iov: [*]const iovec_const, count: usize, offset: u64) WriteError!void {
434426 if (darwin.is_the_target) {
435427 // Darwin does not have pwritev but it does have pwrite.
436428 var off: usize = 0;
......@@ -473,8 +465,7 @@ pub fn pwritev(fd: FileHandle, iov: [*]const iovec_const, count: usize, offset:
473465
474466 while (true) {
475467 const rc = system.pwritev(fd, iov, count, offset);
476 const err = system.getErrno(rc);
477 switch (err) {
468 switch (errno(rc)) {
478469 0 => return,
479470 EINTR => continue,
480471 EINVAL => unreachable,
......@@ -488,7 +479,7 @@ pub fn pwritev(fd: FileHandle, iov: [*]const iovec_const, count: usize, offset:
488479 ENOSPC => return error.NoSpaceLeft,
489480 EPERM => return error.AccessDenied,
490481 EPIPE => return error.BrokenPipe,
491 else => return unexpectedErrno(err),
482 else => |err| return unexpectedErrno(err),
492483 }
493484 }
494485}
......@@ -514,7 +505,7 @@ pub const OpenError = error{
514505/// Open and possibly create a file. Keeps trying if it gets interrupted.
515506/// `file_path` needs to be copied in memory to add a null terminating byte.
516507/// See also `openC`.
517pub fn open(file_path: []const u8, flags: u32, perm: usize) OpenError!FileHandle {
508pub fn open(file_path: []const u8, flags: u32, perm: usize) OpenError!fd_t {
518509 const file_path_c = try toPosixPath(file_path);
519510 return openC(&file_path_c, flags, perm);
520511}
......@@ -522,11 +513,11 @@ pub fn open(file_path: []const u8, flags: u32, perm: usize) OpenError!FileHandle
522513/// Open and possibly create a file. Keeps trying if it gets interrupted.
523514/// See also `open`.
524515/// TODO https://github.com/ziglang/zig/issues/265
525pub fn openC(file_path: [*]const u8, flags: u32, perm: usize) OpenError!FileHandle {
516pub fn openC(file_path: [*]const u8, flags: u32, perm: usize) OpenError!fd_t {
526517 while (true) {
527518 const rc = system.open(file_path, flags, perm);
528 switch (system.getErrno(rc)) {
529 0 => return @intCast(FileHandle, rc),
519 switch (errno(rc)) {
520 0 => return @intCast(fd_t, rc),
530521 EINTR => continue,
531522
532523 EFAULT => unreachable,
......@@ -582,7 +573,7 @@ pub fn openWindows(
582573 share_mode: windows.DWORD,
583574 creation_disposition: windows.DWORD,
584575 flags_and_attrs: windows.DWORD,
585) WindowsOpenError!FileHandle {
576) WindowsOpenError!fd_t {
586577 const file_path_w = try sliceToPrefixedFileW(file_path);
587578 return openW(&file_path_w, desired_access, share_mode, creation_disposition, flags_and_attrs);
588579}
......@@ -613,9 +604,9 @@ pub fn openW(
613604 return result;
614605}
615606
616pub fn dup2(old_fd: FileHandle, new_fd: FileHandle) !void {
607pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void {
617608 while (true) {
618 switch (system.getErrno(system.dup2(old_fd, new_fd))) {
609 switch (errno(system.dup2(old_fd, new_fd))) {
619610 0 => return,
620611 EBUSY, EINTR => continue,
621612 EMFILE => return error.ProcessFdQuotaExceeded,
......@@ -630,6 +621,7 @@ pub fn dup2(old_fd: FileHandle, new_fd: FileHandle) !void {
630621/// pointers after the args and after the environment variables.
631622/// `argv[0]` is the executable path.
632623/// 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
633625pub fn execve(allocator: *Allocator, argv: []const []const u8, env_map: *const BufMap) !void {
634626 const argv_buf = try allocator.alloc(?[*]u8, argv.len + 1);
635627 mem.set(?[*]u8, argv_buf, null);
......@@ -654,7 +646,7 @@ pub fn execve(allocator: *Allocator, argv: []const []const u8, env_map: *const B
654646
655647 const exe_path = argv[0];
656648 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)));
658650 }
659651
660652 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
671663 path_buf[search_path.len] = '/';
672664 mem.copy(u8, path_buf[search_path.len + 1 ..], exe_path);
673665 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));
675667 assert(err > 0);
676668 if (err == EACCES) {
677669 seen_eacces = true;
......@@ -776,7 +768,7 @@ pub fn getenv(key: []const u8) ?[]const u8 {
776768/// TODO https://github.com/ziglang/zig/issues/265
777769pub fn getenvC(key: [*]const u8) ?[]const u8 {
778770 if (builtin.link_libc) {
779 const value = std.c.getenv(key) orelse return null;
771 const value = system.getenv(key) orelse return null;
780772 return mem.toSliceConst(u8, value);
781773 }
782774 return getenv(mem.toSliceConst(u8, key));
......@@ -785,7 +777,7 @@ pub fn getenvC(key: [*]const u8) ?[]const u8 {
785777/// See std.elf for the constants.
786778pub fn getauxval(index: usize) usize {
787779 if (builtin.link_libc) {
788 return usize(std.c.getauxval(index));
780 return usize(system.getauxval(index));
789781 } else if (linux.elf_aux_maybe) |auxv| {
790782 var i: usize = 0;
791783 while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {
......@@ -829,9 +821,9 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
829821 }
830822
831823 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().*;
833825 } 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));
835827 };
836828 switch (err) {
837829 0 => return mem.toSlice(u8, out_buffer),
......@@ -883,21 +875,14 @@ pub fn symlink(target_path: []const u8, new_path: []const u8) SymLinkError!void
883875 }
884876}
885877
886pub fn symlinkat(target_path: []const u8, newdirfd: FileHandle, new_path: []const u8) SymLinkError!void {
878pub fn symlinkat(target_path: []const u8, newdirfd: fd_t, new_path: []const u8) SymLinkError!void {
887879 const target_path_c = try toPosixPath(target_path);
888880 const new_path_c = try toPosixPath(new_path);
889881 return symlinkatC(target_path_c, newdirfd, new_path_c);
890882}
891883
892pub fn symlinkatC(target_path: [*]const u8, newdirfd: FileHandle, new_path: [*]const u8) SymLinkError!void {
893 const err = blk: {
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) {
884pub fn symlinkatC(target_path: [*]const u8, newdirfd: fd_t, new_path: [*]const u8) SymLinkError!void {
885 switch (errno(system.symlinkat(target_path, newdirfd, new_path))) {
901886 0 => return,
902887 EFAULT => unreachable,
903888 EINVAL => unreachable,
......@@ -913,7 +898,7 @@ pub fn symlinkatC(target_path: [*]const u8, newdirfd: FileHandle, new_path: [*]c
913898 ENOMEM => return error.SystemResources,
914899 ENOSPC => return error.NoSpaceLeft,
915900 EROFS => return error.ReadOnlyFileSystem,
916 else => return unexpectedErrno(err),
901 else => |err| return unexpectedErrno(err),
917902 }
918903}
919904
......@@ -925,12 +910,10 @@ pub fn symlinkC(target_path: [*]const u8, new_path: [*]const u8) SymLinkError!vo
925910 const new_path_w = try cStrToPrefixedFileW(new_path);
926911 return symlinkW(&target_path_w, &new_path_w);
927912 }
928 const err = if (builtin.link_libc) blk: {
929 break :blk if (std.c.symlink(target_path, new_path) == -1) errno().* else 0;
930 } else if (@hasDecl(system, "symlink")) blk: {
931 break :blk system.getErrno(system.symlink(target_path, new_path));
913 const err = if (builtin.link_libc or @hasDecl(system, "SYS_symlink")) blk: {
914 break :blk errno(system.symlink(target_path, new_path));
932915 } 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));
934917 };
935918 switch (err) {
936919 0 => return,
......@@ -1018,12 +1001,10 @@ pub fn unlinkC(file_path: [*]const u8) UnlinkError!void {
10181001 const file_path_w = try cStrToPrefixedFileW(file_path);
10191002 return unlinkW(&file_path_w);
10201003 }
1021 const err = if (builtin.link_libc) blk: {
1022 break :blk if (std.c.unlink(file_path) == -1) errno().* else 0;
1023 } else if (@hasDecl(system, "unlink")) blk: {
1024 break :blk system.getErrno(system.unlink(file_path));
1004 const err = if (builtin.link_libc or @hasDecl(system, "SYS_unlink")) blk: {
1005 break :blk errno(system.unlink(file_path));
10251006 } 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));
10271008 };
10281009 switch (err) {
10291010 0 => return,
......@@ -1066,14 +1047,12 @@ pub fn renameC(old_path: [*]const u8, new_path: [*]const u8) RenameError!void {
10661047 const new_path_w = try cStrToPrefixedFileW(new_path);
10671048 return renameW(&old_path_w, &new_path_w);
10681049 }
1069 const err = if (builtin.link_libc) blk: {
1070 break :blk if (std.c.rename(old_path, new_path) == -1) errno().* else 0;
1071 } else if (@hasDecl(system, "rename")) blk: {
1072 break :blk system.getErrno(system.rename(old_path, new_path));
1073 } else if (@hasDecl(system, "renameat")) blk: {
1074 break :blk system.getErrno(system.renameat(AT_FDCWD, old_path, AT_FDCWD, new_path));
1050 const err = if (builtin.link_libc or @hasDecl(system, "SYS_rename")) blk: {
1051 break :blk errno(system.rename(old_path, new_path));
1052 } else if (@hasDecl(system, "SYS_renameat")) blk: {
1053 break :blk errno(system.renameat(AT_FDCWD, old_path, AT_FDCWD, new_path));
10751054 } 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));
10771056 };
10781057 switch (err) {
10791058 0 => return,
......@@ -1131,12 +1110,10 @@ pub fn mkdirC(dir_path: [*]const u8, mode: u32) MakeDirError!void {
11311110 const dir_path_w = try cStrToPrefixedFileW(dir_path);
11321111 return mkdirW(&dir_path_w, mode);
11331112 }
1134 const err = if (builtin.link_libc) blk: {
1135 break :blk if (std.c.mkdir(dir_path, mode) == -1) errno().* else 0;
1136 } else if (@hasDecl(system, "mkdir")) blk: {
1137 break :blk system.getErrno(system.mkdir(dir_path, mode));
1113 const err = if (builtin.link_libc or @hasDecl(system, "SYS_mkdir")) blk: {
1114 break :blk errno(system.mkdir(dir_path, mode));
11381115 } 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));
11401117 };
11411118 switch (err) {
11421119 0 => return,
......@@ -1203,12 +1180,10 @@ pub fn rmdirC(dir_path: [*]const u8) DeleteDirError!void {
12031180 const dir_path_w = try cStrToPrefixedFileW(dir_path);
12041181 return rmdirW(&dir_path_w);
12051182 }
1206 const err = if (builtin.link_libc) blk: {
1207 break :blk if (std.c.rmdir(dir_path) == -1) errno().* else 0;
1208 } else if (@hasDecl(system, "rmdir")) blk: {
1209 break :blk system.getErrno(system.rmdir(dir_path));
1183 const err = if (builtin.link_libc or @hasDecl(system, "SYS_rmdir")) blk: {
1184 break :blk errno(system.rmdir(dir_path));
12101185 } 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));
12121187 };
12131188 switch (err) {
12141189 0 => return,
......@@ -1262,12 +1237,7 @@ pub fn chdirC(dir_path: [*]const u8) ChangeCurDirError!void {
12621237 const dir_path_w = try cStrToPrefixedFileW(dir_path);
12631238 return chdirW(&dir_path_w);
12641239 }
1265 const err = if (builtin.link_libc) blk: {
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) {
1240 switch (errno(system.chdir(dir_path))) {
12711241 0 => return,
12721242 EACCES => return error.AccessDenied,
12731243 EFAULT => unreachable,
......@@ -1277,7 +1247,7 @@ pub fn chdirC(dir_path: [*]const u8) ChangeCurDirError!void {
12771247 ENOENT => return error.FileNotFound,
12781248 ENOMEM => return error.SystemResources,
12791249 ENOTDIR => return error.NotDir,
1280 else => return unexpectedErrno(err),
1250 else => |err| return unexpectedErrno(err),
12811251 }
12821252}
12831253
......@@ -1307,15 +1277,12 @@ pub fn readlinkC(file_path: [*]const u8, out_buffer: []u8) ReadLinkError![]u8 {
13071277 const file_path_w = try cStrToPrefixedFileW(file_path);
13081278 return readlinkW(&file_path_w, out_buffer);
13091279 }
1310 const err = if (builtin.link_libc) blk: {
1311 break :blk if (std.c.readlink(file_path, out_buffer.ptr, out_buffer.len) == -1) errno().* else 0;
1312 } else if (@hasDecl(system, "readlink")) blk: {
1313 break :blk system.getErrno(system.readlink(file_path, out_buffer.ptr, out_buffer.len));
1280 const rc = if (builtin.link_libc or @hasDecl(system, "SYS_readlink")) blk: {
1281 break :blk system.readlink(file_path, out_buffer.ptr, out_buffer.len);
13141282 } 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);
13161284 };
1317 const rc = system.readlink(file_path, out_buffer, out_buffer.len);
1318 switch (system.getErrno(rc)) {
1285 switch (errno(rc)) {
13191286 0 => return out_buffer[0..rc],
13201287 EACCES => return error.AccessDenied,
13211288 EFAULT => unreachable,
......@@ -1338,7 +1305,7 @@ pub const SetIdError = error{
13381305};
13391306
13401307pub fn setuid(uid: u32) SetIdError!void {
1341 switch (system.getErrno(system.setuid(uid))) {
1308 switch (errno(system.setuid(uid))) {
13421309 0 => return,
13431310 EAGAIN => return error.ResourceLimitReached,
13441311 EINVAL => return error.InvalidUserId,
......@@ -1348,7 +1315,7 @@ pub fn setuid(uid: u32) SetIdError!void {
13481315}
13491316
13501317pub fn setreuid(ruid: u32, euid: u32) SetIdError!void {
1351 switch (system.getErrno(system.setreuid(ruid, euid))) {
1318 switch (errno(system.setreuid(ruid, euid))) {
13521319 0 => return,
13531320 EAGAIN => return error.ResourceLimitReached,
13541321 EINVAL => return error.InvalidUserId,
......@@ -1358,7 +1325,7 @@ pub fn setreuid(ruid: u32, euid: u32) SetIdError!void {
13581325}
13591326
13601327pub fn setgid(gid: u32) SetIdError!void {
1361 switch (system.getErrno(system.setgid(gid))) {
1328 switch (errno(system.setgid(gid))) {
13621329 0 => return,
13631330 EAGAIN => return error.ResourceLimitReached,
13641331 EINVAL => return error.InvalidUserId,
......@@ -1368,7 +1335,7 @@ pub fn setgid(gid: u32) SetIdError!void {
13681335}
13691336
13701337pub fn setregid(rgid: u32, egid: u32) SetIdError!void {
1371 switch (system.getErrno(system.setregid(rgid, egid))) {
1338 switch (errno(system.setregid(rgid, egid))) {
13721339 0 => return,
13731340 EAGAIN => return error.ResourceLimitReached,
13741341 EINVAL => return error.InvalidUserId,
......@@ -1382,7 +1349,7 @@ pub const GetStdHandleError = error{
13821349 Unexpected,
13831350};
13841351
1385pub fn GetStdHandle(handle_id: windows.DWORD) GetStdHandleError!FileHandle {
1352pub fn GetStdHandle(handle_id: windows.DWORD) GetStdHandleError!fd_t {
13861353 if (windows.is_the_target) {
13871354 const handle = windows.GetStdHandle(handle_id) orelse return error.NoStandardHandleAttached;
13881355 if (handle == windows.INVALID_HANDLE_VALUE) {
......@@ -1402,9 +1369,9 @@ pub fn GetStdHandle(handle_id: windows.DWORD) GetStdHandleError!FileHandle {
14021369}
14031370
14041371/// Test whether a file descriptor refers to a terminal.
1405pub fn isatty(handle: FileHandle) bool {
1372pub fn isatty(handle: fd_t) bool {
14061373 if (builtin.link_libc) {
1407 return c.isatty(handle) != 0;
1374 return system.isatty(handle) != 0;
14081375 }
14091376 if (windows.is_the_target) {
14101377 if (isCygwinPty(handle))
......@@ -1421,7 +1388,7 @@ pub fn isatty(handle: FileHandle) bool {
14211388 return system.syscall3(system.SYS_ioctl, @bitCast(usize, isize(handle)), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
14221389}
14231390
1424pub fn isCygwinPty(handle: FileHandle) bool {
1391pub fn isCygwinPty(handle: fd_t) bool {
14251392 if (!windows.is_the_target) return false;
14261393
14271394 const size = @sizeOf(windows.FILE_NAME_INFO);
......@@ -1472,7 +1439,7 @@ pub const SocketError = error{
14721439
14731440pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!i32 {
14741441 const rc = system.socket(domain, socket_type, protocol);
1475 switch (system.getErrno(rc)) {
1442 switch (errno(rc)) {
14761443 0 => return @intCast(i32, rc),
14771444 EACCES => return error.PermissionDenied,
14781445 EAFNOSUPPORT => return error.AddressFamilyNotSupported,
......@@ -1525,7 +1492,7 @@ pub const BindError = error{
15251492/// addr is `*const T` where T is one of the sockaddr
15261493pub fn bind(fd: i32, addr: *const sockaddr) BindError!void {
15271494 const rc = system.bind(fd, system, @sizeOf(sockaddr));
1528 switch (system.getErrno(rc)) {
1495 switch (errno(rc)) {
15291496 0 => return,
15301497 EACCES => return error.AccessDenied,
15311498 EADDRINUSE => return error.AddressInUse,
......@@ -1563,7 +1530,7 @@ const ListenError = error{
15631530
15641531pub fn listen(sockfd: i32, backlog: u32) ListenError!void {
15651532 const rc = system.listen(sockfd, backlog);
1566 switch (system.getErrno(rc)) {
1533 switch (errno(rc)) {
15671534 0 => return,
15681535 EADDRINUSE => return error.AddressInUse,
15691536 EBADF => unreachable,
......@@ -1606,7 +1573,7 @@ pub fn accept4(fd: i32, addr: *sockaddr, flags: u32) AcceptError!i32 {
16061573 while (true) {
16071574 var sockaddr_size = u32(@sizeOf(sockaddr));
16081575 const rc = system.accept4(fd, addr, &sockaddr_size, flags);
1609 switch (system.getErrno(rc)) {
1576 switch (errno(rc)) {
16101577 0 => return @intCast(i32, rc),
16111578 EINTR => continue,
16121579 else => |err| return unexpectedErrno(err),
......@@ -1634,7 +1601,7 @@ pub fn accept4_async(fd: i32, addr: *sockaddr, flags: u32) AcceptError!i32 {
16341601 while (true) {
16351602 var sockaddr_size = u32(@sizeOf(sockaddr));
16361603 const rc = system.accept4(fd, addr, &sockaddr_size, flags);
1637 switch (system.getErrno(rc)) {
1604 switch (errno(rc)) {
16381605 0 => return @intCast(i32, rc),
16391606 EINTR => continue,
16401607 else => |err| return unexpectedErrno(err),
......@@ -1674,7 +1641,7 @@ pub const EpollCreateError = error{
16741641
16751642pub fn epoll_create1(flags: u32) EpollCreateError!i32 {
16761643 const rc = system.epoll_create1(flags);
1677 switch (system.getErrno(rc)) {
1644 switch (errno(rc)) {
16781645 0 => return @intCast(i32, rc),
16791646 else => |err| return unexpectedErrno(err),
16801647
......@@ -1715,7 +1682,7 @@ pub const EpollCtlError = error{
17151682
17161683pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: *epoll_event) EpollCtlError!void {
17171684 const rc = system.epoll_ctl(epfd, op, fd, event);
1718 switch (system.getErrno(rc)) {
1685 switch (errno(rc)) {
17191686 0 => return,
17201687 else => |err| return unexpectedErrno(err),
17211688
......@@ -1737,7 +1704,7 @@ pub fn epoll_wait(epfd: i32, events: []epoll_event, timeout: i32) usize {
17371704 while (true) {
17381705 // TODO get rid of the @intCast
17391706 const rc = system.epoll_wait(epfd, events.ptr, @intCast(u32, events.len), timeout);
1740 switch (system.getErrno(rc)) {
1707 switch (errno(rc)) {
17411708 0 => return rc,
17421709 EINTR => continue,
17431710 EBADF => unreachable,
......@@ -1757,7 +1724,7 @@ pub const EventFdError = error{
17571724
17581725pub fn eventfd(initval: u32, flags: u32) EventFdError!i32 {
17591726 const rc = system.eventfd(initval, flags);
1760 switch (system.getErrno(rc)) {
1727 switch (errno(rc)) {
17611728 0 => return @intCast(i32, rc),
17621729 else => |err| return unexpectedErrno(err),
17631730
......@@ -1779,7 +1746,7 @@ pub const GetSockNameError = error{
17791746pub fn getsockname(sockfd: i32) GetSockNameError!sockaddr {
17801747 var addr: sockaddr = undefined;
17811748 var addrlen: socklen_t = @sizeOf(sockaddr);
1782 switch (system.getErrno(system.getsockname(sockfd, &addr, &addrlen))) {
1749 switch (errno(system.getsockname(sockfd, &addr, &addrlen))) {
17831750 0 => return addr,
17841751 else => |err| return unexpectedErrno(err),
17851752
......@@ -1832,7 +1799,7 @@ pub const ConnectError = error{
18321799/// For non-blocking, see `connect_async`.
18331800pub fn connect(sockfd: i32, sockaddr: *const sockaddr) ConnectError!void {
18341801 while (true) {
1835 switch (system.getErrno(system.connect(sockfd, sockaddr, @sizeOf(sockaddr)))) {
1802 switch (errno(system.connect(sockfd, sockaddr, @sizeOf(sockaddr)))) {
18361803 0 => return,
18371804 else => |err| return unexpectedErrno(err),
18381805
......@@ -1861,10 +1828,10 @@ pub fn connect(sockfd: i32, sockaddr: *const sockaddr) ConnectError!void {
18611828/// It expects to receive EINPROGRESS`.
18621829pub fn connect_async(sockfd: i32, sockaddr: *const c_void, len: u32) ConnectError!void {
18631830 while (true) {
1864 switch (system.getErrno(system.connect(sockfd, sockaddr, len))) {
1831 switch (errno(system.connect(sockfd, sockaddr, len))) {
18651832 0, EINPROGRESS => return,
18661833 EINTR => continue,
1867 else => return unexpectedErrno(err),
1834 else => |err| return unexpectedErrno(err),
18681835
18691836 EACCES => return error.PermissionDenied,
18701837 EPERM => return error.PermissionDenied,
......@@ -1890,7 +1857,7 @@ pub fn getsockoptError(sockfd: i32) ConnectError!void {
18901857 var size: u32 = @sizeOf(i32);
18911858 const rc = system.getsockopt(sockfd, SOL_SOCKET, SO_ERROR, @ptrCast([*]u8, &err_code), &size);
18921859 assert(size == 4);
1893 switch (system.getErrno(rc)) {
1860 switch (errno(rc)) {
18941861 0 => switch (err_code) {
18951862 0 => return,
18961863 EACCES => return error.PermissionDenied,
......@@ -1919,10 +1886,10 @@ pub fn getsockoptError(sockfd: i32) ConnectError!void {
19191886 }
19201887}
19211888
1922pub fn wait(pid: i32) i32 {
1889pub fn waitpid(pid: i32) i32 {
19231890 var status: i32 = undefined;
19241891 while (true) {
1925 switch (system.getErrno(system.waitpid(pid, &status, 0))) {
1892 switch (errno(system.waitpid(pid, &status, 0))) {
19261893 0 => return status,
19271894 EINTR => continue,
19281895 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 {
19321899 }
19331900}
19341901
1935pub fn fstat(fd: FileHandle) !Stat {
1902pub const FStatError = error{
1903 SystemResources,
1904 Unexpected,
1905};
1906
1907pub fn fstat(fd: fd_t) FStatError!Stat {
19361908 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))) {
19381919 0 => return stat,
19391920 EBADF => unreachable, // Always a race condition.
19401921 ENOMEM => return error.SystemResources,
19411922 else => |err| return unexpectedErrno(err),
19421923 }
1943
1944 return stat;
19451924}
19461925
19471926pub const KQueueError = error{
......@@ -1956,7 +1935,7 @@ pub const KQueueError = error{
19561935
19571936pub fn kqueue() KQueueError!i32 {
19581937 const rc = system.kqueue();
1959 switch (system.getErrno(rc)) {
1938 switch (errno(rc)) {
19601939 0 => return @intCast(i32, rc),
19611940 EMFILE => return error.ProcessFdQuotaExceeded,
19621941 ENFILE => return error.SystemFdQuotaExceeded,
......@@ -1986,7 +1965,7 @@ pub fn kevent(
19861965) KEventError!usize {
19871966 while (true) {
19881967 const rc = system.kevent(kq, changelist, eventlist, timeout);
1989 switch (system.getErrno(rc)) {
1968 switch (errno(rc)) {
19901969 0 => return rc,
19911970 EACCES => return error.AccessDenied,
19921971 EFAULT => unreachable,
......@@ -2011,7 +1990,7 @@ pub const INotifyInitError = error{
20111990/// initialize an inotify instance
20121991pub fn inotify_init1(flags: u32) INotifyInitError!i32 {
20131992 const rc = system.inotify_init1(flags);
2014 switch (system.getErrno(rc)) {
1993 switch (errno(rc)) {
20151994 0 => return @intCast(i32, rc),
20161995 EINVAL => unreachable,
20171996 EMFILE => return error.ProcessFdQuotaExceeded,
......@@ -2039,7 +2018,7 @@ pub fn inotify_add_watch(inotify_fd: i32, pathname: []const u8, mask: u32) INoti
20392018/// Same as `inotify_add_watch` except pathname is null-terminated.
20402019pub fn inotify_add_watchC(inotify_fd: i32, pathname: [*]const u8, mask: u32) INotifyAddWatchError!i32 {
20412020 const rc = system.inotify_add_watch(inotify_fd, pathname, mask);
2042 switch (system.getErrno(rc)) {
2021 switch (errno(rc)) {
20432022 0 => return @intCast(i32, rc),
20442023 EACCES => return error.AccessDenied,
20452024 EBADF => unreachable,
......@@ -2055,7 +2034,7 @@ pub fn inotify_add_watchC(inotify_fd: i32, pathname: [*]const u8, mask: u32) INo
20552034
20562035/// remove an existing watch from an inotify instance
20572036pub 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))) {
20592038 0 => return,
20602039 EBADF => unreachable,
20612040 EINVAL => unreachable,
......@@ -2071,12 +2050,12 @@ pub const MProtectError = error{
20712050
20722051/// address and length must be page-aligned
20732052pub 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));
20752054 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;
20772056 assert(address == aligned_address);
20782057 assert(length == aligned_end - aligned_address);
2079 switch (system.getErrno(system.mprotect(address, length, protection))) {
2058 switch (errno(system.mprotect(address, length, protection))) {
20802059 0 => return,
20812060 EINVAL => unreachable,
20822061 EACCES => return error.AccessDenied,
......@@ -2085,6 +2064,238 @@ pub fn mprotect(address: usize, length: usize, protection: u32) MProtectError!vo
20852064 }
20862065}
20872066
2067pub const ForkError = error{
2068 SystemResources,
2069 Unexpected,
2070};
2071
2072pub 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
2087pub 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
2100pub 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.
2132pub 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
2141pub 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
2156pub 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`.
2168pub 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`.
2182pub 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
2205pub const PipeError = error{
2206 SystemFdQuotaExceeded,
2207 ProcessFdQuotaExceeded,
2208};
2209
2210/// Creates a unidirectional data channel that can be used for interprocess communication.
2211pub 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
2226pub 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
2237pub const SysCtlError = error{
2238 PermissionDenied,
2239 SystemResources,
2240 Unexpected,
2241};
2242
2243pub 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
2259pub 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
2275pub 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
2283pub 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
2295pub const realpath = std.os.path.real;
2296pub const realpathC = std.os.path.realC;
2297pub const realpathW = std.os.path.realW;
2298
20882299/// Used to convert a slice to a null terminated slice on the stack.
20892300/// TODO https://github.com/ziglang/zig/issues/287
20902301pub fn toPosixPath(file_path: []const u8) ![PATH_MAX]u8 {
std/os/wasi.zig+2-318
......@@ -4,10 +4,8 @@ const std = @import("std");
44const assert = std.debug.assert;
55
66pub const is_the_target = @import("builtin").os == .wasi;
7
8pub const STDIN_FILENO = 0;
9pub const STDOUT_FILENO = 1;
10pub const STDERR_FILENO = 2;
7pub const posix = @import("wasi/posix.zig");
8pub use posix;
119
1210comptime {
1311 assert(@alignOf(i8) == 1);
......@@ -20,320 +18,6 @@ comptime {
2018 assert(@alignOf(u64) == 8);
2119}
2220
23pub const advice_t = u8;
24pub const ADVICE_NORMAL: advice_t = 0;
25pub const ADVICE_SEQUENTIAL: advice_t = 1;
26pub const ADVICE_RANDOM: advice_t = 2;
27pub const ADVICE_WILLNEED: advice_t = 3;
28pub const ADVICE_DONTNEED: advice_t = 4;
29pub const ADVICE_NOREUSE: advice_t = 5;
30
31pub const ciovec_t = extern struct {
32 buf: [*]const u8,
33 buf_len: usize,
34};
35
36pub const clockid_t = u32;
37pub const CLOCK_REALTIME: clockid_t = 0;
38pub const CLOCK_MONOTONIC: clockid_t = 1;
39pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2;
40pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3;
41
42pub const device_t = u64;
43
44pub const dircookie_t = u64;
45pub const DIRCOOKIE_START: dircookie_t = 0;
46
47pub 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
54pub const errno_t = u16;
55pub const ESUCCESS: errno_t = 0;
56pub const E2BIG: errno_t = 1;
57pub const EACCES: errno_t = 2;
58pub const EADDRINUSE: errno_t = 3;
59pub const EADDRNOTAVAIL: errno_t = 4;
60pub const EAFNOSUPPORT: errno_t = 5;
61pub const EAGAIN: errno_t = 6;
62pub const EALREADY: errno_t = 7;
63pub const EBADF: errno_t = 8;
64pub const EBADMSG: errno_t = 9;
65pub const EBUSY: errno_t = 10;
66pub const ECANCELED: errno_t = 11;
67pub const ECHILD: errno_t = 12;
68pub const ECONNABORTED: errno_t = 13;
69pub const ECONNREFUSED: errno_t = 14;
70pub const ECONNRESET: errno_t = 15;
71pub const EDEADLK: errno_t = 16;
72pub const EDESTADDRREQ: errno_t = 17;
73pub const EDOM: errno_t = 18;
74pub const EDQUOT: errno_t = 19;
75pub const EEXIST: errno_t = 20;
76pub const EFAULT: errno_t = 21;
77pub const EFBIG: errno_t = 22;
78pub const EHOSTUNREACH: errno_t = 23;
79pub const EIDRM: errno_t = 24;
80pub const EILSEQ: errno_t = 25;
81pub const EINPROGRESS: errno_t = 26;
82pub const EINTR: errno_t = 27;
83pub const EINVAL: errno_t = 28;
84pub const EIO: errno_t = 29;
85pub const EISCONN: errno_t = 30;
86pub const EISDIR: errno_t = 31;
87pub const ELOOP: errno_t = 32;
88pub const EMFILE: errno_t = 33;
89pub const EMLINK: errno_t = 34;
90pub const EMSGSIZE: errno_t = 35;
91pub const EMULTIHOP: errno_t = 36;
92pub const ENAMETOOLONG: errno_t = 37;
93pub const ENETDOWN: errno_t = 38;
94pub const ENETRESET: errno_t = 39;
95pub const ENETUNREACH: errno_t = 40;
96pub const ENFILE: errno_t = 41;
97pub const ENOBUFS: errno_t = 42;
98pub const ENODEV: errno_t = 43;
99pub const ENOENT: errno_t = 44;
100pub const ENOEXEC: errno_t = 45;
101pub const ENOLCK: errno_t = 46;
102pub const ENOLINK: errno_t = 47;
103pub const ENOMEM: errno_t = 48;
104pub const ENOMSG: errno_t = 49;
105pub const ENOPROTOOPT: errno_t = 50;
106pub const ENOSPC: errno_t = 51;
107pub const ENOSYS: errno_t = 52;
108pub const ENOTCONN: errno_t = 53;
109pub const ENOTDIR: errno_t = 54;
110pub const ENOTEMPTY: errno_t = 55;
111pub const ENOTRECOVERABLE: errno_t = 56;
112pub const ENOTSOCK: errno_t = 57;
113pub const ENOTSUP: errno_t = 58;
114pub const ENOTTY: errno_t = 59;
115pub const ENXIO: errno_t = 60;
116pub const EOVERFLOW: errno_t = 61;
117pub const EOWNERDEAD: errno_t = 62;
118pub const EPERM: errno_t = 63;
119pub const EPIPE: errno_t = 64;
120pub const EPROTO: errno_t = 65;
121pub const EPROTONOSUPPORT: errno_t = 66;
122pub const EPROTOTYPE: errno_t = 67;
123pub const ERANGE: errno_t = 68;
124pub const EROFS: errno_t = 69;
125pub const ESPIPE: errno_t = 70;
126pub const ESRCH: errno_t = 71;
127pub const ESTALE: errno_t = 72;
128pub const ETIMEDOUT: errno_t = 73;
129pub const ETXTBSY: errno_t = 74;
130pub const EXDEV: errno_t = 75;
131pub const ENOTCAPABLE: errno_t = 76;
132
133pub 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
145pub const eventrwflags_t = u16;
146pub const EVENT_FD_READWRITE_HANGUP: eventrwflags_t = 0x0001;
147
148pub const eventtype_t = u8;
149pub const EVENTTYPE_CLOCK: eventtype_t = 0;
150pub const EVENTTYPE_FD_READ: eventtype_t = 1;
151pub const EVENTTYPE_FD_WRITE: eventtype_t = 2;
152
153pub const exitcode_t = u32;
154
155pub const fd_t = u32;
156
157pub const fdflags_t = u16;
158pub const FDFLAG_APPEND: fdflags_t = 0x0001;
159pub const FDFLAG_DSYNC: fdflags_t = 0x0002;
160pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004;
161pub const FDFLAG_RSYNC: fdflags_t = 0x0008;
162pub const FDFLAG_SYNC: fdflags_t = 0x0010;
163
164const 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
171pub const filedelta_t = i64;
172
173pub const filesize_t = u64;
174
175pub 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
186pub const filetype_t = u8;
187pub const FILETYPE_UNKNOWN: filetype_t = 0;
188pub const FILETYPE_BLOCK_DEVICE: filetype_t = 1;
189pub const FILETYPE_CHARACTER_DEVICE: filetype_t = 2;
190pub const FILETYPE_DIRECTORY: filetype_t = 3;
191pub const FILETYPE_REGULAR_FILE: filetype_t = 4;
192pub const FILETYPE_SOCKET_DGRAM: filetype_t = 5;
193pub const FILETYPE_SOCKET_STREAM: filetype_t = 6;
194pub const FILETYPE_SYMBOLIC_LINK: filetype_t = 7;
195
196pub const fstflags_t = u16;
197pub const FILESTAT_SET_ATIM: fstflags_t = 0x0001;
198pub const FILESTAT_SET_ATIM_NOW: fstflags_t = 0x0002;
199pub const FILESTAT_SET_MTIM: fstflags_t = 0x0004;
200pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008;
201
202pub const inode_t = u64;
203
204pub const iovec_t = extern struct {
205 buf: [*]u8,
206 buf_len: usize,
207};
208
209pub const linkcount_t = u32;
210
211pub const lookupflags_t = u32;
212pub const LOOKUP_SYMLINK_FOLLOW: lookupflags_t = 0x00000001;
213
214pub const oflags_t = u16;
215pub const O_CREAT: oflags_t = 0x0001;
216pub const O_DIRECTORY: oflags_t = 0x0002;
217pub const O_EXCL: oflags_t = 0x0004;
218pub const O_TRUNC: oflags_t = 0x0008;
219
220pub const preopentype_t = u8;
221pub const PREOPENTYPE_DIR: preopentype_t = 0;
222
223pub 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
232pub const riflags_t = u16;
233pub const SOCK_RECV_PEEK: riflags_t = 0x0001;
234pub const SOCK_RECV_WAITALL: riflags_t = 0x0002;
235
236pub const rights_t = u64;
237pub const RIGHT_FD_DATASYNC: rights_t = 0x0000000000000001;
238pub const RIGHT_FD_READ: rights_t = 0x0000000000000002;
239pub const RIGHT_FD_SEEK: rights_t = 0x0000000000000004;
240pub const RIGHT_FD_FDSTAT_SET_FLAGS: rights_t = 0x0000000000000008;
241pub const RIGHT_FD_SYNC: rights_t = 0x0000000000000010;
242pub const RIGHT_FD_TELL: rights_t = 0x0000000000000020;
243pub const RIGHT_FD_WRITE: rights_t = 0x0000000000000040;
244pub const RIGHT_FD_ADVISE: rights_t = 0x0000000000000080;
245pub const RIGHT_FD_ALLOCATE: rights_t = 0x0000000000000100;
246pub const RIGHT_PATH_CREATE_DIRECTORY: rights_t = 0x0000000000000200;
247pub const RIGHT_PATH_CREATE_FILE: rights_t = 0x0000000000000400;
248pub const RIGHT_PATH_LINK_SOURCE: rights_t = 0x0000000000000800;
249pub const RIGHT_PATH_LINK_TARGET: rights_t = 0x0000000000001000;
250pub const RIGHT_PATH_OPEN: rights_t = 0x0000000000002000;
251pub const RIGHT_FD_READDIR: rights_t = 0x0000000000004000;
252pub const RIGHT_PATH_READLINK: rights_t = 0x0000000000008000;
253pub const RIGHT_PATH_RENAME_SOURCE: rights_t = 0x0000000000010000;
254pub const RIGHT_PATH_RENAME_TARGET: rights_t = 0x0000000000020000;
255pub const RIGHT_PATH_FILESTAT_GET: rights_t = 0x0000000000040000;
256pub const RIGHT_PATH_FILESTAT_SET_SIZE: rights_t = 0x0000000000080000;
257pub const RIGHT_PATH_FILESTAT_SET_TIMES: rights_t = 0x0000000000100000;
258pub const RIGHT_FD_FILESTAT_GET: rights_t = 0x0000000000200000;
259pub const RIGHT_FD_FILESTAT_SET_SIZE: rights_t = 0x0000000000400000;
260pub const RIGHT_FD_FILESTAT_SET_TIMES: rights_t = 0x0000000000800000;
261pub const RIGHT_PATH_SYMLINK: rights_t = 0x0000000001000000;
262pub const RIGHT_PATH_REMOVE_DIRECTORY: rights_t = 0x0000000002000000;
263pub const RIGHT_PATH_UNLINK_FILE: rights_t = 0x0000000004000000;
264pub const RIGHT_POLL_FD_READWRITE: rights_t = 0x0000000008000000;
265pub const RIGHT_SOCK_SHUTDOWN: rights_t = 0x0000000010000000;
266
267pub const roflags_t = u16;
268pub const SOCK_RECV_DATA_TRUNCATED: roflags_t = 0x0001;
269
270pub const sdflags_t = u8;
271pub const SHUT_RD: sdflags_t = 0x01;
272pub const SHUT_WR: sdflags_t = 0x02;
273
274pub const siflags_t = u16;
275
276pub const signal_t = u8;
277pub const SIGHUP: signal_t = 1;
278pub const SIGINT: signal_t = 2;
279pub const SIGQUIT: signal_t = 3;
280pub const SIGILL: signal_t = 4;
281pub const SIGTRAP: signal_t = 5;
282pub const SIGABRT: signal_t = 6;
283pub const SIGBUS: signal_t = 7;
284pub const SIGFPE: signal_t = 8;
285pub const SIGKILL: signal_t = 9;
286pub const SIGUSR1: signal_t = 10;
287pub const SIGSEGV: signal_t = 11;
288pub const SIGUSR2: signal_t = 12;
289pub const SIGPIPE: signal_t = 13;
290pub const SIGALRM: signal_t = 14;
291pub const SIGTERM: signal_t = 15;
292pub const SIGCHLD: signal_t = 16;
293pub const SIGCONT: signal_t = 17;
294pub const SIGSTOP: signal_t = 18;
295pub const SIGTSTP: signal_t = 19;
296pub const SIGTTIN: signal_t = 20;
297pub const SIGTTOU: signal_t = 21;
298pub const SIGURG: signal_t = 22;
299pub const SIGXCPU: signal_t = 23;
300pub const SIGXFSZ: signal_t = 24;
301pub const SIGVTALRM: signal_t = 25;
302pub const SIGPROF: signal_t = 26;
303pub const SIGWINCH: signal_t = 27;
304pub const SIGPOLL: signal_t = 28;
305pub const SIGPWR: signal_t = 29;
306pub const SIGSYS: signal_t = 30;
307
308pub const subclockflags_t = u16;
309pub const SUBSCRIPTION_CLOCK_ABSTIME: subclockflags_t = 0x0001;
310
311pub 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
328pub const timestamp_t = u64;
329
330pub const userdata_t = u64;
331
332pub const whence_t = u8;
333pub const WHENCE_CUR: whence_t = 0;
334pub const WHENCE_END: whence_t = 1;
335pub const WHENCE_SET: whence_t = 2;
336
33721pub extern "wasi_unstable" fn args_get(argv: [*][*]u8, argv_buf: [*]u8) errno_t;
33822pub extern "wasi_unstable" fn args_sizes_get(argc: *usize, argv_buf_size: *usize) errno_t;
33923
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
4pub const STDIN_FILENO = 0;
5pub const STDOUT_FILENO = 1;
6pub const STDERR_FILENO = 2;
7
8pub const advice_t = u8;
9pub const ADVICE_NORMAL: advice_t = 0;
10pub const ADVICE_SEQUENTIAL: advice_t = 1;
11pub const ADVICE_RANDOM: advice_t = 2;
12pub const ADVICE_WILLNEED: advice_t = 3;
13pub const ADVICE_DONTNEED: advice_t = 4;
14pub const ADVICE_NOREUSE: advice_t = 5;
15
16pub const ciovec_t = extern struct {
17 buf: [*]const u8,
18 buf_len: usize,
19};
20
21pub const clockid_t = u32;
22pub const CLOCK_REALTIME: clockid_t = 0;
23pub const CLOCK_MONOTONIC: clockid_t = 1;
24pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2;
25pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3;
26
27pub const device_t = u64;
28
29pub const dircookie_t = u64;
30pub const DIRCOOKIE_START: dircookie_t = 0;
31
32pub 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
39pub const errno_t = u16;
40pub const ESUCCESS: errno_t = 0;
41pub const E2BIG: errno_t = 1;
42pub const EACCES: errno_t = 2;
43pub const EADDRINUSE: errno_t = 3;
44pub const EADDRNOTAVAIL: errno_t = 4;
45pub const EAFNOSUPPORT: errno_t = 5;
46pub const EAGAIN: errno_t = 6;
47pub const EALREADY: errno_t = 7;
48pub const EBADF: errno_t = 8;
49pub const EBADMSG: errno_t = 9;
50pub const EBUSY: errno_t = 10;
51pub const ECANCELED: errno_t = 11;
52pub const ECHILD: errno_t = 12;
53pub const ECONNABORTED: errno_t = 13;
54pub const ECONNREFUSED: errno_t = 14;
55pub const ECONNRESET: errno_t = 15;
56pub const EDEADLK: errno_t = 16;
57pub const EDESTADDRREQ: errno_t = 17;
58pub const EDOM: errno_t = 18;
59pub const EDQUOT: errno_t = 19;
60pub const EEXIST: errno_t = 20;
61pub const EFAULT: errno_t = 21;
62pub const EFBIG: errno_t = 22;
63pub const EHOSTUNREACH: errno_t = 23;
64pub const EIDRM: errno_t = 24;
65pub const EILSEQ: errno_t = 25;
66pub const EINPROGRESS: errno_t = 26;
67pub const EINTR: errno_t = 27;
68pub const EINVAL: errno_t = 28;
69pub const EIO: errno_t = 29;
70pub const EISCONN: errno_t = 30;
71pub const EISDIR: errno_t = 31;
72pub const ELOOP: errno_t = 32;
73pub const EMFILE: errno_t = 33;
74pub const EMLINK: errno_t = 34;
75pub const EMSGSIZE: errno_t = 35;
76pub const EMULTIHOP: errno_t = 36;
77pub const ENAMETOOLONG: errno_t = 37;
78pub const ENETDOWN: errno_t = 38;
79pub const ENETRESET: errno_t = 39;
80pub const ENETUNREACH: errno_t = 40;
81pub const ENFILE: errno_t = 41;
82pub const ENOBUFS: errno_t = 42;
83pub const ENODEV: errno_t = 43;
84pub const ENOENT: errno_t = 44;
85pub const ENOEXEC: errno_t = 45;
86pub const ENOLCK: errno_t = 46;
87pub const ENOLINK: errno_t = 47;
88pub const ENOMEM: errno_t = 48;
89pub const ENOMSG: errno_t = 49;
90pub const ENOPROTOOPT: errno_t = 50;
91pub const ENOSPC: errno_t = 51;
92pub const ENOSYS: errno_t = 52;
93pub const ENOTCONN: errno_t = 53;
94pub const ENOTDIR: errno_t = 54;
95pub const ENOTEMPTY: errno_t = 55;
96pub const ENOTRECOVERABLE: errno_t = 56;
97pub const ENOTSOCK: errno_t = 57;
98pub const ENOTSUP: errno_t = 58;
99pub const ENOTTY: errno_t = 59;
100pub const ENXIO: errno_t = 60;
101pub const EOVERFLOW: errno_t = 61;
102pub const EOWNERDEAD: errno_t = 62;
103pub const EPERM: errno_t = 63;
104pub const EPIPE: errno_t = 64;
105pub const EPROTO: errno_t = 65;
106pub const EPROTONOSUPPORT: errno_t = 66;
107pub const EPROTOTYPE: errno_t = 67;
108pub const ERANGE: errno_t = 68;
109pub const EROFS: errno_t = 69;
110pub const ESPIPE: errno_t = 70;
111pub const ESRCH: errno_t = 71;
112pub const ESTALE: errno_t = 72;
113pub const ETIMEDOUT: errno_t = 73;
114pub const ETXTBSY: errno_t = 74;
115pub const EXDEV: errno_t = 75;
116pub const ENOTCAPABLE: errno_t = 76;
117
118pub 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
130pub const eventrwflags_t = u16;
131pub const EVENT_FD_READWRITE_HANGUP: eventrwflags_t = 0x0001;
132
133pub const eventtype_t = u8;
134pub const EVENTTYPE_CLOCK: eventtype_t = 0;
135pub const EVENTTYPE_FD_READ: eventtype_t = 1;
136pub const EVENTTYPE_FD_WRITE: eventtype_t = 2;
137
138pub const exitcode_t = u32;
139
140pub const fd_t = u32;
141
142pub const fdflags_t = u16;
143pub const FDFLAG_APPEND: fdflags_t = 0x0001;
144pub const FDFLAG_DSYNC: fdflags_t = 0x0002;
145pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004;
146pub const FDFLAG_RSYNC: fdflags_t = 0x0008;
147pub const FDFLAG_SYNC: fdflags_t = 0x0010;
148
149const 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
156pub const filedelta_t = i64;
157
158pub const filesize_t = u64;
159
160pub 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
171pub const filetype_t = u8;
172pub const FILETYPE_UNKNOWN: filetype_t = 0;
173pub const FILETYPE_BLOCK_DEVICE: filetype_t = 1;
174pub const FILETYPE_CHARACTER_DEVICE: filetype_t = 2;
175pub const FILETYPE_DIRECTORY: filetype_t = 3;
176pub const FILETYPE_REGULAR_FILE: filetype_t = 4;
177pub const FILETYPE_SOCKET_DGRAM: filetype_t = 5;
178pub const FILETYPE_SOCKET_STREAM: filetype_t = 6;
179pub const FILETYPE_SYMBOLIC_LINK: filetype_t = 7;
180
181pub const fstflags_t = u16;
182pub const FILESTAT_SET_ATIM: fstflags_t = 0x0001;
183pub const FILESTAT_SET_ATIM_NOW: fstflags_t = 0x0002;
184pub const FILESTAT_SET_MTIM: fstflags_t = 0x0004;
185pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008;
186
187pub const inode_t = u64;
188
189pub const iovec_t = extern struct {
190 buf: [*]u8,
191 buf_len: usize,
192};
193
194pub const linkcount_t = u32;
195
196pub const lookupflags_t = u32;
197pub const LOOKUP_SYMLINK_FOLLOW: lookupflags_t = 0x00000001;
198
199pub const oflags_t = u16;
200pub const O_CREAT: oflags_t = 0x0001;
201pub const O_DIRECTORY: oflags_t = 0x0002;
202pub const O_EXCL: oflags_t = 0x0004;
203pub const O_TRUNC: oflags_t = 0x0008;
204
205pub const preopentype_t = u8;
206pub const PREOPENTYPE_DIR: preopentype_t = 0;
207
208pub 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
217pub const riflags_t = u16;
218pub const SOCK_RECV_PEEK: riflags_t = 0x0001;
219pub const SOCK_RECV_WAITALL: riflags_t = 0x0002;
220
221pub const rights_t = u64;
222pub const RIGHT_FD_DATASYNC: rights_t = 0x0000000000000001;
223pub const RIGHT_FD_READ: rights_t = 0x0000000000000002;
224pub const RIGHT_FD_SEEK: rights_t = 0x0000000000000004;
225pub const RIGHT_FD_FDSTAT_SET_FLAGS: rights_t = 0x0000000000000008;
226pub const RIGHT_FD_SYNC: rights_t = 0x0000000000000010;
227pub const RIGHT_FD_TELL: rights_t = 0x0000000000000020;
228pub const RIGHT_FD_WRITE: rights_t = 0x0000000000000040;
229pub const RIGHT_FD_ADVISE: rights_t = 0x0000000000000080;
230pub const RIGHT_FD_ALLOCATE: rights_t = 0x0000000000000100;
231pub const RIGHT_PATH_CREATE_DIRECTORY: rights_t = 0x0000000000000200;
232pub const RIGHT_PATH_CREATE_FILE: rights_t = 0x0000000000000400;
233pub const RIGHT_PATH_LINK_SOURCE: rights_t = 0x0000000000000800;
234pub const RIGHT_PATH_LINK_TARGET: rights_t = 0x0000000000001000;
235pub const RIGHT_PATH_OPEN: rights_t = 0x0000000000002000;
236pub const RIGHT_FD_READDIR: rights_t = 0x0000000000004000;
237pub const RIGHT_PATH_READLINK: rights_t = 0x0000000000008000;
238pub const RIGHT_PATH_RENAME_SOURCE: rights_t = 0x0000000000010000;
239pub const RIGHT_PATH_RENAME_TARGET: rights_t = 0x0000000000020000;
240pub const RIGHT_PATH_FILESTAT_GET: rights_t = 0x0000000000040000;
241pub const RIGHT_PATH_FILESTAT_SET_SIZE: rights_t = 0x0000000000080000;
242pub const RIGHT_PATH_FILESTAT_SET_TIMES: rights_t = 0x0000000000100000;
243pub const RIGHT_FD_FILESTAT_GET: rights_t = 0x0000000000200000;
244pub const RIGHT_FD_FILESTAT_SET_SIZE: rights_t = 0x0000000000400000;
245pub const RIGHT_FD_FILESTAT_SET_TIMES: rights_t = 0x0000000000800000;
246pub const RIGHT_PATH_SYMLINK: rights_t = 0x0000000001000000;
247pub const RIGHT_PATH_REMOVE_DIRECTORY: rights_t = 0x0000000002000000;
248pub const RIGHT_PATH_UNLINK_FILE: rights_t = 0x0000000004000000;
249pub const RIGHT_POLL_FD_READWRITE: rights_t = 0x0000000008000000;
250pub const RIGHT_SOCK_SHUTDOWN: rights_t = 0x0000000010000000;
251
252pub const roflags_t = u16;
253pub const SOCK_RECV_DATA_TRUNCATED: roflags_t = 0x0001;
254
255pub const sdflags_t = u8;
256pub const SHUT_RD: sdflags_t = 0x01;
257pub const SHUT_WR: sdflags_t = 0x02;
258
259pub const siflags_t = u16;
260
261pub const signal_t = u8;
262pub const SIGHUP: signal_t = 1;
263pub const SIGINT: signal_t = 2;
264pub const SIGQUIT: signal_t = 3;
265pub const SIGILL: signal_t = 4;
266pub const SIGTRAP: signal_t = 5;
267pub const SIGABRT: signal_t = 6;
268pub const SIGBUS: signal_t = 7;
269pub const SIGFPE: signal_t = 8;
270pub const SIGKILL: signal_t = 9;
271pub const SIGUSR1: signal_t = 10;
272pub const SIGSEGV: signal_t = 11;
273pub const SIGUSR2: signal_t = 12;
274pub const SIGPIPE: signal_t = 13;
275pub const SIGALRM: signal_t = 14;
276pub const SIGTERM: signal_t = 15;
277pub const SIGCHLD: signal_t = 16;
278pub const SIGCONT: signal_t = 17;
279pub const SIGSTOP: signal_t = 18;
280pub const SIGTSTP: signal_t = 19;
281pub const SIGTTIN: signal_t = 20;
282pub const SIGTTOU: signal_t = 21;
283pub const SIGURG: signal_t = 22;
284pub const SIGXCPU: signal_t = 23;
285pub const SIGXFSZ: signal_t = 24;
286pub const SIGVTALRM: signal_t = 25;
287pub const SIGPROF: signal_t = 26;
288pub const SIGWINCH: signal_t = 27;
289pub const SIGPOLL: signal_t = 28;
290pub const SIGPWR: signal_t = 29;
291pub const SIGSYS: signal_t = 30;
292
293pub const subclockflags_t = u16;
294pub const SUBSCRIPTION_CLOCK_ABSTIME: subclockflags_t = 0x0001;
295
296pub 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
313pub const timestamp_t = u64;
314
315pub const userdata_t = u64;
316
317pub const whence_t = u8;
318pub const WHENCE_CUR: whence_t = 0;
319pub const WHENCE_END: whence_t = 1;
320pub const WHENCE_SET: whence_t = 2;
std/os/windows.zig+2-10
......@@ -6,6 +6,8 @@ pub const is_the_target = switch (builtin.os) {
66 .windows => true,
77 else => false,
88};
9pub const posix = @import("windows/posix.zig");
10pub use posix;
911
1012pub use @import("windows/advapi32.zig");
1113pub use @import("windows/kernel32.zig");
......@@ -20,7 +22,6 @@ test "import" {
2022}
2123
2224pub const ERROR = @import("windows/error.zig");
23pub const errno_codes = @import("windows/errno.zig");
2425
2526pub const SHORT = c_short;
2627pub const BOOL = c_int;
......@@ -65,15 +66,6 @@ pub const LONGLONG = i64;
6566pub const TRUE = 1;
6667pub const FALSE = 0;
6768
68/// The standard input device. Initially, this is the console input buffer, CONIN$.
69pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1;
70
71/// The standard output device. Initially, this is the active console screen buffer, CONOUT$.
72pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1;
73
74/// The standard error device. Initially, this is the active console screen buffer, CONOUT$.
75pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1;
76
7769pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize));
7870
7971pub 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.
2const std = @import("../../std.zig");
3const maxInt = std.math.maxInt;
4use std.os.windows;
5
6pub const fd_t = HANDLE;
7
8/// The standard input device. Initially, this is the console input buffer, CONIN$.
9pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1;
10
11/// The standard output device. Initially, this is the active console screen buffer, CONOUT$.
12pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1;
13
14/// The standard error device. Initially, this is the active console screen buffer, CONOUT$.
15pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1;
std/os/windows/util.zig-2
......@@ -11,8 +11,6 @@ const cstr = std.cstr;
1111pub const WaitError = error{
1212 WaitAbandoned,
1313 WaitTimeOut,
14
15 /// See https://github.com/ziglang/zig/issues/1396
1614 Unexpected,
1715};
1816