authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-08-24 17:21:53-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-01 17:54:06-07:00
log1bbfcb95abc471374e5f8d74e04f0a002cc85c95
tree76cb0df86a8a5f55e1f7f3bb0fd7dd4422581487
parent3deda15e21ea3a8138d5b628f2649bbbfe7fa910

std: reorganize std.c to eliminate `usingnamespace`

Behavior tests pass on x86_64-linux with -lc

34 files changed, 9658 insertions(+), 9536 deletions(-)

lib/std/c.zig+110-86
...@@ -10,7 +10,8 @@ test {...@@ -10,7 +10,8 @@ test {
10 _ = tokenizer;10 _ = tokenizer;
11}11}
1212
13pub usingnamespace switch (std.Target.current.os.tag) {13const generic = @import("c/generic.zig");
14const system = switch (builtin.os.tag) {
14 .linux => @import("c/linux.zig"),15 .linux => @import("c/linux.zig"),
15 .windows => @import("c/windows.zig"),16 .windows => @import("c/windows.zig"),
16 .macos, .ios, .tvos, .watchos => @import("c/darwin.zig"),17 .macos, .ios, .tvos, .watchos => @import("c/darwin.zig"),
...@@ -27,6 +28,109 @@ pub usingnamespace switch (std.Target.current.os.tag) {...@@ -27,6 +28,109 @@ pub usingnamespace switch (std.Target.current.os.tag) {
27 .wasi => @import("c/wasi.zig"),28 .wasi => @import("c/wasi.zig"),
28 else => struct {},29 else => struct {},
29};30};
31pub const E = system.E;
32pub const _errno = system._errno;
33pub const MAP_FAILED = system.MAP_FAILED;
34pub const AI = system.AI;
35pub const NI = system.NI;
36pub const EAI = system.EAI;
37pub const timespec = system.timespec;
38pub const Sigaction = system.Sigaction;
39pub const fallocate64 = system.fallocate64;
40pub const fopen64 = system.fopen64;
41pub const fstat64 = system.fstat64;
42pub const fstatat64 = system.fstatat64;
43pub const ftruncate64 = system.ftruncate64;
44pub const getrlimit64 = system.getrlimit64;
45pub const lseek64 = system.lseek64;
46pub const mmap64 = system.mmap64;
47pub const open64 = system.open64;
48pub const openat64 = system.openat64;
49pub const pread64 = system.pread64;
50pub const preadv64 = system.preadv64;
51pub const pwrite64 = system.pwrite64;
52pub const pwritev64 = system.pwritev64;
53pub const sendfile64 = system.sendfile64;
54pub const setrlimit64 = system.setrlimit64;
55
56pub const AT = system.AT;
57pub const CLOCK = system.CLOCK;
58pub const IOV_MAX = system.IOV_MAX;
59pub const NAME_MAX = system.NAME_MAX;
60pub const PATH_MAX = system.PATH_MAX;
61pub const PROT = system.PROT;
62pub const RTLD = system.RTLD;
63pub const S = system.S;
64pub const SA = system.SA;
65pub const SIG = system.SIG;
66pub const STDERR_FILENO = system.STDIN_FILENO;
67pub const STDIN_FILENO = system.STDIN_FILENO;
68pub const STDOUT_FILENO = system.STDIN_FILENO;
69pub const Stat = system.Stat;
70pub const copy_file_range = system.copy_file_range;
71pub const dl_iterate_phdr_callback = system.dl_iterate_phdr_callback;
72pub const dl_phdr_info = system.dl_phdr_info;
73pub const empty_sigset = system.empty_sigset;
74pub const epoll_create1 = system.epoll_create1;
75pub const epoll_ctl = system.epoll_ctl;
76pub const epoll_pwait = system.epoll_pwait;
77pub const epoll_wait = system.epoll_wait;
78pub const eventfd = system.eventfd;
79pub const fallocate = system.fallocate;
80pub const fd_t = system.fd_t;
81pub const getauxval = system.getauxval;
82pub const getdents = system.getdents;
83pub const getrandom = system.getrandom;
84pub const inotify_add_watch = system.inotify_add_watch;
85pub const inotify_init1 = system.inotify_init1;
86pub const inotify_rm_watch = system.inotify_rm_watch;
87pub const madvise = system.madvise;
88pub const malloc_usable_size = system.malloc_usable_size;
89pub const memfd_create = system.memfd_create;
90pub const pipe2 = system.pipe2;
91pub const pollfd = system.pollfd;
92pub const posix_memalign = system.posix_memalign;
93pub const prlimit = system.prlimit;
94pub const pthread_attr_t = system.pthread_attr_t;
95pub const pthread_cond_t = system.pthread_cond_t;
96pub const pthread_getname_np = system.pthread_getname_np;
97pub const pthread_mutex_t = system.pthread_mutex_t;
98pub const pthread_rwlock_t = system.pthread_rwlock_t;
99pub const pthread_setname_np = system.pthread_setname_np;
100pub const rlimit = system.rlimit;
101pub const rlimit_resource = system.rlimit_resource;
102pub const sched_getaffinity = system.sched_getaffinity;
103pub const sem_t = system.sem_t;
104pub const sendfile = system.sendfile;
105pub const sigaltstack = system.sigaltstack;
106pub const siginfo_t = system.siginfo_t;
107pub const signalfd = system.signalfd;
108pub const sigset_t = system.sigset_t;
109pub const MAP = system.MAP;
110pub const LOCK = system.LOCK;
111pub const REG = system.REG;
112pub const dl_iterate_phdr = system.dl_iterate_phdr;
113pub const ino_t = system.ino_t;
114pub const mode_t = system.mode_t;
115pub const ucontext_t = system.ucontext_t;
116pub const O = system.O;
117
118pub const alarm = if (@hasDecl(system, "alarm")) system.alarm else generic.alarm;
119pub const clock_getres = if (@hasDecl(system, "clock_getres")) system.clock_getres else generic.clock_getres;
120pub const clock_gettime = if (@hasDecl(system, "clock_gettime")) system.clock_gettime else generic.clock_gettime;
121pub const fstat = if (@hasDecl(system, "fstat")) system.fstat else generic.fstat;
122pub const fstatat = if (@hasDecl(system, "fstatat")) system.fstatat else generic.fstatat;
123pub const getrusage = if (@hasDecl(system, "getrusage")) system.getrusage else generic.getrusage;
124pub const gettimeofday = if (@hasDecl(system, "gettimeofday")) system.gettimeofday else generic.gettimeofday;
125pub const nanosleep = if (@hasDecl(system, "nanosleep")) system.nanosleep else generic.nanosleep;
126pub const realpath = if (@hasDecl(system, "realpath")) system.realpath else generic.realpath;
127pub const sched_yield = if (@hasDecl(system, "sched_yield")) system.sched_yield else generic.sched_yield;
128pub const sigaction = if (@hasDecl(system, "sigaction")) system.sigaction else generic.sigaction;
129pub const sigfillset = if (@hasDecl(system, "sigfillset")) system.sigfillset else generic.sigfillset;
130pub const sigprocmask = if (@hasDecl(system, "sigprocmask")) system.sigprocmask else generic.sigprocmask;
131pub const sigwait = if (@hasDecl(system, "sigwait")) system.sigwait else generic.sigwait;
132pub const socket = if (@hasDecl(system, "socket")) system.socket else generic.socket;
133pub const stat = if (@hasDecl(system, "stat")) system.stat else generic.stat;
30134
31pub fn getErrno(rc: anytype) E {135pub fn getErrno(rc: anytype) E {
32 if (rc == -1) {136 if (rc == -1) {
...@@ -47,9 +151,9 @@ pub fn versionCheck(glibc_version: builtin.Version) type {...@@ -47,9 +151,9 @@ pub fn versionCheck(glibc_version: builtin.Version) type {
47 return struct {151 return struct {
48 pub const ok = blk: {152 pub const ok = blk: {
49 if (!builtin.link_libc) break :blk false;153 if (!builtin.link_libc) break :blk false;
50 if (std.Target.current.abi.isMusl()) break :blk true;154 if (builtin.abi.isMusl()) break :blk true;
51 if (std.Target.current.isGnuLibC()) {155 if (builtin.target.isGnuLibC()) {
52 const ver = std.Target.current.os.version_range.linux.glibc;156 const ver = builtin.os.version_range.linux.glibc;
53 const order = ver.order(glibc_version);157 const order = ver.order(glibc_version);
54 break :blk switch (order) {158 break :blk switch (order) {
55 .gt, .eq => true,159 .gt, .eq => true,
...@@ -115,17 +219,6 @@ pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int;...@@ -115,17 +219,6 @@ pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int;
115pub extern "c" fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;219pub extern "c" fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
116pub extern "c" fn readlinkat(dirfd: fd_t, noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;220pub extern "c" fn readlinkat(dirfd: fd_t, noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
117221
118pub usingnamespace switch (builtin.os.tag) {
119 .macos, .ios, .watchos, .tvos => struct {
120 pub const realpath = @"realpath$DARWIN_EXTSN";
121 pub const fstatat = _fstatat;
122 },
123 else => struct {
124 pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
125 pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *libc_stat, flags: u32) c_int;
126 },
127};
128
129pub extern "c" fn rmdir(path: [*:0]const u8) c_int;222pub extern "c" fn rmdir(path: [*:0]const u8) c_int;
130pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;223pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;
131pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;224pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
...@@ -172,75 +265,6 @@ pub extern "c" fn recvfrom(...@@ -172,75 +265,6 @@ pub extern "c" fn recvfrom(
172) isize;265) isize;
173pub extern "c" fn recvmsg(sockfd: fd_t, msg: *std.x.os.Socket.Message, flags: c_int) isize;266pub extern "c" fn recvmsg(sockfd: fd_t, msg: *std.x.os.Socket.Message, flags: c_int) isize;
174267
175pub usingnamespace switch (builtin.os.tag) {
176 .netbsd => struct {
177 pub const clock_getres = __clock_getres50;
178 pub const clock_gettime = __clock_gettime50;
179 pub const fstat = __fstat50;
180 pub const getdents = __getdents30;
181 pub const getrusage = __getrusage50;
182 pub const gettimeofday = __gettimeofday50;
183 pub const nanosleep = __nanosleep50;
184 pub const sched_yield = __libc_thr_yield;
185 pub const sigaction = __sigaction14;
186 pub const sigaltstack = __sigaltstack14;
187 pub const sigprocmask = __sigprocmask14;
188 pub const socket = __socket30;
189 pub const stat = __stat50;
190 },
191 .macos, .ios, .watchos, .tvos => struct {
192 // XXX: close -> close$NOCANCEL
193 // XXX: getdirentries -> _getdirentries64
194 pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
195 pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
196 pub const fstat = _fstat;
197 pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
198 pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
199 pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
200 pub extern "c" fn sched_yield() c_int;
201 pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
202 pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
203 pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
204 pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int;
205 pub extern "c" fn sigfillset(set: ?*sigset_t) void;
206 pub extern "c" fn alarm(seconds: c_uint) c_uint;
207 pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
208 },
209 .windows => struct {
210 // TODO: copied the else case and removed the socket function (because its in ws2_32)
211 // need to verify which of these is actually supported on windows
212 pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
213 pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
214 pub extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int;
215 pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
216 pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
217 pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
218 pub extern "c" fn sched_yield() c_int;
219 pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
220 pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
221 pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int;
222 pub extern "c" fn sigfillset(set: ?*sigset_t) void;
223 pub extern "c" fn alarm(seconds: c_uint) c_uint;
224 pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
225 },
226 else => struct {
227 pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
228 pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
229 pub extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int;
230 pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
231 pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
232 pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
233 pub extern "c" fn sched_yield() c_int;
234 pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
235 pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
236 pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
237 pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int;
238 pub extern "c" fn sigfillset(set: ?*sigset_t) void;
239 pub extern "c" fn alarm(seconds: c_uint) c_uint;
240 pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
241 },
242};
243
244pub extern "c" fn kill(pid: pid_t, sig: c_int) c_int;268pub extern "c" fn kill(pid: pid_t, sig: c_int) c_int;
245pub extern "c" fn getdirentries(fd: fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;269pub extern "c" fn getdirentries(fd: fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
246270
...@@ -375,9 +399,9 @@ pub extern "c" fn openlog(ident: [*:0]const u8, logopt: c_int, facility: c_int)...@@ -375,9 +399,9 @@ pub extern "c" fn openlog(ident: [*:0]const u8, logopt: c_int, facility: c_int)
375pub extern "c" fn closelog() void;399pub extern "c" fn closelog() void;
376pub extern "c" fn setlogmask(maskpri: c_int) c_int;400pub extern "c" fn setlogmask(maskpri: c_int) c_int;
377401
378pub const max_align_t = if (std.Target.current.abi == .msvc)402pub const max_align_t = if (builtin.abi == .msvc)
379 f64403 f64
380else if (std.Target.current.isDarwin())404else if (builtin.target.isDarwin())
381 c_longdouble405 c_longdouble
382else406else
383 extern struct {407 extern struct {
lib/std/c/darwin.zig+1812-10
...@@ -3,6 +3,7 @@ const assert = std.debug.assert;...@@ -3,6 +3,7 @@ const assert = std.debug.assert;
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const macho = std.macho;4const macho = std.macho;
5const native_arch = builtin.target.cpu.arch;5const native_arch = builtin.target.cpu.arch;
6const maxInt = std.math.maxInt;
67
7extern "c" fn __error() *c_int;8extern "c" fn __error() *c_int;
8pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32;9pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32;
...@@ -21,20 +22,25 @@ pub const copyfile_state_t = *opaque {};...@@ -21,20 +22,25 @@ pub const copyfile_state_t = *opaque {};
21pub extern "c" fn fcopyfile(from: fd_t, to: fd_t, state: ?copyfile_state_t, flags: u32) c_int;22pub extern "c" fn fcopyfile(from: fd_t, to: fd_t, state: ?copyfile_state_t, flags: u32) c_int;
2223
23pub extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;24pub extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
25pub const realpath = @"realpath$DARWIN_EXTSN";
2426
25pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;27pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
2628
27extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int;29const private = struct {
28/// On x86_64 Darwin, fstat has to be manully linked with $INODE64 suffix to force 64bit version.30 extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
29/// Note that this is fixed on aarch64 and no longer necessary.31 /// On x86_64 Darwin, fstat has to be manully linked with $INODE64 suffix to
30extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *libc_stat) c_int;32 /// force 64bit version.
31pub const _fstat = if (native_arch == .aarch64) fstat else @"fstat$INODE64";33 /// Note that this is fixed on aarch64 and no longer necessary.
34 extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;
3235
33extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *libc_stat, flags: u32) c_int;36 extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
34/// On x86_64 Darwin, fstatat has to be manully linked with $INODE64 suffix to force 64bit version.37 /// On x86_64 Darwin, fstatat has to be manully linked with $INODE64 suffix to
35/// Note that this is fixed on aarch64 and no longer necessary.38 /// force 64bit version.
36extern "c" fn @"fstatat$INODE64"(dirfd: fd_t, path_name: [*:0]const u8, buf: *libc_stat, flags: u32) c_int;39 /// Note that this is fixed on aarch64 and no longer necessary.
37pub const _fstatat = if (native_arch == .aarch64) fstatat else @"fstatat$INODE64";40 extern "c" fn @"fstatat$INODE64"(dirfd: fd_t, path_name: [*:0]const u8, buf: *Stat, flags: u32) c_int;
41};
42pub const fstat = if (native_arch == .aarch64) private.fstat else private.@"fstat$INODE64";
43pub const fstatat = if (native_arch == .aarch64) private.fstatat else private.@"fstatat$INODE64";
3844
39pub extern "c" fn mach_absolute_time() u64;45pub extern "c" fn mach_absolute_time() u64;
40pub extern "c" fn mach_timebase_info(tinfo: ?*mach_timebase_info_data) void;46pub extern "c" fn mach_timebase_info(tinfo: ?*mach_timebase_info_data) void;
...@@ -254,3 +260,1799 @@ pub extern "c" fn os_unfair_lock_unlock(o: os_unfair_lock_t) void;...@@ -254,3 +260,1799 @@ pub extern "c" fn os_unfair_lock_unlock(o: os_unfair_lock_t) void;
254pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool;260pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool;
255pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void;261pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void;
256pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;262pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;
263
264// XXX: close -> close$NOCANCEL
265// XXX: getdirentries -> _getdirentries64
266pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
267pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
268pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
269pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
270pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
271pub extern "c" fn sched_yield() c_int;
272pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
273pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
274pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
275pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
276pub extern "c" fn sigfillset(set: ?*sigset_t) void;
277pub extern "c" fn alarm(seconds: c_uint) c_uint;
278pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
279
280// See: https://opensource.apple.com/source/xnu/xnu-6153.141.1/bsd/sys/_types.h.auto.html
281// TODO: audit mode_t/pid_t, should likely be u16/i32
282pub const fd_t = c_int;
283pub const pid_t = c_int;
284pub const mode_t = c_uint;
285pub const uid_t = u32;
286pub const gid_t = u32;
287
288pub const in_port_t = u16;
289pub const sa_family_t = u8;
290pub const socklen_t = u32;
291pub const sockaddr = extern struct {
292 len: u8,
293 family: sa_family_t,
294 data: [14]u8,
295};
296pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
297pub const sockaddr_in = extern struct {
298 len: u8 = @sizeOf(sockaddr_in),
299 family: sa_family_t = AF_INET,
300 port: in_port_t,
301 addr: u32,
302 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
303};
304pub const sockaddr_in6 = extern struct {
305 len: u8 = @sizeOf(sockaddr_in6),
306 family: sa_family_t = AF_INET6,
307 port: in_port_t,
308 flowinfo: u32,
309 addr: [16]u8,
310 scope_id: u32,
311};
312
313/// UNIX domain socket
314pub const sockaddr_un = extern struct {
315 len: u8 = @sizeOf(sockaddr_un),
316 family: sa_family_t = AF_UNIX,
317 path: [104]u8,
318};
319
320pub const timeval = extern struct {
321 tv_sec: c_long,
322 tv_usec: i32,
323};
324
325pub const timezone = extern struct {
326 tz_minuteswest: i32,
327 tz_dsttime: i32,
328};
329
330pub const mach_timebase_info_data = extern struct {
331 numer: u32,
332 denom: u32,
333};
334
335pub const off_t = i64;
336pub const ino_t = u64;
337
338pub const Flock = extern struct {
339 l_start: off_t,
340 l_len: off_t,
341 l_pid: pid_t,
342 l_type: i16,
343 l_whence: i16,
344};
345
346pub const Stat = extern struct {
347 dev: i32,
348 mode: u16,
349 nlink: u16,
350 ino: ino_t,
351 uid: uid_t,
352 gid: gid_t,
353 rdev: i32,
354 atimesec: isize,
355 atimensec: isize,
356 mtimesec: isize,
357 mtimensec: isize,
358 ctimesec: isize,
359 ctimensec: isize,
360 birthtimesec: isize,
361 birthtimensec: isize,
362 size: off_t,
363 blocks: i64,
364 blksize: i32,
365 flags: u32,
366 gen: u32,
367 lspare: i32,
368 qspare: [2]i64,
369
370 pub fn atime(self: @This()) timespec {
371 return timespec{
372 .tv_sec = self.atimesec,
373 .tv_nsec = self.atimensec,
374 };
375 }
376
377 pub fn mtime(self: @This()) timespec {
378 return timespec{
379 .tv_sec = self.mtimesec,
380 .tv_nsec = self.mtimensec,
381 };
382 }
383
384 pub fn ctime(self: @This()) timespec {
385 return timespec{
386 .tv_sec = self.ctimesec,
387 .tv_nsec = self.ctimensec,
388 };
389 }
390};
391
392pub const timespec = extern struct {
393 tv_sec: isize,
394 tv_nsec: isize,
395};
396
397pub const sigset_t = u32;
398pub const empty_sigset: sigset_t = 0;
399
400pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
401pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
402pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
403pub const SIG_HOLD = @intToPtr(?Sigaction.sigaction_fn, 5);
404
405pub const siginfo_t = extern struct {
406 signo: c_int,
407 errno: c_int,
408 code: c_int,
409 pid: pid_t,
410 uid: uid_t,
411 status: c_int,
412 addr: *c_void,
413 value: extern union {
414 int: c_int,
415 ptr: *c_void,
416 },
417 si_band: c_long,
418 _pad: [7]c_ulong,
419};
420
421/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
422pub const Sigaction = extern struct {
423 pub const handler_fn = fn (c_int) callconv(.C) void;
424 pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void;
425
426 handler: extern union {
427 handler: ?handler_fn,
428 sigaction: ?sigaction_fn,
429 },
430 mask: sigset_t,
431 flags: c_uint,
432};
433
434pub const dirent = extern struct {
435 d_ino: usize,
436 d_seekoff: usize,
437 d_reclen: u16,
438 d_namlen: u16,
439 d_type: u8,
440 d_name: u8, // field address is address of first byte of name
441
442 pub fn reclen(self: dirent) u16 {
443 return self.d_reclen;
444 }
445};
446
447/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
448pub const Kevent = extern struct {
449 ident: usize,
450 filter: i16,
451 flags: u16,
452 fflags: u32,
453 data: isize,
454 udata: usize,
455};
456
457// sys/types.h on macos uses #pragma pack(4) so these checks are
458// to make sure the struct is laid out the same. These values were
459// produced from C code using the offsetof macro.
460comptime {
461 assert(@offsetOf(Kevent, "ident") == 0);
462 assert(@offsetOf(Kevent, "filter") == 8);
463 assert(@offsetOf(Kevent, "flags") == 10);
464 assert(@offsetOf(Kevent, "fflags") == 12);
465 assert(@offsetOf(Kevent, "data") == 16);
466 assert(@offsetOf(Kevent, "udata") == 24);
467}
468
469pub const kevent64_s = extern struct {
470 ident: u64,
471 filter: i16,
472 flags: u16,
473 fflags: u32,
474 data: i64,
475 udata: u64,
476 ext: [2]u64,
477};
478
479// sys/types.h on macos uses #pragma pack() so these checks are
480// to make sure the struct is laid out the same. These values were
481// produced from C code using the offsetof macro.
482comptime {
483 assert(@offsetOf(kevent64_s, "ident") == 0);
484 assert(@offsetOf(kevent64_s, "filter") == 8);
485 assert(@offsetOf(kevent64_s, "flags") == 10);
486 assert(@offsetOf(kevent64_s, "fflags") == 12);
487 assert(@offsetOf(kevent64_s, "data") == 16);
488 assert(@offsetOf(kevent64_s, "udata") == 24);
489 assert(@offsetOf(kevent64_s, "ext") == 32);
490}
491
492pub const mach_port_t = c_uint;
493pub const clock_serv_t = mach_port_t;
494pub const clock_res_t = c_int;
495pub const mach_port_name_t = natural_t;
496pub const natural_t = c_uint;
497pub const mach_timespec_t = extern struct {
498 tv_sec: c_uint,
499 tv_nsec: clock_res_t,
500};
501pub const kern_return_t = c_int;
502pub const host_t = mach_port_t;
503pub const CALENDAR_CLOCK = 1;
504
505pub const PATH_MAX = 1024;
506pub const IOV_MAX = 16;
507
508pub const STDIN_FILENO = 0;
509pub const STDOUT_FILENO = 1;
510pub const STDERR_FILENO = 2;
511
512/// [MC2] no permissions
513pub const PROT_NONE = 0x00;
514
515/// [MC2] pages can be read
516pub const PROT_READ = 0x01;
517
518/// [MC2] pages can be written
519pub const PROT_WRITE = 0x02;
520
521/// [MC2] pages can be executed
522pub const PROT_EXEC = 0x04;
523
524/// allocated from memory, swap space
525pub const MAP_ANONYMOUS = 0x1000;
526
527/// map from file (default)
528pub const MAP_FILE = 0x0000;
529
530/// interpret addr exactly
531pub const MAP_FIXED = 0x0010;
532
533/// region may contain semaphores
534pub const MAP_HASSEMAPHORE = 0x0200;
535
536/// changes are private
537pub const MAP_PRIVATE = 0x0002;
538
539/// share changes
540pub const MAP_SHARED = 0x0001;
541
542/// don't cache pages for this mapping
543pub const MAP_NOCACHE = 0x0400;
544
545/// don't reserve needed swap area
546pub const MAP_NORESERVE = 0x0040;
547pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
548
549/// [XSI] no hang in wait/no child to reap
550pub const WNOHANG = 0x00000001;
551
552/// [XSI] notify on stop, untraced child
553pub const WUNTRACED = 0x00000002;
554
555/// take signal on signal stack
556pub const SA_ONSTACK = 0x0001;
557
558/// restart system on signal return
559pub const SA_RESTART = 0x0002;
560
561/// reset to SIG_DFL when taking signal
562pub const SA_RESETHAND = 0x0004;
563
564/// do not generate SIGCHLD on child stop
565pub const SA_NOCLDSTOP = 0x0008;
566
567/// don't mask the signal we're delivering
568pub const SA_NODEFER = 0x0010;
569
570/// don't keep zombies around
571pub const SA_NOCLDWAIT = 0x0020;
572
573/// signal handler with SA_SIGINFO args
574pub const SA_SIGINFO = 0x0040;
575
576/// do not bounce off kernel's sigtramp
577pub const SA_USERTRAMP = 0x0100;
578
579/// signal handler with SA_SIGINFO args with 64bit regs information
580pub const SA_64REGSET = 0x0200;
581
582pub const O_PATH = 0x0000;
583
584pub const F_OK = 0;
585pub const X_OK = 1;
586pub const W_OK = 2;
587pub const R_OK = 4;
588
589/// open for reading only
590pub const O_RDONLY = 0x0000;
591
592/// open for writing only
593pub const O_WRONLY = 0x0001;
594
595/// open for reading and writing
596pub const O_RDWR = 0x0002;
597
598/// do not block on open or for data to become available
599pub const O_NONBLOCK = 0x0004;
600
601/// append on each write
602pub const O_APPEND = 0x0008;
603
604/// create file if it does not exist
605pub const O_CREAT = 0x0200;
606
607/// truncate size to 0
608pub const O_TRUNC = 0x0400;
609
610/// error if O_CREAT and the file exists
611pub const O_EXCL = 0x0800;
612
613/// atomically obtain a shared lock
614pub const O_SHLOCK = 0x0010;
615
616/// atomically obtain an exclusive lock
617pub const O_EXLOCK = 0x0020;
618
619/// do not follow symlinks
620pub const O_NOFOLLOW = 0x0100;
621
622/// allow open of symlinks
623pub const O_SYMLINK = 0x200000;
624
625/// descriptor requested for event notifications only
626pub const O_EVTONLY = 0x8000;
627
628/// mark as close-on-exec
629pub const O_CLOEXEC = 0x1000000;
630
631pub const O_ACCMODE = 3;
632pub const O_ALERT = 536870912;
633pub const O_ASYNC = 64;
634pub const O_DIRECTORY = 1048576;
635pub const O_DP_GETRAWENCRYPTED = 1;
636pub const O_DP_GETRAWUNENCRYPTED = 2;
637pub const O_DSYNC = 4194304;
638pub const O_FSYNC = O_SYNC;
639pub const O_NOCTTY = 131072;
640pub const O_POPUP = 2147483648;
641pub const O_SYNC = 128;
642
643pub const SEEK_SET = 0x0;
644pub const SEEK_CUR = 0x1;
645pub const SEEK_END = 0x2;
646
647pub const DT_UNKNOWN = 0;
648pub const DT_FIFO = 1;
649pub const DT_CHR = 2;
650pub const DT_DIR = 4;
651pub const DT_BLK = 6;
652pub const DT_REG = 8;
653pub const DT_LNK = 10;
654pub const DT_SOCK = 12;
655pub const DT_WHT = 14;
656
657/// block specified signal set
658pub const SIG_BLOCK = 1;
659
660/// unblock specified signal set
661pub const SIG_UNBLOCK = 2;
662
663/// set specified signal set
664pub const SIG_SETMASK = 3;
665
666/// hangup
667pub const SIGHUP = 1;
668
669/// interrupt
670pub const SIGINT = 2;
671
672/// quit
673pub const SIGQUIT = 3;
674
675/// illegal instruction (not reset when caught)
676pub const SIGILL = 4;
677
678/// trace trap (not reset when caught)
679pub const SIGTRAP = 5;
680
681/// abort()
682pub const SIGABRT = 6;
683
684/// pollable event ([XSR] generated, not supported)
685pub const SIGPOLL = 7;
686
687/// compatibility
688pub const SIGIOT = SIGABRT;
689
690/// EMT instruction
691pub const SIGEMT = 7;
692
693/// floating point exception
694pub const SIGFPE = 8;
695
696/// kill (cannot be caught or ignored)
697pub const SIGKILL = 9;
698
699/// bus error
700pub const SIGBUS = 10;
701
702/// segmentation violation
703pub const SIGSEGV = 11;
704
705/// bad argument to system call
706pub const SIGSYS = 12;
707
708/// write on a pipe with no one to read it
709pub const SIGPIPE = 13;
710
711/// alarm clock
712pub const SIGALRM = 14;
713
714/// software termination signal from kill
715pub const SIGTERM = 15;
716
717/// urgent condition on IO channel
718pub const SIGURG = 16;
719
720/// sendable stop signal not from tty
721pub const SIGSTOP = 17;
722
723/// stop signal from tty
724pub const SIGTSTP = 18;
725
726/// continue a stopped process
727pub const SIGCONT = 19;
728
729/// to parent on child stop or exit
730pub const SIGCHLD = 20;
731
732/// to readers pgrp upon background tty read
733pub const SIGTTIN = 21;
734
735/// like TTIN for output if (tp->t_local&LTOSTOP)
736pub const SIGTTOU = 22;
737
738/// input/output possible signal
739pub const SIGIO = 23;
740
741/// exceeded CPU time limit
742pub const SIGXCPU = 24;
743
744/// exceeded file size limit
745pub const SIGXFSZ = 25;
746
747/// virtual time alarm
748pub const SIGVTALRM = 26;
749
750/// profiling time alarm
751pub const SIGPROF = 27;
752
753/// window size changes
754pub const SIGWINCH = 28;
755
756/// information request
757pub const SIGINFO = 29;
758
759/// user defined signal 1
760pub const SIGUSR1 = 30;
761
762/// user defined signal 2
763pub const SIGUSR2 = 31;
764
765/// no flag value
766pub const KEVENT_FLAG_NONE = 0x000;
767
768/// immediate timeout
769pub const KEVENT_FLAG_IMMEDIATE = 0x001;
770
771/// output events only include change
772pub const KEVENT_FLAG_ERROR_EVENTS = 0x002;
773
774/// add event to kq (implies enable)
775pub const EV_ADD = 0x0001;
776
777/// delete event from kq
778pub const EV_DELETE = 0x0002;
779
780/// enable event
781pub const EV_ENABLE = 0x0004;
782
783/// disable event (not reported)
784pub const EV_DISABLE = 0x0008;
785
786/// only report one occurrence
787pub const EV_ONESHOT = 0x0010;
788
789/// clear event state after reporting
790pub const EV_CLEAR = 0x0020;
791
792/// force immediate event output
793/// ... with or without EV_ERROR
794/// ... use KEVENT_FLAG_ERROR_EVENTS
795/// on syscalls supporting flags
796pub const EV_RECEIPT = 0x0040;
797
798/// disable event after reporting
799pub const EV_DISPATCH = 0x0080;
800
801/// unique kevent per udata value
802pub const EV_UDATA_SPECIFIC = 0x0100;
803
804/// ... in combination with EV_DELETE
805/// will defer delete until udata-specific
806/// event enabled. EINPROGRESS will be
807/// returned to indicate the deferral
808pub const EV_DISPATCH2 = EV_DISPATCH | EV_UDATA_SPECIFIC;
809
810/// report that source has vanished
811/// ... only valid with EV_DISPATCH2
812pub const EV_VANISHED = 0x0200;
813
814/// reserved by system
815pub const EV_SYSFLAGS = 0xF000;
816
817/// filter-specific flag
818pub const EV_FLAG0 = 0x1000;
819
820/// filter-specific flag
821pub const EV_FLAG1 = 0x2000;
822
823/// EOF detected
824pub const EV_EOF = 0x8000;
825
826/// error, data contains errno
827pub const EV_ERROR = 0x4000;
828
829pub const EV_POLL = EV_FLAG0;
830pub const EV_OOBAND = EV_FLAG1;
831
832pub const EVFILT_READ = -1;
833pub const EVFILT_WRITE = -2;
834
835/// attached to aio requests
836pub const EVFILT_AIO = -3;
837
838/// attached to vnodes
839pub const EVFILT_VNODE = -4;
840
841/// attached to struct proc
842pub const EVFILT_PROC = -5;
843
844/// attached to struct proc
845pub const EVFILT_SIGNAL = -6;
846
847/// timers
848pub const EVFILT_TIMER = -7;
849
850/// Mach portsets
851pub const EVFILT_MACHPORT = -8;
852
853/// Filesystem events
854pub const EVFILT_FS = -9;
855
856/// User events
857pub const EVFILT_USER = -10;
858
859/// Virtual memory events
860pub const EVFILT_VM = -12;
861
862/// Exception events
863pub const EVFILT_EXCEPT = -15;
864
865pub const EVFILT_SYSCOUNT = 17;
866
867/// On input, NOTE_TRIGGER causes the event to be triggered for output.
868pub const NOTE_TRIGGER = 0x01000000;
869
870/// ignore input fflags
871pub const NOTE_FFNOP = 0x00000000;
872
873/// and fflags
874pub const NOTE_FFAND = 0x40000000;
875
876/// or fflags
877pub const NOTE_FFOR = 0x80000000;
878
879/// copy fflags
880pub const NOTE_FFCOPY = 0xc0000000;
881
882/// mask for operations
883pub const NOTE_FFCTRLMASK = 0xc0000000;
884pub const NOTE_FFLAGSMASK = 0x00ffffff;
885
886/// low water mark
887pub const NOTE_LOWAT = 0x00000001;
888
889/// OOB data
890pub const NOTE_OOB = 0x00000002;
891
892/// vnode was removed
893pub const NOTE_DELETE = 0x00000001;
894
895/// data contents changed
896pub const NOTE_WRITE = 0x00000002;
897
898/// size increased
899pub const NOTE_EXTEND = 0x00000004;
900
901/// attributes changed
902pub const NOTE_ATTRIB = 0x00000008;
903
904/// link count changed
905pub const NOTE_LINK = 0x00000010;
906
907/// vnode was renamed
908pub const NOTE_RENAME = 0x00000020;
909
910/// vnode access was revoked
911pub const NOTE_REVOKE = 0x00000040;
912
913/// No specific vnode event: to test for EVFILT_READ activation
914pub const NOTE_NONE = 0x00000080;
915
916/// vnode was unlocked by flock(2)
917pub const NOTE_FUNLOCK = 0x00000100;
918
919/// process exited
920pub const NOTE_EXIT = 0x80000000;
921
922/// process forked
923pub const NOTE_FORK = 0x40000000;
924
925/// process exec'd
926pub const NOTE_EXEC = 0x20000000;
927
928/// shared with EVFILT_SIGNAL
929pub const NOTE_SIGNAL = 0x08000000;
930
931/// exit status to be returned, valid for child process only
932pub const NOTE_EXITSTATUS = 0x04000000;
933
934/// provide details on reasons for exit
935pub const NOTE_EXIT_DETAIL = 0x02000000;
936
937/// mask for signal & exit status
938pub const NOTE_PDATAMASK = 0x000fffff;
939pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
940
941pub const NOTE_EXIT_DETAIL_MASK = 0x00070000;
942pub const NOTE_EXIT_DECRYPTFAIL = 0x00010000;
943pub const NOTE_EXIT_MEMORY = 0x00020000;
944pub const NOTE_EXIT_CSERROR = 0x00040000;
945
946/// will react on memory pressure
947pub const NOTE_VM_PRESSURE = 0x80000000;
948
949/// will quit on memory pressure, possibly after cleaning up dirty state
950pub const NOTE_VM_PRESSURE_TERMINATE = 0x40000000;
951
952/// will quit immediately on memory pressure
953pub const NOTE_VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000;
954
955/// there was an error
956pub const NOTE_VM_ERROR = 0x10000000;
957
958/// data is seconds
959pub const NOTE_SECONDS = 0x00000001;
960
961/// data is microseconds
962pub const NOTE_USECONDS = 0x00000002;
963
964/// data is nanoseconds
965pub const NOTE_NSECONDS = 0x00000004;
966
967/// absolute timeout
968pub const NOTE_ABSOLUTE = 0x00000008;
969
970/// ext[1] holds leeway for power aware timers
971pub const NOTE_LEEWAY = 0x00000010;
972
973/// system does minimal timer coalescing
974pub const NOTE_CRITICAL = 0x00000020;
975
976/// system does maximum timer coalescing
977pub const NOTE_BACKGROUND = 0x00000040;
978pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080;
979
980/// data is mach absolute time units
981pub const NOTE_MACHTIME = 0x00000100;
982
983pub const AF_UNSPEC = 0;
984pub const AF_LOCAL = 1;
985pub const AF_UNIX = AF_LOCAL;
986pub const AF_INET = 2;
987pub const AF_SYS_CONTROL = 2;
988pub const AF_IMPLINK = 3;
989pub const AF_PUP = 4;
990pub const AF_CHAOS = 5;
991pub const AF_NS = 6;
992pub const AF_ISO = 7;
993pub const AF_OSI = AF_ISO;
994pub const AF_ECMA = 8;
995pub const AF_DATAKIT = 9;
996pub const AF_CCITT = 10;
997pub const AF_SNA = 11;
998pub const AF_DECnet = 12;
999pub const AF_DLI = 13;
1000pub const AF_LAT = 14;
1001pub const AF_HYLINK = 15;
1002pub const AF_APPLETALK = 16;
1003pub const AF_ROUTE = 17;
1004pub const AF_LINK = 18;
1005pub const AF_XTP = 19;
1006pub const AF_COIP = 20;
1007pub const AF_CNT = 21;
1008pub const AF_RTIP = 22;
1009pub const AF_IPX = 23;
1010pub const AF_SIP = 24;
1011pub const AF_PIP = 25;
1012pub const AF_ISDN = 28;
1013pub const AF_E164 = AF_ISDN;
1014pub const AF_KEY = 29;
1015pub const AF_INET6 = 30;
1016pub const AF_NATM = 31;
1017pub const AF_SYSTEM = 32;
1018pub const AF_NETBIOS = 33;
1019pub const AF_PPP = 34;
1020pub const AF_MAX = 40;
1021
1022pub const PF_UNSPEC = AF_UNSPEC;
1023pub const PF_LOCAL = AF_LOCAL;
1024pub const PF_UNIX = PF_LOCAL;
1025pub const PF_INET = AF_INET;
1026pub const PF_IMPLINK = AF_IMPLINK;
1027pub const PF_PUP = AF_PUP;
1028pub const PF_CHAOS = AF_CHAOS;
1029pub const PF_NS = AF_NS;
1030pub const PF_ISO = AF_ISO;
1031pub const PF_OSI = AF_ISO;
1032pub const PF_ECMA = AF_ECMA;
1033pub const PF_DATAKIT = AF_DATAKIT;
1034pub const PF_CCITT = AF_CCITT;
1035pub const PF_SNA = AF_SNA;
1036pub const PF_DECnet = AF_DECnet;
1037pub const PF_DLI = AF_DLI;
1038pub const PF_LAT = AF_LAT;
1039pub const PF_HYLINK = AF_HYLINK;
1040pub const PF_APPLETALK = AF_APPLETALK;
1041pub const PF_ROUTE = AF_ROUTE;
1042pub const PF_LINK = AF_LINK;
1043pub const PF_XTP = AF_XTP;
1044pub const PF_COIP = AF_COIP;
1045pub const PF_CNT = AF_CNT;
1046pub const PF_SIP = AF_SIP;
1047pub const PF_IPX = AF_IPX;
1048pub const PF_RTIP = AF_RTIP;
1049pub const PF_PIP = AF_PIP;
1050pub const PF_ISDN = AF_ISDN;
1051pub const PF_KEY = AF_KEY;
1052pub const PF_INET6 = AF_INET6;
1053pub const PF_NATM = AF_NATM;
1054pub const PF_SYSTEM = AF_SYSTEM;
1055pub const PF_NETBIOS = AF_NETBIOS;
1056pub const PF_PPP = AF_PPP;
1057pub const PF_MAX = AF_MAX;
1058
1059pub const SYSPROTO_EVENT = 1;
1060pub const SYSPROTO_CONTROL = 2;
1061
1062pub const SOCK_STREAM = 1;
1063pub const SOCK_DGRAM = 2;
1064pub const SOCK_RAW = 3;
1065pub const SOCK_RDM = 4;
1066pub const SOCK_SEQPACKET = 5;
1067pub const SOCK_MAXADDRLEN = 255;
1068
1069/// Not actually supported by Darwin, but Zig supplies a shim.
1070/// This numerical value is not ABI-stable. It need only not conflict
1071/// with any other "SOCK_" bits.
1072pub const SOCK_CLOEXEC = 1 << 15;
1073/// Not actually supported by Darwin, but Zig supplies a shim.
1074/// This numerical value is not ABI-stable. It need only not conflict
1075/// with any other "SOCK_" bits.
1076pub const SOCK_NONBLOCK = 1 << 16;
1077
1078pub const IPPROTO_ICMP = 1;
1079pub const IPPROTO_ICMPV6 = 58;
1080pub const IPPROTO_TCP = 6;
1081pub const IPPROTO_UDP = 17;
1082pub const IPPROTO_IP = 0;
1083pub const IPPROTO_IPV6 = 41;
1084
1085pub const SOL_SOCKET = 0xffff;
1086
1087pub const SO_DEBUG = 0x0001;
1088pub const SO_ACCEPTCONN = 0x0002;
1089pub const SO_REUSEADDR = 0x0004;
1090pub const SO_KEEPALIVE = 0x0008;
1091pub const SO_DONTROUTE = 0x0010;
1092pub const SO_BROADCAST = 0x0020;
1093pub const SO_USELOOPBACK = 0x0040;
1094pub const SO_LINGER = 0x1080;
1095pub const SO_OOBINLINE = 0x0100;
1096pub const SO_REUSEPORT = 0x0200;
1097pub const SO_ACCEPTFILTER = 0x1000;
1098pub const SO_SNDBUF = 0x1001;
1099pub const SO_RCVBUF = 0x1002;
1100pub const SO_SNDLOWAT = 0x1003;
1101pub const SO_RCVLOWAT = 0x1004;
1102pub const SO_SNDTIMEO = 0x1005;
1103pub const SO_RCVTIMEO = 0x1006;
1104pub const SO_ERROR = 0x1007;
1105pub const SO_TYPE = 0x1008;
1106
1107pub const SO_NREAD = 0x1020;
1108pub const SO_NKE = 0x1021;
1109pub const SO_NOSIGPIPE = 0x1022;
1110pub const SO_NOADDRERR = 0x1023;
1111pub const SO_NWRITE = 0x1024;
1112pub const SO_REUSESHAREUID = 0x1025;
1113
1114fn wstatus(x: u32) u32 {
1115 return x & 0o177;
1116}
1117const wstopped = 0o177;
1118pub fn WEXITSTATUS(x: u32) u8 {
1119 return @intCast(u8, x >> 8);
1120}
1121pub fn WTERMSIG(x: u32) u32 {
1122 return wstatus(x);
1123}
1124pub fn WSTOPSIG(x: u32) u32 {
1125 return x >> 8;
1126}
1127pub fn WIFEXITED(x: u32) bool {
1128 return wstatus(x) == 0;
1129}
1130pub fn WIFSTOPPED(x: u32) bool {
1131 return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13;
1132}
1133pub fn WIFSIGNALED(x: u32) bool {
1134 return wstatus(x) != wstopped and wstatus(x) != 0;
1135}
1136
1137pub const E = enum(u16) {
1138 /// No error occurred.
1139 SUCCESS = 0,
1140
1141 /// Operation not permitted
1142 PERM = 1,
1143
1144 /// No such file or directory
1145 NOENT = 2,
1146
1147 /// No such process
1148 SRCH = 3,
1149
1150 /// Interrupted system call
1151 INTR = 4,
1152
1153 /// Input/output error
1154 IO = 5,
1155
1156 /// Device not configured
1157 NXIO = 6,
1158
1159 /// Argument list too long
1160 @"2BIG" = 7,
1161
1162 /// Exec format error
1163 NOEXEC = 8,
1164
1165 /// Bad file descriptor
1166 BADF = 9,
1167
1168 /// No child processes
1169 CHILD = 10,
1170
1171 /// Resource deadlock avoided
1172 DEADLK = 11,
1173
1174 /// Cannot allocate memory
1175 NOMEM = 12,
1176
1177 /// Permission denied
1178 ACCES = 13,
1179
1180 /// Bad address
1181 FAULT = 14,
1182
1183 /// Block device required
1184 NOTBLK = 15,
1185
1186 /// Device / Resource busy
1187 BUSY = 16,
1188
1189 /// File exists
1190 EXIST = 17,
1191
1192 /// Cross-device link
1193 XDEV = 18,
1194
1195 /// Operation not supported by device
1196 NODEV = 19,
1197
1198 /// Not a directory
1199 NOTDIR = 20,
1200
1201 /// Is a directory
1202 ISDIR = 21,
1203
1204 /// Invalid argument
1205 INVAL = 22,
1206
1207 /// Too many open files in system
1208 NFILE = 23,
1209
1210 /// Too many open files
1211 MFILE = 24,
1212
1213 /// Inappropriate ioctl for device
1214 NOTTY = 25,
1215
1216 /// Text file busy
1217 TXTBSY = 26,
1218
1219 /// File too large
1220 FBIG = 27,
1221
1222 /// No space left on device
1223 NOSPC = 28,
1224
1225 /// Illegal seek
1226 SPIPE = 29,
1227
1228 /// Read-only file system
1229 ROFS = 30,
1230
1231 /// Too many links
1232 MLINK = 31,
1233
1234 /// Broken pipe
1235 PIPE = 32,
1236
1237 // math software
1238
1239 /// Numerical argument out of domain
1240 DOM = 33,
1241
1242 /// Result too large
1243 RANGE = 34,
1244
1245 // non-blocking and interrupt i/o
1246
1247 /// Resource temporarily unavailable
1248 /// This is the same code used for `WOULDBLOCK`.
1249 AGAIN = 35,
1250
1251 /// Operation now in progress
1252 INPROGRESS = 36,
1253
1254 /// Operation already in progress
1255 ALREADY = 37,
1256
1257 // ipc/network software -- argument errors
1258
1259 /// Socket operation on non-socket
1260 NOTSOCK = 38,
1261
1262 /// Destination address required
1263 DESTADDRREQ = 39,
1264
1265 /// Message too long
1266 MSGSIZE = 40,
1267
1268 /// Protocol wrong type for socket
1269 PROTOTYPE = 41,
1270
1271 /// Protocol not available
1272 NOPROTOOPT = 42,
1273
1274 /// Protocol not supported
1275 PROTONOSUPPORT = 43,
1276
1277 /// Socket type not supported
1278 SOCKTNOSUPPORT = 44,
1279
1280 /// Operation not supported
1281 /// The same code is used for `NOTSUP`.
1282 OPNOTSUPP = 45,
1283
1284 /// Protocol family not supported
1285 PFNOSUPPORT = 46,
1286
1287 /// Address family not supported by protocol family
1288 AFNOSUPPORT = 47,
1289
1290 /// Address already in use
1291 ADDRINUSE = 48,
1292 /// Can't assign requested address
1293
1294 // ipc/network software -- operational errors
1295 ADDRNOTAVAIL = 49,
1296
1297 /// Network is down
1298 NETDOWN = 50,
1299
1300 /// Network is unreachable
1301 NETUNREACH = 51,
1302
1303 /// Network dropped connection on reset
1304 NETRESET = 52,
1305
1306 /// Software caused connection abort
1307 CONNABORTED = 53,
1308
1309 /// Connection reset by peer
1310 CONNRESET = 54,
1311
1312 /// No buffer space available
1313 NOBUFS = 55,
1314
1315 /// Socket is already connected
1316 ISCONN = 56,
1317
1318 /// Socket is not connected
1319 NOTCONN = 57,
1320
1321 /// Can't send after socket shutdown
1322 SHUTDOWN = 58,
1323
1324 /// Too many references: can't splice
1325 TOOMANYREFS = 59,
1326
1327 /// Operation timed out
1328 TIMEDOUT = 60,
1329
1330 /// Connection refused
1331 CONNREFUSED = 61,
1332
1333 /// Too many levels of symbolic links
1334 LOOP = 62,
1335
1336 /// File name too long
1337 NAMETOOLONG = 63,
1338
1339 /// Host is down
1340 HOSTDOWN = 64,
1341
1342 /// No route to host
1343 HOSTUNREACH = 65,
1344 /// Directory not empty
1345
1346 // quotas & mush
1347 NOTEMPTY = 66,
1348
1349 /// Too many processes
1350 PROCLIM = 67,
1351
1352 /// Too many users
1353 USERS = 68,
1354 /// Disc quota exceeded
1355
1356 // Network File System
1357 DQUOT = 69,
1358
1359 /// Stale NFS file handle
1360 STALE = 70,
1361
1362 /// Too many levels of remote in path
1363 REMOTE = 71,
1364
1365 /// RPC struct is bad
1366 BADRPC = 72,
1367
1368 /// RPC version wrong
1369 RPCMISMATCH = 73,
1370
1371 /// RPC prog. not avail
1372 PROGUNAVAIL = 74,
1373
1374 /// Program version wrong
1375 PROGMISMATCH = 75,
1376
1377 /// Bad procedure for program
1378 PROCUNAVAIL = 76,
1379
1380 /// No locks available
1381 NOLCK = 77,
1382
1383 /// Function not implemented
1384 NOSYS = 78,
1385
1386 /// Inappropriate file type or format
1387 FTYPE = 79,
1388
1389 /// Authentication error
1390 AUTH = 80,
1391
1392 /// Need authenticator
1393 NEEDAUTH = 81,
1394
1395 // Intelligent device errors
1396
1397 /// Device power is off
1398 PWROFF = 82,
1399
1400 /// Device error, e.g. paper out
1401 DEVERR = 83,
1402
1403 /// Value too large to be stored in data type
1404 OVERFLOW = 84,
1405
1406 // Program loading errors
1407
1408 /// Bad executable
1409 BADEXEC = 85,
1410
1411 /// Bad CPU type in executable
1412 BADARCH = 86,
1413
1414 /// Shared library version mismatch
1415 SHLIBVERS = 87,
1416
1417 /// Malformed Macho file
1418 BADMACHO = 88,
1419
1420 /// Operation canceled
1421 CANCELED = 89,
1422
1423 /// Identifier removed
1424 IDRM = 90,
1425
1426 /// No message of desired type
1427 NOMSG = 91,
1428
1429 /// Illegal byte sequence
1430 ILSEQ = 92,
1431
1432 /// Attribute not found
1433 NOATTR = 93,
1434
1435 /// Bad message
1436 BADMSG = 94,
1437
1438 /// Reserved
1439 MULTIHOP = 95,
1440
1441 /// No message available on STREAM
1442 NODATA = 96,
1443
1444 /// Reserved
1445 NOLINK = 97,
1446
1447 /// No STREAM resources
1448 NOSR = 98,
1449
1450 /// Not a STREAM
1451 NOSTR = 99,
1452
1453 /// Protocol error
1454 PROTO = 100,
1455
1456 /// STREAM ioctl timeout
1457 TIME = 101,
1458
1459 /// No such policy registered
1460 NOPOLICY = 103,
1461
1462 /// State not recoverable
1463 NOTRECOVERABLE = 104,
1464
1465 /// Previous owner died
1466 OWNERDEAD = 105,
1467
1468 /// Interface output queue is full
1469 QFULL = 106,
1470
1471 _,
1472};
1473
1474pub const SIGSTKSZ = 131072;
1475pub const MINSIGSTKSZ = 32768;
1476
1477pub const SS_ONSTACK = 1;
1478pub const SS_DISABLE = 4;
1479
1480pub const stack_t = extern struct {
1481 ss_sp: [*]u8,
1482 ss_size: isize,
1483 ss_flags: i32,
1484};
1485
1486pub const S_IFMT = 0o170000;
1487
1488pub const S_IFIFO = 0o010000;
1489pub const S_IFCHR = 0o020000;
1490pub const S_IFDIR = 0o040000;
1491pub const S_IFBLK = 0o060000;
1492pub const S_IFREG = 0o100000;
1493pub const S_IFLNK = 0o120000;
1494pub const S_IFSOCK = 0o140000;
1495pub const S_IFWHT = 0o160000;
1496
1497pub const S_ISUID = 0o4000;
1498pub const S_ISGID = 0o2000;
1499pub const S_ISVTX = 0o1000;
1500pub const S_IRWXU = 0o700;
1501pub const S_IRUSR = 0o400;
1502pub const S_IWUSR = 0o200;
1503pub const S_IXUSR = 0o100;
1504pub const S_IRWXG = 0o070;
1505pub const S_IRGRP = 0o040;
1506pub const S_IWGRP = 0o020;
1507pub const S_IXGRP = 0o010;
1508pub const S_IRWXO = 0o007;
1509pub const S_IROTH = 0o004;
1510pub const S_IWOTH = 0o002;
1511pub const S_IXOTH = 0o001;
1512
1513pub fn S_ISFIFO(m: u32) bool {
1514 return m & S_IFMT == S_IFIFO;
1515}
1516
1517pub fn S_ISCHR(m: u32) bool {
1518 return m & S_IFMT == S_IFCHR;
1519}
1520
1521pub fn S_ISDIR(m: u32) bool {
1522 return m & S_IFMT == S_IFDIR;
1523}
1524
1525pub fn S_ISBLK(m: u32) bool {
1526 return m & S_IFMT == S_IFBLK;
1527}
1528
1529pub fn S_ISREG(m: u32) bool {
1530 return m & S_IFMT == S_IFREG;
1531}
1532
1533pub fn S_ISLNK(m: u32) bool {
1534 return m & S_IFMT == S_IFLNK;
1535}
1536
1537pub fn S_ISSOCK(m: u32) bool {
1538 return m & S_IFMT == S_IFSOCK;
1539}
1540
1541pub fn S_IWHT(m: u32) bool {
1542 return m & S_IFMT == S_IFWHT;
1543}
1544
1545pub const HOST_NAME_MAX = 72;
1546
1547pub const AT_FDCWD = -2;
1548
1549/// Use effective ids in access check
1550pub const AT_EACCESS = 0x0010;
1551
1552/// Act on the symlink itself not the target
1553pub const AT_SYMLINK_NOFOLLOW = 0x0020;
1554
1555/// Act on target of symlink
1556pub const AT_SYMLINK_FOLLOW = 0x0040;
1557
1558/// Path refers to directory
1559pub const AT_REMOVEDIR = 0x0080;
1560
1561pub const addrinfo = extern struct {
1562 flags: i32,
1563 family: i32,
1564 socktype: i32,
1565 protocol: i32,
1566 addrlen: socklen_t,
1567 canonname: ?[*:0]u8,
1568 addr: ?*sockaddr,
1569 next: ?*addrinfo,
1570};
1571
1572pub const RTLD_LAZY = 0x1;
1573pub const RTLD_NOW = 0x2;
1574pub const RTLD_LOCAL = 0x4;
1575pub const RTLD_GLOBAL = 0x8;
1576pub const RTLD_NOLOAD = 0x10;
1577pub const RTLD_NODELETE = 0x80;
1578pub const RTLD_FIRST = 0x100;
1579
1580pub const RTLD_NEXT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -1)));
1581pub const RTLD_DEFAULT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -2)));
1582pub const RTLD_SELF = @intToPtr(*c_void, @bitCast(usize, @as(isize, -3)));
1583pub const RTLD_MAIN_ONLY = @intToPtr(*c_void, @bitCast(usize, @as(isize, -5)));
1584
1585/// duplicate file descriptor
1586pub const F_DUPFD = 0;
1587
1588/// get file descriptor flags
1589pub const F_GETFD = 1;
1590
1591/// set file descriptor flags
1592pub const F_SETFD = 2;
1593
1594/// get file status flags
1595pub const F_GETFL = 3;
1596
1597/// set file status flags
1598pub const F_SETFL = 4;
1599
1600/// get SIGIO/SIGURG proc/pgrp
1601pub const F_GETOWN = 5;
1602
1603/// set SIGIO/SIGURG proc/pgrp
1604pub const F_SETOWN = 6;
1605
1606/// get record locking information
1607pub const F_GETLK = 7;
1608
1609/// set record locking information
1610pub const F_SETLK = 8;
1611
1612/// F_SETLK; wait if blocked
1613pub const F_SETLKW = 9;
1614
1615/// F_SETLK; wait if blocked, return on timeout
1616pub const F_SETLKWTIMEOUT = 10;
1617pub const F_FLUSH_DATA = 40;
1618
1619/// Used for regression test
1620pub const F_CHKCLEAN = 41;
1621
1622/// Preallocate storage
1623pub const F_PREALLOCATE = 42;
1624
1625/// Truncate a file without zeroing space
1626pub const F_SETSIZE = 43;
1627
1628/// Issue an advisory read async with no copy to user
1629pub const F_RDADVISE = 44;
1630
1631/// turn read ahead off/on for this fd
1632pub const F_RDAHEAD = 45;
1633
1634/// turn data caching off/on for this fd
1635pub const F_NOCACHE = 48;
1636
1637/// file offset to device offset
1638pub const F_LOG2PHYS = 49;
1639
1640/// return the full path of the fd
1641pub const F_GETPATH = 50;
1642
1643/// fsync + ask the drive to flush to the media
1644pub const F_FULLFSYNC = 51;
1645
1646/// find which component (if any) is a package
1647pub const F_PATHPKG_CHECK = 52;
1648
1649/// "freeze" all fs operations
1650pub const F_FREEZE_FS = 53;
1651
1652/// "thaw" all fs operations
1653pub const F_THAW_FS = 54;
1654
1655/// turn data caching off/on (globally) for this file
1656pub const F_GLOBAL_NOCACHE = 55;
1657
1658/// add detached signatures
1659pub const F_ADDSIGS = 59;
1660
1661/// add signature from same file (used by dyld for shared libs)
1662pub const F_ADDFILESIGS = 61;
1663
1664/// used in conjunction with F_NOCACHE to indicate that DIRECT, synchonous writes
1665/// should not be used (i.e. its ok to temporaily create cached pages)
1666pub const F_NODIRECT = 62;
1667
1668///Get the protection class of a file from the EA, returns int
1669pub const F_GETPROTECTIONCLASS = 63;
1670
1671///Set the protection class of a file for the EA, requires int
1672pub const F_SETPROTECTIONCLASS = 64;
1673
1674///file offset to device offset, extended
1675pub const F_LOG2PHYS_EXT = 65;
1676
1677///get record locking information, per-process
1678pub const F_GETLKPID = 66;
1679
1680///Mark the file as being the backing store for another filesystem
1681pub const F_SETBACKINGSTORE = 70;
1682
1683///return the full path of the FD, but error in specific mtmd circumstances
1684pub const F_GETPATH_MTMINFO = 71;
1685
1686///Returns the code directory, with associated hashes, to the caller
1687pub const F_GETCODEDIR = 72;
1688
1689///No SIGPIPE generated on EPIPE
1690pub const F_SETNOSIGPIPE = 73;
1691
1692///Status of SIGPIPE for this fd
1693pub const F_GETNOSIGPIPE = 74;
1694
1695///For some cases, we need to rewrap the key for AKS/MKB
1696pub const F_TRANSCODEKEY = 75;
1697
1698///file being written to a by single writer... if throttling enabled, writes
1699///may be broken into smaller chunks with throttling in between
1700pub const F_SINGLE_WRITER = 76;
1701
1702///Get the protection version number for this filesystem
1703pub const F_GETPROTECTIONLEVEL = 77;
1704
1705///Add detached code signatures (used by dyld for shared libs)
1706pub const F_FINDSIGS = 78;
1707
1708///Add signature from same file, only if it is signed by Apple (used by dyld for simulator)
1709pub const F_ADDFILESIGS_FOR_DYLD_SIM = 83;
1710
1711///fsync + issue barrier to drive
1712pub const F_BARRIERFSYNC = 85;
1713
1714///Add signature from same file, return end offset in structure on success
1715pub const F_ADDFILESIGS_RETURN = 97;
1716
1717///Check if Library Validation allows this Mach-O file to be mapped into the calling process
1718pub const F_CHECK_LV = 98;
1719
1720///Deallocate a range of the file
1721pub const F_PUNCHHOLE = 99;
1722
1723///Trim an active file
1724pub const F_TRIM_ACTIVE_FILE = 100;
1725
1726pub const FCNTL_FS_SPECIFIC_BASE = 0x00010000;
1727
1728///mark the dup with FD_CLOEXEC
1729pub const F_DUPFD_CLOEXEC = 67;
1730
1731///close-on-exec flag
1732pub const FD_CLOEXEC = 1;
1733
1734/// shared or read lock
1735pub const F_RDLCK = 1;
1736
1737/// unlock
1738pub const F_UNLCK = 2;
1739
1740/// exclusive or write lock
1741pub const F_WRLCK = 3;
1742
1743pub const LOCK_SH = 1;
1744pub const LOCK_EX = 2;
1745pub const LOCK_UN = 8;
1746pub const LOCK_NB = 4;
1747
1748pub const nfds_t = u32;
1749pub const pollfd = extern struct {
1750 fd: fd_t,
1751 events: i16,
1752 revents: i16,
1753};
1754
1755pub const POLLIN = 0x001;
1756pub const POLLPRI = 0x002;
1757pub const POLLOUT = 0x004;
1758pub const POLLRDNORM = 0x040;
1759pub const POLLWRNORM = POLLOUT;
1760pub const POLLRDBAND = 0x080;
1761pub const POLLWRBAND = 0x100;
1762
1763pub const POLLEXTEND = 0x0200;
1764pub const POLLATTRIB = 0x0400;
1765pub const POLLNLINK = 0x0800;
1766pub const POLLWRITE = 0x1000;
1767
1768pub const POLLERR = 0x008;
1769pub const POLLHUP = 0x010;
1770pub const POLLNVAL = 0x020;
1771
1772pub const POLLSTANDARD = POLLIN | POLLPRI | POLLOUT | POLLRDNORM | POLLRDBAND | POLLWRBAND | POLLERR | POLLHUP | POLLNVAL;
1773
1774pub const CLOCK_REALTIME = 0;
1775pub const CLOCK_MONOTONIC = 6;
1776pub const CLOCK_MONOTONIC_RAW = 4;
1777pub const CLOCK_MONOTONIC_RAW_APPROX = 5;
1778pub const CLOCK_UPTIME_RAW = 8;
1779pub const CLOCK_UPTIME_RAW_APPROX = 9;
1780pub const CLOCK_PROCESS_CPUTIME_ID = 12;
1781pub const CLOCK_THREAD_CPUTIME_ID = 16;
1782
1783/// Max open files per process
1784/// https://opensource.apple.com/source/xnu/xnu-4903.221.2/bsd/sys/syslimits.h.auto.html
1785pub const OPEN_MAX = 10240;
1786pub const RUSAGE_SELF = 0;
1787pub const RUSAGE_CHILDREN = -1;
1788
1789pub const rusage = extern struct {
1790 utime: timeval,
1791 stime: timeval,
1792 maxrss: isize,
1793 ixrss: isize,
1794 idrss: isize,
1795 isrss: isize,
1796 minflt: isize,
1797 majflt: isize,
1798 nswap: isize,
1799 inblock: isize,
1800 oublock: isize,
1801 msgsnd: isize,
1802 msgrcv: isize,
1803 nsignals: isize,
1804 nvcsw: isize,
1805 nivcsw: isize,
1806};
1807
1808pub const rlimit_resource = enum(c_int) {
1809 CPU = 0,
1810 FSIZE = 1,
1811 DATA = 2,
1812 STACK = 3,
1813 CORE = 4,
1814 RSS = 5,
1815 MEMLOCK = 6,
1816 NPROC = 7,
1817 NOFILE = 8,
1818 _,
1819
1820 pub const AS: rlimit_resource = .RSS;
1821};
1822
1823pub const rlim_t = u64;
1824
1825/// No limit
1826pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
1827
1828pub const RLIM_SAVED_MAX = RLIM_INFINITY;
1829pub const RLIM_SAVED_CUR = RLIM_INFINITY;
1830
1831pub const rlimit = extern struct {
1832 /// Soft limit
1833 cur: rlim_t,
1834 /// Hard limit
1835 max: rlim_t,
1836};
1837
1838pub const SHUT_RD = 0;
1839pub const SHUT_WR = 1;
1840pub const SHUT_RDWR = 2;
1841
1842// Term
1843pub const VEOF = 0;
1844pub const VEOL = 1;
1845pub const VEOL2 = 2;
1846pub const VERASE = 3;
1847pub const VWERASE = 4;
1848pub const VKILL = 5;
1849pub const VREPRINT = 6;
1850pub const VINTR = 8;
1851pub const VQUIT = 9;
1852pub const VSUSP = 10;
1853pub const VDSUSP = 11;
1854pub const VSTART = 12;
1855pub const VSTOP = 13;
1856pub const VLNEXT = 14;
1857pub const VDISCARD = 15;
1858pub const VMIN = 16;
1859pub const VTIME = 17;
1860pub const VSTATUS = 18;
1861pub const NCCS = 20; // 2 spares (7, 19)
1862
1863pub const IGNBRK = 0x00000001; // ignore BREAK condition
1864pub const BRKINT = 0x00000002; // map BREAK to SIGINTR
1865pub const IGNPAR = 0x00000004; // ignore (discard) parity errors
1866pub const PARMRK = 0x00000008; // mark parity and framing errors
1867pub const INPCK = 0x00000010; // enable checking of parity errors
1868pub const ISTRIP = 0x00000020; // strip 8th bit off chars
1869pub const INLCR = 0x00000040; // map NL into CR
1870pub const IGNCR = 0x00000080; // ignore CR
1871pub const ICRNL = 0x00000100; // map CR to NL (ala CRMOD)
1872pub const IXON = 0x00000200; // enable output flow control
1873pub const IXOFF = 0x00000400; // enable input flow control
1874pub const IXANY = 0x00000800; // any char will restart after stop
1875pub const IMAXBEL = 0x00002000; // ring bell on input queue full
1876pub const IUTF8 = 0x00004000; // maintain state for UTF-8 VERASE
1877
1878pub const OPOST = 0x00000001; //enable following output processing
1879pub const ONLCR = 0x00000002; // map NL to CR-NL (ala CRMOD)
1880pub const OXTABS = 0x00000004; // expand tabs to spaces
1881pub const ONOEOT = 0x00000008; // discard EOT's (^D) on output)
1882
1883pub const OCRNL = 0x00000010; // map CR to NL on output
1884pub const ONOCR = 0x00000020; // no CR output at column 0
1885pub const ONLRET = 0x00000040; // NL performs CR function
1886pub const OFILL = 0x00000080; // use fill characters for delay
1887pub const NLDLY = 0x00000300; // \n delay
1888pub const TABDLY = 0x00000c04; // horizontal tab delay
1889pub const CRDLY = 0x00003000; // \r delay
1890pub const FFDLY = 0x00004000; // form feed delay
1891pub const BSDLY = 0x00008000; // \b delay
1892pub const VTDLY = 0x00010000; // vertical tab delay
1893pub const OFDEL = 0x00020000; // fill is DEL, else NUL
1894
1895pub const NL0 = 0x00000000;
1896pub const NL1 = 0x00000100;
1897pub const NL2 = 0x00000200;
1898pub const NL3 = 0x00000300;
1899pub const TAB0 = 0x00000000;
1900pub const TAB1 = 0x00000400;
1901pub const TAB2 = 0x00000800;
1902pub const TAB3 = 0x00000004;
1903pub const CR0 = 0x00000000;
1904pub const CR1 = 0x00001000;
1905pub const CR2 = 0x00002000;
1906pub const CR3 = 0x00003000;
1907pub const FF0 = 0x00000000;
1908pub const FF1 = 0x00004000;
1909pub const BS0 = 0x00000000;
1910pub const BS1 = 0x00008000;
1911pub const VT0 = 0x00000000;
1912pub const VT1 = 0x00010000;
1913
1914pub const CIGNORE = 0x00000001; // ignore control flags
1915pub const CSIZE = 0x00000300; // character size mask
1916pub const CS5 = 0x00000000; // 5 bits (pseudo)
1917pub const CS6 = 0x00000100; // 6 bits
1918pub const CS7 = 0x00000200; // 7 bits
1919pub const CS8 = 0x00000300; // 8 bits
1920pub const CSTOPB = 0x0000040; // send 2 stop bits
1921pub const CREAD = 0x00000800; // enable receiver
1922pub const PARENB = 0x00001000; // parity enable
1923pub const PARODD = 0x00002000; // odd parity, else even
1924pub const HUPCL = 0x00004000; // hang up on last close
1925pub const CLOCAL = 0x00008000; // ignore modem status lines
1926pub const CCTS_OFLOW = 0x00010000; // CTS flow control of output
1927pub const CRTSCTS = (CCTS_OFLOW | CRTS_IFLOW);
1928pub const CRTS_IFLOW = 0x00020000; // RTS flow control of input
1929pub const CDTR_IFLOW = 0x00040000; // DTR flow control of input
1930pub const CDSR_OFLOW = 0x00080000; // DSR flow control of output
1931pub const CCAR_OFLOW = 0x00100000; // DCD flow control of output
1932pub const MDMBUF = 0x00100000; // old name for CCAR_OFLOW
1933
1934pub const ECHOKE = 0x00000001; // visual erase for line kill
1935pub const ECHOE = 0x00000002; // visually erase chars
1936pub const ECHOK = 0x00000004; // echo NL after line kill
1937pub const ECHO = 0x00000008; // enable echoing
1938pub const ECHONL = 0x00000010; // echo NL even if ECHO is off
1939pub const ECHOPRT = 0x00000020; // visual erase mode for hardcopy
1940pub const ECHOCTL = 0x00000040; // echo control chars as ^(Char)
1941pub const ISIG = 0x00000080; // enable signals INTR, QUIT, [D]SUSP
1942pub const ICANON = 0x00000100; // canonicalize input lines
1943pub const ALTWERASE = 0x00000200; // use alternate WERASE algorithm
1944pub const IEXTEN = 0x00000400; // enable DISCARD and LNEXT
1945pub const EXTPROC = 0x00000800; // external processing
1946pub const TOSTOP = 0x00400000; // stop background jobs from output
1947pub const FLUSHO = 0x00800000; // output being flushed (state)
1948pub const NOKERNINFO = 0x02000000; // no kernel output from VSTATUS
1949pub const PENDIN = 0x20000000; // XXX retype pending input (state)
1950pub const NOFLSH = 0x80000000; // don't flush after interrupt
1951
1952pub const TCSANOW = 0; // make change immediate
1953pub const TCSADRAIN = 1; // drain output, then change
1954pub const TCSAFLUSH = 2; // drain output, flush input
1955pub const TCSASOFT = 0x10; // flag - don't alter h.w. state
1956pub const TCSA = enum(c_uint) {
1957 NOW,
1958 DRAIN,
1959 FLUSH,
1960 _,
1961};
1962
1963pub const B0 = 0;
1964pub const B50 = 50;
1965pub const B75 = 75;
1966pub const B110 = 110;
1967pub const B134 = 134;
1968pub const B150 = 150;
1969pub const B200 = 200;
1970pub const B300 = 300;
1971pub const B600 = 600;
1972pub const B1200 = 1200;
1973pub const B1800 = 1800;
1974pub const B2400 = 2400;
1975pub const B4800 = 4800;
1976pub const B9600 = 9600;
1977pub const B19200 = 19200;
1978pub const B38400 = 38400;
1979pub const B7200 = 7200;
1980pub const B14400 = 14400;
1981pub const B28800 = 28800;
1982pub const B57600 = 57600;
1983pub const B76800 = 76800;
1984pub const B115200 = 115200;
1985pub const B230400 = 230400;
1986pub const EXTA = 19200;
1987pub const EXTB = 38400;
1988
1989pub const TCIFLUSH = 1;
1990pub const TCOFLUSH = 2;
1991pub const TCIOFLUSH = 3;
1992pub const TCOOFF = 1;
1993pub const TCOON = 2;
1994pub const TCIOFF = 3;
1995pub const TCION = 4;
1996
1997pub const cc_t = u8;
1998pub const speed_t = u64;
1999pub const tcflag_t = u64;
2000
2001pub const termios = extern struct {
2002 iflag: tcflag_t, // input flags
2003 oflag: tcflag_t, // output flags
2004 cflag: tcflag_t, // control flags
2005 lflag: tcflag_t, // local flags
2006 cc: [NCCS]cc_t, // control chars
2007 ispeed: speed_t align(8), // input speed
2008 ospeed: speed_t, // output speed
2009};
2010
2011pub const winsize = extern struct {
2012 ws_row: u16,
2013 ws_col: u16,
2014 ws_xpixel: u16,
2015 ws_ypixel: u16,
2016};
2017
2018pub const TIOCGWINSZ = ior(0x40000000, 't', 104, @sizeOf(winsize));
2019pub const IOCPARM_MASK = 0x1fff;
2020
2021fn ior(inout: u32, group: usize, num: usize, len: usize) usize {
2022 return (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num));
2023}
2024
2025// CPU families mapping
2026pub const CPUFAMILY = enum(u32) {
2027 UNKNOWN = 0,
2028 POWERPC_G3 = 0xcee41549,
2029 POWERPC_G4 = 0x77c184ae,
2030 POWERPC_G5 = 0xed76d8aa,
2031 INTEL_6_13 = 0xaa33392b,
2032 INTEL_PENRYN = 0x78ea4fbc,
2033 INTEL_NEHALEM = 0x6b5a4cd2,
2034 INTEL_WESTMERE = 0x573b5eec,
2035 INTEL_SANDYBRIDGE = 0x5490b78c,
2036 INTEL_IVYBRIDGE = 0x1f65e835,
2037 INTEL_HASWELL = 0x10b282dc,
2038 INTEL_BROADWELL = 0x582ed09c,
2039 INTEL_SKYLAKE = 0x37fc219f,
2040 INTEL_KABYLAKE = 0x0f817246,
2041 ARM_9 = 0xe73283ae,
2042 ARM_11 = 0x8ff620d8,
2043 ARM_XSCALE = 0x53b005f5,
2044 ARM_12 = 0xbd1b0ae9,
2045 ARM_13 = 0x0cc90e64,
2046 ARM_14 = 0x96077ef1,
2047 ARM_15 = 0xa8511bca,
2048 ARM_SWIFT = 0x1e2d6381,
2049 ARM_CYCLONE = 0x37a09642,
2050 ARM_TYPHOON = 0x2c91a47e,
2051 ARM_TWISTER = 0x92fb37c8,
2052 ARM_HURRICANE = 0x67ceee93,
2053 ARM_MONSOON_MISTRAL = 0xe81e7ef6,
2054 ARM_VORTEX_TEMPEST = 0x07d34b9f,
2055 ARM_LIGHTNING_THUNDER = 0x462504d2,
2056 ARM_FIRESTORM_ICESTORM = 0x1b588bb3,
2057 _,
2058};
lib/std/c/dragonfly.zig+1031-1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2usingnamespace std.c;2const maxInt = std.math.maxInt;
3
3extern "c" threadlocal var errno: c_int;4extern "c" threadlocal var errno: c_int;
4pub fn _errno() *c_int {5pub fn _errno() *c_int {
5 return &errno;6 return &errno;
...@@ -30,3 +31,1032 @@ pub const pthread_attr_t = extern struct { // copied from freebsd...@@ -30,3 +31,1032 @@ pub const pthread_attr_t = extern struct { // copied from freebsd
30};31};
3132
32pub const sem_t = ?*opaque {};33pub const sem_t = ?*opaque {};
34
35pub fn S_ISCHR(m: u32) bool {
36 return m & S_IFMT == S_IFCHR;
37}
38
39// See:
40// - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/include/unistd.h
41// - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/sys/sys/types.h
42// TODO: mode_t should probably be changed to a u16, audit pid_t/off_t as well
43pub const fd_t = c_int;
44pub const pid_t = c_int;
45pub const off_t = c_long;
46pub const mode_t = c_uint;
47pub const uid_t = u32;
48pub const gid_t = u32;
49pub const time_t = isize;
50pub const suseconds_t = c_long;
51
52pub const E = enum(u16) {
53 /// No error occurred.
54 SUCCESS = 0,
55
56 PERM = 1,
57 NOENT = 2,
58 SRCH = 3,
59 INTR = 4,
60 IO = 5,
61 NXIO = 6,
62 @"2BIG" = 7,
63 NOEXEC = 8,
64 BADF = 9,
65 CHILD = 10,
66 DEADLK = 11,
67 NOMEM = 12,
68 ACCES = 13,
69 FAULT = 14,
70 NOTBLK = 15,
71 BUSY = 16,
72 EXIST = 17,
73 XDEV = 18,
74 NODEV = 19,
75 NOTDIR = 20,
76 ISDIR = 21,
77 INVAL = 22,
78 NFILE = 23,
79 MFILE = 24,
80 NOTTY = 25,
81 TXTBSY = 26,
82 FBIG = 27,
83 NOSPC = 28,
84 SPIPE = 29,
85 ROFS = 30,
86 MLINK = 31,
87 PIPE = 32,
88 DOM = 33,
89 RANGE = 34,
90 /// This code is also used for `WOULDBLOCK`.
91 AGAIN = 35,
92 INPROGRESS = 36,
93 ALREADY = 37,
94 NOTSOCK = 38,
95 DESTADDRREQ = 39,
96 MSGSIZE = 40,
97 PROTOTYPE = 41,
98 NOPROTOOPT = 42,
99 PROTONOSUPPORT = 43,
100 SOCKTNOSUPPORT = 44,
101 /// This code is also used for `NOTSUP`.
102 OPNOTSUPP = 45,
103 PFNOSUPPORT = 46,
104 AFNOSUPPORT = 47,
105 ADDRINUSE = 48,
106 ADDRNOTAVAIL = 49,
107 NETDOWN = 50,
108 NETUNREACH = 51,
109 NETRESET = 52,
110 CONNABORTED = 53,
111 CONNRESET = 54,
112 NOBUFS = 55,
113 ISCONN = 56,
114 NOTCONN = 57,
115 SHUTDOWN = 58,
116 TOOMANYREFS = 59,
117 TIMEDOUT = 60,
118 CONNREFUSED = 61,
119 LOOP = 62,
120 NAMETOOLONG = 63,
121 HOSTDOWN = 64,
122 HOSTUNREACH = 65,
123 NOTEMPTY = 66,
124 PROCLIM = 67,
125 USERS = 68,
126 DQUOT = 69,
127 STALE = 70,
128 REMOTE = 71,
129 BADRPC = 72,
130 RPCMISMATCH = 73,
131 PROGUNAVAIL = 74,
132 PROGMISMATCH = 75,
133 PROCUNAVAIL = 76,
134 NOLCK = 77,
135 NOSYS = 78,
136 FTYPE = 79,
137 AUTH = 80,
138 NEEDAUTH = 81,
139 IDRM = 82,
140 NOMSG = 83,
141 OVERFLOW = 84,
142 CANCELED = 85,
143 ILSEQ = 86,
144 NOATTR = 87,
145 DOOFUS = 88,
146 BADMSG = 89,
147 MULTIHOP = 90,
148 NOLINK = 91,
149 PROTO = 92,
150 NOMEDIUM = 93,
151 ASYNC = 99,
152 _,
153};
154
155pub const STDIN_FILENO = 0;
156pub const STDOUT_FILENO = 1;
157pub const STDERR_FILENO = 2;
158
159pub const PROT_NONE = 0;
160pub const PROT_READ = 1;
161pub const PROT_WRITE = 2;
162pub const PROT_EXEC = 4;
163
164pub const MAP_FILE = 0;
165pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
166pub const MAP_ANONYMOUS = MAP_ANON;
167pub const MAP_COPY = MAP_PRIVATE;
168pub const MAP_SHARED = 1;
169pub const MAP_PRIVATE = 2;
170pub const MAP_FIXED = 16;
171pub const MAP_RENAME = 32;
172pub const MAP_NORESERVE = 64;
173pub const MAP_INHERIT = 128;
174pub const MAP_NOEXTEND = 256;
175pub const MAP_HASSEMAPHORE = 512;
176pub const MAP_STACK = 1024;
177pub const MAP_NOSYNC = 2048;
178pub const MAP_ANON = 4096;
179pub const MAP_VPAGETABLE = 8192;
180pub const MAP_TRYFIXED = 65536;
181pub const MAP_NOCORE = 131072;
182pub const MAP_SIZEALIGN = 262144;
183
184pub const WNOHANG = 0x0001;
185pub const WUNTRACED = 0x0002;
186pub const WCONTINUED = 0x0004;
187pub const WSTOPPED = WUNTRACED;
188pub const WNOWAIT = 0x0008;
189pub const WEXITED = 0x0010;
190pub const WTRAPPED = 0x0020;
191
192pub const SA_ONSTACK = 0x0001;
193pub const SA_RESTART = 0x0002;
194pub const SA_RESETHAND = 0x0004;
195pub const SA_NODEFER = 0x0010;
196pub const SA_NOCLDWAIT = 0x0020;
197pub const SA_SIGINFO = 0x0040;
198
199pub const PATH_MAX = 1024;
200pub const IOV_MAX = KERN_IOV_MAX;
201
202pub const ino_t = c_ulong;
203
204pub const Stat = extern struct {
205 ino: ino_t,
206 nlink: c_uint,
207 dev: c_uint,
208 mode: c_ushort,
209 padding1: u16,
210 uid: uid_t,
211 gid: gid_t,
212 rdev: c_uint,
213 atim: timespec,
214 mtim: timespec,
215 ctim: timespec,
216 size: c_ulong,
217 blocks: i64,
218 blksize: u32,
219 flags: u32,
220 gen: u32,
221 lspare: i32,
222 qspare1: i64,
223 qspare2: i64,
224 pub fn atime(self: @This()) timespec {
225 return self.atim;
226 }
227
228 pub fn mtime(self: @This()) timespec {
229 return self.mtim;
230 }
231
232 pub fn ctime(self: @This()) timespec {
233 return self.ctim;
234 }
235};
236
237pub const timespec = extern struct {
238 tv_sec: c_long,
239 tv_nsec: c_long,
240};
241
242pub const timeval = extern struct {
243 /// seconds
244 tv_sec: time_t,
245 /// microseconds
246 tv_usec: suseconds_t,
247};
248
249pub const CTL_UNSPEC = 0;
250pub const CTL_KERN = 1;
251pub const CTL_VM = 2;
252pub const CTL_VFS = 3;
253pub const CTL_NET = 4;
254pub const CTL_DEBUG = 5;
255pub const CTL_HW = 6;
256pub const CTL_MACHDEP = 7;
257pub const CTL_USER = 8;
258pub const CTL_LWKT = 10;
259pub const CTL_MAXID = 11;
260pub const CTL_MAXNAME = 12;
261
262pub const KERN_PROC_ALL = 0;
263pub const KERN_OSTYPE = 1;
264pub const KERN_PROC_PID = 1;
265pub const KERN_OSRELEASE = 2;
266pub const KERN_PROC_PGRP = 2;
267pub const KERN_OSREV = 3;
268pub const KERN_PROC_SESSION = 3;
269pub const KERN_VERSION = 4;
270pub const KERN_PROC_TTY = 4;
271pub const KERN_MAXVNODES = 5;
272pub const KERN_PROC_UID = 5;
273pub const KERN_MAXPROC = 6;
274pub const KERN_PROC_RUID = 6;
275pub const KERN_MAXFILES = 7;
276pub const KERN_PROC_ARGS = 7;
277pub const KERN_ARGMAX = 8;
278pub const KERN_PROC_CWD = 8;
279pub const KERN_PROC_PATHNAME = 9;
280pub const KERN_SECURELVL = 9;
281pub const KERN_PROC_SIGTRAMP = 10;
282pub const KERN_HOSTNAME = 10;
283pub const KERN_HOSTID = 11;
284pub const KERN_CLOCKRATE = 12;
285pub const KERN_VNODE = 13;
286pub const KERN_PROC = 14;
287pub const KERN_FILE = 15;
288pub const KERN_PROC_FLAGMASK = 16;
289pub const KERN_PROF = 16;
290pub const KERN_PROC_FLAG_LWP = 16;
291pub const KERN_POSIX1 = 17;
292pub const KERN_NGROUPS = 18;
293pub const KERN_JOB_CONTROL = 19;
294pub const KERN_SAVED_IDS = 20;
295pub const KERN_BOOTTIME = 21;
296pub const KERN_NISDOMAINNAME = 22;
297pub const KERN_UPDATEINTERVAL = 23;
298pub const KERN_OSRELDATE = 24;
299pub const KERN_NTP_PLL = 25;
300pub const KERN_BOOTFILE = 26;
301pub const KERN_MAXFILESPERPROC = 27;
302pub const KERN_MAXPROCPERUID = 28;
303pub const KERN_DUMPDEV = 29;
304pub const KERN_IPC = 30;
305pub const KERN_DUMMY = 31;
306pub const KERN_PS_STRINGS = 32;
307pub const KERN_USRSTACK = 33;
308pub const KERN_LOGSIGEXIT = 34;
309pub const KERN_IOV_MAX = 35;
310pub const KERN_MAXPOSIXLOCKSPERUID = 36;
311pub const KERN_MAXID = 37;
312
313pub const HOST_NAME_MAX = 255;
314
315// access function
316pub const F_OK = 0; // test for existence of file
317pub const X_OK = 1; // test for execute or search permission
318pub const W_OK = 2; // test for write permission
319pub const R_OK = 4; // test for read permission
320
321pub const O_RDONLY = 0;
322pub const O_NDELAY = O_NONBLOCK;
323pub const O_WRONLY = 1;
324pub const O_RDWR = 2;
325pub const O_ACCMODE = 3;
326pub const O_NONBLOCK = 4;
327pub const O_APPEND = 8;
328pub const O_SHLOCK = 16;
329pub const O_EXLOCK = 32;
330pub const O_ASYNC = 64;
331pub const O_FSYNC = 128;
332pub const O_SYNC = 128;
333pub const O_NOFOLLOW = 256;
334pub const O_CREAT = 512;
335pub const O_TRUNC = 1024;
336pub const O_EXCL = 2048;
337pub const O_NOCTTY = 32768;
338pub const O_DIRECT = 65536;
339pub const O_CLOEXEC = 131072;
340pub const O_FBLOCKING = 262144;
341pub const O_FNONBLOCKING = 524288;
342pub const O_FAPPEND = 1048576;
343pub const O_FOFFSET = 2097152;
344pub const O_FSYNCWRITE = 4194304;
345pub const O_FASYNCWRITE = 8388608;
346pub const O_DIRECTORY = 134217728;
347
348pub const SEEK_SET = 0;
349pub const SEEK_CUR = 1;
350pub const SEEK_END = 2;
351pub const SEEK_DATA = 3;
352pub const SEEK_HOLE = 4;
353
354pub const F_ULOCK = 0;
355pub const F_LOCK = 1;
356pub const F_TLOCK = 2;
357pub const F_TEST = 3;
358
359pub const FD_CLOEXEC = 1;
360
361pub const AT_FDCWD = -328243;
362pub const AT_SYMLINK_NOFOLLOW = 1;
363pub const AT_REMOVEDIR = 2;
364pub const AT_EACCESS = 4;
365pub const AT_SYMLINK_FOLLOW = 8;
366
367pub fn WEXITSTATUS(s: u32) u8 {
368 return @intCast(u8, (s & 0xff00) >> 8);
369}
370pub fn WTERMSIG(s: u32) u32 {
371 return s & 0x7f;
372}
373pub fn WSTOPSIG(s: u32) u32 {
374 return WEXITSTATUS(s);
375}
376pub fn WIFEXITED(s: u32) bool {
377 return WTERMSIG(s) == 0;
378}
379pub fn WIFSTOPPED(s: u32) bool {
380 return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
381}
382pub fn WIFSIGNALED(s: u32) bool {
383 return (s & 0xffff) -% 1 < 0xff;
384}
385
386pub const dirent = extern struct {
387 d_fileno: c_ulong,
388 d_namlen: u16,
389 d_type: u8,
390 d_unused1: u8,
391 d_unused2: u32,
392 d_name: [256]u8,
393
394 pub fn reclen(self: dirent) u16 {
395 return (@offsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~@as(u16, 7);
396 }
397};
398
399pub const DT_UNKNOWN = 0;
400pub const DT_FIFO = 1;
401pub const DT_CHR = 2;
402pub const DT_DIR = 4;
403pub const DT_BLK = 6;
404pub const DT_REG = 8;
405pub const DT_LNK = 10;
406pub const DT_SOCK = 12;
407pub const DT_WHT = 14;
408pub const DT_DBF = 15;
409
410pub const CLOCK_REALTIME = 0;
411pub const CLOCK_VIRTUAL = 1;
412pub const CLOCK_PROF = 2;
413pub const CLOCK_MONOTONIC = 4;
414pub const CLOCK_UPTIME = 5;
415pub const CLOCK_UPTIME_PRECISE = 7;
416pub const CLOCK_UPTIME_FAST = 8;
417pub const CLOCK_REALTIME_PRECISE = 9;
418pub const CLOCK_REALTIME_FAST = 10;
419pub const CLOCK_MONOTONIC_PRECISE = 11;
420pub const CLOCK_MONOTONIC_FAST = 12;
421pub const CLOCK_SECOND = 13;
422pub const CLOCK_THREAD_CPUTIME_ID = 14;
423pub const CLOCK_PROCESS_CPUTIME_ID = 15;
424
425pub const sockaddr = extern struct {
426 len: u8,
427 family: u8,
428 data: [14]u8,
429};
430
431pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
432
433pub const Kevent = extern struct {
434 ident: usize,
435 filter: c_short,
436 flags: c_ushort,
437 fflags: c_uint,
438 data: isize,
439 udata: usize,
440};
441
442pub const EVFILT_FS = -10;
443pub const EVFILT_USER = -9;
444pub const EVFILT_EXCEPT = -8;
445pub const EVFILT_TIMER = -7;
446pub const EVFILT_SIGNAL = -6;
447pub const EVFILT_PROC = -5;
448pub const EVFILT_VNODE = -4;
449pub const EVFILT_AIO = -3;
450pub const EVFILT_WRITE = -2;
451pub const EVFILT_READ = -1;
452pub const EVFILT_SYSCOUNT = 10;
453pub const EVFILT_MARKER = 15;
454
455pub const EV_ADD = 1;
456pub const EV_DELETE = 2;
457pub const EV_ENABLE = 4;
458pub const EV_DISABLE = 8;
459pub const EV_ONESHOT = 16;
460pub const EV_CLEAR = 32;
461pub const EV_RECEIPT = 64;
462pub const EV_DISPATCH = 128;
463pub const EV_NODATA = 4096;
464pub const EV_FLAG1 = 8192;
465pub const EV_ERROR = 16384;
466pub const EV_EOF = 32768;
467pub const EV_SYSFLAGS = 61440;
468
469pub const NOTE_FFNOP = 0;
470pub const NOTE_TRACK = 1;
471pub const NOTE_DELETE = 1;
472pub const NOTE_LOWAT = 1;
473pub const NOTE_TRACKERR = 2;
474pub const NOTE_OOB = 2;
475pub const NOTE_WRITE = 2;
476pub const NOTE_EXTEND = 4;
477pub const NOTE_CHILD = 4;
478pub const NOTE_ATTRIB = 8;
479pub const NOTE_LINK = 16;
480pub const NOTE_RENAME = 32;
481pub const NOTE_REVOKE = 64;
482pub const NOTE_PDATAMASK = 1048575;
483pub const NOTE_FFLAGSMASK = 16777215;
484pub const NOTE_TRIGGER = 16777216;
485pub const NOTE_EXEC = 536870912;
486pub const NOTE_FFAND = 1073741824;
487pub const NOTE_FORK = 1073741824;
488pub const NOTE_EXIT = 2147483648;
489pub const NOTE_FFOR = 2147483648;
490pub const NOTE_FFCTRLMASK = 3221225472;
491pub const NOTE_FFCOPY = 3221225472;
492pub const NOTE_PCTRLMASK = 4026531840;
493
494pub const stack_t = extern struct {
495 ss_sp: [*]u8,
496 ss_size: isize,
497 ss_flags: i32,
498};
499
500pub const S_IREAD = S_IRUSR;
501pub const S_IEXEC = S_IXUSR;
502pub const S_IWRITE = S_IWUSR;
503pub const S_IXOTH = 1;
504pub const S_IWOTH = 2;
505pub const S_IROTH = 4;
506pub const S_IRWXO = 7;
507pub const S_IXGRP = 8;
508pub const S_IWGRP = 16;
509pub const S_IRGRP = 32;
510pub const S_IRWXG = 56;
511pub const S_IXUSR = 64;
512pub const S_IWUSR = 128;
513pub const S_IRUSR = 256;
514pub const S_IRWXU = 448;
515pub const S_ISTXT = 512;
516pub const S_BLKSIZE = 512;
517pub const S_ISVTX = 512;
518pub const S_ISGID = 1024;
519pub const S_ISUID = 2048;
520pub const S_IFIFO = 4096;
521pub const S_IFCHR = 8192;
522pub const S_IFDIR = 16384;
523pub const S_IFBLK = 24576;
524pub const S_IFREG = 32768;
525pub const S_IFDB = 36864;
526pub const S_IFLNK = 40960;
527pub const S_IFSOCK = 49152;
528pub const S_IFWHT = 57344;
529pub const S_IFMT = 61440;
530
531pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
532pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
533pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
534pub const BADSIG = SIG_ERR;
535
536pub const SIG_BLOCK = 1;
537pub const SIG_UNBLOCK = 2;
538pub const SIG_SETMASK = 3;
539
540pub const SIGIOT = SIGABRT;
541pub const SIGHUP = 1;
542pub const SIGINT = 2;
543pub const SIGQUIT = 3;
544pub const SIGILL = 4;
545pub const SIGTRAP = 5;
546pub const SIGABRT = 6;
547pub const SIGEMT = 7;
548pub const SIGFPE = 8;
549pub const SIGKILL = 9;
550pub const SIGBUS = 10;
551pub const SIGSEGV = 11;
552pub const SIGSYS = 12;
553pub const SIGPIPE = 13;
554pub const SIGALRM = 14;
555pub const SIGTERM = 15;
556pub const SIGURG = 16;
557pub const SIGSTOP = 17;
558pub const SIGTSTP = 18;
559pub const SIGCONT = 19;
560pub const SIGCHLD = 20;
561pub const SIGTTIN = 21;
562pub const SIGTTOU = 22;
563pub const SIGIO = 23;
564pub const SIGXCPU = 24;
565pub const SIGXFSZ = 25;
566pub const SIGVTALRM = 26;
567pub const SIGPROF = 27;
568pub const SIGWINCH = 28;
569pub const SIGINFO = 29;
570pub const SIGUSR1 = 30;
571pub const SIGUSR2 = 31;
572pub const SIGTHR = 32;
573pub const SIGCKPT = 33;
574pub const SIGCKPTEXIT = 34;
575
576pub const siginfo_t = extern struct {
577 signo: c_int,
578 errno: c_int,
579 code: c_int,
580 pid: c_int,
581 uid: uid_t,
582 status: c_int,
583 addr: ?*c_void,
584 value: sigval,
585 band: c_long,
586 __spare__: [7]c_int,
587};
588
589pub const sigval = extern union {
590 sival_int: c_int,
591 sival_ptr: ?*c_void,
592};
593
594pub const _SIG_WORDS = 4;
595
596pub const sigset_t = extern struct {
597 __bits: [_SIG_WORDS]c_uint,
598};
599
600pub const empty_sigset = sigset_t{ .__bits = [_]c_uint{0} ** _SIG_WORDS };
601
602pub const sig_atomic_t = c_int;
603
604pub const Sigaction = extern struct {
605 pub const handler_fn = fn (c_int) callconv(.C) void;
606 pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void;
607
608 /// signal handler
609 handler: extern union {
610 handler: ?handler_fn,
611 sigaction: ?sigaction_fn,
612 },
613 flags: c_uint,
614 mask: sigset_t,
615};
616
617pub const sig_t = [*c]fn (c_int) callconv(.C) void;
618
619pub const SOCK_STREAM = 1;
620pub const SOCK_DGRAM = 2;
621pub const SOCK_RAW = 3;
622pub const SOCK_RDM = 4;
623pub const SOCK_SEQPACKET = 5;
624pub const SOCK_MAXADDRLEN = 255;
625pub const SOCK_CLOEXEC = 0x10000000;
626pub const SOCK_NONBLOCK = 0x20000000;
627
628pub const SO_DEBUG = 0x0001;
629pub const SO_ACCEPTCONN = 0x0002;
630pub const SO_REUSEADDR = 0x0004;
631pub const SO_KEEPALIVE = 0x0008;
632pub const SO_DONTROUTE = 0x0010;
633pub const SO_BROADCAST = 0x0020;
634pub const SO_USELOOPBACK = 0x0040;
635pub const SO_LINGER = 0x0080;
636pub const SO_OOBINLINE = 0x0100;
637pub const SO_REUSEPORT = 0x0200;
638pub const SO_TIMESTAMP = 0x0400;
639pub const SO_NOSIGPIPE = 0x0800;
640pub const SO_ACCEPTFILTER = 0x1000;
641pub const SO_RERROR = 0x2000;
642pub const SO_PASSCRED = 0x4000;
643
644pub const SO_SNDBUF = 0x1001;
645pub const SO_RCVBUF = 0x1002;
646pub const SO_SNDLOWAT = 0x1003;
647pub const SO_RCVLOWAT = 0x1004;
648pub const SO_SNDTIMEO = 0x1005;
649pub const SO_RCVTIMEO = 0x1006;
650pub const SO_ERROR = 0x1007;
651pub const SO_TYPE = 0x1008;
652pub const SO_SNDSPACE = 0x100a;
653pub const SO_CPUHINT = 0x1030;
654
655pub const SOL_SOCKET = 0xffff;
656
657pub const PF_INET6 = AF_INET6;
658pub const PF_IMPLINK = AF_IMPLINK;
659pub const PF_ROUTE = AF_ROUTE;
660pub const PF_ISO = AF_ISO;
661pub const PF_PIP = pseudo_AF_PIP;
662pub const PF_CHAOS = AF_CHAOS;
663pub const PF_DATAKIT = AF_DATAKIT;
664pub const PF_INET = AF_INET;
665pub const PF_APPLETALK = AF_APPLETALK;
666pub const PF_SIP = AF_SIP;
667pub const PF_OSI = AF_ISO;
668pub const PF_CNT = AF_CNT;
669pub const PF_LINK = AF_LINK;
670pub const PF_HYLINK = AF_HYLINK;
671pub const PF_MAX = AF_MAX;
672pub const PF_KEY = pseudo_AF_KEY;
673pub const PF_PUP = AF_PUP;
674pub const PF_COIP = AF_COIP;
675pub const PF_SNA = AF_SNA;
676pub const PF_LOCAL = AF_LOCAL;
677pub const PF_NETBIOS = AF_NETBIOS;
678pub const PF_NATM = AF_NATM;
679pub const PF_BLUETOOTH = AF_BLUETOOTH;
680pub const PF_UNSPEC = AF_UNSPEC;
681pub const PF_NETGRAPH = AF_NETGRAPH;
682pub const PF_ECMA = AF_ECMA;
683pub const PF_IPX = AF_IPX;
684pub const PF_DLI = AF_DLI;
685pub const PF_ATM = AF_ATM;
686pub const PF_CCITT = AF_CCITT;
687pub const PF_ISDN = AF_ISDN;
688pub const PF_RTIP = pseudo_AF_RTIP;
689pub const PF_LAT = AF_LAT;
690pub const PF_UNIX = PF_LOCAL;
691pub const PF_XTP = pseudo_AF_XTP;
692pub const PF_DECnet = AF_DECnet;
693
694pub const AF_UNSPEC = 0;
695pub const AF_OSI = AF_ISO;
696pub const AF_UNIX = AF_LOCAL;
697pub const AF_LOCAL = 1;
698pub const AF_INET = 2;
699pub const AF_IMPLINK = 3;
700pub const AF_PUP = 4;
701pub const AF_CHAOS = 5;
702pub const AF_NETBIOS = 6;
703pub const AF_ISO = 7;
704pub const AF_ECMA = 8;
705pub const AF_DATAKIT = 9;
706pub const AF_CCITT = 10;
707pub const AF_SNA = 11;
708pub const AF_DLI = 13;
709pub const AF_LAT = 14;
710pub const AF_HYLINK = 15;
711pub const AF_APPLETALK = 16;
712pub const AF_ROUTE = 17;
713pub const AF_LINK = 18;
714pub const AF_COIP = 20;
715pub const AF_CNT = 21;
716pub const AF_IPX = 23;
717pub const AF_SIP = 24;
718pub const AF_ISDN = 26;
719pub const AF_INET6 = 28;
720pub const AF_NATM = 29;
721pub const AF_ATM = 30;
722pub const AF_NETGRAPH = 32;
723pub const AF_BLUETOOTH = 33;
724pub const AF_MPLS = 34;
725pub const AF_MAX = 36;
726
727pub const in_port_t = u16;
728pub const sa_family_t = u8;
729pub const socklen_t = u32;
730
731pub const sockaddr_in = extern struct {
732 len: u8 = @sizeOf(sockaddr_in),
733 family: sa_family_t = AF_INET,
734 port: in_port_t,
735 addr: u32,
736 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
737};
738
739pub const sockaddr_in6 = extern struct {
740 len: u8 = @sizeOf(sockaddr_in6),
741 family: sa_family_t = AF_INET6,
742 port: in_port_t,
743 flowinfo: u32,
744 addr: [16]u8,
745 scope_id: u32,
746};
747
748pub const EAI = enum(c_int) {
749 ADDRFAMILY = 1,
750 AGAIN = 2,
751 BADFLAGS = 3,
752 FAIL = 4,
753 FAMILY = 5,
754 MEMORY = 6,
755 NODATA = 7,
756 NONAME = 8,
757 SERVICE = 9,
758 SOCKTYPE = 10,
759 SYSTEM = 11,
760 BADHINTS = 12,
761 PROTOCOL = 13,
762 OVERFLOW = 14,
763 _,
764};
765
766pub const AI_PASSIVE = 0x00000001;
767pub const AI_CANONNAME = 0x00000002;
768pub const AI_NUMERICHOST = 0x00000004;
769pub const AI_NUMERICSERV = 0x00000008;
770pub const AI_MASK = AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | AI_ADDRCONFIG;
771pub const AI_ALL = 0x00000100;
772pub const AI_V4MAPPED_CFG = 0x00000200;
773pub const AI_ADDRCONFIG = 0x00000400;
774pub const AI_V4MAPPED = 0x00000800;
775pub const AI_DEFAULT = AI_V4MAPPED_CFG | AI_ADDRCONFIG;
776
777pub const RTLD_LAZY = 1;
778pub const RTLD_NOW = 2;
779pub const RTLD_MODEMASK = 0x3;
780pub const RTLD_GLOBAL = 0x100;
781pub const RTLD_LOCAL = 0;
782pub const RTLD_TRACE = 0x200;
783pub const RTLD_NODELETE = 0x01000;
784pub const RTLD_NOLOAD = 0x02000;
785
786pub const RTLD_NEXT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -1)));
787pub const RTLD_DEFAULT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -2)));
788pub const RTLD_SELF = @intToPtr(*c_void, @bitCast(usize, @as(isize, -3)));
789pub const RTLD_ALL = @intToPtr(*c_void, @bitCast(usize, @as(isize, -4)));
790
791pub const dl_phdr_info = extern struct {
792 dlpi_addr: usize,
793 dlpi_name: ?[*:0]const u8,
794 dlpi_phdr: [*]std.elf.Phdr,
795 dlpi_phnum: u16,
796};
797pub const cmsghdr = extern struct {
798 cmsg_len: socklen_t,
799 cmsg_level: c_int,
800 cmsg_type: c_int,
801};
802pub const msghdr = extern struct {
803 msg_name: ?*c_void,
804 msg_namelen: socklen_t,
805 msg_iov: [*c]iovec,
806 msg_iovlen: c_int,
807 msg_control: ?*c_void,
808 msg_controllen: socklen_t,
809 msg_flags: c_int,
810};
811pub const cmsgcred = extern struct {
812 cmcred_pid: pid_t,
813 cmcred_uid: uid_t,
814 cmcred_euid: uid_t,
815 cmcred_gid: gid_t,
816 cmcred_ngroups: c_short,
817 cmcred_groups: [16]gid_t,
818};
819pub const sf_hdtr = extern struct {
820 headers: [*c]iovec,
821 hdr_cnt: c_int,
822 trailers: [*c]iovec,
823 trl_cnt: c_int,
824};
825
826pub const MS_SYNC = 0;
827pub const MS_ASYNC = 1;
828pub const MS_INVALIDATE = 2;
829
830pub const POSIX_MADV_SEQUENTIAL = 2;
831pub const POSIX_MADV_RANDOM = 1;
832pub const POSIX_MADV_DONTNEED = 4;
833pub const POSIX_MADV_NORMAL = 0;
834pub const POSIX_MADV_WILLNEED = 3;
835
836pub const MADV_SEQUENTIAL = 2;
837pub const MADV_CONTROL_END = MADV_SETMAP;
838pub const MADV_DONTNEED = 4;
839pub const MADV_RANDOM = 1;
840pub const MADV_WILLNEED = 3;
841pub const MADV_NORMAL = 0;
842pub const MADV_CONTROL_START = MADV_INVAL;
843pub const MADV_FREE = 5;
844pub const MADV_NOSYNC = 6;
845pub const MADV_AUTOSYNC = 7;
846pub const MADV_NOCORE = 8;
847pub const MADV_CORE = 9;
848pub const MADV_INVAL = 10;
849pub const MADV_SETMAP = 11;
850
851pub const F_DUPFD = 0;
852pub const F_GETFD = 1;
853pub const F_RDLCK = 1;
854pub const F_SETFD = 2;
855pub const F_UNLCK = 2;
856pub const F_WRLCK = 3;
857pub const F_GETFL = 3;
858pub const F_SETFL = 4;
859pub const F_GETOWN = 5;
860pub const F_SETOWN = 6;
861pub const F_GETLK = 7;
862pub const F_SETLK = 8;
863pub const F_SETLKW = 9;
864pub const F_DUP2FD = 10;
865pub const F_DUPFD_CLOEXEC = 17;
866pub const F_DUP2FD_CLOEXEC = 18;
867
868pub const LOCK_SH = 1;
869pub const LOCK_EX = 2;
870pub const LOCK_UN = 8;
871pub const LOCK_NB = 4;
872
873pub const Flock = extern struct {
874 l_start: off_t,
875 l_len: off_t,
876 l_pid: pid_t,
877 l_type: c_short,
878 l_whence: c_short,
879};
880
881pub const addrinfo = extern struct {
882 flags: i32,
883 family: i32,
884 socktype: i32,
885 protocol: i32,
886 addrlen: socklen_t,
887 canonname: ?[*:0]u8,
888 addr: ?*sockaddr,
889 next: ?*addrinfo,
890};
891
892pub const IPPROTO_IP = 0;
893pub const IPPROTO_ICMP = 1;
894pub const IPPROTO_TCP = 6;
895pub const IPPROTO_UDP = 17;
896pub const IPPROTO_IPV6 = 41;
897pub const IPPROTO_RAW = 255;
898pub const IPPROTO_HOPOPTS = 0;
899pub const IPPROTO_IGMP = 2;
900pub const IPPROTO_GGP = 3;
901pub const IPPROTO_IPV4 = 4;
902pub const IPPROTO_IPIP = IPPROTO_IPV4;
903pub const IPPROTO_ST = 7;
904pub const IPPROTO_EGP = 8;
905pub const IPPROTO_PIGP = 9;
906pub const IPPROTO_RCCMON = 10;
907pub const IPPROTO_NVPII = 11;
908pub const IPPROTO_PUP = 12;
909pub const IPPROTO_ARGUS = 13;
910pub const IPPROTO_EMCON = 14;
911pub const IPPROTO_XNET = 15;
912pub const IPPROTO_CHAOS = 16;
913pub const IPPROTO_MUX = 18;
914pub const IPPROTO_MEAS = 19;
915pub const IPPROTO_HMP = 20;
916pub const IPPROTO_PRM = 21;
917pub const IPPROTO_IDP = 22;
918pub const IPPROTO_TRUNK1 = 23;
919pub const IPPROTO_TRUNK2 = 24;
920pub const IPPROTO_LEAF1 = 25;
921pub const IPPROTO_LEAF2 = 26;
922pub const IPPROTO_RDP = 27;
923pub const IPPROTO_IRTP = 28;
924pub const IPPROTO_TP = 29;
925pub const IPPROTO_BLT = 30;
926pub const IPPROTO_NSP = 31;
927pub const IPPROTO_INP = 32;
928pub const IPPROTO_SEP = 33;
929pub const IPPROTO_3PC = 34;
930pub const IPPROTO_IDPR = 35;
931pub const IPPROTO_XTP = 36;
932pub const IPPROTO_DDP = 37;
933pub const IPPROTO_CMTP = 38;
934pub const IPPROTO_TPXX = 39;
935pub const IPPROTO_IL = 40;
936pub const IPPROTO_SDRP = 42;
937pub const IPPROTO_ROUTING = 43;
938pub const IPPROTO_FRAGMENT = 44;
939pub const IPPROTO_IDRP = 45;
940pub const IPPROTO_RSVP = 46;
941pub const IPPROTO_GRE = 47;
942pub const IPPROTO_MHRP = 48;
943pub const IPPROTO_BHA = 49;
944pub const IPPROTO_ESP = 50;
945pub const IPPROTO_AH = 51;
946pub const IPPROTO_INLSP = 52;
947pub const IPPROTO_SWIPE = 53;
948pub const IPPROTO_NHRP = 54;
949pub const IPPROTO_MOBILE = 55;
950pub const IPPROTO_TLSP = 56;
951pub const IPPROTO_SKIP = 57;
952pub const IPPROTO_ICMPV6 = 58;
953pub const IPPROTO_NONE = 59;
954pub const IPPROTO_DSTOPTS = 60;
955pub const IPPROTO_AHIP = 61;
956pub const IPPROTO_CFTP = 62;
957pub const IPPROTO_HELLO = 63;
958pub const IPPROTO_SATEXPAK = 64;
959pub const IPPROTO_KRYPTOLAN = 65;
960pub const IPPROTO_RVD = 66;
961pub const IPPROTO_IPPC = 67;
962pub const IPPROTO_ADFS = 68;
963pub const IPPROTO_SATMON = 69;
964pub const IPPROTO_VISA = 70;
965pub const IPPROTO_IPCV = 71;
966pub const IPPROTO_CPNX = 72;
967pub const IPPROTO_CPHB = 73;
968pub const IPPROTO_WSN = 74;
969pub const IPPROTO_PVP = 75;
970pub const IPPROTO_BRSATMON = 76;
971pub const IPPROTO_ND = 77;
972pub const IPPROTO_WBMON = 78;
973pub const IPPROTO_WBEXPAK = 79;
974pub const IPPROTO_EON = 80;
975pub const IPPROTO_VMTP = 81;
976pub const IPPROTO_SVMTP = 82;
977pub const IPPROTO_VINES = 83;
978pub const IPPROTO_TTP = 84;
979pub const IPPROTO_IGP = 85;
980pub const IPPROTO_DGP = 86;
981pub const IPPROTO_TCF = 87;
982pub const IPPROTO_IGRP = 88;
983pub const IPPROTO_OSPFIGP = 89;
984pub const IPPROTO_SRPC = 90;
985pub const IPPROTO_LARP = 91;
986pub const IPPROTO_MTP = 92;
987pub const IPPROTO_AX25 = 93;
988pub const IPPROTO_IPEIP = 94;
989pub const IPPROTO_MICP = 95;
990pub const IPPROTO_SCCSP = 96;
991pub const IPPROTO_ETHERIP = 97;
992pub const IPPROTO_ENCAP = 98;
993pub const IPPROTO_APES = 99;
994pub const IPPROTO_GMTP = 100;
995pub const IPPROTO_IPCOMP = 108;
996pub const IPPROTO_PIM = 103;
997pub const IPPROTO_CARP = 112;
998pub const IPPROTO_PGM = 113;
999pub const IPPROTO_PFSYNC = 240;
1000pub const IPPROTO_DIVERT = 254;
1001pub const IPPROTO_MAX = 256;
1002pub const IPPROTO_DONE = 257;
1003pub const IPPROTO_UNKNOWN = 258;
1004
1005pub const rlimit_resource = enum(c_int) {
1006 CPU = 0,
1007 FSIZE = 1,
1008 DATA = 2,
1009 STACK = 3,
1010 CORE = 4,
1011 RSS = 5,
1012 MEMLOCK = 6,
1013 NPROC = 7,
1014 NOFILE = 8,
1015 SBSIZE = 9,
1016 VMEM = 10,
1017 POSIXLOCKS = 11,
1018 _,
1019
1020 pub const AS: rlimit_resource = .VMEM;
1021};
1022
1023pub const rlim_t = i64;
1024
1025/// No limit
1026pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
1027
1028pub const RLIM_SAVED_MAX = RLIM_INFINITY;
1029pub const RLIM_SAVED_CUR = RLIM_INFINITY;
1030
1031pub const rlimit = extern struct {
1032 /// Soft limit
1033 cur: rlim_t,
1034 /// Hard limit
1035 max: rlim_t,
1036};
1037
1038pub const SHUT_RD = 0;
1039pub const SHUT_WR = 1;
1040pub const SHUT_RDWR = 2;
1041
1042pub const nfds_t = u32;
1043
1044pub const pollfd = extern struct {
1045 fd: fd_t,
1046 events: i16,
1047 revents: i16,
1048};
1049
1050/// Requestable events.
1051pub const POLLIN = 0x0001;
1052pub const POLLPRI = 0x0002;
1053pub const POLLOUT = 0x0004;
1054pub const POLLRDNORM = 0x0040;
1055pub const POLLWRNORM = POLLOUT;
1056pub const POLLRDBAND = 0x0080;
1057pub const POLLWRBAND = 0x0100;
1058
1059/// These events are set if they occur regardless of whether they were requested.
1060pub const POLLERR = 0x0008;
1061pub const POLLHUP = 0x0010;
1062pub const POLLNVAL = 0x0020;
lib/std/c/freebsd.zig+1538-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2usingnamespace std.c;2const maxInt = std.math.maxInt;
33
4extern "c" fn __error() *c_int;4extern "c" fn __error() *c_int;
5pub const _errno = __error;5pub const _errno = __error;
...@@ -136,3 +136,1540 @@ pub const AI_V4MAPPED = 0x00000800;...@@ -136,3 +136,1540 @@ pub const AI_V4MAPPED = 0x00000800;
136136
137/// special recommended flags for getipnodebyname137/// special recommended flags for getipnodebyname
138pub const AI_DEFAULT = (AI_V4MAPPED_CFG | AI_ADDRCONFIG);138pub const AI_DEFAULT = (AI_V4MAPPED_CFG | AI_ADDRCONFIG);
139
140pub const blksize_t = i32;
141pub const blkcnt_t = i64;
142pub const clockid_t = i32;
143pub const fsblkcnt_t = u64;
144pub const fsfilcnt_t = u64;
145pub const nlink_t = u64;
146pub const fd_t = i32;
147pub const pid_t = i32;
148pub const uid_t = u32;
149pub const gid_t = u32;
150pub const mode_t = u16;
151pub const off_t = i64;
152pub const ino_t = u64;
153pub const dev_t = u64;
154pub const time_t = i64;
155// The signedness is not constant across different architectures.
156pub const clock_t = isize;
157
158pub const socklen_t = u32;
159pub const suseconds_t = c_long;
160
161/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
162pub const Kevent = extern struct {
163 ident: usize,
164 filter: i16,
165 flags: u16,
166 fflags: u32,
167 data: i64,
168 udata: usize,
169 // TODO ext
170};
171
172// Modes and flags for dlopen()
173// include/dlfcn.h
174
175/// Bind function calls lazily.
176pub const RTLD_LAZY = 1;
177
178/// Bind function calls immediately.
179pub const RTLD_NOW = 2;
180
181pub const RTLD_MODEMASK = 0x3;
182
183/// Make symbols globally available.
184pub const RTLD_GLOBAL = 0x100;
185
186/// Opposite of RTLD_GLOBAL, and the default.
187pub const RTLD_LOCAL = 0;
188
189/// Trace loaded objects and exit.
190pub const RTLD_TRACE = 0x200;
191
192/// Do not remove members.
193pub const RTLD_NODELETE = 0x01000;
194
195/// Do not load if not already loaded.
196pub const RTLD_NOLOAD = 0x02000;
197
198pub const dl_phdr_info = extern struct {
199 dlpi_addr: usize,
200 dlpi_name: ?[*:0]const u8,
201 dlpi_phdr: [*]std.elf.Phdr,
202 dlpi_phnum: u16,
203};
204
205pub const Flock = extern struct {
206 l_start: off_t,
207 l_len: off_t,
208 l_pid: pid_t,
209 l_type: i16,
210 l_whence: i16,
211 l_sysid: i32,
212 __unused: [4]u8,
213};
214
215pub const msghdr = extern struct {
216 /// optional address
217 msg_name: ?*sockaddr,
218
219 /// size of address
220 msg_namelen: socklen_t,
221
222 /// scatter/gather array
223 msg_iov: [*]iovec,
224
225 /// # elements in msg_iov
226 msg_iovlen: i32,
227
228 /// ancillary data
229 msg_control: ?*c_void,
230
231 /// ancillary data buffer len
232 msg_controllen: socklen_t,
233
234 /// flags on received message
235 msg_flags: i32,
236};
237
238pub const msghdr_const = extern struct {
239 /// optional address
240 msg_name: ?*const sockaddr,
241
242 /// size of address
243 msg_namelen: socklen_t,
244
245 /// scatter/gather array
246 msg_iov: [*]iovec_const,
247
248 /// # elements in msg_iov
249 msg_iovlen: i32,
250
251 /// ancillary data
252 msg_control: ?*c_void,
253
254 /// ancillary data buffer len
255 msg_controllen: socklen_t,
256
257 /// flags on received message
258 msg_flags: i32,
259};
260
261pub const Stat = extern struct {
262 dev: dev_t,
263 ino: ino_t,
264 nlink: nlink_t,
265
266 mode: mode_t,
267 __pad0: u16,
268 uid: uid_t,
269 gid: gid_t,
270 __pad1: u32,
271 rdev: dev_t,
272
273 atim: timespec,
274 mtim: timespec,
275 ctim: timespec,
276 birthtim: timespec,
277
278 size: off_t,
279 blocks: i64,
280 blksize: isize,
281 flags: u32,
282 gen: u64,
283 __spare: [10]u64,
284
285 pub fn atime(self: @This()) timespec {
286 return self.atim;
287 }
288
289 pub fn mtime(self: @This()) timespec {
290 return self.mtim;
291 }
292
293 pub fn ctime(self: @This()) timespec {
294 return self.ctim;
295 }
296};
297
298pub const timespec = extern struct {
299 tv_sec: isize,
300 tv_nsec: isize,
301};
302
303pub const timeval = extern struct {
304 /// seconds
305 tv_sec: time_t,
306 /// microseconds
307 tv_usec: suseconds_t,
308};
309
310pub const dirent = extern struct {
311 d_fileno: usize,
312 d_off: i64,
313 d_reclen: u16,
314 d_type: u8,
315 d_pad0: u8,
316 d_namlen: u16,
317 d_pad1: u16,
318 d_name: [256]u8,
319
320 pub fn reclen(self: dirent) u16 {
321 return self.d_reclen;
322 }
323};
324
325pub const in_port_t = u16;
326pub const sa_family_t = u8;
327
328pub const sockaddr = extern struct {
329 /// total length
330 len: u8,
331
332 /// address family
333 family: sa_family_t,
334
335 /// actually longer; address value
336 data: [14]u8,
337};
338
339pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
340
341pub const sockaddr_in = extern struct {
342 len: u8 = @sizeOf(sockaddr_in),
343 family: sa_family_t = AF_INET,
344 port: in_port_t,
345 addr: u32,
346 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
347};
348
349pub const sockaddr_in6 = extern struct {
350 len: u8 = @sizeOf(sockaddr_in6),
351 family: sa_family_t = AF_INET6,
352 port: in_port_t,
353 flowinfo: u32,
354 addr: [16]u8,
355 scope_id: u32,
356};
357
358pub const sockaddr_un = extern struct {
359 len: u8 = @sizeOf(sockaddr_un),
360 family: sa_family_t = AF_UNIX,
361 path: [104]u8,
362};
363
364pub const CTL_KERN = 1;
365pub const CTL_DEBUG = 5;
366
367pub const KERN_PROC = 14; // struct: process entries
368pub const KERN_PROC_PATHNAME = 12; // path to executable
369pub const KERN_IOV_MAX = 35;
370
371pub const PATH_MAX = 1024;
372pub const IOV_MAX = KERN_IOV_MAX;
373
374pub const STDIN_FILENO = 0;
375pub const STDOUT_FILENO = 1;
376pub const STDERR_FILENO = 2;
377
378pub const PROT_NONE = 0;
379pub const PROT_READ = 1;
380pub const PROT_WRITE = 2;
381pub const PROT_EXEC = 4;
382
383pub const CLOCK_REALTIME = 0;
384pub const CLOCK_VIRTUAL = 1;
385pub const CLOCK_PROF = 2;
386pub const CLOCK_MONOTONIC = 4;
387pub const CLOCK_UPTIME = 5;
388pub const CLOCK_UPTIME_PRECISE = 7;
389pub const CLOCK_UPTIME_FAST = 8;
390pub const CLOCK_REALTIME_PRECISE = 9;
391pub const CLOCK_REALTIME_FAST = 10;
392pub const CLOCK_MONOTONIC_PRECISE = 11;
393pub const CLOCK_MONOTONIC_FAST = 12;
394pub const CLOCK_SECOND = 13;
395pub const CLOCK_THREAD_CPUTIME_ID = 14;
396pub const CLOCK_PROCESS_CPUTIME_ID = 15;
397
398pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
399pub const MAP_SHARED = 0x0001;
400pub const MAP_PRIVATE = 0x0002;
401pub const MAP_FIXED = 0x0010;
402pub const MAP_STACK = 0x0400;
403pub const MAP_NOSYNC = 0x0800;
404pub const MAP_ANON = 0x1000;
405pub const MAP_ANONYMOUS = MAP_ANON;
406pub const MAP_FILE = 0;
407
408pub const MAP_GUARD = 0x00002000;
409pub const MAP_EXCL = 0x00004000;
410pub const MAP_NOCORE = 0x00020000;
411pub const MAP_PREFAULT_READ = 0x00040000;
412pub const MAP_32BIT = 0x00080000;
413
414pub const WNOHANG = 1;
415pub const WUNTRACED = 2;
416pub const WSTOPPED = WUNTRACED;
417pub const WCONTINUED = 4;
418pub const WNOWAIT = 8;
419pub const WEXITED = 16;
420pub const WTRAPPED = 32;
421
422pub const SA_ONSTACK = 0x0001;
423pub const SA_RESTART = 0x0002;
424pub const SA_RESETHAND = 0x0004;
425pub const SA_NOCLDSTOP = 0x0008;
426pub const SA_NODEFER = 0x0010;
427pub const SA_NOCLDWAIT = 0x0020;
428pub const SA_SIGINFO = 0x0040;
429
430pub const SIGHUP = 1;
431pub const SIGINT = 2;
432pub const SIGQUIT = 3;
433pub const SIGILL = 4;
434pub const SIGTRAP = 5;
435pub const SIGABRT = 6;
436pub const SIGIOT = SIGABRT;
437pub const SIGEMT = 7;
438pub const SIGFPE = 8;
439pub const SIGKILL = 9;
440pub const SIGBUS = 10;
441pub const SIGSEGV = 11;
442pub const SIGSYS = 12;
443pub const SIGPIPE = 13;
444pub const SIGALRM = 14;
445pub const SIGTERM = 15;
446pub const SIGURG = 16;
447pub const SIGSTOP = 17;
448pub const SIGTSTP = 18;
449pub const SIGCONT = 19;
450pub const SIGCHLD = 20;
451pub const SIGTTIN = 21;
452pub const SIGTTOU = 22;
453pub const SIGIO = 23;
454pub const SIGXCPU = 24;
455pub const SIGXFSZ = 25;
456pub const SIGVTALRM = 26;
457pub const SIGPROF = 27;
458pub const SIGWINCH = 28;
459pub const SIGINFO = 29;
460pub const SIGUSR1 = 30;
461pub const SIGUSR2 = 31;
462pub const SIGTHR = 32;
463pub const SIGLWP = SIGTHR;
464pub const SIGLIBRT = 33;
465
466pub const SIGRTMIN = 65;
467pub const SIGRTMAX = 126;
468
469// access function
470pub const F_OK = 0; // test for existence of file
471pub const X_OK = 1; // test for execute or search permission
472pub const W_OK = 2; // test for write permission
473pub const R_OK = 4; // test for read permission
474
475pub const O_RDONLY = 0x0000;
476pub const O_WRONLY = 0x0001;
477pub const O_RDWR = 0x0002;
478pub const O_ACCMODE = 0x0003;
479
480pub const O_SHLOCK = 0x0010;
481pub const O_EXLOCK = 0x0020;
482
483pub const O_CREAT = 0x0200;
484pub const O_EXCL = 0x0800;
485pub const O_NOCTTY = 0x8000;
486pub const O_TRUNC = 0x0400;
487pub const O_APPEND = 0x0008;
488pub const O_NONBLOCK = 0x0004;
489pub const O_DSYNC = 0o10000;
490pub const O_SYNC = 0x0080;
491pub const O_RSYNC = 0o4010000;
492pub const O_DIRECTORY = 0x20000;
493pub const O_NOFOLLOW = 0x0100;
494pub const O_CLOEXEC = 0x00100000;
495
496pub const O_ASYNC = 0x0040;
497pub const O_DIRECT = 0x00010000;
498pub const O_NOATIME = 0o1000000;
499pub const O_PATH = 0o10000000;
500pub const O_TMPFILE = 0o20200000;
501pub const O_NDELAY = O_NONBLOCK;
502
503pub const F_DUPFD = 0;
504pub const F_GETFD = 1;
505pub const F_SETFD = 2;
506pub const F_GETFL = 3;
507pub const F_SETFL = 4;
508
509pub const F_GETOWN = 5;
510pub const F_SETOWN = 6;
511
512pub const F_GETLK = 11;
513pub const F_SETLK = 12;
514pub const F_SETLKW = 13;
515
516pub const F_RDLCK = 1;
517pub const F_WRLCK = 3;
518pub const F_UNLCK = 2;
519
520pub const LOCK_SH = 1;
521pub const LOCK_EX = 2;
522pub const LOCK_UN = 8;
523pub const LOCK_NB = 4;
524
525pub const F_SETOWN_EX = 15;
526pub const F_GETOWN_EX = 16;
527
528pub const F_GETOWNER_UIDS = 17;
529
530pub const FD_CLOEXEC = 1;
531
532pub const SEEK_SET = 0;
533pub const SEEK_CUR = 1;
534pub const SEEK_END = 2;
535
536pub const SIG_BLOCK = 1;
537pub const SIG_UNBLOCK = 2;
538pub const SIG_SETMASK = 3;
539
540pub const SOCK_STREAM = 1;
541pub const SOCK_DGRAM = 2;
542pub const SOCK_RAW = 3;
543pub const SOCK_RDM = 4;
544pub const SOCK_SEQPACKET = 5;
545
546pub const SOCK_CLOEXEC = 0x10000000;
547pub const SOCK_NONBLOCK = 0x20000000;
548
549pub const SO_DEBUG = 0x00000001;
550pub const SO_ACCEPTCONN = 0x00000002;
551pub const SO_REUSEADDR = 0x00000004;
552pub const SO_KEEPALIVE = 0x00000008;
553pub const SO_DONTROUTE = 0x00000010;
554pub const SO_BROADCAST = 0x00000020;
555pub const SO_USELOOPBACK = 0x00000040;
556pub const SO_LINGER = 0x00000080;
557pub const SO_OOBINLINE = 0x00000100;
558pub const SO_REUSEPORT = 0x00000200;
559pub const SO_TIMESTAMP = 0x00000400;
560pub const SO_NOSIGPIPE = 0x00000800;
561pub const SO_ACCEPTFILTER = 0x00001000;
562pub const SO_BINTIME = 0x00002000;
563pub const SO_NO_OFFLOAD = 0x00004000;
564pub const SO_NO_DDP = 0x00008000;
565pub const SO_REUSEPORT_LB = 0x00010000;
566
567pub const SO_SNDBUF = 0x1001;
568pub const SO_RCVBUF = 0x1002;
569pub const SO_SNDLOWAT = 0x1003;
570pub const SO_RCVLOWAT = 0x1004;
571pub const SO_SNDTIMEO = 0x1005;
572pub const SO_RCVTIMEO = 0x1006;
573pub const SO_ERROR = 0x1007;
574pub const SO_TYPE = 0x1008;
575pub const SO_LABEL = 0x1009;
576pub const SO_PEERLABEL = 0x1010;
577pub const SO_LISTENQLIMIT = 0x1011;
578pub const SO_LISTENQLEN = 0x1012;
579pub const SO_LISTENINCQLEN = 0x1013;
580pub const SO_SETFIB = 0x1014;
581pub const SO_USER_COOKIE = 0x1015;
582pub const SO_PROTOCOL = 0x1016;
583pub const SO_PROTOTYPE = SO_PROTOCOL;
584pub const SO_TS_CLOCK = 0x1017;
585pub const SO_MAX_PACING_RATE = 0x1018;
586pub const SO_DOMAIN = 0x1019;
587
588pub const SOL_SOCKET = 0xffff;
589
590pub const PF_UNSPEC = AF_UNSPEC;
591pub const PF_LOCAL = AF_LOCAL;
592pub const PF_UNIX = PF_LOCAL;
593pub const PF_INET = AF_INET;
594pub const PF_IMPLINK = AF_IMPLINK;
595pub const PF_PUP = AF_PUP;
596pub const PF_CHAOS = AF_CHAOS;
597pub const PF_NETBIOS = AF_NETBIOS;
598pub const PF_ISO = AF_ISO;
599pub const PF_OSI = AF_ISO;
600pub const PF_ECMA = AF_ECMA;
601pub const PF_DATAKIT = AF_DATAKIT;
602pub const PF_CCITT = AF_CCITT;
603pub const PF_DECnet = AF_DECnet;
604pub const PF_DLI = AF_DLI;
605pub const PF_LAT = AF_LAT;
606pub const PF_HYLINK = AF_HYLINK;
607pub const PF_APPLETALK = AF_APPLETALK;
608pub const PF_ROUTE = AF_ROUTE;
609pub const PF_LINK = AF_LINK;
610pub const PF_XTP = pseudo_AF_XTP;
611pub const PF_COIP = AF_COIP;
612pub const PF_CNT = AF_CNT;
613pub const PF_SIP = AF_SIP;
614pub const PF_IPX = AF_IPX;
615pub const PF_RTIP = pseudo_AF_RTIP;
616pub const PF_PIP = psuedo_AF_PIP;
617pub const PF_ISDN = AF_ISDN;
618pub const PF_KEY = pseudo_AF_KEY;
619pub const PF_INET6 = pseudo_AF_INET6;
620pub const PF_NATM = AF_NATM;
621pub const PF_ATM = AF_ATM;
622pub const PF_NETGRAPH = AF_NETGRAPH;
623pub const PF_SLOW = AF_SLOW;
624pub const PF_SCLUSTER = AF_SCLUSTER;
625pub const PF_ARP = AF_ARP;
626pub const PF_BLUETOOTH = AF_BLUETOOTH;
627pub const PF_IEEE80211 = AF_IEEE80211;
628pub const PF_INET_SDP = AF_INET_SDP;
629pub const PF_INET6_SDP = AF_INET6_SDP;
630pub const PF_MAX = AF_MAX;
631
632pub const AF_UNSPEC = 0;
633pub const AF_UNIX = 1;
634pub const AF_LOCAL = AF_UNIX;
635pub const AF_FILE = AF_LOCAL;
636pub const AF_INET = 2;
637pub const AF_IMPLINK = 3;
638pub const AF_PUP = 4;
639pub const AF_CHAOS = 5;
640pub const AF_NETBIOS = 6;
641pub const AF_ISO = 7;
642pub const AF_OSI = AF_ISO;
643pub const AF_ECMA = 8;
644pub const AF_DATAKIT = 9;
645pub const AF_CCITT = 10;
646pub const AF_SNA = 11;
647pub const AF_DECnet = 12;
648pub const AF_DLI = 13;
649pub const AF_LAT = 14;
650pub const AF_HYLINK = 15;
651pub const AF_APPLETALK = 16;
652pub const AF_ROUTE = 17;
653pub const AF_LINK = 18;
654pub const pseudo_AF_XTP = 19;
655pub const AF_COIP = 20;
656pub const AF_CNT = 21;
657pub const pseudo_AF_RTIP = 22;
658pub const AF_IPX = 23;
659pub const AF_SIP = 24;
660pub const pseudo_AF_PIP = 25;
661pub const AF_ISDN = 26;
662pub const AF_E164 = AF_ISDN;
663pub const pseudo_AF_KEY = 27;
664pub const AF_INET6 = 28;
665pub const AF_NATM = 29;
666pub const AF_ATM = 30;
667pub const pseudo_AF_HDRCMPLT = 31;
668pub const AF_NETGRAPH = 32;
669pub const AF_SLOW = 33;
670pub const AF_SCLUSTER = 34;
671pub const AF_ARP = 35;
672pub const AF_BLUETOOTH = 36;
673pub const AF_IEEE80211 = 37;
674pub const AF_INET_SDP = 40;
675pub const AF_INET6_SDP = 42;
676pub const AF_MAX = 42;
677
678pub const DT_UNKNOWN = 0;
679pub const DT_FIFO = 1;
680pub const DT_CHR = 2;
681pub const DT_DIR = 4;
682pub const DT_BLK = 6;
683pub const DT_REG = 8;
684pub const DT_LNK = 10;
685pub const DT_SOCK = 12;
686pub const DT_WHT = 14;
687
688/// add event to kq (implies enable)
689pub const EV_ADD = 0x0001;
690
691/// delete event from kq
692pub const EV_DELETE = 0x0002;
693
694/// enable event
695pub const EV_ENABLE = 0x0004;
696
697/// disable event (not reported)
698pub const EV_DISABLE = 0x0008;
699
700/// only report one occurrence
701pub const EV_ONESHOT = 0x0010;
702
703/// clear event state after reporting
704pub const EV_CLEAR = 0x0020;
705
706/// error, event data contains errno
707pub const EV_ERROR = 0x4000;
708
709/// force immediate event output
710/// ... with or without EV_ERROR
711/// ... use KEVENT_FLAG_ERROR_EVENTS
712/// on syscalls supporting flags
713pub const EV_RECEIPT = 0x0040;
714
715/// disable event after reporting
716pub const EV_DISPATCH = 0x0080;
717
718pub const EVFILT_READ = -1;
719pub const EVFILT_WRITE = -2;
720
721/// attached to aio requests
722pub const EVFILT_AIO = -3;
723
724/// attached to vnodes
725pub const EVFILT_VNODE = -4;
726
727/// attached to struct proc
728pub const EVFILT_PROC = -5;
729
730/// attached to struct proc
731pub const EVFILT_SIGNAL = -6;
732
733/// timers
734pub const EVFILT_TIMER = -7;
735
736/// Process descriptors
737pub const EVFILT_PROCDESC = -8;
738
739/// Filesystem events
740pub const EVFILT_FS = -9;
741
742pub const EVFILT_LIO = -10;
743
744/// User events
745pub const EVFILT_USER = -11;
746
747/// Sendfile events
748pub const EVFILT_SENDFILE = -12;
749
750pub const EVFILT_EMPTY = -13;
751
752/// On input, NOTE_TRIGGER causes the event to be triggered for output.
753pub const NOTE_TRIGGER = 0x01000000;
754
755/// ignore input fflags
756pub const NOTE_FFNOP = 0x00000000;
757
758/// and fflags
759pub const NOTE_FFAND = 0x40000000;
760
761/// or fflags
762pub const NOTE_FFOR = 0x80000000;
763
764/// copy fflags
765pub const NOTE_FFCOPY = 0xc0000000;
766
767/// mask for operations
768pub const NOTE_FFCTRLMASK = 0xc0000000;
769pub const NOTE_FFLAGSMASK = 0x00ffffff;
770
771/// low water mark
772pub const NOTE_LOWAT = 0x00000001;
773
774/// behave like poll()
775pub const NOTE_FILE_POLL = 0x00000002;
776
777/// vnode was removed
778pub const NOTE_DELETE = 0x00000001;
779
780/// data contents changed
781pub const NOTE_WRITE = 0x00000002;
782
783/// size increased
784pub const NOTE_EXTEND = 0x00000004;
785
786/// attributes changed
787pub const NOTE_ATTRIB = 0x00000008;
788
789/// link count changed
790pub const NOTE_LINK = 0x00000010;
791
792/// vnode was renamed
793pub const NOTE_RENAME = 0x00000020;
794
795/// vnode access was revoked
796pub const NOTE_REVOKE = 0x00000040;
797
798/// vnode was opened
799pub const NOTE_OPEN = 0x00000080;
800
801/// file closed, fd did not allow write
802pub const NOTE_CLOSE = 0x00000100;
803
804/// file closed, fd did allow write
805pub const NOTE_CLOSE_WRITE = 0x00000200;
806
807/// file was read
808pub const NOTE_READ = 0x00000400;
809
810/// process exited
811pub const NOTE_EXIT = 0x80000000;
812
813/// process forked
814pub const NOTE_FORK = 0x40000000;
815
816/// process exec'd
817pub const NOTE_EXEC = 0x20000000;
818
819/// mask for signal & exit status
820pub const NOTE_PDATAMASK = 0x000fffff;
821pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
822
823/// data is seconds
824pub const NOTE_SECONDS = 0x00000001;
825
826/// data is milliseconds
827pub const NOTE_MSECONDS = 0x00000002;
828
829/// data is microseconds
830pub const NOTE_USECONDS = 0x00000004;
831
832/// data is nanoseconds
833pub const NOTE_NSECONDS = 0x00000008;
834
835/// timeout is absolute
836pub const NOTE_ABSTIME = 0x00000010;
837
838pub const TIOCEXCL = 0x2000740d;
839pub const TIOCNXCL = 0x2000740e;
840pub const TIOCSCTTY = 0x20007461;
841pub const TIOCGPGRP = 0x40047477;
842pub const TIOCSPGRP = 0x80047476;
843pub const TIOCOUTQ = 0x40047473;
844pub const TIOCSTI = 0x80017472;
845pub const TIOCGWINSZ = 0x40087468;
846pub const TIOCSWINSZ = 0x80087467;
847pub const TIOCMGET = 0x4004746a;
848pub const TIOCMBIS = 0x8004746c;
849pub const TIOCMBIC = 0x8004746b;
850pub const TIOCMSET = 0x8004746d;
851pub const FIONREAD = 0x4004667f;
852pub const TIOCCONS = 0x80047462;
853pub const TIOCPKT = 0x80047470;
854pub const FIONBIO = 0x8004667e;
855pub const TIOCNOTTY = 0x20007471;
856pub const TIOCSETD = 0x8004741b;
857pub const TIOCGETD = 0x4004741a;
858pub const TIOCSBRK = 0x2000747b;
859pub const TIOCCBRK = 0x2000747a;
860pub const TIOCGSID = 0x40047463;
861pub const TIOCGPTN = 0x4004740f;
862pub const TIOCSIG = 0x2004745f;
863
864pub fn WEXITSTATUS(s: u32) u8 {
865 return @intCast(u8, (s & 0xff00) >> 8);
866}
867pub fn WTERMSIG(s: u32) u32 {
868 return s & 0x7f;
869}
870pub fn WSTOPSIG(s: u32) u32 {
871 return WEXITSTATUS(s);
872}
873pub fn WIFEXITED(s: u32) bool {
874 return WTERMSIG(s) == 0;
875}
876pub fn WIFSTOPPED(s: u32) bool {
877 return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
878}
879pub fn WIFSIGNALED(s: u32) bool {
880 return (s & 0xffff) -% 1 < 0xff;
881}
882
883pub const winsize = extern struct {
884 ws_row: u16,
885 ws_col: u16,
886 ws_xpixel: u16,
887 ws_ypixel: u16,
888};
889
890const NSIG = 32;
891
892pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
893pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
894pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
895
896/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
897pub const Sigaction = extern struct {
898 pub const handler_fn = fn (c_int) callconv(.C) void;
899 pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void;
900
901 /// signal handler
902 handler: extern union {
903 handler: ?handler_fn,
904 sigaction: ?sigaction_fn,
905 },
906
907 /// see signal options
908 flags: c_uint,
909
910 /// signal mask to apply
911 mask: sigset_t,
912};
913
914pub const siginfo_t = extern struct {
915 signo: c_int,
916 errno: c_int,
917 code: c_int,
918 pid: pid_t,
919 uid: uid_t,
920 status: c_int,
921 addr: ?*c_void,
922 value: sigval,
923 reason: extern union {
924 fault: extern struct {
925 trapno: c_int,
926 },
927 timer: extern struct {
928 timerid: c_int,
929 overrun: c_int,
930 },
931 mesgq: extern struct {
932 mqd: c_int,
933 },
934 poll: extern struct {
935 band: c_long,
936 },
937 spare: extern struct {
938 spare1: c_long,
939 spare2: [7]c_int,
940 },
941 },
942};
943
944pub const sigval = extern union {
945 int: c_int,
946 ptr: ?*c_void,
947};
948
949pub const _SIG_WORDS = 4;
950pub const _SIG_MAXSIG = 128;
951
952pub inline fn _SIG_IDX(sig: usize) usize {
953 return sig - 1;
954}
955pub inline fn _SIG_WORD(sig: usize) usize {
956 return_SIG_IDX(sig) >> 5;
957}
958pub inline fn _SIG_BIT(sig: usize) usize {
959 return 1 << (_SIG_IDX(sig) & 31);
960}
961pub inline fn _SIG_VALID(sig: usize) usize {
962 return sig <= _SIG_MAXSIG and sig > 0;
963}
964
965pub const sigset_t = extern struct {
966 __bits: [_SIG_WORDS]u32,
967};
968
969pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** _SIG_WORDS };
970
971pub usingnamespace switch (builtin.cpu.arch) {
972 .x86_64 => struct {
973 pub const ucontext_t = extern struct {
974 sigmask: sigset_t,
975 mcontext: mcontext_t,
976 link: ?*ucontext_t,
977 stack: stack_t,
978 flags: c_int,
979 __spare__: [4]c_int,
980 };
981
982 /// XXX x86_64 specific
983 pub const mcontext_t = extern struct {
984 onstack: u64,
985 rdi: u64,
986 rsi: u64,
987 rdx: u64,
988 rcx: u64,
989 r8: u64,
990 r9: u64,
991 rax: u64,
992 rbx: u64,
993 rbp: u64,
994 r10: u64,
995 r11: u64,
996 r12: u64,
997 r13: u64,
998 r14: u64,
999 r15: u64,
1000 trapno: u32,
1001 fs: u16,
1002 gs: u16,
1003 addr: u64,
1004 flags: u32,
1005 es: u16,
1006 ds: u16,
1007 err: u64,
1008 rip: u64,
1009 cs: u64,
1010 rflags: u64,
1011 rsp: u64,
1012 ss: u64,
1013 };
1014 },
1015 else => struct {},
1016};
1017
1018pub const E = enum(u16) {
1019 /// No error occurred.
1020 SUCCESS = 0,
1021
1022 PERM = 1, // Operation not permitted
1023 NOENT = 2, // No such file or directory
1024 SRCH = 3, // No such process
1025 INTR = 4, // Interrupted system call
1026 IO = 5, // Input/output error
1027 NXIO = 6, // Device not configured
1028 @"2BIG" = 7, // Argument list too long
1029 NOEXEC = 8, // Exec format error
1030 BADF = 9, // Bad file descriptor
1031 CHILD = 10, // No child processes
1032 DEADLK = 11, // Resource deadlock avoided
1033 // 11 was AGAIN
1034 NOMEM = 12, // Cannot allocate memory
1035 ACCES = 13, // Permission denied
1036 FAULT = 14, // Bad address
1037 NOTBLK = 15, // Block device required
1038 BUSY = 16, // Device busy
1039 EXIST = 17, // File exists
1040 XDEV = 18, // Cross-device link
1041 NODEV = 19, // Operation not supported by device
1042 NOTDIR = 20, // Not a directory
1043 ISDIR = 21, // Is a directory
1044 INVAL = 22, // Invalid argument
1045 NFILE = 23, // Too many open files in system
1046 MFILE = 24, // Too many open files
1047 NOTTY = 25, // Inappropriate ioctl for device
1048 TXTBSY = 26, // Text file busy
1049 FBIG = 27, // File too large
1050 NOSPC = 28, // No space left on device
1051 SPIPE = 29, // Illegal seek
1052 ROFS = 30, // Read-only filesystem
1053 MLINK = 31, // Too many links
1054 PIPE = 32, // Broken pipe
1055
1056 // math software
1057 DOM = 33, // Numerical argument out of domain
1058 RANGE = 34, // Result too large
1059
1060 // non-blocking and interrupt i/o
1061
1062 /// Resource temporarily unavailable
1063 /// This code is also used for `WOULDBLOCK`: operation would block.
1064 AGAIN = 35,
1065 INPROGRESS = 36, // Operation now in progress
1066 ALREADY = 37, // Operation already in progress
1067
1068 // ipc/network software -- argument errors
1069 NOTSOCK = 38, // Socket operation on non-socket
1070 DESTADDRREQ = 39, // Destination address required
1071 MSGSIZE = 40, // Message too long
1072 PROTOTYPE = 41, // Protocol wrong type for socket
1073 NOPROTOOPT = 42, // Protocol not available
1074 PROTONOSUPPORT = 43, // Protocol not supported
1075 SOCKTNOSUPPORT = 44, // Socket type not supported
1076 /// Operation not supported
1077 /// This code is also used for `NOTSUP`.
1078 OPNOTSUPP = 45,
1079 PFNOSUPPORT = 46, // Protocol family not supported
1080 AFNOSUPPORT = 47, // Address family not supported by protocol family
1081 ADDRINUSE = 48, // Address already in use
1082 ADDRNOTAVAIL = 49, // Can't assign requested address
1083
1084 // ipc/network software -- operational errors
1085 NETDOWN = 50, // Network is down
1086 NETUNREACH = 51, // Network is unreachable
1087 NETRESET = 52, // Network dropped connection on reset
1088 CONNABORTED = 53, // Software caused connection abort
1089 CONNRESET = 54, // Connection reset by peer
1090 NOBUFS = 55, // No buffer space available
1091 ISCONN = 56, // Socket is already connected
1092 NOTCONN = 57, // Socket is not connected
1093 SHUTDOWN = 58, // Can't send after socket shutdown
1094 TOOMANYREFS = 59, // Too many references: can't splice
1095 TIMEDOUT = 60, // Operation timed out
1096 CONNREFUSED = 61, // Connection refused
1097
1098 LOOP = 62, // Too many levels of symbolic links
1099 NAMETOOLONG = 63, // File name too long
1100
1101 // should be rearranged
1102 HOSTDOWN = 64, // Host is down
1103 HOSTUNREACH = 65, // No route to host
1104 NOTEMPTY = 66, // Directory not empty
1105
1106 // quotas & mush
1107 PROCLIM = 67, // Too many processes
1108 USERS = 68, // Too many users
1109 DQUOT = 69, // Disc quota exceeded
1110
1111 // Network File System
1112 STALE = 70, // Stale NFS file handle
1113 REMOTE = 71, // Too many levels of remote in path
1114 BADRPC = 72, // RPC struct is bad
1115 RPCMISMATCH = 73, // RPC version wrong
1116 PROGUNAVAIL = 74, // RPC prog. not avail
1117 PROGMISMATCH = 75, // Program version wrong
1118 PROCUNAVAIL = 76, // Bad procedure for program
1119
1120 NOLCK = 77, // No locks available
1121 NOSYS = 78, // Function not implemented
1122
1123 FTYPE = 79, // Inappropriate file type or format
1124 AUTH = 80, // Authentication error
1125 NEEDAUTH = 81, // Need authenticator
1126 IDRM = 82, // Identifier removed
1127 NOMSG = 83, // No message of desired type
1128 OVERFLOW = 84, // Value too large to be stored in data type
1129 CANCELED = 85, // Operation canceled
1130 ILSEQ = 86, // Illegal byte sequence
1131 NOATTR = 87, // Attribute not found
1132
1133 DOOFUS = 88, // Programming error
1134
1135 BADMSG = 89, // Bad message
1136 MULTIHOP = 90, // Multihop attempted
1137 NOLINK = 91, // Link has been severed
1138 PROTO = 92, // Protocol error
1139
1140 NOTCAPABLE = 93, // Capabilities insufficient
1141 CAPMODE = 94, // Not permitted in capability mode
1142 NOTRECOVERABLE = 95, // State not recoverable
1143 OWNERDEAD = 96, // Previous owner died
1144 _,
1145};
1146
1147pub const MINSIGSTKSZ = switch (builtin.cpu.arch) {
1148 .i386, .x86_64 => 2048,
1149 .arm, .aarch64 => 4096,
1150 else => @compileError("MINSIGSTKSZ not defined for this architecture"),
1151};
1152pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
1153
1154pub const SS_ONSTACK = 1;
1155pub const SS_DISABLE = 4;
1156
1157pub const stack_t = extern struct {
1158 ss_sp: [*]u8,
1159 ss_size: isize,
1160 ss_flags: i32,
1161};
1162
1163pub const S_IFMT = 0o170000;
1164
1165pub const S_IFIFO = 0o010000;
1166pub const S_IFCHR = 0o020000;
1167pub const S_IFDIR = 0o040000;
1168pub const S_IFBLK = 0o060000;
1169pub const S_IFREG = 0o100000;
1170pub const S_IFLNK = 0o120000;
1171pub const S_IFSOCK = 0o140000;
1172pub const S_IFWHT = 0o160000;
1173
1174pub const S_ISUID = 0o4000;
1175pub const S_ISGID = 0o2000;
1176pub const S_ISVTX = 0o1000;
1177pub const S_IRWXU = 0o700;
1178pub const S_IRUSR = 0o400;
1179pub const S_IWUSR = 0o200;
1180pub const S_IXUSR = 0o100;
1181pub const S_IRWXG = 0o070;
1182pub const S_IRGRP = 0o040;
1183pub const S_IWGRP = 0o020;
1184pub const S_IXGRP = 0o010;
1185pub const S_IRWXO = 0o007;
1186pub const S_IROTH = 0o004;
1187pub const S_IWOTH = 0o002;
1188pub const S_IXOTH = 0o001;
1189
1190pub fn S_ISFIFO(m: u32) bool {
1191 return m & S_IFMT == S_IFIFO;
1192}
1193
1194pub fn S_ISCHR(m: u32) bool {
1195 return m & S_IFMT == S_IFCHR;
1196}
1197
1198pub fn S_ISDIR(m: u32) bool {
1199 return m & S_IFMT == S_IFDIR;
1200}
1201
1202pub fn S_ISBLK(m: u32) bool {
1203 return m & S_IFMT == S_IFBLK;
1204}
1205
1206pub fn S_ISREG(m: u32) bool {
1207 return m & S_IFMT == S_IFREG;
1208}
1209
1210pub fn S_ISLNK(m: u32) bool {
1211 return m & S_IFMT == S_IFLNK;
1212}
1213
1214pub fn S_ISSOCK(m: u32) bool {
1215 return m & S_IFMT == S_IFSOCK;
1216}
1217
1218pub fn S_IWHT(m: u32) bool {
1219 return m & S_IFMT == S_IFWHT;
1220}
1221
1222pub const HOST_NAME_MAX = 255;
1223
1224/// Magic value that specify the use of the current working directory
1225/// to determine the target of relative file paths in the openat() and
1226/// similar syscalls.
1227pub const AT_FDCWD = -100;
1228
1229/// Check access using effective user and group ID
1230pub const AT_EACCESS = 0x0100;
1231
1232/// Do not follow symbolic links
1233pub const AT_SYMLINK_NOFOLLOW = 0x0200;
1234
1235/// Follow symbolic link
1236pub const AT_SYMLINK_FOLLOW = 0x0400;
1237
1238/// Remove directory instead of file
1239pub const AT_REMOVEDIR = 0x0800;
1240
1241pub const addrinfo = extern struct {
1242 flags: i32,
1243 family: i32,
1244 socktype: i32,
1245 protocol: i32,
1246 addrlen: socklen_t,
1247 canonname: ?[*:0]u8,
1248 addr: ?*sockaddr,
1249 next: ?*addrinfo,
1250};
1251
1252/// Fail if not under dirfd
1253pub const AT_BENEATH = 0x1000;
1254
1255/// dummy for IP
1256pub const IPPROTO_IP = 0;
1257
1258/// control message protocol
1259pub const IPPROTO_ICMP = 1;
1260
1261/// tcp
1262pub const IPPROTO_TCP = 6;
1263
1264/// user datagram protocol
1265pub const IPPROTO_UDP = 17;
1266
1267/// IP6 header
1268pub const IPPROTO_IPV6 = 41;
1269
1270/// raw IP packet
1271pub const IPPROTO_RAW = 255;
1272
1273/// IP6 hop-by-hop options
1274pub const IPPROTO_HOPOPTS = 0;
1275
1276/// group mgmt protocol
1277pub const IPPROTO_IGMP = 2;
1278
1279/// gateway^2 (deprecated)
1280pub const IPPROTO_GGP = 3;
1281
1282/// IPv4 encapsulation
1283pub const IPPROTO_IPV4 = 4;
1284
1285/// for compatibility
1286pub const IPPROTO_IPIP = IPPROTO_IPV4;
1287
1288/// Stream protocol II
1289pub const IPPROTO_ST = 7;
1290
1291/// exterior gateway protocol
1292pub const IPPROTO_EGP = 8;
1293
1294/// private interior gateway
1295pub const IPPROTO_PIGP = 9;
1296
1297/// BBN RCC Monitoring
1298pub const IPPROTO_RCCMON = 10;
1299
1300/// network voice protocol
1301pub const IPPROTO_NVPII = 11;
1302
1303/// pup
1304pub const IPPROTO_PUP = 12;
1305
1306/// Argus
1307pub const IPPROTO_ARGUS = 13;
1308
1309/// EMCON
1310pub const IPPROTO_EMCON = 14;
1311
1312/// Cross Net Debugger
1313pub const IPPROTO_XNET = 15;
1314
1315/// Chaos
1316pub const IPPROTO_CHAOS = 16;
1317
1318/// Multiplexing
1319pub const IPPROTO_MUX = 18;
1320
1321/// DCN Measurement Subsystems
1322pub const IPPROTO_MEAS = 19;
1323
1324/// Host Monitoring
1325pub const IPPROTO_HMP = 20;
1326
1327/// Packet Radio Measurement
1328pub const IPPROTO_PRM = 21;
1329
1330/// xns idp
1331pub const IPPROTO_IDP = 22;
1332
1333/// Trunk-1
1334pub const IPPROTO_TRUNK1 = 23;
1335
1336/// Trunk-2
1337pub const IPPROTO_TRUNK2 = 24;
1338
1339/// Leaf-1
1340pub const IPPROTO_LEAF1 = 25;
1341
1342/// Leaf-2
1343pub const IPPROTO_LEAF2 = 26;
1344
1345/// Reliable Data
1346pub const IPPROTO_RDP = 27;
1347
1348/// Reliable Transaction
1349pub const IPPROTO_IRTP = 28;
1350
1351/// tp-4 w/ class negotiation
1352pub const IPPROTO_TP = 29;
1353
1354/// Bulk Data Transfer
1355pub const IPPROTO_BLT = 30;
1356
1357/// Network Services
1358pub const IPPROTO_NSP = 31;
1359
1360/// Merit Internodal
1361pub const IPPROTO_INP = 32;
1362
1363/// Datagram Congestion Control Protocol
1364pub const IPPROTO_DCCP = 33;
1365
1366/// Third Party Connect
1367pub const IPPROTO_3PC = 34;
1368
1369/// InterDomain Policy Routing
1370pub const IPPROTO_IDPR = 35;
1371
1372/// XTP
1373pub const IPPROTO_XTP = 36;
1374
1375/// Datagram Delivery
1376pub const IPPROTO_DDP = 37;
1377
1378/// Control Message Transport
1379pub const IPPROTO_CMTP = 38;
1380
1381/// TP++ Transport
1382pub const IPPROTO_TPXX = 39;
1383
1384/// IL transport protocol
1385pub const IPPROTO_IL = 40;
1386
1387/// Source Demand Routing
1388pub const IPPROTO_SDRP = 42;
1389
1390/// IP6 routing header
1391pub const IPPROTO_ROUTING = 43;
1392
1393/// IP6 fragmentation header
1394pub const IPPROTO_FRAGMENT = 44;
1395
1396/// InterDomain Routing
1397pub const IPPROTO_IDRP = 45;
1398
1399/// resource reservation
1400pub const IPPROTO_RSVP = 46;
1401
1402/// General Routing Encap.
1403pub const IPPROTO_GRE = 47;
1404
1405/// Mobile Host Routing
1406pub const IPPROTO_MHRP = 48;
1407
1408/// BHA
1409pub const IPPROTO_BHA = 49;
1410
1411/// IP6 Encap Sec. Payload
1412pub const IPPROTO_ESP = 50;
1413
1414/// IP6 Auth Header
1415pub const IPPROTO_AH = 51;
1416
1417/// Integ. Net Layer Security
1418pub const IPPROTO_INLSP = 52;
1419
1420/// IP with encryption
1421pub const IPPROTO_SWIPE = 53;
1422
1423/// Next Hop Resolution
1424pub const IPPROTO_NHRP = 54;
1425
1426/// IP Mobility
1427pub const IPPROTO_MOBILE = 55;
1428
1429/// Transport Layer Security
1430pub const IPPROTO_TLSP = 56;
1431
1432/// SKIP
1433pub const IPPROTO_SKIP = 57;
1434
1435/// ICMP6
1436pub const IPPROTO_ICMPV6 = 58;
1437
1438/// IP6 no next header
1439pub const IPPROTO_NONE = 59;
1440
1441/// IP6 destination option
1442pub const IPPROTO_DSTOPTS = 60;
1443
1444/// any host internal protocol
1445pub const IPPROTO_AHIP = 61;
1446
1447/// CFTP
1448pub const IPPROTO_CFTP = 62;
1449
1450/// "hello" routing protocol
1451pub const IPPROTO_HELLO = 63;
1452
1453/// SATNET/Backroom EXPAK
1454pub const IPPROTO_SATEXPAK = 64;
1455
1456/// Kryptolan
1457pub const IPPROTO_KRYPTOLAN = 65;
1458
1459/// Remote Virtual Disk
1460pub const IPPROTO_RVD = 66;
1461
1462/// Pluribus Packet Core
1463pub const IPPROTO_IPPC = 67;
1464
1465/// Any distributed FS
1466pub const IPPROTO_ADFS = 68;
1467
1468/// Satnet Monitoring
1469pub const IPPROTO_SATMON = 69;
1470
1471/// VISA Protocol
1472pub const IPPROTO_VISA = 70;
1473
1474/// Packet Core Utility
1475pub const IPPROTO_IPCV = 71;
1476
1477/// Comp. Prot. Net. Executive
1478pub const IPPROTO_CPNX = 72;
1479
1480/// Comp. Prot. HeartBeat
1481pub const IPPROTO_CPHB = 73;
1482
1483/// Wang Span Network
1484pub const IPPROTO_WSN = 74;
1485
1486/// Packet Video Protocol
1487pub const IPPROTO_PVP = 75;
1488
1489/// BackRoom SATNET Monitoring
1490pub const IPPROTO_BRSATMON = 76;
1491
1492/// Sun net disk proto (temp.)
1493pub const IPPROTO_ND = 77;
1494
1495/// WIDEBAND Monitoring
1496pub const IPPROTO_WBMON = 78;
1497
1498/// WIDEBAND EXPAK
1499pub const IPPROTO_WBEXPAK = 79;
1500
1501/// ISO cnlp
1502pub const IPPROTO_EON = 80;
1503
1504/// VMTP
1505pub const IPPROTO_VMTP = 81;
1506
1507/// Secure VMTP
1508pub const IPPROTO_SVMTP = 82;
1509
1510/// Banyon VINES
1511pub const IPPROTO_VINES = 83;
1512
1513/// TTP
1514pub const IPPROTO_TTP = 84;
1515
1516/// NSFNET-IGP
1517pub const IPPROTO_IGP = 85;
1518
1519/// dissimilar gateway prot.
1520pub const IPPROTO_DGP = 86;
1521
1522/// TCF
1523pub const IPPROTO_TCF = 87;
1524
1525/// Cisco/GXS IGRP
1526pub const IPPROTO_IGRP = 88;
1527
1528/// OSPFIGP
1529pub const IPPROTO_OSPFIGP = 89;
1530
1531/// Strite RPC protocol
1532pub const IPPROTO_SRPC = 90;
1533
1534/// Locus Address Resoloution
1535pub const IPPROTO_LARP = 91;
1536
1537/// Multicast Transport
1538pub const IPPROTO_MTP = 92;
1539
1540/// AX.25 Frames
1541pub const IPPROTO_AX25 = 93;
1542
1543/// IP encapsulated in IP
1544pub const IPPROTO_IPEIP = 94;
1545
1546/// Mobile Int.ing control
1547pub const IPPROTO_MICP = 95;
1548
1549/// Semaphore Comm. security
1550pub const IPPROTO_SCCSP = 96;
1551
1552/// Ethernet IP encapsulation
1553pub const IPPROTO_ETHERIP = 97;
1554
1555/// encapsulation header
1556pub const IPPROTO_ENCAP = 98;
1557
1558/// any private encr. scheme
1559pub const IPPROTO_APES = 99;
1560
1561/// GMTP
1562pub const IPPROTO_GMTP = 100;
1563
1564/// payload compression (IPComp)
1565pub const IPPROTO_IPCOMP = 108;
1566
1567/// SCTP
1568pub const IPPROTO_SCTP = 132;
1569
1570/// IPv6 Mobility Header
1571pub const IPPROTO_MH = 135;
1572
1573/// UDP-Lite
1574pub const IPPROTO_UDPLITE = 136;
1575
1576/// IP6 Host Identity Protocol
1577pub const IPPROTO_HIP = 139;
1578
1579/// IP6 Shim6 Protocol
1580pub const IPPROTO_SHIM6 = 140;
1581
1582/// Protocol Independent Mcast
1583pub const IPPROTO_PIM = 103;
1584
1585/// CARP
1586pub const IPPROTO_CARP = 112;
1587
1588/// PGM
1589pub const IPPROTO_PGM = 113;
1590
1591/// MPLS-in-IP
1592pub const IPPROTO_MPLS = 137;
1593
1594/// PFSYNC
1595pub const IPPROTO_PFSYNC = 240;
1596
1597/// Reserved
1598pub const IPPROTO_RESERVED_253 = 253;
1599
1600/// Reserved
1601pub const IPPROTO_RESERVED_254 = 254;
1602
1603pub const rlimit_resource = enum(c_int) {
1604 CPU = 0,
1605 FSIZE = 1,
1606 DATA = 2,
1607 STACK = 3,
1608 CORE = 4,
1609 RSS = 5,
1610 MEMLOCK = 6,
1611 NPROC = 7,
1612 NOFILE = 8,
1613 SBSIZE = 9,
1614 VMEM = 10,
1615 NPTS = 11,
1616 SWAP = 12,
1617 KQUEUES = 13,
1618 UMTXP = 14,
1619 _,
1620
1621 pub const AS: rlimit_resource = .VMEM;
1622};
1623
1624pub const rlim_t = i64;
1625
1626/// No limit
1627pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
1628
1629pub const RLIM_SAVED_MAX = RLIM_INFINITY;
1630pub const RLIM_SAVED_CUR = RLIM_INFINITY;
1631
1632pub const rlimit = extern struct {
1633 /// Soft limit
1634 cur: rlim_t,
1635 /// Hard limit
1636 max: rlim_t,
1637};
1638
1639pub const SHUT_RD = 0;
1640pub const SHUT_WR = 1;
1641pub const SHUT_RDWR = 2;
1642
1643pub const nfds_t = u32;
1644
1645pub const pollfd = extern struct {
1646 fd: fd_t,
1647 events: i16,
1648 revents: i16,
1649};
1650
1651/// any readable data available.
1652pub const POLLIN = 0x0001;
1653/// OOB/Urgent readable data.
1654pub const POLLPRI = 0x0002;
1655/// file descriptor is writeable.
1656pub const POLLOUT = 0x0004;
1657/// non-OOB/URG data available.
1658pub const POLLRDNORM = 0x0040;
1659/// no write type differentiation.
1660pub const POLLWRNORM = POLLOUT;
1661/// OOB/Urgent readable data.
1662pub const POLLRDBAND = 0x0080;
1663/// OOB/Urgent data can be written.
1664pub const POLLWRBAND = 0x0100;
1665/// like POLLIN, except ignore EOF.
1666pub const POLLINIGNEOF = 0x2000;
1667/// some poll error occurred.
1668pub const POLLERR = 0x0008;
1669/// file descriptor was "hung up".
1670pub const POLLHUP = 0x0010;
1671/// requested events "invalid".
1672pub const POLLNVAL = 0x0020;
1673
1674pub const POLLSTANDARD = POLLIN | POLLPRI | POLLOUT | POLLRDNORM | POLLRDBAND |
1675 POLLWRBAND | POLLERR | POLLHUP | POLLNVAL;
lib/std/c/generic.zig created+22
...@@ -0,0 +1,22 @@
1const std = @import("../std.zig");
2const Stat = std.c.Stat;
3const timespec = std.c.timespec;
4const Sigaction = std.c.Sigaction;
5const sigset_t = std.c.sigset_t;
6
7pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
8pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
9pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
10pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
11pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
12pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
13pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
14pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
15pub extern "c" fn sched_yield() c_int;
16pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
17pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
18pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
19pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
20pub extern "c" fn sigfillset(set: ?*sigset_t) void;
21pub extern "c" fn alarm(seconds: c_uint) c_uint;
22pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
lib/std/c/haiku.zig+1373-3
...@@ -1,6 +1,5 @@...@@ -1,6 +1,5 @@
1//
2const std = @import("../std.zig");1const std = @import("../std.zig");
3const builtin = std.builtin;2const maxInt = std.math.maxInt;
43
5usingnamespace std.c;4usingnamespace std.c;
65
...@@ -19,7 +18,7 @@ pub extern "c" fn _get_next_image_info(team: c_int, cookie: *i32, image_info: *i...@@ -19,7 +18,7 @@ pub extern "c" fn _get_next_image_info(team: c_int, cookie: *i32, image_info: *i
1918
20pub extern "c" fn _kern_read_dir(fd: c_int, buf_ptr: [*]u8, nbytes: usize, maxcount: u32) usize;19pub extern "c" fn _kern_read_dir(fd: c_int, buf_ptr: [*]u8, nbytes: usize, maxcount: u32) usize;
2120
22pub extern "c" fn _kern_read_stat(fd: c_int, path_ptr: [*]u8, traverse_link: bool, libc_stat: *libc_stat, stat_size: i32) usize;21pub extern "c" fn _kern_read_stat(fd: c_int, path_ptr: [*]u8, traverse_link: bool, st: *Stat, stat_size: i32) usize;
2322
24pub extern "c" fn _kern_get_current_team() i32;23pub extern "c" fn _kern_get_current_team() i32;
2524
...@@ -111,3 +110,1374 @@ pub const EAI = enum(c_int) {...@@ -111,3 +110,1374 @@ pub const EAI = enum(c_int) {
111};110};
112111
113pub const EAI_MAX = 15;112pub const EAI_MAX = 15;
113
114pub const fd_t = c_int;
115pub const pid_t = c_int;
116pub const uid_t = u32;
117pub const gid_t = u32;
118pub const mode_t = c_uint;
119
120pub const socklen_t = u32;
121
122/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
123pub const Kevent = extern struct {
124 ident: usize,
125 filter: i16,
126 flags: u16,
127 fflags: u32,
128 data: i64,
129 udata: usize,
130 // TODO ext
131};
132
133// Modes and flags for dlopen()
134// include/dlfcn.h
135
136pub const POLLIN = 0x0001;
137pub const POLLERR = 0x0004;
138pub const POLLNVAL = 0x1000;
139pub const POLLHUP = 0x0080;
140
141/// Bind function calls lazily.
142pub const RTLD_LAZY = 1;
143
144/// Bind function calls immediately.
145pub const RTLD_NOW = 2;
146
147pub const RTLD_MODEMASK = 0x3;
148
149/// Make symbols globally available.
150pub const RTLD_GLOBAL = 0x100;
151
152/// Opposite of RTLD_GLOBAL, and the default.
153pub const RTLD_LOCAL = 0;
154
155/// Trace loaded objects and exit.
156pub const RTLD_TRACE = 0x200;
157
158/// Do not remove members.
159pub const RTLD_NODELETE = 0x01000;
160
161/// Do not load if not already loaded.
162pub const RTLD_NOLOAD = 0x02000;
163
164pub const dl_phdr_info = extern struct {
165 dlpi_addr: usize,
166 dlpi_name: ?[*:0]const u8,
167 dlpi_phdr: [*]std.elf.Phdr,
168 dlpi_phnum: u16,
169};
170
171pub const Flock = extern struct {
172 l_start: off_t,
173 l_len: off_t,
174 l_pid: pid_t,
175 l_type: i16,
176 l_whence: i16,
177 l_sysid: i32,
178 __unused: [4]u8,
179};
180
181pub const msghdr = extern struct {
182 /// optional address
183 msg_name: ?*sockaddr,
184
185 /// size of address
186 msg_namelen: socklen_t,
187
188 /// scatter/gather array
189 msg_iov: [*]iovec,
190
191 /// # elements in msg_iov
192 msg_iovlen: i32,
193
194 /// ancillary data
195 msg_control: ?*c_void,
196
197 /// ancillary data buffer len
198 msg_controllen: socklen_t,
199
200 /// flags on received message
201 msg_flags: i32,
202};
203
204pub const msghdr_const = extern struct {
205 /// optional address
206 msg_name: ?*const sockaddr,
207
208 /// size of address
209 msg_namelen: socklen_t,
210
211 /// scatter/gather array
212 msg_iov: [*]iovec_const,
213
214 /// # elements in msg_iov
215 msg_iovlen: i32,
216
217 /// ancillary data
218 msg_control: ?*c_void,
219
220 /// ancillary data buffer len
221 msg_controllen: socklen_t,
222
223 /// flags on received message
224 msg_flags: i32,
225};
226
227pub const off_t = i64;
228pub const ino_t = u64;
229
230pub const nfds_t = u32;
231
232pub const pollfd = extern struct {
233 fd: i32,
234 events: i16,
235 revents: i16,
236};
237
238pub const Stat = extern struct {
239 dev: i32,
240 ino: u64,
241 mode: u32,
242 nlink: i32,
243 uid: i32,
244 gid: i32,
245 size: i64,
246 rdev: i32,
247 blksize: i32,
248 atim: timespec,
249 mtim: timespec,
250 ctim: timespec,
251 crtim: timespec,
252 st_type: u32,
253 blocks: i64,
254
255 pub fn atime(self: @This()) timespec {
256 return self.atim;
257 }
258 pub fn mtime(self: @This()) timespec {
259 return self.mtim;
260 }
261 pub fn ctime(self: @This()) timespec {
262 return self.ctim;
263 }
264 pub fn crtime(self: @This()) timespec {
265 return self.crtim;
266 }
267};
268
269pub const timespec = extern struct {
270 tv_sec: isize,
271 tv_nsec: isize,
272};
273
274pub const dirent = extern struct {
275 d_dev: i32,
276 d_pdev: i32,
277 d_ino: i64,
278 d_pino: i64,
279 d_reclen: u16,
280 d_name: [256]u8,
281
282 pub fn reclen(self: dirent) u16 {
283 return self.d_reclen;
284 }
285};
286
287pub const image_info = extern struct {
288 id: u32,
289 type: u32,
290 sequence: i32,
291 init_order: i32,
292 init_routine: *c_void,
293 term_routine: *c_void,
294 device: i32,
295 node: i32,
296 name: [1024]u8,
297 text: *c_void,
298 data: *c_void,
299 text_size: i32,
300 data_size: i32,
301 api_version: i32,
302 abi: i32,
303};
304
305pub const system_info = extern struct {
306 boot_time: i64,
307 cpu_count: u32,
308 max_pages: u64,
309 used_pages: u64,
310 cached_pages: u64,
311 block_cache_pages: u64,
312 ignored_pages: u64,
313 needed_memory: u64,
314 free_memory: u64,
315 max_swap_pages: u64,
316 free_swap_pages: u64,
317 page_faults: u32,
318 max_sems: u32,
319 used_sems: u32,
320 max_ports: u32,
321 used_ports: u32,
322 max_threads: u32,
323 used_threads: u32,
324 max_teams: u32,
325 used_teams: u32,
326 kernel_name: [256]u8,
327 kernel_build_date: [32]u8,
328 kernel_build_time: [32]u8,
329 kernel_version: i64,
330 abi: u32,
331};
332
333pub const in_port_t = u16;
334pub const sa_family_t = u8;
335
336pub const sockaddr = extern struct {
337 /// total length
338 len: u8,
339
340 /// address family
341 family: sa_family_t,
342
343 /// actually longer; address value
344 data: [14]u8,
345};
346
347pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
348
349pub const sockaddr_in = extern struct {
350 len: u8 = @sizeOf(sockaddr_in),
351 family: sa_family_t = AF_INET,
352 port: in_port_t,
353 addr: u32,
354 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
355};
356
357pub const sockaddr_in6 = extern struct {
358 len: u8 = @sizeOf(sockaddr_in6),
359 family: sa_family_t = AF_INET6,
360 port: in_port_t,
361 flowinfo: u32,
362 addr: [16]u8,
363 scope_id: u32,
364};
365
366pub const sockaddr_un = extern struct {
367 len: u8 = @sizeOf(sockaddr_un),
368 family: sa_family_t = AF_UNIX,
369 path: [104]u8,
370};
371
372pub const CTL_KERN = 1;
373pub const CTL_DEBUG = 5;
374
375pub const KERN_PROC = 14; // struct: process entries
376pub const KERN_PROC_PATHNAME = 12; // path to executable
377
378pub const PATH_MAX = 1024;
379
380pub const STDIN_FILENO = 0;
381pub const STDOUT_FILENO = 1;
382pub const STDERR_FILENO = 2;
383
384pub const PROT_NONE = 0;
385pub const PROT_READ = 1;
386pub const PROT_WRITE = 2;
387pub const PROT_EXEC = 4;
388
389pub const CLOCK_MONOTONIC = 0;
390pub const CLOCK_REALTIME = -1;
391pub const CLOCK_PROCESS_CPUTIME_ID = -2;
392pub const CLOCK_THREAD_CPUTIME_ID = -3;
393
394pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
395pub const MAP_SHARED = 0x0001;
396pub const MAP_PRIVATE = 0x0002;
397pub const MAP_FIXED = 0x0010;
398pub const MAP_STACK = 0x0400;
399pub const MAP_NOSYNC = 0x0800;
400pub const MAP_ANON = 0x1000;
401pub const MAP_ANONYMOUS = MAP_ANON;
402pub const MAP_FILE = 0;
403
404pub const MAP_GUARD = 0x00002000;
405pub const MAP_EXCL = 0x00004000;
406pub const MAP_NOCORE = 0x00020000;
407pub const MAP_PREFAULT_READ = 0x00040000;
408pub const MAP_32BIT = 0x00080000;
409
410pub const WNOHANG = 0x1;
411pub const WUNTRACED = 0x2;
412pub const WSTOPPED = 0x10;
413pub const WCONTINUED = 0x4;
414pub const WNOWAIT = 0x20;
415pub const WEXITED = 0x08;
416
417pub const SA_ONSTACK = 0x20;
418pub const SA_RESTART = 0x10;
419pub const SA_RESETHAND = 0x04;
420pub const SA_NOCLDSTOP = 0x01;
421pub const SA_NODEFER = 0x08;
422pub const SA_NOCLDWAIT = 0x02;
423pub const SA_SIGINFO = 0x40;
424pub const SA_NOMASK = SA_NODEFER;
425pub const SA_STACK = SA_ONSTACK;
426pub const SA_ONESHOT = SA_RESETHAND;
427
428pub const SIGHUP = 1;
429pub const SIGINT = 2;
430pub const SIGQUIT = 3;
431pub const SIGILL = 4;
432pub const SIGCHLD = 5;
433pub const SIGABRT = 6;
434pub const SIGIOT = SIGABRT;
435pub const SIGPIPE = 7;
436pub const SIGFPE = 8;
437pub const SIGKILL = 9;
438pub const SIGSTOP = 10;
439pub const SIGSEGV = 11;
440pub const SIGCONT = 12;
441pub const SIGTSTP = 13;
442pub const SIGALRM = 14;
443pub const SIGTERM = 15;
444pub const SIGTTIN = 16;
445pub const SIGTTOU = 17;
446pub const SIGUSR1 = 18;
447pub const SIGUSR2 = 19;
448pub const SIGWINCH = 20;
449pub const SIGKILLTHR = 21;
450pub const SIGTRAP = 22;
451pub const SIGPOLL = 23;
452pub const SIGPROF = 24;
453pub const SIGSYS = 25;
454pub const SIGURG = 26;
455pub const SIGVTALRM = 27;
456pub const SIGXCPU = 28;
457pub const SIGXFSZ = 29;
458pub const SIGBUS = 30;
459pub const SIGRESERVED1 = 31;
460pub const SIGRESERVED2 = 32;
461
462// TODO: check
463pub const SIGRTMIN = 65;
464pub const SIGRTMAX = 126;
465
466// access function
467pub const F_OK = 0; // test for existence of file
468pub const X_OK = 1; // test for execute or search permission
469pub const W_OK = 2; // test for write permission
470pub const R_OK = 4; // test for read permission
471
472pub const O_RDONLY = 0x0000;
473pub const O_WRONLY = 0x0001;
474pub const O_RDWR = 0x0002;
475pub const O_ACCMODE = 0x0003;
476
477pub const O_SHLOCK = 0x0010;
478pub const O_EXLOCK = 0x0020;
479
480pub const O_CREAT = 0x0200;
481pub const O_EXCL = 0x0800;
482pub const O_NOCTTY = 0x8000;
483pub const O_TRUNC = 0x0400;
484pub const O_APPEND = 0x0008;
485pub const O_NONBLOCK = 0x0004;
486pub const O_DSYNC = 0o10000;
487pub const O_SYNC = 0x0080;
488pub const O_RSYNC = 0o4010000;
489pub const O_DIRECTORY = 0x20000;
490pub const O_NOFOLLOW = 0x0100;
491pub const O_CLOEXEC = 0x00100000;
492
493pub const O_ASYNC = 0x0040;
494pub const O_DIRECT = 0x00010000;
495pub const O_NOATIME = 0o1000000;
496pub const O_PATH = 0o10000000;
497pub const O_TMPFILE = 0o20200000;
498pub const O_NDELAY = O_NONBLOCK;
499
500pub const F_DUPFD = 0;
501pub const F_GETFD = 1;
502pub const F_SETFD = 2;
503pub const F_GETFL = 3;
504pub const F_SETFL = 4;
505
506pub const F_GETOWN = 5;
507pub const F_SETOWN = 6;
508
509pub const F_GETLK = 11;
510pub const F_SETLK = 12;
511pub const F_SETLKW = 13;
512
513pub const F_RDLCK = 1;
514pub const F_WRLCK = 3;
515pub const F_UNLCK = 2;
516
517pub const LOCK_SH = 1;
518pub const LOCK_EX = 2;
519pub const LOCK_UN = 8;
520pub const LOCK_NB = 4;
521
522pub const F_SETOWN_EX = 15;
523pub const F_GETOWN_EX = 16;
524
525pub const F_GETOWNER_UIDS = 17;
526
527pub const FD_CLOEXEC = 1;
528
529pub const SEEK_SET = 0;
530pub const SEEK_CUR = 1;
531pub const SEEK_END = 2;
532
533pub const SIG_BLOCK = 1;
534pub const SIG_UNBLOCK = 2;
535pub const SIG_SETMASK = 3;
536
537pub const SOCK_STREAM = 1;
538pub const SOCK_DGRAM = 2;
539pub const SOCK_RAW = 3;
540pub const SOCK_RDM = 4;
541pub const SOCK_SEQPACKET = 5;
542
543pub const SOCK_CLOEXEC = 0x10000000;
544pub const SOCK_NONBLOCK = 0x20000000;
545
546pub const SO_DEBUG = 0x00000001;
547pub const SO_ACCEPTCONN = 0x00000002;
548pub const SO_REUSEADDR = 0x00000004;
549pub const SO_KEEPALIVE = 0x00000008;
550pub const SO_DONTROUTE = 0x00000010;
551pub const SO_BROADCAST = 0x00000020;
552pub const SO_USELOOPBACK = 0x00000040;
553pub const SO_LINGER = 0x00000080;
554pub const SO_OOBINLINE = 0x00000100;
555pub const SO_REUSEPORT = 0x00000200;
556pub const SO_TIMESTAMP = 0x00000400;
557pub const SO_NOSIGPIPE = 0x00000800;
558pub const SO_ACCEPTFILTER = 0x00001000;
559pub const SO_BINTIME = 0x00002000;
560pub const SO_NO_OFFLOAD = 0x00004000;
561pub const SO_NO_DDP = 0x00008000;
562pub const SO_REUSEPORT_LB = 0x00010000;
563
564pub const SO_SNDBUF = 0x1001;
565pub const SO_RCVBUF = 0x1002;
566pub const SO_SNDLOWAT = 0x1003;
567pub const SO_RCVLOWAT = 0x1004;
568pub const SO_SNDTIMEO = 0x1005;
569pub const SO_RCVTIMEO = 0x1006;
570pub const SO_ERROR = 0x1007;
571pub const SO_TYPE = 0x1008;
572pub const SO_LABEL = 0x1009;
573pub const SO_PEERLABEL = 0x1010;
574pub const SO_LISTENQLIMIT = 0x1011;
575pub const SO_LISTENQLEN = 0x1012;
576pub const SO_LISTENINCQLEN = 0x1013;
577pub const SO_SETFIB = 0x1014;
578pub const SO_USER_COOKIE = 0x1015;
579pub const SO_PROTOCOL = 0x1016;
580pub const SO_PROTOTYPE = SO_PROTOCOL;
581pub const SO_TS_CLOCK = 0x1017;
582pub const SO_MAX_PACING_RATE = 0x1018;
583pub const SO_DOMAIN = 0x1019;
584
585pub const SOL_SOCKET = 0xffff;
586
587pub const PF_UNSPEC = AF_UNSPEC;
588pub const PF_LOCAL = AF_LOCAL;
589pub const PF_UNIX = PF_LOCAL;
590pub const PF_INET = AF_INET;
591pub const PF_IMPLINK = AF_IMPLINK;
592pub const PF_PUP = AF_PUP;
593pub const PF_CHAOS = AF_CHAOS;
594pub const PF_NETBIOS = AF_NETBIOS;
595pub const PF_ISO = AF_ISO;
596pub const PF_OSI = AF_ISO;
597pub const PF_ECMA = AF_ECMA;
598pub const PF_DATAKIT = AF_DATAKIT;
599pub const PF_CCITT = AF_CCITT;
600pub const PF_DECnet = AF_DECnet;
601pub const PF_DLI = AF_DLI;
602pub const PF_LAT = AF_LAT;
603pub const PF_HYLINK = AF_HYLINK;
604pub const PF_APPLETALK = AF_APPLETALK;
605pub const PF_ROUTE = AF_ROUTE;
606pub const PF_LINK = AF_LINK;
607pub const PF_XTP = pseudo_AF_XTP;
608pub const PF_COIP = AF_COIP;
609pub const PF_CNT = AF_CNT;
610pub const PF_SIP = AF_SIP;
611pub const PF_IPX = AF_IPX;
612pub const PF_RTIP = pseudo_AF_RTIP;
613pub const PF_PIP = psuedo_AF_PIP;
614pub const PF_ISDN = AF_ISDN;
615pub const PF_KEY = pseudo_AF_KEY;
616pub const PF_INET6 = pseudo_AF_INET6;
617pub const PF_NATM = AF_NATM;
618pub const PF_ATM = AF_ATM;
619pub const PF_NETGRAPH = AF_NETGRAPH;
620pub const PF_SLOW = AF_SLOW;
621pub const PF_SCLUSTER = AF_SCLUSTER;
622pub const PF_ARP = AF_ARP;
623pub const PF_BLUETOOTH = AF_BLUETOOTH;
624pub const PF_IEEE80211 = AF_IEEE80211;
625pub const PF_INET_SDP = AF_INET_SDP;
626pub const PF_INET6_SDP = AF_INET6_SDP;
627pub const PF_MAX = AF_MAX;
628
629pub const AF_UNSPEC = 0;
630pub const AF_UNIX = 1;
631pub const AF_LOCAL = AF_UNIX;
632pub const AF_FILE = AF_LOCAL;
633pub const AF_INET = 2;
634pub const AF_IMPLINK = 3;
635pub const AF_PUP = 4;
636pub const AF_CHAOS = 5;
637pub const AF_NETBIOS = 6;
638pub const AF_ISO = 7;
639pub const AF_OSI = AF_ISO;
640pub const AF_ECMA = 8;
641pub const AF_DATAKIT = 9;
642pub const AF_CCITT = 10;
643pub const AF_SNA = 11;
644pub const AF_DECnet = 12;
645pub const AF_DLI = 13;
646pub const AF_LAT = 14;
647pub const AF_HYLINK = 15;
648pub const AF_APPLETALK = 16;
649pub const AF_ROUTE = 17;
650pub const AF_LINK = 18;
651pub const pseudo_AF_XTP = 19;
652pub const AF_COIP = 20;
653pub const AF_CNT = 21;
654pub const pseudo_AF_RTIP = 22;
655pub const AF_IPX = 23;
656pub const AF_SIP = 24;
657pub const pseudo_AF_PIP = 25;
658pub const AF_ISDN = 26;
659pub const AF_E164 = AF_ISDN;
660pub const pseudo_AF_KEY = 27;
661pub const AF_INET6 = 28;
662pub const AF_NATM = 29;
663pub const AF_ATM = 30;
664pub const pseudo_AF_HDRCMPLT = 31;
665pub const AF_NETGRAPH = 32;
666pub const AF_SLOW = 33;
667pub const AF_SCLUSTER = 34;
668pub const AF_ARP = 35;
669pub const AF_BLUETOOTH = 36;
670pub const AF_IEEE80211 = 37;
671pub const AF_INET_SDP = 40;
672pub const AF_INET6_SDP = 42;
673pub const AF_MAX = 42;
674
675pub const DT_UNKNOWN = 0;
676pub const DT_FIFO = 1;
677pub const DT_CHR = 2;
678pub const DT_DIR = 4;
679pub const DT_BLK = 6;
680pub const DT_REG = 8;
681pub const DT_LNK = 10;
682pub const DT_SOCK = 12;
683pub const DT_WHT = 14;
684
685/// add event to kq (implies enable)
686pub const EV_ADD = 0x0001;
687
688/// delete event from kq
689pub const EV_DELETE = 0x0002;
690
691/// enable event
692pub const EV_ENABLE = 0x0004;
693
694/// disable event (not reported)
695pub const EV_DISABLE = 0x0008;
696
697/// only report one occurrence
698pub const EV_ONESHOT = 0x0010;
699
700/// clear event state after reporting
701pub const EV_CLEAR = 0x0020;
702
703/// force immediate event output
704/// ... with or without EV_ERROR
705/// ... use KEVENT_FLAG_ERROR_EVENTS
706/// on syscalls supporting flags
707pub const EV_RECEIPT = 0x0040;
708
709/// disable event after reporting
710pub const EV_DISPATCH = 0x0080;
711
712pub const EVFILT_READ = -1;
713pub const EVFILT_WRITE = -2;
714
715/// attached to aio requests
716pub const EVFILT_AIO = -3;
717
718/// attached to vnodes
719pub const EVFILT_VNODE = -4;
720
721/// attached to struct proc
722pub const EVFILT_PROC = -5;
723
724/// attached to struct proc
725pub const EVFILT_SIGNAL = -6;
726
727/// timers
728pub const EVFILT_TIMER = -7;
729
730/// Process descriptors
731pub const EVFILT_PROCDESC = -8;
732
733/// Filesystem events
734pub const EVFILT_FS = -9;
735
736pub const EVFILT_LIO = -10;
737
738/// User events
739pub const EVFILT_USER = -11;
740
741/// Sendfile events
742pub const EVFILT_SENDFILE = -12;
743
744pub const EVFILT_EMPTY = -13;
745
746pub const TCGETA = 0x8000;
747pub const TCSETA = 0x8001;
748pub const TCSETAW = 0x8004;
749pub const TCSETAF = 0x8003;
750pub const TCSBRK = 08005;
751pub const TCXONC = 0x8007;
752pub const TCFLSH = 0x8006;
753
754pub const TIOCSCTTY = 0x8017;
755pub const TIOCGPGRP = 0x8015;
756pub const TIOCSPGRP = 0x8016;
757pub const TIOCGWINSZ = 0x8012;
758pub const TIOCSWINSZ = 0x8013;
759pub const TIOCMGET = 0x8018;
760pub const TIOCMBIS = 0x8022;
761pub const TIOCMBIC = 0x8023;
762pub const TIOCMSET = 0x8019;
763pub const FIONREAD = 0xbe000001;
764pub const FIONBIO = 0xbe000000;
765pub const TIOCSBRK = 0x8020;
766pub const TIOCCBRK = 0x8021;
767pub const TIOCGSID = 0x8024;
768
769pub fn WEXITSTATUS(s: u32) u8 {
770 return @intCast(u8, s & 0xff);
771}
772
773pub fn WTERMSIG(s: u32) u32 {
774 return (s >> 8) & 0xff;
775}
776
777pub fn WSTOPSIG(s: u32) u32 {
778 return WEXITSTATUS(s);
779}
780
781pub fn WIFEXITED(s: u32) bool {
782 return WTERMSIG(s) == 0;
783}
784
785pub fn WIFSTOPPED(s: u32) bool {
786 return ((s >> 16) & 0xff) != 0;
787}
788
789pub fn WIFSIGNALED(s: u32) bool {
790 return ((s >> 8) & 0xff) != 0;
791}
792
793pub const winsize = extern struct {
794 ws_row: u16,
795 ws_col: u16,
796 ws_xpixel: u16,
797 ws_ypixel: u16,
798};
799
800const NSIG = 32;
801
802pub const SIG_ERR = @intToPtr(fn (i32) callconv(.C) void, maxInt(usize));
803pub const SIG_DFL = @intToPtr(fn (i32) callconv(.C) void, 0);
804pub const SIG_IGN = @intToPtr(fn (i32) callconv(.C) void, 1);
805
806/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
807pub const Sigaction = extern struct {
808 /// signal handler
809 __sigaction_u: extern union {
810 __sa_handler: fn (i32) callconv(.C) void,
811 __sa_sigaction: fn (i32, *__siginfo, usize) callconv(.C) void,
812 },
813
814 /// see signal options
815 sa_flags: u32,
816
817 /// signal mask to apply
818 sa_mask: sigset_t,
819};
820
821pub const _SIG_WORDS = 4;
822pub const _SIG_MAXSIG = 128;
823pub inline fn _SIG_IDX(sig: usize) usize {
824 return sig - 1;
825}
826pub inline fn _SIG_WORD(sig: usize) usize {
827 return_SIG_IDX(sig) >> 5;
828}
829pub inline fn _SIG_BIT(sig: usize) usize {
830 return 1 << (_SIG_IDX(sig) & 31);
831}
832pub inline fn _SIG_VALID(sig: usize) usize {
833 return sig <= _SIG_MAXSIG and sig > 0;
834}
835
836pub const sigset_t = extern struct {
837 __bits: [_SIG_WORDS]u32,
838};
839
840pub const E = enum(i32) {
841 /// No error occurred.
842 SUCCESS = 0,
843 PERM = -0x7ffffff1, // Operation not permitted
844 NOENT = -0x7fff9ffd, // No such file or directory
845 SRCH = -0x7fff8ff3, // No such process
846 INTR = -0x7ffffff6, // Interrupted system call
847 IO = -0x7fffffff, // Input/output error
848 NXIO = -0x7fff8ff5, // Device not configured
849 @"2BIG" = -0x7fff8fff, // Argument list too long
850 NOEXEC = -0x7fffecfe, // Exec format error
851 CHILD = -0x7fff8ffe, // No child processes
852 DEADLK = -0x7fff8ffd, // Resource deadlock avoided
853 NOMEM = -0x80000000, // Cannot allocate memory
854 ACCES = -0x7ffffffe, // Permission denied
855 FAULT = -0x7fffecff, // Bad address
856 BUSY = -0x7ffffff2, // Device busy
857 EXIST = -0x7fff9ffe, // File exists
858 XDEV = -0x7fff9ff5, // Cross-device link
859 NODEV = -0x7fff8ff9, // Operation not supported by device
860 NOTDIR = -0x7fff9ffb, // Not a directory
861 ISDIR = -0x7fff9ff7, // Is a directory
862 INVAL = -0x7ffffffb, // Invalid argument
863 NFILE = -0x7fff8ffa, // Too many open files in system
864 MFILE = -0x7fff9ff6, // Too many open files
865 NOTTY = -0x7fff8ff6, // Inappropriate ioctl for device
866 TXTBSY = -0x7fff8fc5, // Text file busy
867 FBIG = -0x7fff8ffc, // File too large
868 NOSPC = -0x7fff9ff9, // No space left on device
869 SPIPE = -0x7fff8ff4, // Illegal seek
870 ROFS = -0x7fff9ff8, // Read-only filesystem
871 MLINK = -0x7fff8ffb, // Too many links
872 PIPE = -0x7fff9ff3, // Broken pipe
873 BADF = -0x7fffa000, // Bad file descriptor
874
875 // math software
876 DOM = 33, // Numerical argument out of domain
877 RANGE = 34, // Result too large
878
879 // non-blocking and interrupt i/o
880
881 /// Also used for `WOULDBLOCK`.
882 AGAIN = -0x7ffffff5,
883 INPROGRESS = -0x7fff8fdc,
884 ALREADY = -0x7fff8fdb,
885
886 // ipc/network software -- argument errors
887 NOTSOCK = 38, // Socket operation on non-socket
888 DESTADDRREQ = 39, // Destination address required
889 MSGSIZE = 40, // Message too long
890 PROTOTYPE = 41, // Protocol wrong type for socket
891 NOPROTOOPT = 42, // Protocol not available
892 PROTONOSUPPORT = 43, // Protocol not supported
893 SOCKTNOSUPPORT = 44, // Socket type not supported
894 /// Also used for `NOTSUP`.
895 OPNOTSUPP = 45, // Operation not supported
896 PFNOSUPPORT = 46, // Protocol family not supported
897 AFNOSUPPORT = 47, // Address family not supported by protocol family
898 ADDRINUSE = 48, // Address already in use
899 ADDRNOTAVAIL = 49, // Can't assign requested address
900
901 // ipc/network software -- operational errors
902 NETDOWN = 50, // Network is down
903 NETUNREACH = 51, // Network is unreachable
904 NETRESET = 52, // Network dropped connection on reset
905 CONNABORTED = 53, // Software caused connection abort
906 CONNRESET = 54, // Connection reset by peer
907 NOBUFS = 55, // No buffer space available
908 ISCONN = 56, // Socket is already connected
909 NOTCONN = 57, // Socket is not connected
910 SHUTDOWN = 58, // Can't send after socket shutdown
911 TOOMANYREFS = 59, // Too many references: can't splice
912 TIMEDOUT = 60, // Operation timed out
913 CONNREFUSED = 61, // Connection refused
914
915 LOOP = 62, // Too many levels of symbolic links
916 NAMETOOLONG = 63, // File name too long
917
918 // should be rearranged
919 HOSTDOWN = 64, // Host is down
920 HOSTUNREACH = 65, // No route to host
921 NOTEMPTY = 66, // Directory not empty
922
923 // quotas & mush
924 PROCLIM = 67, // Too many processes
925 USERS = 68, // Too many users
926 DQUOT = 69, // Disc quota exceeded
927
928 // Network File System
929 STALE = 70, // Stale NFS file handle
930 REMOTE = 71, // Too many levels of remote in path
931 BADRPC = 72, // RPC struct is bad
932 RPCMISMATCH = 73, // RPC version wrong
933 PROGUNAVAIL = 74, // RPC prog. not avail
934 PROGMISMATCH = 75, // Program version wrong
935 PROCUNAVAIL = 76, // Bad procedure for program
936
937 NOLCK = 77, // No locks available
938 NOSYS = 78, // Function not implemented
939
940 FTYPE = 79, // Inappropriate file type or format
941 AUTH = 80, // Authentication error
942 NEEDAUTH = 81, // Need authenticator
943 IDRM = 82, // Identifier removed
944 NOMSG = 83, // No message of desired type
945 OVERFLOW = 84, // Value too large to be stored in data type
946 CANCELED = 85, // Operation canceled
947 ILSEQ = 86, // Illegal byte sequence
948 NOATTR = 87, // Attribute not found
949
950 DOOFUS = 88, // Programming error
951
952 BADMSG = 89, // Bad message
953 MULTIHOP = 90, // Multihop attempted
954 NOLINK = 91, // Link has been severed
955 PROTO = 92, // Protocol error
956
957 NOTCAPABLE = 93, // Capabilities insufficient
958 CAPMODE = 94, // Not permitted in capability mode
959 NOTRECOVERABLE = 95, // State not recoverable
960 OWNERDEAD = 96, // Previous owner died
961
962 _,
963};
964
965pub const MINSIGSTKSZ = switch (builtin.cpu.arch) {
966 .i386, .x86_64 => 2048,
967 .arm, .aarch64 => 4096,
968 else => @compileError("MINSIGSTKSZ not defined for this architecture"),
969};
970pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
971
972pub const SS_ONSTACK = 1;
973pub const SS_DISABLE = 4;
974
975pub const stack_t = extern struct {
976 ss_sp: [*]u8,
977 ss_size: isize,
978 ss_flags: i32,
979};
980
981pub const S_IFMT = 0o170000;
982
983pub const S_IFIFO = 0o010000;
984pub const S_IFCHR = 0o020000;
985pub const S_IFDIR = 0o040000;
986pub const S_IFBLK = 0o060000;
987pub const S_IFREG = 0o100000;
988pub const S_IFLNK = 0o120000;
989pub const S_IFSOCK = 0o140000;
990pub const S_IFWHT = 0o160000;
991
992pub const S_ISUID = 0o4000;
993pub const S_ISGID = 0o2000;
994pub const S_ISVTX = 0o1000;
995pub const S_IRWXU = 0o700;
996pub const S_IRUSR = 0o400;
997pub const S_IWUSR = 0o200;
998pub const S_IXUSR = 0o100;
999pub const S_IRWXG = 0o070;
1000pub const S_IRGRP = 0o040;
1001pub const S_IWGRP = 0o020;
1002pub const S_IXGRP = 0o010;
1003pub const S_IRWXO = 0o007;
1004pub const S_IROTH = 0o004;
1005pub const S_IWOTH = 0o002;
1006pub const S_IXOTH = 0o001;
1007
1008pub fn S_ISFIFO(m: u32) bool {
1009 return m & S_IFMT == S_IFIFO;
1010}
1011
1012pub fn S_ISCHR(m: u32) bool {
1013 return m & S_IFMT == S_IFCHR;
1014}
1015
1016pub fn S_ISDIR(m: u32) bool {
1017 return m & S_IFMT == S_IFDIR;
1018}
1019
1020pub fn S_ISBLK(m: u32) bool {
1021 return m & S_IFMT == S_IFBLK;
1022}
1023
1024pub fn S_ISREG(m: u32) bool {
1025 return m & S_IFMT == S_IFREG;
1026}
1027
1028pub fn S_ISLNK(m: u32) bool {
1029 return m & S_IFMT == S_IFLNK;
1030}
1031
1032pub fn S_ISSOCK(m: u32) bool {
1033 return m & S_IFMT == S_IFSOCK;
1034}
1035
1036pub fn S_IWHT(m: u32) bool {
1037 return m & S_IFMT == S_IFWHT;
1038}
1039
1040pub const HOST_NAME_MAX = 255;
1041
1042/// Magic value that specify the use of the current working directory
1043/// to determine the target of relative file paths in the openat() and
1044/// similar syscalls.
1045pub const AT_FDCWD = -100;
1046
1047/// Check access using effective user and group ID
1048pub const AT_EACCESS = 0x0100;
1049
1050/// Do not follow symbolic links
1051pub const AT_SYMLINK_NOFOLLOW = 0x0200;
1052
1053/// Follow symbolic link
1054pub const AT_SYMLINK_FOLLOW = 0x0400;
1055
1056/// Remove directory instead of file
1057pub const AT_REMOVEDIR = 0x0800;
1058
1059pub const addrinfo = extern struct {
1060 flags: i32,
1061 family: i32,
1062 socktype: i32,
1063 protocol: i32,
1064 addrlen: socklen_t,
1065 canonname: ?[*:0]u8,
1066 addr: ?*sockaddr,
1067 next: ?*addrinfo,
1068};
1069
1070/// Fail if not under dirfd
1071pub const AT_BENEATH = 0x1000;
1072
1073/// dummy for IP
1074pub const IPPROTO_IP = 0;
1075
1076/// control message protocol
1077pub const IPPROTO_ICMP = 1;
1078
1079/// tcp
1080pub const IPPROTO_TCP = 6;
1081
1082/// user datagram protocol
1083pub const IPPROTO_UDP = 17;
1084
1085/// IP6 header
1086pub const IPPROTO_IPV6 = 41;
1087
1088/// raw IP packet
1089pub const IPPROTO_RAW = 255;
1090
1091/// IP6 hop-by-hop options
1092pub const IPPROTO_HOPOPTS = 0;
1093
1094/// group mgmt protocol
1095pub const IPPROTO_IGMP = 2;
1096
1097/// gateway^2 (deprecated)
1098pub const IPPROTO_GGP = 3;
1099
1100/// IPv4 encapsulation
1101pub const IPPROTO_IPV4 = 4;
1102
1103/// for compatibility
1104pub const IPPROTO_IPIP = IPPROTO_IPV4;
1105
1106/// Stream protocol II
1107pub const IPPROTO_ST = 7;
1108
1109/// exterior gateway protocol
1110pub const IPPROTO_EGP = 8;
1111
1112/// private interior gateway
1113pub const IPPROTO_PIGP = 9;
1114
1115/// BBN RCC Monitoring
1116pub const IPPROTO_RCCMON = 10;
1117
1118/// network voice protocol
1119pub const IPPROTO_NVPII = 11;
1120
1121/// pup
1122pub const IPPROTO_PUP = 12;
1123
1124/// Argus
1125pub const IPPROTO_ARGUS = 13;
1126
1127/// EMCON
1128pub const IPPROTO_EMCON = 14;
1129
1130/// Cross Net Debugger
1131pub const IPPROTO_XNET = 15;
1132
1133/// Chaos
1134pub const IPPROTO_CHAOS = 16;
1135
1136/// Multiplexing
1137pub const IPPROTO_MUX = 18;
1138
1139/// DCN Measurement Subsystems
1140pub const IPPROTO_MEAS = 19;
1141
1142/// Host Monitoring
1143pub const IPPROTO_HMP = 20;
1144
1145/// Packet Radio Measurement
1146pub const IPPROTO_PRM = 21;
1147
1148/// xns idp
1149pub const IPPROTO_IDP = 22;
1150
1151/// Trunk-1
1152pub const IPPROTO_TRUNK1 = 23;
1153
1154/// Trunk-2
1155pub const IPPROTO_TRUNK2 = 24;
1156
1157/// Leaf-1
1158pub const IPPROTO_LEAF1 = 25;
1159
1160/// Leaf-2
1161pub const IPPROTO_LEAF2 = 26;
1162
1163/// Reliable Data
1164pub const IPPROTO_RDP = 27;
1165
1166/// Reliable Transaction
1167pub const IPPROTO_IRTP = 28;
1168
1169/// tp-4 w/ class negotiation
1170pub const IPPROTO_TP = 29;
1171
1172/// Bulk Data Transfer
1173pub const IPPROTO_BLT = 30;
1174
1175/// Network Services
1176pub const IPPROTO_NSP = 31;
1177
1178/// Merit Internodal
1179pub const IPPROTO_INP = 32;
1180
1181/// Datagram Congestion Control Protocol
1182pub const IPPROTO_DCCP = 33;
1183
1184/// Third Party Connect
1185pub const IPPROTO_3PC = 34;
1186
1187/// InterDomain Policy Routing
1188pub const IPPROTO_IDPR = 35;
1189
1190/// XTP
1191pub const IPPROTO_XTP = 36;
1192
1193/// Datagram Delivery
1194pub const IPPROTO_DDP = 37;
1195
1196/// Control Message Transport
1197pub const IPPROTO_CMTP = 38;
1198
1199/// TP++ Transport
1200pub const IPPROTO_TPXX = 39;
1201
1202/// IL transport protocol
1203pub const IPPROTO_IL = 40;
1204
1205/// Source Demand Routing
1206pub const IPPROTO_SDRP = 42;
1207
1208/// IP6 routing header
1209pub const IPPROTO_ROUTING = 43;
1210
1211/// IP6 fragmentation header
1212pub const IPPROTO_FRAGMENT = 44;
1213
1214/// InterDomain Routing
1215pub const IPPROTO_IDRP = 45;
1216
1217/// resource reservation
1218pub const IPPROTO_RSVP = 46;
1219
1220/// General Routing Encap.
1221pub const IPPROTO_GRE = 47;
1222
1223/// Mobile Host Routing
1224pub const IPPROTO_MHRP = 48;
1225
1226/// BHA
1227pub const IPPROTO_BHA = 49;
1228
1229/// IP6 Encap Sec. Payload
1230pub const IPPROTO_ESP = 50;
1231
1232/// IP6 Auth Header
1233pub const IPPROTO_AH = 51;
1234
1235/// Integ. Net Layer Security
1236pub const IPPROTO_INLSP = 52;
1237
1238/// IP with encryption
1239pub const IPPROTO_SWIPE = 53;
1240
1241/// Next Hop Resolution
1242pub const IPPROTO_NHRP = 54;
1243
1244/// IP Mobility
1245pub const IPPROTO_MOBILE = 55;
1246
1247/// Transport Layer Security
1248pub const IPPROTO_TLSP = 56;
1249
1250/// SKIP
1251pub const IPPROTO_SKIP = 57;
1252
1253/// ICMP6
1254pub const IPPROTO_ICMPV6 = 58;
1255
1256/// IP6 no next header
1257pub const IPPROTO_NONE = 59;
1258
1259/// IP6 destination option
1260pub const IPPROTO_DSTOPTS = 60;
1261
1262/// any host internal protocol
1263pub const IPPROTO_AHIP = 61;
1264
1265/// CFTP
1266pub const IPPROTO_CFTP = 62;
1267
1268/// "hello" routing protocol
1269pub const IPPROTO_HELLO = 63;
1270
1271/// SATNET/Backroom EXPAK
1272pub const IPPROTO_SATEXPAK = 64;
1273
1274/// Kryptolan
1275pub const IPPROTO_KRYPTOLAN = 65;
1276
1277/// Remote Virtual Disk
1278pub const IPPROTO_RVD = 66;
1279
1280/// Pluribus Packet Core
1281pub const IPPROTO_IPPC = 67;
1282
1283/// Any distributed FS
1284pub const IPPROTO_ADFS = 68;
1285
1286/// Satnet Monitoring
1287pub const IPPROTO_SATMON = 69;
1288
1289/// VISA Protocol
1290pub const IPPROTO_VISA = 70;
1291
1292/// Packet Core Utility
1293pub const IPPROTO_IPCV = 71;
1294
1295/// Comp. Prot. Net. Executive
1296pub const IPPROTO_CPNX = 72;
1297
1298/// Comp. Prot. HeartBeat
1299pub const IPPROTO_CPHB = 73;
1300
1301/// Wang Span Network
1302pub const IPPROTO_WSN = 74;
1303
1304/// Packet Video Protocol
1305pub const IPPROTO_PVP = 75;
1306
1307/// BackRoom SATNET Monitoring
1308pub const IPPROTO_BRSATMON = 76;
1309
1310/// Sun net disk proto (temp.)
1311pub const IPPROTO_ND = 77;
1312
1313/// WIDEBAND Monitoring
1314pub const IPPROTO_WBMON = 78;
1315
1316/// WIDEBAND EXPAK
1317pub const IPPROTO_WBEXPAK = 79;
1318
1319/// ISO cnlp
1320pub const IPPROTO_EON = 80;
1321
1322/// VMTP
1323pub const IPPROTO_VMTP = 81;
1324
1325/// Secure VMTP
1326pub const IPPROTO_SVMTP = 82;
1327
1328/// Banyon VINES
1329pub const IPPROTO_VINES = 83;
1330
1331/// TTP
1332pub const IPPROTO_TTP = 84;
1333
1334/// NSFNET-IGP
1335pub const IPPROTO_IGP = 85;
1336
1337/// dissimilar gateway prot.
1338pub const IPPROTO_DGP = 86;
1339
1340/// TCF
1341pub const IPPROTO_TCF = 87;
1342
1343/// Cisco/GXS IGRP
1344pub const IPPROTO_IGRP = 88;
1345
1346/// OSPFIGP
1347pub const IPPROTO_OSPFIGP = 89;
1348
1349/// Strite RPC protocol
1350pub const IPPROTO_SRPC = 90;
1351
1352/// Locus Address Resoloution
1353pub const IPPROTO_LARP = 91;
1354
1355/// Multicast Transport
1356pub const IPPROTO_MTP = 92;
1357
1358/// AX.25 Frames
1359pub const IPPROTO_AX25 = 93;
1360
1361/// IP encapsulated in IP
1362pub const IPPROTO_IPEIP = 94;
1363
1364/// Mobile Int.ing control
1365pub const IPPROTO_MICP = 95;
1366
1367/// Semaphore Comm. security
1368pub const IPPROTO_SCCSP = 96;
1369
1370/// Ethernet IP encapsulation
1371pub const IPPROTO_ETHERIP = 97;
1372
1373/// encapsulation header
1374pub const IPPROTO_ENCAP = 98;
1375
1376/// any private encr. scheme
1377pub const IPPROTO_APES = 99;
1378
1379/// GMTP
1380pub const IPPROTO_GMTP = 100;
1381
1382/// payload compression (IPComp)
1383pub const IPPROTO_IPCOMP = 108;
1384
1385/// SCTP
1386pub const IPPROTO_SCTP = 132;
1387
1388/// IPv6 Mobility Header
1389pub const IPPROTO_MH = 135;
1390
1391/// UDP-Lite
1392pub const IPPROTO_UDPLITE = 136;
1393
1394/// IP6 Host Identity Protocol
1395pub const IPPROTO_HIP = 139;
1396
1397/// IP6 Shim6 Protocol
1398pub const IPPROTO_SHIM6 = 140;
1399
1400/// Protocol Independent Mcast
1401pub const IPPROTO_PIM = 103;
1402
1403/// CARP
1404pub const IPPROTO_CARP = 112;
1405
1406/// PGM
1407pub const IPPROTO_PGM = 113;
1408
1409/// MPLS-in-IP
1410pub const IPPROTO_MPLS = 137;
1411
1412/// PFSYNC
1413pub const IPPROTO_PFSYNC = 240;
1414
1415/// Reserved
1416pub const IPPROTO_RESERVED_253 = 253;
1417
1418/// Reserved
1419pub const IPPROTO_RESERVED_254 = 254;
1420
1421pub const rlimit_resource = enum(c_int) {
1422 CPU = 0,
1423 FSIZE = 1,
1424 DATA = 2,
1425 STACK = 3,
1426 CORE = 4,
1427 RSS = 5,
1428 MEMLOCK = 6,
1429 NPROC = 7,
1430 NOFILE = 8,
1431 SBSIZE = 9,
1432 VMEM = 10,
1433 NPTS = 11,
1434 SWAP = 12,
1435 KQUEUES = 13,
1436 UMTXP = 14,
1437 _,
1438
1439 pub const AS: rlimit_resource = .VMEM;
1440};
1441
1442pub const rlim_t = i64;
1443
1444/// No limit
1445pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
1446
1447pub const RLIM_SAVED_MAX = RLIM_INFINITY;
1448pub const RLIM_SAVED_CUR = RLIM_INFINITY;
1449
1450pub const rlimit = extern struct {
1451 /// Soft limit
1452 cur: rlim_t,
1453 /// Hard limit
1454 max: rlim_t,
1455};
1456
1457pub const SHUT_RD = 0;
1458pub const SHUT_WR = 1;
1459pub const SHUT_RDWR = 2;
1460
1461// TODO fill out if needed
1462pub const directory_which = enum(c_int) {
1463 B_USER_SETTINGS_DIRECTORY = 0xbbe,
1464
1465 _,
1466};
1467
1468pub const cc_t = u8;
1469pub const speed_t = u8;
1470pub const tcflag_t = u32;
1471
1472pub const NCCS = 32;
1473
1474pub const termios = extern struct {
1475 c_iflag: tcflag_t,
1476 c_oflag: tcflag_t,
1477 c_cflag: tcflag_t,
1478 c_lflag: tcflag_t,
1479 c_line: cc_t,
1480 c_ispeed: speed_t,
1481 c_ospeed: speed_t,
1482 cc_t: [NCCS]cc_t,
1483};
lib/std/c/linux.zig+160-31
...@@ -1,11 +1,66 @@...@@ -1,11 +1,66 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = @import("builtin");
2const maxInt = std.math.maxInt;3const maxInt = std.math.maxInt;
3const abi = std.Target.current.abi;4const native_abi = builtin.abi;
4const arch = std.Target.current.cpu.arch;5const native_arch = builtin.cpu.arch;
5const os_tag = std.Target.current.os.tag;6const linux = std.os.linux;
6usingnamespace std.c;
77
8pub const _errno = switch (abi) {8pub const E = linux.E;
9pub const Sigaction = linux.Sigaction;
10pub const dl_phdr_info = linux.dl_phdr_info;
11pub const fd_t = linux.fd_t;
12pub const rlimit = linux.rlimit;
13pub const rlimit_resource = linux.rlimit_resource;
14pub const timespec = linux.timespec;
15pub const NAME_MAX = linux.NAME_MAX;
16pub const PATH_MAX = linux.PATH_MAX;
17pub const IOV_MAX = linux.IOV_MAX;
18pub const STDIN_FILENO = linux.STDIN_FILENO;
19pub const STDOUT_FILENO = linux.STDIN_FILENO;
20pub const STDERR_FILENO = linux.STDIN_FILENO;
21pub const AT = linux.AT;
22pub const PROT = linux.PROT;
23pub const CLOCK = linux.CLOCK;
24pub const SIG = linux.SIG;
25pub const empty_sigset = linux.empty_sigset;
26pub const S = linux.S;
27pub const siginfo_t = linux.siginfo_t;
28pub const SA = linux.SA;
29pub const pollfd = linux.pollfd;
30pub const sigset_t = linux.sigset_t;
31pub const ARCH = linux.ARCH;
32pub const Elf_Symndx = linux.Elf_Symndx;
33pub const F = linux.F;
34pub const Flock = linux.Flock;
35pub const LOCK = linux.LOCK;
36pub const MAP = linux.MAP;
37pub const MMAP2_UNIT = linux.MMAP2_UNIT;
38pub const O = linux.O;
39pub const REG = linux.REG;
40pub const SC = linux.SC;
41pub const SYS = linux.SYS;
42pub const VDSO = linux.VDSO;
43pub const blkcnt_t = linux.blkcnt_t;
44pub const blksize_t = linux.blksize_t;
45pub const dev_t = linux.dev_t;
46pub const ino_t = linux.ino_t;
47pub const mcontext_t = linux.mcontext_t;
48pub const mode_t = linux.mode_t;
49pub const msghdr = linux.msghdr;
50pub const msghdr_const = linux.msghdr_const;
51pub const nlink_t = linux.nlink_t;
52pub const off_t = linux.off_t;
53pub const time_t = linux.time_t;
54pub const timeval = linux.timeval;
55pub const timezone = linux.timezone;
56pub const ucontext_t = linux.ucontext_t;
57pub const user_desc = linux.user_desc;
58pub const pid_t = linux.pid_t;
59pub const uid_t = linux.uid_t;
60pub const gid_t = linux.gid_t;
61pub const clock_t = linux.clock_t;
62
63pub const _errno = switch (native_abi) {
9 .android => struct {64 .android => struct {
10 extern "c" var __errno: c_int;65 extern "c" var __errno: c_int;
11 fn getErrno() *c_int {66 fn getErrno() *c_int {
...@@ -17,22 +72,94 @@ pub const _errno = switch (abi) {...@@ -17,22 +72,94 @@ pub const _errno = switch (abi) {
17 }.__errno_location,72 }.__errno_location,
18};73};
1974
75pub const Stat = switch (native_arch) {
76 .sparcv9 => extern struct {
77 dev: u64,
78 ino: ino_t,
79 mode: u32,
80 nlink: usize,
81
82 uid: u32,
83 gid: u32,
84 rdev: u64,
85 __pad0: u32,
86
87 size: off_t,
88 blksize: isize,
89 blocks: i64,
90
91 atim: timespec,
92 mtim: timespec,
93 ctim: timespec,
94 __unused: [2]isize,
95
96 pub fn atime(self: @This()) timespec {
97 return self.atim;
98 }
99
100 pub fn mtime(self: @This()) timespec {
101 return self.mtim;
102 }
103
104 pub fn ctime(self: @This()) timespec {
105 return self.ctim;
106 }
107 },
108 .mips, .mipsel => extern struct {
109 dev: dev_t,
110 __pad0: [2]u32,
111 ino: ino_t,
112 mode: mode_t,
113 nlink: nlink_t,
114 uid: uid_t,
115 gid: gid_t,
116 rdev: dev_t,
117 __pad1: [2]u32,
118 size: off_t,
119 atim: timespec,
120 mtim: timespec,
121 ctim: timespec,
122 blksize: blksize_t,
123 __pad3: u32,
124 blocks: blkcnt_t,
125 __pad4: [14]u32,
126
127 pub fn atime(self: @This()) timespec {
128 return self.atim;
129 }
130
131 pub fn mtime(self: @This()) timespec {
132 return self.mtim;
133 }
134
135 pub fn ctime(self: @This()) timespec {
136 return self.ctim;
137 }
138 },
139
140 else => std.os.linux.Stat, // libc stat is the same as kernel stat.
141};
142
20pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));143pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
21144
22pub const AI_PASSIVE = 0x01;145pub const AI = struct {
23pub const AI_CANONNAME = 0x02;146 pub const PASSIVE = 0x01;
24pub const AI_NUMERICHOST = 0x04;147 pub const CANONNAME = 0x02;
25pub const AI_V4MAPPED = 0x08;148 pub const NUMERICHOST = 0x04;
26pub const AI_ALL = 0x10;149 pub const V4MAPPED = 0x08;
27pub const AI_ADDRCONFIG = 0x20;150 pub const ALL = 0x10;
28pub const AI_NUMERICSERV = 0x400;151 pub const ADDRCONFIG = 0x20;
29152 pub const NUMERICSERV = 0x400;
30pub const NI_NUMERICHOST = 0x01;153};
31pub const NI_NUMERICSERV = 0x02;154
32pub const NI_NOFQDN = 0x04;155pub const NI = struct {
33pub const NI_NAMEREQD = 0x08;156 pub const NUMERICHOST = 0x01;
34pub const NI_DGRAM = 0x10;157 pub const NUMERICSERV = 0x02;
35pub const NI_NUMERICSCOPE = 0x100;158 pub const NOFQDN = 0x04;
159 pub const NAMEREQD = 0x08;
160 pub const DGRAM = 0x10;
161 pub const NUMERICSCOPE = 0x100;
162};
36163
37pub const EAI = enum(c_int) {164pub const EAI = enum(c_int) {
38 BADFLAGS = -1,165 BADFLAGS = -1,
...@@ -60,8 +187,8 @@ pub const EAI = enum(c_int) {...@@ -60,8 +187,8 @@ pub const EAI = enum(c_int) {
60187
61pub extern "c" fn fallocate64(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int;188pub extern "c" fn fallocate64(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int;
62pub extern "c" fn fopen64(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;189pub extern "c" fn fopen64(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;
63pub extern "c" fn fstat64(fd: fd_t, buf: *libc_stat) c_int;190pub extern "c" fn fstat64(fd: fd_t, buf: *Stat) c_int;
64pub extern "c" fn fstatat64(dirfd: fd_t, path: [*:0]const u8, stat_buf: *libc_stat, flags: u32) c_int;191pub extern "c" fn fstatat64(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
65pub extern "c" fn ftruncate64(fd: c_int, length: off_t) c_int;192pub extern "c" fn ftruncate64(fd: c_int, length: off_t) c_int;
66pub extern "c" fn getrlimit64(resource: rlimit_resource, rlim: *rlimit) c_int;193pub extern "c" fn getrlimit64(resource: rlimit_resource, rlim: *rlimit) c_int;
67pub extern "c" fn lseek64(fd: fd_t, offset: i64, whence: c_int) i64;194pub extern "c" fn lseek64(fd: fd_t, offset: i64, whence: c_int) i64;
...@@ -137,7 +264,7 @@ pub const pthread_mutex_t = extern struct {...@@ -137,7 +264,7 @@ pub const pthread_mutex_t = extern struct {
137pub const pthread_cond_t = extern struct {264pub const pthread_cond_t = extern struct {
138 size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T,265 size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T,
139};266};
140pub const pthread_rwlock_t = switch (abi) {267pub const pthread_rwlock_t = switch (native_abi) {
141 .android => switch (@sizeOf(usize)) {268 .android => switch (@sizeOf(usize)) {
142 4 => extern struct {269 4 => extern struct {
143 lock: std.c.pthread_mutex_t = std.c.PTHREAD_MUTEX_INITIALIZER,270 lock: std.c.pthread_mutex_t = std.c.PTHREAD_MUTEX_INITIALIZER,
...@@ -168,11 +295,11 @@ pub const sem_t = extern struct {...@@ -168,11 +295,11 @@ pub const sem_t = extern struct {
168};295};
169296
170const __SIZEOF_PTHREAD_COND_T = 48;297const __SIZEOF_PTHREAD_COND_T = 48;
171const __SIZEOF_PTHREAD_MUTEX_T = if (os_tag == .fuchsia) 40 else switch (abi) {298const __SIZEOF_PTHREAD_MUTEX_T = switch (native_abi) {
172 .musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24,299 .musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24,
173 .gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (arch) {300 .gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (native_arch) {
174 .aarch64 => 48,301 .aarch64 => 48,
175 .x86_64 => if (abi == .gnux32) 40 else 32,302 .x86_64 => if (native_abi == .gnux32) 40 else 32,
176 .mips64, .powerpc64, .powerpc64le, .sparcv9 => 40,303 .mips64, .powerpc64, .powerpc64le, .sparcv9 => 40,
177 else => if (@sizeOf(usize) == 8) 40 else 24,304 else => if (@sizeOf(usize) == 8) 40 else 24,
178 },305 },
...@@ -184,9 +311,11 @@ const __SIZEOF_SEM_T = 4 * @sizeOf(usize);...@@ -184,9 +311,11 @@ const __SIZEOF_SEM_T = 4 * @sizeOf(usize);
184pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;311pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;
185pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;312pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
186313
187pub const RTLD_LAZY = 1;314pub const RTLD = struct {
188pub const RTLD_NOW = 2;315 pub const LAZY = 1;
189pub const RTLD_NOLOAD = 4;316 pub const NOW = 2;
190pub const RTLD_NODELETE = 4096;317 pub const NOLOAD = 4;
191pub const RTLD_GLOBAL = 256;318 pub const NODELETE = 4096;
192pub const RTLD_LOCAL = 0;319 pub const GLOBAL = 256;
320 pub const LOCAL = 0;
321};
lib/std/c/netbsd.zig+1343-4
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;2const builtin = @import("builtin");
3const maxInt = std.math.maxInt;
34
4usingnamespace std.c;5usingnamespace std.c;
56
...@@ -13,8 +14,8 @@ pub extern "c" fn _lwp_self() lwpid_t;...@@ -13,8 +14,8 @@ pub extern "c" fn _lwp_self() lwpid_t;
1314
14pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;15pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;
15pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;16pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
16pub extern "c" fn __fstat50(fd: fd_t, buf: *libc_stat) c_int;17pub extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int;
17pub extern "c" fn __stat50(path: [*:0]const u8, buf: *libc_stat) c_int;18pub extern "c" fn __stat50(path: [*:0]const u8, buf: *Stat) c_int;
18pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int;19pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int;
19pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int;20pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int;
20pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;21pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
...@@ -51,7 +52,7 @@ pub const pthread_cond_t = extern struct {...@@ -51,7 +52,7 @@ pub const pthread_cond_t = extern struct {
5152
52pub const pthread_rwlock_t = extern struct {53pub const pthread_rwlock_t = extern struct {
53 ptr_magic: c_uint = 0x99990009,54 ptr_magic: c_uint = 0x99990009,
54 ptr_interlock: switch (std.builtin.cpu.arch) {55 ptr_interlock: switch (builtin.cpu.arch) {
55 .aarch64, .sparc, .x86_64, .i386 => u8,56 .aarch64, .sparc, .x86_64, .i386 => u8,
56 .arm, .powerpc => c_int,57 .arm, .powerpc => c_int,
57 else => unreachable,58 else => unreachable,
...@@ -92,3 +93,1341 @@ pub const sem_t = ?*opaque {};...@@ -92,3 +93,1341 @@ pub const sem_t = ?*opaque {};
9293
93pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*c_void) E;94pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*c_void) E;
94pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;95pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
96
97pub const clock_getres = __clock_getres50;
98pub const clock_gettime = __clock_gettime50;
99pub const fstat = __fstat50;
100pub const getdents = __getdents30;
101pub const getrusage = __getrusage50;
102pub const gettimeofday = __gettimeofday50;
103pub const nanosleep = __nanosleep50;
104pub const sched_yield = __libc_thr_yield;
105pub const sigaction = __sigaction14;
106pub const sigaltstack = __sigaltstack14;
107pub const sigprocmask = __sigprocmask14;
108pub const socket = __socket30;
109pub const stat = __stat50;
110
111pub const blkcnt_t = i64;
112pub const blksize_t = i32;
113pub const clock_t = u32;
114pub const dev_t = u64;
115pub const fd_t = i32;
116pub const gid_t = u32;
117pub const ino_t = u64;
118pub const mode_t = u32;
119pub const nlink_t = u32;
120pub const off_t = i64;
121pub const pid_t = i32;
122pub const socklen_t = u32;
123pub const time_t = i64;
124pub const uid_t = u32;
125pub const lwpid_t = i32;
126pub const suseconds_t = c_int;
127
128/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
129pub const Kevent = extern struct {
130 ident: usize,
131 filter: i32,
132 flags: u32,
133 fflags: u32,
134 data: i64,
135 udata: usize,
136};
137
138pub const RTLD_LAZY = 1;
139pub const RTLD_NOW = 2;
140pub const RTLD_GLOBAL = 0x100;
141pub const RTLD_LOCAL = 0x200;
142pub const RTLD_NODELETE = 0x01000;
143pub const RTLD_NOLOAD = 0x02000;
144
145pub const RTLD_NEXT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -1)));
146pub const RTLD_DEFAULT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -2)));
147pub const RTLD_SELF = @intToPtr(*c_void, @bitCast(usize, @as(isize, -3)));
148
149pub const dl_phdr_info = extern struct {
150 dlpi_addr: usize,
151 dlpi_name: ?[*:0]const u8,
152 dlpi_phdr: [*]std.elf.Phdr,
153 dlpi_phnum: u16,
154};
155
156pub const Flock = extern struct {
157 l_start: off_t,
158 l_len: off_t,
159 l_pid: pid_t,
160 l_type: i16,
161 l_whence: i16,
162};
163
164pub const addrinfo = extern struct {
165 flags: i32,
166 family: i32,
167 socktype: i32,
168 protocol: i32,
169 addrlen: socklen_t,
170 canonname: ?[*:0]u8,
171 addr: ?*sockaddr,
172 next: ?*addrinfo,
173};
174
175pub const EAI = enum(c_int) {
176 /// address family for hostname not supported
177 ADDRFAMILY = 1,
178
179 /// name could not be resolved at this time
180 AGAIN = 2,
181
182 /// flags parameter had an invalid value
183 BADFLAGS = 3,
184
185 /// non-recoverable failure in name resolution
186 FAIL = 4,
187
188 /// address family not recognized
189 FAMILY = 5,
190
191 /// memory allocation failure
192 MEMORY = 6,
193
194 /// no address associated with hostname
195 NODATA = 7,
196
197 /// name does not resolve
198 NONAME = 8,
199
200 /// service not recognized for socket type
201 SERVICE = 9,
202
203 /// intended socket type was not recognized
204 SOCKTYPE = 10,
205
206 /// system error returned in errno
207 SYSTEM = 11,
208
209 /// invalid value for hints
210 BADHINTS = 12,
211
212 /// resolved protocol is unknown
213 PROTOCOL = 13,
214
215 /// argument buffer overflow
216 OVERFLOW = 14,
217
218 _,
219};
220
221pub const EAI_MAX = 15;
222
223pub const msghdr = extern struct {
224 /// optional address
225 msg_name: ?*sockaddr,
226
227 /// size of address
228 msg_namelen: socklen_t,
229
230 /// scatter/gather array
231 msg_iov: [*]iovec,
232
233 /// # elements in msg_iov
234 msg_iovlen: i32,
235
236 /// ancillary data
237 msg_control: ?*c_void,
238
239 /// ancillary data buffer len
240 msg_controllen: socklen_t,
241
242 /// flags on received message
243 msg_flags: i32,
244};
245
246pub const msghdr_const = extern struct {
247 /// optional address
248 msg_name: ?*const sockaddr,
249
250 /// size of address
251 msg_namelen: socklen_t,
252
253 /// scatter/gather array
254 msg_iov: [*]iovec_const,
255
256 /// # elements in msg_iov
257 msg_iovlen: i32,
258
259 /// ancillary data
260 msg_control: ?*c_void,
261
262 /// ancillary data buffer len
263 msg_controllen: socklen_t,
264
265 /// flags on received message
266 msg_flags: i32,
267};
268
269/// The stat structure used by libc.
270pub const Stat = extern struct {
271 dev: dev_t,
272 mode: mode_t,
273 ino: ino_t,
274 nlink: nlink_t,
275 uid: uid_t,
276 gid: gid_t,
277 rdev: dev_t,
278 atim: timespec,
279 mtim: timespec,
280 ctim: timespec,
281 birthtim: timespec,
282 size: off_t,
283 blocks: blkcnt_t,
284 blksize: blksize_t,
285 flags: u32,
286 gen: u32,
287 __spare: [2]u32,
288
289 pub fn atime(self: @This()) timespec {
290 return self.atim;
291 }
292
293 pub fn mtime(self: @This()) timespec {
294 return self.mtim;
295 }
296
297 pub fn ctime(self: @This()) timespec {
298 return self.ctim;
299 }
300};
301
302pub const timespec = extern struct {
303 tv_sec: i64,
304 tv_nsec: isize,
305};
306
307pub const timeval = extern struct {
308 /// seconds
309 tv_sec: time_t,
310 /// microseconds
311 tv_usec: suseconds_t,
312};
313
314pub const MAXNAMLEN = 511;
315
316pub const dirent = extern struct {
317 d_fileno: ino_t,
318 d_reclen: u16,
319 d_namlen: u16,
320 d_type: u8,
321 d_name: [MAXNAMLEN:0]u8,
322
323 pub fn reclen(self: dirent) u16 {
324 return self.d_reclen;
325 }
326};
327
328pub const SOCK_STREAM = 1;
329pub const SOCK_DGRAM = 2;
330pub const SOCK_RAW = 3;
331pub const SOCK_RDM = 4;
332pub const SOCK_SEQPACKET = 5;
333pub const SOCK_CONN_DGRAM = 6;
334pub const SOCK_DCCP = SOCK_CONN_DGRAM;
335
336pub const SOCK_CLOEXEC = 0x10000000;
337pub const SOCK_NONBLOCK = 0x20000000;
338pub const SOCK_NOSIGPIPE = 0x40000000;
339pub const SOCK_FLAGS_MASK = 0xf0000000;
340
341pub const SO_DEBUG = 0x0001;
342pub const SO_ACCEPTCONN = 0x0002;
343pub const SO_REUSEADDR = 0x0004;
344pub const SO_KEEPALIVE = 0x0008;
345pub const SO_DONTROUTE = 0x0010;
346pub const SO_BROADCAST = 0x0020;
347pub const SO_USELOOPBACK = 0x0040;
348pub const SO_LINGER = 0x0080;
349pub const SO_OOBINLINE = 0x0100;
350pub const SO_REUSEPORT = 0x0200;
351pub const SO_NOSIGPIPE = 0x0800;
352pub const SO_ACCEPTFILTER = 0x1000;
353pub const SO_TIMESTAMP = 0x2000;
354pub const SO_RERROR = 0x4000;
355
356pub const SO_SNDBUF = 0x1001;
357pub const SO_RCVBUF = 0x1002;
358pub const SO_SNDLOWAT = 0x1003;
359pub const SO_RCVLOWAT = 0x1004;
360pub const SO_ERROR = 0x1007;
361pub const SO_TYPE = 0x1008;
362pub const SO_OVERFLOWED = 0x1009;
363
364pub const SO_NOHEADER = 0x100a;
365pub const SO_SNDTIMEO = 0x100b;
366pub const SO_RCVTIMEO = 0x100c;
367
368pub const SOL_SOCKET = 0xffff;
369
370pub const PF_UNSPEC = AF_UNSPEC;
371pub const PF_LOCAL = AF_LOCAL;
372pub const PF_UNIX = PF_LOCAL;
373pub const PF_INET = AF_INET;
374pub const PF_IMPLINK = AF_IMPLINK;
375pub const PF_PUP = AF_PUP;
376pub const PF_CHAOS = AF_CHAOS;
377pub const PF_NS = AF_NS;
378pub const PF_ISO = AF_ISO;
379pub const PF_OSI = AF_ISO;
380pub const PF_ECMA = AF_ECMA;
381pub const PF_DATAKIT = AF_DATAKIT;
382pub const PF_CCITT = AF_CCITT;
383pub const PF_SNA = AF_SNA;
384pub const PF_DECnet = AF_DECnet;
385pub const PF_DLI = AF_DLI;
386pub const PF_LAT = AF_LAT;
387pub const PF_HYLINK = AF_HYLINK;
388pub const PF_APPLETALK = AF_APPLETALK;
389pub const PF_OROUTE = AF_OROUTE;
390pub const PF_LINK = AF_LINK;
391pub const PF_COIP = AF_COIP;
392pub const PF_CNT = AF_CNT;
393pub const PF_INET6 = AF_INET6;
394pub const PF_IPX = AF_IPX;
395pub const PF_ISDN = AF_ISDN;
396pub const PF_E164 = AF_E164;
397pub const PF_NATM = AF_NATM;
398pub const PF_ARP = AF_ARP;
399pub const PF_BLUETOOTH = AF_BLUETOOTH;
400pub const PF_MPLS = AF_MPLS;
401pub const PF_ROUTE = AF_ROUTE;
402pub const PF_CAN = AF_CAN;
403pub const PF_ETHER = AF_ETHER;
404pub const PF_MAX = AF_MAX;
405
406pub const AF_UNSPEC = 0;
407pub const AF_LOCAL = 1;
408pub const AF_UNIX = AF_LOCAL;
409pub const AF_INET = 2;
410pub const AF_IMPLINK = 3;
411pub const AF_PUP = 4;
412pub const AF_CHAOS = 5;
413pub const AF_NS = 6;
414pub const AF_ISO = 7;
415pub const AF_OSI = AF_ISO;
416pub const AF_ECMA = 8;
417pub const AF_DATAKIT = 9;
418pub const AF_CCITT = 10;
419pub const AF_SNA = 11;
420pub const AF_DECnet = 12;
421pub const AF_DLI = 13;
422pub const AF_LAT = 14;
423pub const AF_HYLINK = 15;
424pub const AF_APPLETALK = 16;
425pub const AF_OROUTE = 17;
426pub const AF_LINK = 18;
427pub const AF_COIP = 20;
428pub const AF_CNT = 21;
429pub const AF_IPX = 23;
430pub const AF_INET6 = 24;
431pub const AF_ISDN = 26;
432pub const AF_E164 = AF_ISDN;
433pub const AF_NATM = 27;
434pub const AF_ARP = 28;
435pub const AF_BLUETOOTH = 31;
436pub const AF_IEEE80211 = 32;
437pub const AF_MPLS = 33;
438pub const AF_ROUTE = 34;
439pub const AF_CAN = 35;
440pub const AF_ETHER = 36;
441pub const AF_MAX = 37;
442
443pub const in_port_t = u16;
444pub const sa_family_t = u8;
445
446pub const sockaddr = extern struct {
447 /// total length
448 len: u8,
449
450 /// address family
451 family: sa_family_t,
452
453 /// actually longer; address value
454 data: [14]u8,
455};
456
457pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
458
459pub const sockaddr_in = extern struct {
460 len: u8 = @sizeOf(sockaddr_in),
461 family: sa_family_t = AF_INET,
462 port: in_port_t,
463 addr: u32,
464 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
465};
466
467pub const sockaddr_in6 = extern struct {
468 len: u8 = @sizeOf(sockaddr_in6),
469 family: sa_family_t = AF_INET6,
470 port: in_port_t,
471 flowinfo: u32,
472 addr: [16]u8,
473 scope_id: u32,
474};
475
476/// Definitions for UNIX IPC domain.
477pub const sockaddr_un = extern struct {
478 /// total sockaddr length
479 len: u8 = @sizeOf(sockaddr_un),
480
481 /// AF_LOCAL
482 family: sa_family_t = AF_LOCAL,
483
484 /// path name
485 path: [104]u8,
486};
487
488/// get address to use bind()
489pub const AI_PASSIVE = 0x00000001;
490
491/// fill ai_canonname
492pub const AI_CANONNAME = 0x00000002;
493
494/// prevent host name resolution
495pub const AI_NUMERICHOST = 0x00000004;
496
497/// prevent service name resolution
498pub const AI_NUMERICSERV = 0x00000008;
499
500/// only if any address is assigned
501pub const AI_ADDRCONFIG = 0x00000400;
502
503pub const CTL_KERN = 1;
504pub const CTL_DEBUG = 5;
505
506pub const KERN_PROC_ARGS = 48; // struct: process argv/env
507pub const KERN_PROC_PATHNAME = 5; // path to executable
508pub const KERN_IOV_MAX = 38;
509
510pub const PATH_MAX = 1024;
511pub const IOV_MAX = KERN_IOV_MAX;
512
513pub const STDIN_FILENO = 0;
514pub const STDOUT_FILENO = 1;
515pub const STDERR_FILENO = 2;
516
517pub const PROT_NONE = 0;
518pub const PROT_READ = 1;
519pub const PROT_WRITE = 2;
520pub const PROT_EXEC = 4;
521
522pub const CLOCK_REALTIME = 0;
523pub const CLOCK_VIRTUAL = 1;
524pub const CLOCK_PROF = 2;
525pub const CLOCK_MONOTONIC = 3;
526pub const CLOCK_THREAD_CPUTIME_ID = 0x20000000;
527pub const CLOCK_PROCESS_CPUTIME_ID = 0x40000000;
528
529pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
530pub const MAP_SHARED = 0x0001;
531pub const MAP_PRIVATE = 0x0002;
532pub const MAP_REMAPDUP = 0x0004;
533pub const MAP_FIXED = 0x0010;
534pub const MAP_RENAME = 0x0020;
535pub const MAP_NORESERVE = 0x0040;
536pub const MAP_INHERIT = 0x0080;
537pub const MAP_HASSEMAPHORE = 0x0200;
538pub const MAP_TRYFIXED = 0x0400;
539pub const MAP_WIRED = 0x0800;
540
541pub const MAP_FILE = 0x0000;
542pub const MAP_NOSYNC = 0x0800;
543pub const MAP_ANON = 0x1000;
544pub const MAP_ANONYMOUS = MAP_ANON;
545pub const MAP_STACK = 0x2000;
546
547pub const WNOHANG = 0x00000001;
548pub const WUNTRACED = 0x00000002;
549pub const WSTOPPED = WUNTRACED;
550pub const WCONTINUED = 0x00000010;
551pub const WNOWAIT = 0x00010000;
552pub const WEXITED = 0x00000020;
553pub const WTRAPPED = 0x00000040;
554
555pub const SA_ONSTACK = 0x0001;
556pub const SA_RESTART = 0x0002;
557pub const SA_RESETHAND = 0x0004;
558pub const SA_NOCLDSTOP = 0x0008;
559pub const SA_NODEFER = 0x0010;
560pub const SA_NOCLDWAIT = 0x0020;
561pub const SA_SIGINFO = 0x0040;
562
563pub const SIGHUP = 1;
564pub const SIGINT = 2;
565pub const SIGQUIT = 3;
566pub const SIGILL = 4;
567pub const SIGTRAP = 5;
568pub const SIGABRT = 6;
569pub const SIGIOT = SIGABRT;
570pub const SIGEMT = 7;
571pub const SIGFPE = 8;
572pub const SIGKILL = 9;
573pub const SIGBUS = 10;
574pub const SIGSEGV = 11;
575pub const SIGSYS = 12;
576pub const SIGPIPE = 13;
577pub const SIGALRM = 14;
578pub const SIGTERM = 15;
579pub const SIGURG = 16;
580pub const SIGSTOP = 17;
581pub const SIGTSTP = 18;
582pub const SIGCONT = 19;
583pub const SIGCHLD = 20;
584pub const SIGTTIN = 21;
585pub const SIGTTOU = 22;
586pub const SIGIO = 23;
587pub const SIGXCPU = 24;
588pub const SIGXFSZ = 25;
589pub const SIGVTALRM = 26;
590pub const SIGPROF = 27;
591pub const SIGWINCH = 28;
592pub const SIGINFO = 29;
593pub const SIGUSR1 = 30;
594pub const SIGUSR2 = 31;
595pub const SIGPWR = 32;
596
597pub const SIGRTMIN = 33;
598pub const SIGRTMAX = 63;
599
600// access function
601pub const F_OK = 0; // test for existence of file
602pub const X_OK = 1; // test for execute or search permission
603pub const W_OK = 2; // test for write permission
604pub const R_OK = 4; // test for read permission
605
606/// open for reading only
607pub const O_RDONLY = 0x00000000;
608
609/// open for writing only
610pub const O_WRONLY = 0x00000001;
611
612/// open for reading and writing
613pub const O_RDWR = 0x00000002;
614
615/// mask for above modes
616pub const O_ACCMODE = 0x00000003;
617
618/// no delay
619pub const O_NONBLOCK = 0x00000004;
620
621/// set append mode
622pub const O_APPEND = 0x00000008;
623
624/// open with shared file lock
625pub const O_SHLOCK = 0x00000010;
626
627/// open with exclusive file lock
628pub const O_EXLOCK = 0x00000020;
629
630/// signal pgrp when data ready
631pub const O_ASYNC = 0x00000040;
632
633/// synchronous writes
634pub const O_SYNC = 0x00000080;
635
636/// don't follow symlinks on the last
637pub const O_NOFOLLOW = 0x00000100;
638
639/// create if nonexistent
640pub const O_CREAT = 0x00000200;
641
642/// truncate to zero length
643pub const O_TRUNC = 0x00000400;
644
645/// error if already exists
646pub const O_EXCL = 0x00000800;
647
648/// don't assign controlling terminal
649pub const O_NOCTTY = 0x00008000;
650
651/// write: I/O data completion
652pub const O_DSYNC = 0x00010000;
653
654/// read: I/O completion as for write
655pub const O_RSYNC = 0x00020000;
656
657/// use alternate i/o semantics
658pub const O_ALT_IO = 0x00040000;
659
660/// direct I/O hint
661pub const O_DIRECT = 0x00080000;
662
663/// fail if not a directory
664pub const O_DIRECTORY = 0x00200000;
665
666/// set close on exec
667pub const O_CLOEXEC = 0x00400000;
668
669/// skip search permission checks
670pub const O_SEARCH = 0x00800000;
671
672pub const F_DUPFD = 0;
673pub const F_GETFD = 1;
674pub const F_SETFD = 2;
675pub const F_GETFL = 3;
676pub const F_SETFL = 4;
677
678pub const F_GETOWN = 5;
679pub const F_SETOWN = 6;
680
681pub const F_GETLK = 7;
682pub const F_SETLK = 8;
683pub const F_SETLKW = 9;
684
685pub const F_RDLCK = 1;
686pub const F_WRLCK = 3;
687pub const F_UNLCK = 2;
688
689pub const LOCK_SH = 1;
690pub const LOCK_EX = 2;
691pub const LOCK_UN = 8;
692pub const LOCK_NB = 4;
693
694pub const FD_CLOEXEC = 1;
695
696pub const SEEK_SET = 0;
697pub const SEEK_CUR = 1;
698pub const SEEK_END = 2;
699
700pub const SIG_BLOCK = 1;
701pub const SIG_UNBLOCK = 2;
702pub const SIG_SETMASK = 3;
703
704pub const DT_UNKNOWN = 0;
705pub const DT_FIFO = 1;
706pub const DT_CHR = 2;
707pub const DT_DIR = 4;
708pub const DT_BLK = 6;
709pub const DT_REG = 8;
710pub const DT_LNK = 10;
711pub const DT_SOCK = 12;
712pub const DT_WHT = 14;
713
714/// add event to kq (implies enable)
715pub const EV_ADD = 0x0001;
716
717/// delete event from kq
718pub const EV_DELETE = 0x0002;
719
720/// enable event
721pub const EV_ENABLE = 0x0004;
722
723/// disable event (not reported)
724pub const EV_DISABLE = 0x0008;
725
726/// only report one occurrence
727pub const EV_ONESHOT = 0x0010;
728
729/// clear event state after reporting
730pub const EV_CLEAR = 0x0020;
731
732/// force immediate event output
733/// ... with or without EV_ERROR
734/// ... use KEVENT_FLAG_ERROR_EVENTS
735/// on syscalls supporting flags
736pub const EV_RECEIPT = 0x0040;
737
738/// disable event after reporting
739pub const EV_DISPATCH = 0x0080;
740
741pub const EVFILT_READ = 0;
742pub const EVFILT_WRITE = 1;
743
744/// attached to aio requests
745pub const EVFILT_AIO = 2;
746
747/// attached to vnodes
748pub const EVFILT_VNODE = 3;
749
750/// attached to struct proc
751pub const EVFILT_PROC = 4;
752
753/// attached to struct proc
754pub const EVFILT_SIGNAL = 5;
755
756/// timers
757pub const EVFILT_TIMER = 6;
758
759/// Filesystem events
760pub const EVFILT_FS = 7;
761
762/// On input, NOTE_TRIGGER causes the event to be triggered for output.
763pub const NOTE_TRIGGER = 0x08000000;
764
765/// low water mark
766pub const NOTE_LOWAT = 0x00000001;
767
768/// vnode was removed
769pub const NOTE_DELETE = 0x00000001;
770
771/// data contents changed
772pub const NOTE_WRITE = 0x00000002;
773
774/// size increased
775pub const NOTE_EXTEND = 0x00000004;
776
777/// attributes changed
778pub const NOTE_ATTRIB = 0x00000008;
779
780/// link count changed
781pub const NOTE_LINK = 0x00000010;
782
783/// vnode was renamed
784pub const NOTE_RENAME = 0x00000020;
785
786/// vnode access was revoked
787pub const NOTE_REVOKE = 0x00000040;
788
789/// process exited
790pub const NOTE_EXIT = 0x80000000;
791
792/// process forked
793pub const NOTE_FORK = 0x40000000;
794
795/// process exec'd
796pub const NOTE_EXEC = 0x20000000;
797
798/// mask for signal & exit status
799pub const NOTE_PDATAMASK = 0x000fffff;
800pub const NOTE_PCTRLMASK = 0xf0000000;
801
802pub const TIOCCBRK = 0x2000747a;
803pub const TIOCCDTR = 0x20007478;
804pub const TIOCCONS = 0x80047462;
805pub const TIOCDCDTIMESTAMP = 0x40107458;
806pub const TIOCDRAIN = 0x2000745e;
807pub const TIOCEXCL = 0x2000740d;
808pub const TIOCEXT = 0x80047460;
809pub const TIOCFLAG_CDTRCTS = 0x10;
810pub const TIOCFLAG_CLOCAL = 0x2;
811pub const TIOCFLAG_CRTSCTS = 0x4;
812pub const TIOCFLAG_MDMBUF = 0x8;
813pub const TIOCFLAG_SOFTCAR = 0x1;
814pub const TIOCFLUSH = 0x80047410;
815pub const TIOCGETA = 0x402c7413;
816pub const TIOCGETD = 0x4004741a;
817pub const TIOCGFLAGS = 0x4004745d;
818pub const TIOCGLINED = 0x40207442;
819pub const TIOCGPGRP = 0x40047477;
820pub const TIOCGQSIZE = 0x40047481;
821pub const TIOCGRANTPT = 0x20007447;
822pub const TIOCGSID = 0x40047463;
823pub const TIOCGSIZE = 0x40087468;
824pub const TIOCGWINSZ = 0x40087468;
825pub const TIOCMBIC = 0x8004746b;
826pub const TIOCMBIS = 0x8004746c;
827pub const TIOCMGET = 0x4004746a;
828pub const TIOCMSET = 0x8004746d;
829pub const TIOCM_CAR = 0x40;
830pub const TIOCM_CD = 0x40;
831pub const TIOCM_CTS = 0x20;
832pub const TIOCM_DSR = 0x100;
833pub const TIOCM_DTR = 0x2;
834pub const TIOCM_LE = 0x1;
835pub const TIOCM_RI = 0x80;
836pub const TIOCM_RNG = 0x80;
837pub const TIOCM_RTS = 0x4;
838pub const TIOCM_SR = 0x10;
839pub const TIOCM_ST = 0x8;
840pub const TIOCNOTTY = 0x20007471;
841pub const TIOCNXCL = 0x2000740e;
842pub const TIOCOUTQ = 0x40047473;
843pub const TIOCPKT = 0x80047470;
844pub const TIOCPKT_DATA = 0x0;
845pub const TIOCPKT_DOSTOP = 0x20;
846pub const TIOCPKT_FLUSHREAD = 0x1;
847pub const TIOCPKT_FLUSHWRITE = 0x2;
848pub const TIOCPKT_IOCTL = 0x40;
849pub const TIOCPKT_NOSTOP = 0x10;
850pub const TIOCPKT_START = 0x8;
851pub const TIOCPKT_STOP = 0x4;
852pub const TIOCPTMGET = 0x40287446;
853pub const TIOCPTSNAME = 0x40287448;
854pub const TIOCRCVFRAME = 0x80087445;
855pub const TIOCREMOTE = 0x80047469;
856pub const TIOCSBRK = 0x2000747b;
857pub const TIOCSCTTY = 0x20007461;
858pub const TIOCSDTR = 0x20007479;
859pub const TIOCSETA = 0x802c7414;
860pub const TIOCSETAF = 0x802c7416;
861pub const TIOCSETAW = 0x802c7415;
862pub const TIOCSETD = 0x8004741b;
863pub const TIOCSFLAGS = 0x8004745c;
864pub const TIOCSIG = 0x2000745f;
865pub const TIOCSLINED = 0x80207443;
866pub const TIOCSPGRP = 0x80047476;
867pub const TIOCSQSIZE = 0x80047480;
868pub const TIOCSSIZE = 0x80087467;
869pub const TIOCSTART = 0x2000746e;
870pub const TIOCSTAT = 0x80047465;
871pub const TIOCSTI = 0x80017472;
872pub const TIOCSTOP = 0x2000746f;
873pub const TIOCSWINSZ = 0x80087467;
874pub const TIOCUCNTL = 0x80047466;
875pub const TIOCXMTFRAME = 0x80087444;
876
877pub fn WEXITSTATUS(s: u32) u8 {
878 return @intCast(u8, (s >> 8) & 0xff);
879}
880pub fn WTERMSIG(s: u32) u32 {
881 return s & 0x7f;
882}
883pub fn WSTOPSIG(s: u32) u32 {
884 return WEXITSTATUS(s);
885}
886pub fn WIFEXITED(s: u32) bool {
887 return WTERMSIG(s) == 0;
888}
889
890pub fn WIFCONTINUED(s: u32) bool {
891 return ((s & 0x7f) == 0xffff);
892}
893
894pub fn WIFSTOPPED(s: u32) bool {
895 return ((s & 0x7f != 0x7f) and !WIFCONTINUED(s));
896}
897
898pub fn WIFSIGNALED(s: u32) bool {
899 return !WIFSTOPPED(s) and !WIFCONTINUED(s) and !WIFEXITED(s);
900}
901
902pub const winsize = extern struct {
903 ws_row: u16,
904 ws_col: u16,
905 ws_xpixel: u16,
906 ws_ypixel: u16,
907};
908
909const NSIG = 32;
910
911pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
912pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
913pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
914
915/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
916pub const Sigaction = extern struct {
917 pub const handler_fn = fn (c_int) callconv(.C) void;
918 pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void;
919
920 /// signal handler
921 handler: extern union {
922 handler: ?handler_fn,
923 sigaction: ?sigaction_fn,
924 },
925 /// signal mask to apply
926 mask: sigset_t,
927 /// signal options
928 flags: c_uint,
929};
930
931pub const sigval_t = extern union {
932 int: i32,
933 ptr: ?*c_void,
934};
935
936pub const siginfo_t = extern union {
937 pad: [128]u8,
938 info: _ksiginfo,
939};
940
941pub const _ksiginfo = extern struct {
942 signo: i32,
943 code: i32,
944 errno: i32,
945 // 64bit architectures insert 4bytes of padding here, this is done by
946 // correctly aligning the reason field
947 reason: extern union {
948 rt: extern struct {
949 pid: pid_t,
950 uid: uid_t,
951 value: sigval_t,
952 },
953 child: extern struct {
954 pid: pid_t,
955 uid: uid_t,
956 status: i32,
957 utime: clock_t,
958 stime: clock_t,
959 },
960 fault: extern struct {
961 addr: ?*c_void,
962 trap: i32,
963 trap2: i32,
964 trap3: i32,
965 },
966 poll: extern struct {
967 band: i32,
968 fd: i32,
969 },
970 syscall: extern struct {
971 sysnum: i32,
972 retval: [2]i32,
973 @"error": i32,
974 args: [8]u64,
975 },
976 ptrace_state: extern struct {
977 pe_report_event: i32,
978 option: extern union {
979 pe_other_pid: pid_t,
980 pe_lwp: lwpid_t,
981 },
982 },
983 } align(@sizeOf(usize)),
984};
985
986pub const _SIG_WORDS = 4;
987pub const _SIG_MAXSIG = 128;
988
989pub inline fn _SIG_IDX(sig: usize) usize {
990 return sig - 1;
991}
992pub inline fn _SIG_WORD(sig: usize) usize {
993 return_SIG_IDX(sig) >> 5;
994}
995pub inline fn _SIG_BIT(sig: usize) usize {
996 return 1 << (_SIG_IDX(sig) & 31);
997}
998pub inline fn _SIG_VALID(sig: usize) usize {
999 return sig <= _SIG_MAXSIG and sig > 0;
1000}
1001
1002pub const sigset_t = extern struct {
1003 __bits: [_SIG_WORDS]u32,
1004};
1005
1006pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** _SIG_WORDS };
1007
1008// XXX x86_64 specific
1009pub const mcontext_t = extern struct {
1010 gregs: [26]u64,
1011 mc_tlsbase: u64,
1012 fpregs: [512]u8 align(8),
1013};
1014
1015pub const REG_RBP = 12;
1016pub const REG_RIP = 21;
1017pub const REG_RSP = 24;
1018
1019pub const ucontext_t = extern struct {
1020 flags: u32,
1021 link: ?*ucontext_t,
1022 sigmask: sigset_t,
1023 stack: stack_t,
1024 mcontext: mcontext_t,
1025 __pad: [
1026 switch (builtin.cpu.arch) {
1027 .i386 => 4,
1028 .mips, .mipsel, .mips64, .mips64el => 14,
1029 .arm, .armeb, .thumb, .thumbeb => 1,
1030 .sparc, .sparcel, .sparcv9 => if (@sizeOf(usize) == 4) 43 else 8,
1031 else => 0,
1032 }
1033 ]u32,
1034};
1035
1036pub const E = enum(u16) {
1037 /// No error occurred.
1038 SUCCESS = 0,
1039 PERM = 1, // Operation not permitted
1040 NOENT = 2, // No such file or directory
1041 SRCH = 3, // No such process
1042 INTR = 4, // Interrupted system call
1043 IO = 5, // Input/output error
1044 NXIO = 6, // Device not configured
1045 @"2BIG" = 7, // Argument list too long
1046 NOEXEC = 8, // Exec format error
1047 BADF = 9, // Bad file descriptor
1048 CHILD = 10, // No child processes
1049 DEADLK = 11, // Resource deadlock avoided
1050 // 11 was AGAIN
1051 NOMEM = 12, // Cannot allocate memory
1052 ACCES = 13, // Permission denied
1053 FAULT = 14, // Bad address
1054 NOTBLK = 15, // Block device required
1055 BUSY = 16, // Device busy
1056 EXIST = 17, // File exists
1057 XDEV = 18, // Cross-device link
1058 NODEV = 19, // Operation not supported by device
1059 NOTDIR = 20, // Not a directory
1060 ISDIR = 21, // Is a directory
1061 INVAL = 22, // Invalid argument
1062 NFILE = 23, // Too many open files in system
1063 MFILE = 24, // Too many open files
1064 NOTTY = 25, // Inappropriate ioctl for device
1065 TXTBSY = 26, // Text file busy
1066 FBIG = 27, // File too large
1067 NOSPC = 28, // No space left on device
1068 SPIPE = 29, // Illegal seek
1069 ROFS = 30, // Read-only file system
1070 MLINK = 31, // Too many links
1071 PIPE = 32, // Broken pipe
1072
1073 // math software
1074 DOM = 33, // Numerical argument out of domain
1075 RANGE = 34, // Result too large or too small
1076
1077 // non-blocking and interrupt i/o
1078 // also: WOULDBLOCK: operation would block
1079 AGAIN = 35, // Resource temporarily unavailable
1080 INPROGRESS = 36, // Operation now in progress
1081 ALREADY = 37, // Operation already in progress
1082
1083 // ipc/network software -- argument errors
1084 NOTSOCK = 38, // Socket operation on non-socket
1085 DESTADDRREQ = 39, // Destination address required
1086 MSGSIZE = 40, // Message too long
1087 PROTOTYPE = 41, // Protocol wrong type for socket
1088 NOPROTOOPT = 42, // Protocol option not available
1089 PROTONOSUPPORT = 43, // Protocol not supported
1090 SOCKTNOSUPPORT = 44, // Socket type not supported
1091 OPNOTSUPP = 45, // Operation not supported
1092 PFNOSUPPORT = 46, // Protocol family not supported
1093 AFNOSUPPORT = 47, // Address family not supported by protocol family
1094 ADDRINUSE = 48, // Address already in use
1095 ADDRNOTAVAIL = 49, // Can't assign requested address
1096
1097 // ipc/network software -- operational errors
1098 NETDOWN = 50, // Network is down
1099 NETUNREACH = 51, // Network is unreachable
1100 NETRESET = 52, // Network dropped connection on reset
1101 CONNABORTED = 53, // Software caused connection abort
1102 CONNRESET = 54, // Connection reset by peer
1103 NOBUFS = 55, // No buffer space available
1104 ISCONN = 56, // Socket is already connected
1105 NOTCONN = 57, // Socket is not connected
1106 SHUTDOWN = 58, // Can't send after socket shutdown
1107 TOOMANYREFS = 59, // Too many references: can't splice
1108 TIMEDOUT = 60, // Operation timed out
1109 CONNREFUSED = 61, // Connection refused
1110
1111 LOOP = 62, // Too many levels of symbolic links
1112 NAMETOOLONG = 63, // File name too long
1113
1114 // should be rearranged
1115 HOSTDOWN = 64, // Host is down
1116 HOSTUNREACH = 65, // No route to host
1117 NOTEMPTY = 66, // Directory not empty
1118
1119 // quotas & mush
1120 PROCLIM = 67, // Too many processes
1121 USERS = 68, // Too many users
1122 DQUOT = 69, // Disc quota exceeded
1123
1124 // Network File System
1125 STALE = 70, // Stale NFS file handle
1126 REMOTE = 71, // Too many levels of remote in path
1127 BADRPC = 72, // RPC struct is bad
1128 RPCMISMATCH = 73, // RPC version wrong
1129 PROGUNAVAIL = 74, // RPC prog. not avail
1130 PROGMISMATCH = 75, // Program version wrong
1131 PROCUNAVAIL = 76, // Bad procedure for program
1132
1133 NOLCK = 77, // No locks available
1134 NOSYS = 78, // Function not implemented
1135
1136 FTYPE = 79, // Inappropriate file type or format
1137 AUTH = 80, // Authentication error
1138 NEEDAUTH = 81, // Need authenticator
1139
1140 // SystemV IPC
1141 IDRM = 82, // Identifier removed
1142 NOMSG = 83, // No message of desired type
1143 OVERFLOW = 84, // Value too large to be stored in data type
1144
1145 // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
1146 ILSEQ = 85, // Illegal byte sequence
1147
1148 // From IEEE Std 1003.1-2001
1149 // Base, Realtime, Threads or Thread Priority Scheduling option errors
1150 NOTSUP = 86, // Not supported
1151
1152 // Realtime option errors
1153 CANCELED = 87, // Operation canceled
1154
1155 // Realtime, XSI STREAMS option errors
1156 BADMSG = 88, // Bad or Corrupt message
1157
1158 // XSI STREAMS option errors
1159 NODATA = 89, // No message available
1160 NOSR = 90, // No STREAM resources
1161 NOSTR = 91, // Not a STREAM
1162 TIME = 92, // STREAM ioctl timeout
1163
1164 // File system extended attribute errors
1165 NOATTR = 93, // Attribute not found
1166
1167 // Realtime, XSI STREAMS option errors
1168 MULTIHOP = 94, // Multihop attempted
1169 NOLINK = 95, // Link has been severed
1170 PROTO = 96, // Protocol error
1171
1172 _,
1173};
1174
1175pub const MINSIGSTKSZ = 8192;
1176pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
1177
1178pub const SS_ONSTACK = 1;
1179pub const SS_DISABLE = 4;
1180
1181pub const stack_t = extern struct {
1182 ss_sp: [*]u8,
1183 ss_size: isize,
1184 ss_flags: i32,
1185};
1186
1187pub const S_IFMT = 0o170000;
1188
1189pub const S_IFIFO = 0o010000;
1190pub const S_IFCHR = 0o020000;
1191pub const S_IFDIR = 0o040000;
1192pub const S_IFBLK = 0o060000;
1193pub const S_IFREG = 0o100000;
1194pub const S_IFLNK = 0o120000;
1195pub const S_IFSOCK = 0o140000;
1196pub const S_IFWHT = 0o160000;
1197
1198pub const S_ISUID = 0o4000;
1199pub const S_ISGID = 0o2000;
1200pub const S_ISVTX = 0o1000;
1201pub const S_IRWXU = 0o700;
1202pub const S_IRUSR = 0o400;
1203pub const S_IWUSR = 0o200;
1204pub const S_IXUSR = 0o100;
1205pub const S_IRWXG = 0o070;
1206pub const S_IRGRP = 0o040;
1207pub const S_IWGRP = 0o020;
1208pub const S_IXGRP = 0o010;
1209pub const S_IRWXO = 0o007;
1210pub const S_IROTH = 0o004;
1211pub const S_IWOTH = 0o002;
1212pub const S_IXOTH = 0o001;
1213
1214pub fn S_ISFIFO(m: u32) bool {
1215 return m & S_IFMT == S_IFIFO;
1216}
1217
1218pub fn S_ISCHR(m: u32) bool {
1219 return m & S_IFMT == S_IFCHR;
1220}
1221
1222pub fn S_ISDIR(m: u32) bool {
1223 return m & S_IFMT == S_IFDIR;
1224}
1225
1226pub fn S_ISBLK(m: u32) bool {
1227 return m & S_IFMT == S_IFBLK;
1228}
1229
1230pub fn S_ISREG(m: u32) bool {
1231 return m & S_IFMT == S_IFREG;
1232}
1233
1234pub fn S_ISLNK(m: u32) bool {
1235 return m & S_IFMT == S_IFLNK;
1236}
1237
1238pub fn S_ISSOCK(m: u32) bool {
1239 return m & S_IFMT == S_IFSOCK;
1240}
1241
1242pub fn S_IWHT(m: u32) bool {
1243 return m & S_IFMT == S_IFWHT;
1244}
1245
1246/// Magic value that specify the use of the current working directory
1247/// to determine the target of relative file paths in the openat() and
1248/// similar syscalls.
1249pub const AT_FDCWD = -100;
1250
1251/// Check access using effective user and group ID
1252pub const AT_EACCESS = 0x0100;
1253
1254/// Do not follow symbolic links
1255pub const AT_SYMLINK_NOFOLLOW = 0x0200;
1256
1257/// Follow symbolic link
1258pub const AT_SYMLINK_FOLLOW = 0x0400;
1259
1260/// Remove directory instead of file
1261pub const AT_REMOVEDIR = 0x0800;
1262
1263pub const HOST_NAME_MAX = 255;
1264
1265/// dummy for IP
1266pub const IPPROTO_IP = 0;
1267
1268/// IP6 hop-by-hop options
1269pub const IPPROTO_HOPOPTS = 0;
1270
1271/// control message protocol
1272pub const IPPROTO_ICMP = 1;
1273
1274/// group mgmt protocol
1275pub const IPPROTO_IGMP = 2;
1276
1277/// gateway^2 (deprecated)
1278pub const IPPROTO_GGP = 3;
1279
1280/// IP header
1281pub const IPPROTO_IPV4 = 4;
1282
1283/// IP inside IP
1284pub const IPPROTO_IPIP = 4;
1285
1286/// tcp
1287pub const IPPROTO_TCP = 6;
1288
1289/// exterior gateway protocol
1290pub const IPPROTO_EGP = 8;
1291
1292/// pup
1293pub const IPPROTO_PUP = 12;
1294
1295/// user datagram protocol
1296pub const IPPROTO_UDP = 17;
1297
1298/// xns idp
1299pub const IPPROTO_IDP = 22;
1300
1301/// tp-4 w/ class negotiation
1302pub const IPPROTO_TP = 29;
1303
1304/// DCCP
1305pub const IPPROTO_DCCP = 33;
1306
1307/// IP6 header
1308pub const IPPROTO_IPV6 = 41;
1309
1310/// IP6 routing header
1311pub const IPPROTO_ROUTING = 43;
1312
1313/// IP6 fragmentation header
1314pub const IPPROTO_FRAGMENT = 44;
1315
1316/// resource reservation
1317pub const IPPROTO_RSVP = 46;
1318
1319/// GRE encaps RFC 1701
1320pub const IPPROTO_GRE = 47;
1321
1322/// encap. security payload
1323pub const IPPROTO_ESP = 50;
1324
1325/// authentication header
1326pub const IPPROTO_AH = 51;
1327
1328/// IP Mobility RFC 2004
1329pub const IPPROTO_MOBILE = 55;
1330
1331/// IPv6 ICMP
1332pub const IPPROTO_IPV6_ICMP = 58;
1333
1334/// ICMP6
1335pub const IPPROTO_ICMPV6 = 58;
1336
1337/// IP6 no next header
1338pub const IPPROTO_NONE = 59;
1339
1340/// IP6 destination option
1341pub const IPPROTO_DSTOPTS = 60;
1342
1343/// ISO cnlp
1344pub const IPPROTO_EON = 80;
1345
1346/// Ethernet-in-IP
1347pub const IPPROTO_ETHERIP = 97;
1348
1349/// encapsulation header
1350pub const IPPROTO_ENCAP = 98;
1351
1352/// Protocol indep. multicast
1353pub const IPPROTO_PIM = 103;
1354
1355/// IP Payload Comp. Protocol
1356pub const IPPROTO_IPCOMP = 108;
1357
1358/// VRRP RFC 2338
1359pub const IPPROTO_VRRP = 112;
1360
1361/// Common Address Resolution Protocol
1362pub const IPPROTO_CARP = 112;
1363
1364/// L2TPv3
1365pub const IPPROTO_L2TP = 115;
1366
1367/// SCTP
1368pub const IPPROTO_SCTP = 132;
1369
1370/// PFSYNC
1371pub const IPPROTO_PFSYNC = 240;
1372
1373/// raw IP packet
1374pub const IPPROTO_RAW = 255;
1375
1376pub const rlimit_resource = enum(c_int) {
1377 CPU = 0,
1378 FSIZE = 1,
1379 DATA = 2,
1380 STACK = 3,
1381 CORE = 4,
1382 RSS = 5,
1383 MEMLOCK = 6,
1384 NPROC = 7,
1385 NOFILE = 8,
1386 SBSIZE = 9,
1387 VMEM = 10,
1388 NTHR = 11,
1389 _,
1390
1391 pub const AS: rlimit_resource = .VMEM;
1392};
1393
1394pub const rlim_t = u64;
1395
1396/// No limit
1397pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
1398
1399pub const RLIM_SAVED_MAX = RLIM_INFINITY;
1400pub const RLIM_SAVED_CUR = RLIM_INFINITY;
1401
1402pub const rlimit = extern struct {
1403 /// Soft limit
1404 cur: rlim_t,
1405 /// Hard limit
1406 max: rlim_t,
1407};
1408
1409pub const SHUT_RD = 0;
1410pub const SHUT_WR = 1;
1411pub const SHUT_RDWR = 2;
1412
1413pub const nfds_t = u32;
1414
1415pub const pollfd = extern struct {
1416 fd: fd_t,
1417 events: i16,
1418 revents: i16,
1419};
1420
1421/// Testable events (may be specified in events field).
1422pub const POLLIN = 0x0001;
1423pub const POLLPRI = 0x0002;
1424pub const POLLOUT = 0x0004;
1425pub const POLLRDNORM = 0x0040;
1426pub const POLLWRNORM = POLLOUT;
1427pub const POLLRDBAND = 0x0080;
1428pub const POLLWRBAND = 0x0100;
1429
1430/// Non-testable events (may not be specified in events field).
1431pub const POLLERR = 0x0008;
1432pub const POLLHUP = 0x0010;
1433pub const POLLNVAL = 0x0020;
lib/std/c/openbsd.zig+1327-3
...@@ -1,7 +1,6 @@...@@ -1,7 +1,6 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = std.builtin;2const maxInt = std.math.maxInt;
33const builtin = @import("builtin");
4usingnamespace std.c;
54
6extern "c" fn __errno() *c_int;5extern "c" fn __errno() *c_int;
7pub const _errno = __errno;6pub const _errno = __errno;
...@@ -43,3 +42,1328 @@ pub extern "c" fn unveil(path: ?[*:0]const u8, permissions: ?[*:0]const u8) c_in...@@ -43,3 +42,1328 @@ pub extern "c" fn unveil(path: ?[*:0]const u8, permissions: ?[*:0]const u8) c_in
4342
44pub extern "c" fn pthread_set_name_np(thread: std.c.pthread_t, name: [*:0]const u8) void;43pub extern "c" fn pthread_set_name_np(thread: std.c.pthread_t, name: [*:0]const u8) void;
45pub extern "c" fn pthread_get_name_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) void;44pub extern "c" fn pthread_get_name_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) void;
45
46pub const blkcnt_t = i64;
47pub const blksize_t = i32;
48pub const clock_t = i64;
49pub const dev_t = i32;
50pub const fd_t = c_int;
51pub const gid_t = u32;
52pub const ino_t = u64;
53pub const mode_t = u32;
54pub const nlink_t = u32;
55pub const off_t = i64;
56pub const pid_t = i32;
57pub const socklen_t = u32;
58pub const time_t = i64;
59pub const uid_t = u32;
60
61/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
62pub const Kevent = extern struct {
63 ident: usize,
64 filter: c_short,
65 flags: u16,
66 fflags: c_uint,
67 data: i64,
68 udata: usize,
69};
70
71// Modes and flags for dlopen()
72// include/dlfcn.h
73
74/// Bind function calls lazily.
75pub const RTLD_LAZY = 1;
76
77/// Bind function calls immediately.
78pub const RTLD_NOW = 2;
79
80/// Make symbols globally available.
81pub const RTLD_GLOBAL = 0x100;
82
83/// Opposite of RTLD_GLOBAL, and the default.
84pub const RTLD_LOCAL = 0x000;
85
86/// Trace loaded objects and exit.
87pub const RTLD_TRACE = 0x200;
88
89pub const dl_phdr_info = extern struct {
90 dlpi_addr: std.elf.Addr,
91 dlpi_name: ?[*:0]const u8,
92 dlpi_phdr: [*]std.elf.Phdr,
93 dlpi_phnum: std.elf.Half,
94};
95
96pub const Flock = extern struct {
97 l_start: off_t,
98 l_len: off_t,
99 l_pid: pid_t,
100 l_type: c_short,
101 l_whence: c_short,
102};
103
104pub const addrinfo = extern struct {
105 flags: c_int,
106 family: c_int,
107 socktype: c_int,
108 protocol: c_int,
109 addrlen: socklen_t,
110 addr: ?*sockaddr,
111 canonname: ?[*:0]u8,
112 next: ?*addrinfo,
113};
114
115pub const EAI = enum(c_int) {
116 /// address family for hostname not supported
117 ADDRFAMILY = -9,
118
119 /// name could not be resolved at this time
120 AGAIN = -3,
121
122 /// flags parameter had an invalid value
123 BADFLAGS = -1,
124
125 /// non-recoverable failure in name resolution
126 FAIL = -4,
127
128 /// address family not recognized
129 FAMILY = -6,
130
131 /// memory allocation failure
132 MEMORY = -10,
133
134 /// no address associated with hostname
135 NODATA = -5,
136
137 /// name does not resolve
138 NONAME = -2,
139
140 /// service not recognized for socket type
141 SERVICE = -8,
142
143 /// intended socket type was not recognized
144 SOCKTYPE = -7,
145
146 /// system error returned in errno
147 SYSTEM = -11,
148
149 /// invalid value for hints
150 BADHINTS = -12,
151
152 /// resolved protocol is unknown
153 PROTOCOL = -13,
154
155 /// argument buffer overflow
156 OVERFLOW = -14,
157
158 _,
159};
160
161pub const EAI_MAX = 15;
162
163pub const msghdr = extern struct {
164 /// optional address
165 msg_name: ?*sockaddr,
166
167 /// size of address
168 msg_namelen: socklen_t,
169
170 /// scatter/gather array
171 msg_iov: [*]iovec,
172
173 /// # elements in msg_iov
174 msg_iovlen: c_uint,
175
176 /// ancillary data
177 msg_control: ?*c_void,
178
179 /// ancillary data buffer len
180 msg_controllen: socklen_t,
181
182 /// flags on received message
183 msg_flags: c_int,
184};
185
186pub const msghdr_const = extern struct {
187 /// optional address
188 msg_name: ?*const sockaddr,
189
190 /// size of address
191 msg_namelen: socklen_t,
192
193 /// scatter/gather array
194 msg_iov: [*]iovec_const,
195
196 /// # elements in msg_iov
197 msg_iovlen: c_uint,
198
199 /// ancillary data
200 msg_control: ?*c_void,
201
202 /// ancillary data buffer len
203 msg_controllen: socklen_t,
204
205 /// flags on received message
206 msg_flags: c_int,
207};
208
209pub const Stat = extern struct {
210 mode: mode_t,
211 dev: dev_t,
212 ino: ino_t,
213 nlink: nlink_t,
214 uid: uid_t,
215 gid: gid_t,
216 rdev: dev_t,
217 atim: timespec,
218 mtim: timespec,
219 ctim: timespec,
220 size: off_t,
221 blocks: blkcnt_t,
222 blksize: blksize_t,
223 flags: u32,
224 gen: u32,
225 birthtim: timespec,
226
227 pub fn atime(self: @This()) timespec {
228 return self.atim;
229 }
230
231 pub fn mtime(self: @This()) timespec {
232 return self.mtim;
233 }
234
235 pub fn ctime(self: @This()) timespec {
236 return self.ctim;
237 }
238};
239
240pub const timespec = extern struct {
241 tv_sec: time_t,
242 tv_nsec: c_long,
243};
244
245pub const timeval = extern struct {
246 tv_sec: time_t,
247 tv_usec: c_long,
248};
249
250pub const timezone = extern struct {
251 tz_minuteswest: c_int,
252 tz_dsttime: c_int,
253};
254
255pub const MAXNAMLEN = 255;
256
257pub const dirent = extern struct {
258 d_fileno: ino_t,
259 d_off: off_t,
260 d_reclen: u16,
261 d_type: u8,
262 d_namlen: u8,
263 __d_padding: [4]u8,
264 d_name: [MAXNAMLEN + 1]u8,
265
266 pub fn reclen(self: dirent) u16 {
267 return self.d_reclen;
268 }
269};
270
271pub const in_port_t = u16;
272pub const sa_family_t = u8;
273
274pub const sockaddr = extern struct {
275 /// total length
276 len: u8,
277
278 /// address family
279 family: sa_family_t,
280
281 /// actually longer; address value
282 data: [14]u8,
283};
284
285pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
286
287pub const sockaddr_in = extern struct {
288 len: u8 = @sizeOf(sockaddr_in),
289 family: sa_family_t = AF_INET,
290 port: in_port_t,
291 addr: u32,
292 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
293};
294
295pub const sockaddr_in6 = extern struct {
296 len: u8 = @sizeOf(sockaddr_in6),
297 family: sa_family_t = AF_INET6,
298 port: in_port_t,
299 flowinfo: u32,
300 addr: [16]u8,
301 scope_id: u32,
302};
303
304/// Definitions for UNIX IPC domain.
305pub const sockaddr_un = extern struct {
306 /// total sockaddr length
307 len: u8 = @sizeOf(sockaddr_un),
308
309 /// AF_LOCAL
310 family: sa_family_t = AF_LOCAL,
311
312 /// path name
313 path: [104]u8,
314};
315
316/// get address to use bind()
317pub const AI_PASSIVE = 1;
318
319/// fill ai_canonname
320pub const AI_CANONNAME = 2;
321
322/// prevent host name resolution
323pub const AI_NUMERICHOST = 4;
324
325/// prevent service name resolution
326pub const AI_NUMERICSERV = 16;
327
328/// only if any address is assigned
329pub const AI_ADDRCONFIG = 64;
330
331pub const PATH_MAX = 1024;
332pub const IOV_MAX = 1024;
333
334pub const STDIN_FILENO = 0;
335pub const STDOUT_FILENO = 1;
336pub const STDERR_FILENO = 2;
337
338pub const PROT_NONE = 0;
339pub const PROT_READ = 1;
340pub const PROT_WRITE = 2;
341pub const PROT_EXEC = 4;
342
343pub const CLOCK_REALTIME = 0;
344pub const CLOCK_PROCESS_CPUTIME_ID = 2;
345pub const CLOCK_MONOTONIC = 3;
346pub const CLOCK_THREAD_CPUTIME_ID = 4;
347
348pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
349pub const MAP_SHARED = 0x0001;
350pub const MAP_PRIVATE = 0x0002;
351pub const MAP_FIXED = 0x0010;
352pub const MAP_RENAME = 0;
353pub const MAP_NORESERVE = 0;
354pub const MAP_INHERIT = 0;
355pub const MAP_HASSEMAPHORE = 0;
356pub const MAP_TRYFIXED = 0;
357
358pub const MAP_FILE = 0;
359pub const MAP_ANON = 0x1000;
360pub const MAP_ANONYMOUS = MAP_ANON;
361pub const MAP_STACK = 0x4000;
362pub const MAP_CONCEAL = 0x8000;
363
364pub const WNOHANG = 1;
365pub const WUNTRACED = 2;
366pub const WCONTINUED = 8;
367
368pub const SA_ONSTACK = 0x0001;
369pub const SA_RESTART = 0x0002;
370pub const SA_RESETHAND = 0x0004;
371pub const SA_NOCLDSTOP = 0x0008;
372pub const SA_NODEFER = 0x0010;
373pub const SA_NOCLDWAIT = 0x0020;
374pub const SA_SIGINFO = 0x0040;
375
376pub const SIGHUP = 1;
377pub const SIGINT = 2;
378pub const SIGQUIT = 3;
379pub const SIGILL = 4;
380pub const SIGTRAP = 5;
381pub const SIGABRT = 6;
382pub const SIGIOT = SIGABRT;
383pub const SIGEMT = 7;
384pub const SIGFPE = 8;
385pub const SIGKILL = 9;
386pub const SIGBUS = 10;
387pub const SIGSEGV = 11;
388pub const SIGSYS = 12;
389pub const SIGPIPE = 13;
390pub const SIGALRM = 14;
391pub const SIGTERM = 15;
392pub const SIGURG = 16;
393pub const SIGSTOP = 17;
394pub const SIGTSTP = 18;
395pub const SIGCONT = 19;
396pub const SIGCHLD = 20;
397pub const SIGTTIN = 21;
398pub const SIGTTOU = 22;
399pub const SIGIO = 23;
400pub const SIGXCPU = 24;
401pub const SIGXFSZ = 25;
402pub const SIGVTALRM = 26;
403pub const SIGPROF = 27;
404pub const SIGWINCH = 28;
405pub const SIGINFO = 29;
406pub const SIGUSR1 = 30;
407pub const SIGUSR2 = 31;
408pub const SIGPWR = 32;
409
410// access function
411pub const F_OK = 0; // test for existence of file
412pub const X_OK = 1; // test for execute or search permission
413pub const W_OK = 2; // test for write permission
414pub const R_OK = 4; // test for read permission
415
416/// open for reading only
417pub const O_RDONLY = 0x00000000;
418
419/// open for writing only
420pub const O_WRONLY = 0x00000001;
421
422/// open for reading and writing
423pub const O_RDWR = 0x00000002;
424
425/// mask for above modes
426pub const O_ACCMODE = 0x00000003;
427
428/// no delay
429pub const O_NONBLOCK = 0x00000004;
430
431/// set append mode
432pub const O_APPEND = 0x00000008;
433
434/// open with shared file lock
435pub const O_SHLOCK = 0x00000010;
436
437/// open with exclusive file lock
438pub const O_EXLOCK = 0x00000020;
439
440/// signal pgrp when data ready
441pub const O_ASYNC = 0x00000040;
442
443/// synchronous writes
444pub const O_SYNC = 0x00000080;
445
446/// don't follow symlinks on the last
447pub const O_NOFOLLOW = 0x00000100;
448
449/// create if nonexistent
450pub const O_CREAT = 0x00000200;
451
452/// truncate to zero length
453pub const O_TRUNC = 0x00000400;
454
455/// error if already exists
456pub const O_EXCL = 0x00000800;
457
458/// don't assign controlling terminal
459pub const O_NOCTTY = 0x00008000;
460
461/// write: I/O data completion
462pub const O_DSYNC = O_SYNC;
463
464/// read: I/O completion as for write
465pub const O_RSYNC = O_SYNC;
466
467/// fail if not a directory
468pub const O_DIRECTORY = 0x20000;
469
470/// set close on exec
471pub const O_CLOEXEC = 0x10000;
472
473pub const F_DUPFD = 0;
474pub const F_GETFD = 1;
475pub const F_SETFD = 2;
476pub const F_GETFL = 3;
477pub const F_SETFL = 4;
478
479pub const F_GETOWN = 5;
480pub const F_SETOWN = 6;
481
482pub const F_GETLK = 7;
483pub const F_SETLK = 8;
484pub const F_SETLKW = 9;
485
486pub const F_RDLCK = 1;
487pub const F_UNLCK = 2;
488pub const F_WRLCK = 3;
489
490pub const LOCK_SH = 0x01;
491pub const LOCK_EX = 0x02;
492pub const LOCK_NB = 0x04;
493pub const LOCK_UN = 0x08;
494
495pub const FD_CLOEXEC = 1;
496
497pub const SEEK_SET = 0;
498pub const SEEK_CUR = 1;
499pub const SEEK_END = 2;
500
501pub const SIG_BLOCK = 1;
502pub const SIG_UNBLOCK = 2;
503pub const SIG_SETMASK = 3;
504
505pub const SOCK_STREAM = 1;
506pub const SOCK_DGRAM = 2;
507pub const SOCK_RAW = 3;
508pub const SOCK_RDM = 4;
509pub const SOCK_SEQPACKET = 5;
510
511pub const SOCK_CLOEXEC = 0x8000;
512pub const SOCK_NONBLOCK = 0x4000;
513
514pub const SO_DEBUG = 0x0001;
515pub const SO_ACCEPTCONN = 0x0002;
516pub const SO_REUSEADDR = 0x0004;
517pub const SO_KEEPALIVE = 0x0008;
518pub const SO_DONTROUTE = 0x0010;
519pub const SO_BROADCAST = 0x0020;
520pub const SO_USELOOPBACK = 0x0040;
521pub const SO_LINGER = 0x0080;
522pub const SO_OOBINLINE = 0x0100;
523pub const SO_REUSEPORT = 0x0200;
524pub const SO_TIMESTAMP = 0x0800;
525pub const SO_BINDANY = 0x1000;
526pub const SO_ZEROIZE = 0x2000;
527pub const SO_SNDBUF = 0x1001;
528pub const SO_RCVBUF = 0x1002;
529pub const SO_SNDLOWAT = 0x1003;
530pub const SO_RCVLOWAT = 0x1004;
531pub const SO_SNDTIMEO = 0x1005;
532pub const SO_RCVTIMEO = 0x1006;
533pub const SO_ERROR = 0x1007;
534pub const SO_TYPE = 0x1008;
535pub const SO_NETPROC = 0x1020;
536pub const SO_RTABLE = 0x1021;
537pub const SO_PEERCRED = 0x1022;
538pub const SO_SPLICE = 0x1023;
539pub const SO_DOMAIN = 0x1024;
540pub const SO_PROTOCOL = 0x1025;
541
542pub const SOL_SOCKET = 0xffff;
543
544pub const PF_UNSPEC = AF_UNSPEC;
545pub const PF_LOCAL = AF_LOCAL;
546pub const PF_UNIX = AF_UNIX;
547pub const PF_INET = AF_INET;
548pub const PF_APPLETALK = AF_APPLETALK;
549pub const PF_INET6 = AF_INET6;
550pub const PF_DECnet = AF_DECnet;
551pub const PF_KEY = AF_KEY;
552pub const PF_ROUTE = AF_ROUTE;
553pub const PF_SNA = AF_SNA;
554pub const PF_MPLS = AF_MPLS;
555pub const PF_BLUETOOTH = AF_BLUETOOTH;
556pub const PF_ISDN = AF_ISDN;
557pub const PF_MAX = AF_MAX;
558
559pub const AF_UNSPEC = 0;
560pub const AF_UNIX = 1;
561pub const AF_LOCAL = AF_UNIX;
562pub const AF_INET = 2;
563pub const AF_APPLETALK = 16;
564pub const AF_INET6 = 24;
565pub const AF_KEY = 30;
566pub const AF_ROUTE = 17;
567pub const AF_SNA = 11;
568pub const AF_MPLS = 33;
569pub const AF_BLUETOOTH = 32;
570pub const AF_ISDN = 26;
571pub const AF_MAX = 36;
572
573pub const DT_UNKNOWN = 0;
574pub const DT_FIFO = 1;
575pub const DT_CHR = 2;
576pub const DT_DIR = 4;
577pub const DT_BLK = 6;
578pub const DT_REG = 8;
579pub const DT_LNK = 10;
580pub const DT_SOCK = 12;
581pub const DT_WHT = 14; // XXX
582
583pub const EV_ADD = 0x0001;
584pub const EV_DELETE = 0x0002;
585pub const EV_ENABLE = 0x0004;
586pub const EV_DISABLE = 0x0008;
587pub const EV_ONESHOT = 0x0010;
588pub const EV_CLEAR = 0x0020;
589pub const EV_RECEIPT = 0x0040;
590pub const EV_DISPATCH = 0x0080;
591pub const EV_FLAG1 = 0x2000;
592pub const EV_ERROR = 0x4000;
593pub const EV_EOF = 0x8000;
594
595pub const EVFILT_READ = -1;
596pub const EVFILT_WRITE = -2;
597pub const EVFILT_AIO = -3;
598pub const EVFILT_VNODE = -4;
599pub const EVFILT_PROC = -5;
600pub const EVFILT_SIGNAL = -6;
601pub const EVFILT_TIMER = -7;
602pub const EVFILT_EXCEPT = -9;
603
604// data/hint flags for EVFILT_{READ|WRITE}
605pub const NOTE_LOWAT = 0x0001;
606pub const NOTE_EOF = 0x0002;
607
608// data/hint flags for EVFILT_EXCEPT and EVFILT_{READ|WRITE}
609pub const NOTE_OOB = 0x0004;
610
611// data/hint flags for EVFILT_VNODE
612pub const NOTE_DELETE = 0x0001;
613pub const NOTE_WRITE = 0x0002;
614pub const NOTE_EXTEND = 0x0004;
615pub const NOTE_ATTRIB = 0x0008;
616pub const NOTE_LINK = 0x0010;
617pub const NOTE_RENAME = 0x0020;
618pub const NOTE_REVOKE = 0x0040;
619pub const NOTE_TRUNCATE = 0x0080;
620
621// data/hint flags for EVFILT_PROC
622pub const NOTE_EXIT = 0x80000000;
623pub const NOTE_FORK = 0x40000000;
624pub const NOTE_EXEC = 0x20000000;
625pub const NOTE_PDATAMASK = 0x000fffff;
626pub const NOTE_PCTRLMASK = 0xf0000000;
627pub const NOTE_TRACK = 0x00000001;
628pub const NOTE_TRACKERR = 0x00000002;
629pub const NOTE_CHILD = 0x00000004;
630
631// data/hint flags for EVFILT_DEVICE
632pub const NOTE_CHANGE = 0x00000001;
633
634pub const TIOCCBRK = 0x2000747a;
635pub const TIOCCDTR = 0x20007478;
636pub const TIOCCONS = 0x80047462;
637pub const TIOCDCDTIMESTAMP = 0x40107458;
638pub const TIOCDRAIN = 0x2000745e;
639pub const TIOCEXCL = 0x2000740d;
640pub const TIOCEXT = 0x80047460;
641pub const TIOCFLAG_CDTRCTS = 0x10;
642pub const TIOCFLAG_CLOCAL = 0x2;
643pub const TIOCFLAG_CRTSCTS = 0x4;
644pub const TIOCFLAG_MDMBUF = 0x8;
645pub const TIOCFLAG_SOFTCAR = 0x1;
646pub const TIOCFLUSH = 0x80047410;
647pub const TIOCGETA = 0x402c7413;
648pub const TIOCGETD = 0x4004741a;
649pub const TIOCGFLAGS = 0x4004745d;
650pub const TIOCGLINED = 0x40207442;
651pub const TIOCGPGRP = 0x40047477;
652pub const TIOCGQSIZE = 0x40047481;
653pub const TIOCGRANTPT = 0x20007447;
654pub const TIOCGSID = 0x40047463;
655pub const TIOCGSIZE = 0x40087468;
656pub const TIOCGWINSZ = 0x40087468;
657pub const TIOCMBIC = 0x8004746b;
658pub const TIOCMBIS = 0x8004746c;
659pub const TIOCMGET = 0x4004746a;
660pub const TIOCMSET = 0x8004746d;
661pub const TIOCM_CAR = 0x40;
662pub const TIOCM_CD = 0x40;
663pub const TIOCM_CTS = 0x20;
664pub const TIOCM_DSR = 0x100;
665pub const TIOCM_DTR = 0x2;
666pub const TIOCM_LE = 0x1;
667pub const TIOCM_RI = 0x80;
668pub const TIOCM_RNG = 0x80;
669pub const TIOCM_RTS = 0x4;
670pub const TIOCM_SR = 0x10;
671pub const TIOCM_ST = 0x8;
672pub const TIOCNOTTY = 0x20007471;
673pub const TIOCNXCL = 0x2000740e;
674pub const TIOCOUTQ = 0x40047473;
675pub const TIOCPKT = 0x80047470;
676pub const TIOCPKT_DATA = 0x0;
677pub const TIOCPKT_DOSTOP = 0x20;
678pub const TIOCPKT_FLUSHREAD = 0x1;
679pub const TIOCPKT_FLUSHWRITE = 0x2;
680pub const TIOCPKT_IOCTL = 0x40;
681pub const TIOCPKT_NOSTOP = 0x10;
682pub const TIOCPKT_START = 0x8;
683pub const TIOCPKT_STOP = 0x4;
684pub const TIOCPTMGET = 0x40287446;
685pub const TIOCPTSNAME = 0x40287448;
686pub const TIOCRCVFRAME = 0x80087445;
687pub const TIOCREMOTE = 0x80047469;
688pub const TIOCSBRK = 0x2000747b;
689pub const TIOCSCTTY = 0x20007461;
690pub const TIOCSDTR = 0x20007479;
691pub const TIOCSETA = 0x802c7414;
692pub const TIOCSETAF = 0x802c7416;
693pub const TIOCSETAW = 0x802c7415;
694pub const TIOCSETD = 0x8004741b;
695pub const TIOCSFLAGS = 0x8004745c;
696pub const TIOCSIG = 0x2000745f;
697pub const TIOCSLINED = 0x80207443;
698pub const TIOCSPGRP = 0x80047476;
699pub const TIOCSQSIZE = 0x80047480;
700pub const TIOCSSIZE = 0x80087467;
701pub const TIOCSTART = 0x2000746e;
702pub const TIOCSTAT = 0x80047465;
703pub const TIOCSTI = 0x80017472;
704pub const TIOCSTOP = 0x2000746f;
705pub const TIOCSWINSZ = 0x80087467;
706pub const TIOCUCNTL = 0x80047466;
707pub const TIOCXMTFRAME = 0x80087444;
708
709pub fn WEXITSTATUS(s: u32) u8 {
710 return @intCast(u8, (s >> 8) & 0xff);
711}
712pub fn WTERMSIG(s: u32) u32 {
713 return (s & 0x7f);
714}
715pub fn WSTOPSIG(s: u32) u32 {
716 return WEXITSTATUS(s);
717}
718pub fn WIFEXITED(s: u32) bool {
719 return WTERMSIG(s) == 0;
720}
721
722pub fn WIFCONTINUED(s: u32) bool {
723 return ((s & 0o177777) == 0o177777);
724}
725
726pub fn WIFSTOPPED(s: u32) bool {
727 return (s & 0xff == 0o177);
728}
729
730pub fn WIFSIGNALED(s: u32) bool {
731 return (((s) & 0o177) != 0o177) and (((s) & 0o177) != 0);
732}
733
734pub const winsize = extern struct {
735 ws_row: c_ushort,
736 ws_col: c_ushort,
737 ws_xpixel: c_ushort,
738 ws_ypixel: c_ushort,
739};
740
741const NSIG = 33;
742
743pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
744pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
745pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
746pub const SIG_CATCH = @intToPtr(?Sigaction.sigaction_fn, 2);
747pub const SIG_HOLD = @intToPtr(?Sigaction.sigaction_fn, 3);
748
749/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
750pub const Sigaction = extern struct {
751 pub const handler_fn = fn (c_int) callconv(.C) void;
752 pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void;
753
754 /// signal handler
755 handler: extern union {
756 handler: ?handler_fn,
757 sigaction: ?sigaction_fn,
758 },
759 /// signal mask to apply
760 mask: sigset_t,
761 /// signal options
762 flags: c_uint,
763};
764
765pub const sigval = extern union {
766 int: c_int,
767 ptr: ?*c_void,
768};
769
770pub const siginfo_t = extern struct {
771 signo: c_int,
772 code: c_int,
773 errno: c_int,
774 data: extern union {
775 proc: extern struct {
776 pid: pid_t,
777 pdata: extern union {
778 kill: extern struct {
779 uid: uid_t,
780 value: sigval,
781 },
782 cld: extern struct {
783 utime: clock_t,
784 stime: clock_t,
785 status: c_int,
786 },
787 },
788 },
789 fault: extern struct {
790 addr: ?*c_void,
791 trapno: c_int,
792 },
793 __pad: [128 - 3 * @sizeOf(c_int)]u8,
794 },
795};
796
797comptime {
798 if (@sizeOf(usize) == 4)
799 std.debug.assert(@sizeOf(siginfo_t) == 128)
800 else
801 // Take into account the padding between errno and data fields.
802 std.debug.assert(@sizeOf(siginfo_t) == 136);
803}
804
805pub usingnamespace switch (builtin.cpu.arch) {
806 .x86_64 => struct {
807 pub const ucontext_t = extern struct {
808 sc_rdi: c_long,
809 sc_rsi: c_long,
810 sc_rdx: c_long,
811 sc_rcx: c_long,
812 sc_r8: c_long,
813 sc_r9: c_long,
814 sc_r10: c_long,
815 sc_r11: c_long,
816 sc_r12: c_long,
817 sc_r13: c_long,
818 sc_r14: c_long,
819 sc_r15: c_long,
820 sc_rbp: c_long,
821 sc_rbx: c_long,
822 sc_rax: c_long,
823 sc_gs: c_long,
824 sc_fs: c_long,
825 sc_es: c_long,
826 sc_ds: c_long,
827 sc_trapno: c_long,
828 sc_err: c_long,
829 sc_rip: c_long,
830 sc_cs: c_long,
831 sc_rflags: c_long,
832 sc_rsp: c_long,
833 sc_ss: c_long,
834
835 sc_fpstate: fxsave64,
836 __sc_unused: c_int,
837 sc_mask: c_int,
838 sc_cookie: c_long,
839 };
840
841 pub const fxsave64 = packed struct {
842 fx_fcw: u16,
843 fx_fsw: u16,
844 fx_ftw: u8,
845 fx_unused1: u8,
846 fx_fop: u16,
847 fx_rip: u64,
848 fx_rdp: u64,
849 fx_mxcsr: u32,
850 fx_mxcsr_mask: u32,
851 fx_st: [8][2]u64,
852 fx_xmm: [16][2]u64,
853 fx_unused3: [96]u8,
854 };
855 },
856 else => struct {},
857};
858
859pub const sigset_t = c_uint;
860pub const empty_sigset: sigset_t = 0;
861
862pub const E = enum(u16) {
863 /// No error occurred.
864 SUCCESS = 0,
865 PERM = 1, // Operation not permitted
866 NOENT = 2, // No such file or directory
867 SRCH = 3, // No such process
868 INTR = 4, // Interrupted system call
869 IO = 5, // Input/output error
870 NXIO = 6, // Device not configured
871 @"2BIG" = 7, // Argument list too long
872 NOEXEC = 8, // Exec format error
873 BADF = 9, // Bad file descriptor
874 CHILD = 10, // No child processes
875 DEADLK = 11, // Resource deadlock avoided
876 // 11 was AGAIN
877 NOMEM = 12, // Cannot allocate memory
878 ACCES = 13, // Permission denied
879 FAULT = 14, // Bad address
880 NOTBLK = 15, // Block device required
881 BUSY = 16, // Device busy
882 EXIST = 17, // File exists
883 XDEV = 18, // Cross-device link
884 NODEV = 19, // Operation not supported by device
885 NOTDIR = 20, // Not a directory
886 ISDIR = 21, // Is a directory
887 INVAL = 22, // Invalid argument
888 NFILE = 23, // Too many open files in system
889 MFILE = 24, // Too many open files
890 NOTTY = 25, // Inappropriate ioctl for device
891 TXTBSY = 26, // Text file busy
892 FBIG = 27, // File too large
893 NOSPC = 28, // No space left on device
894 SPIPE = 29, // Illegal seek
895 ROFS = 30, // Read-only file system
896 MLINK = 31, // Too many links
897 PIPE = 32, // Broken pipe
898
899 // math software
900 DOM = 33, // Numerical argument out of domain
901 RANGE = 34, // Result too large or too small
902
903 // non-blocking and interrupt i/o
904 // also: WOULDBLOCK: operation would block
905 AGAIN = 35, // Resource temporarily unavailable
906 INPROGRESS = 36, // Operation now in progress
907 ALREADY = 37, // Operation already in progress
908
909 // ipc/network software -- argument errors
910 NOTSOCK = 38, // Socket operation on non-socket
911 DESTADDRREQ = 39, // Destination address required
912 MSGSIZE = 40, // Message too long
913 PROTOTYPE = 41, // Protocol wrong type for socket
914 NOPROTOOPT = 42, // Protocol option not available
915 PROTONOSUPPORT = 43, // Protocol not supported
916 SOCKTNOSUPPORT = 44, // Socket type not supported
917 OPNOTSUPP = 45, // Operation not supported
918 PFNOSUPPORT = 46, // Protocol family not supported
919 AFNOSUPPORT = 47, // Address family not supported by protocol family
920 ADDRINUSE = 48, // Address already in use
921 ADDRNOTAVAIL = 49, // Can't assign requested address
922
923 // ipc/network software -- operational errors
924 NETDOWN = 50, // Network is down
925 NETUNREACH = 51, // Network is unreachable
926 NETRESET = 52, // Network dropped connection on reset
927 CONNABORTED = 53, // Software caused connection abort
928 CONNRESET = 54, // Connection reset by peer
929 NOBUFS = 55, // No buffer space available
930 ISCONN = 56, // Socket is already connected
931 NOTCONN = 57, // Socket is not connected
932 SHUTDOWN = 58, // Can't send after socket shutdown
933 TOOMANYREFS = 59, // Too many references: can't splice
934 TIMEDOUT = 60, // Operation timed out
935 CONNREFUSED = 61, // Connection refused
936
937 LOOP = 62, // Too many levels of symbolic links
938 NAMETOOLONG = 63, // File name too long
939
940 // should be rearranged
941 HOSTDOWN = 64, // Host is down
942 HOSTUNREACH = 65, // No route to host
943 NOTEMPTY = 66, // Directory not empty
944
945 // quotas & mush
946 PROCLIM = 67, // Too many processes
947 USERS = 68, // Too many users
948 DQUOT = 69, // Disc quota exceeded
949
950 // Network File System
951 STALE = 70, // Stale NFS file handle
952 REMOTE = 71, // Too many levels of remote in path
953 BADRPC = 72, // RPC struct is bad
954 RPCMISMATCH = 73, // RPC version wrong
955 PROGUNAVAIL = 74, // RPC prog. not avail
956 PROGMISMATCH = 75, // Program version wrong
957 PROCUNAVAIL = 76, // Bad procedure for program
958
959 NOLCK = 77, // No locks available
960 NOSYS = 78, // Function not implemented
961
962 FTYPE = 79, // Inappropriate file type or format
963 AUTH = 80, // Authentication error
964 NEEDAUTH = 81, // Need authenticator
965 IPSEC = 82, // IPsec processing failure
966 NOATTR = 83, // Attribute not found
967
968 // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
969 ILSEQ = 84, // Illegal byte sequence
970
971 NOMEDIUM = 85, // No medium found
972 MEDIUMTYPE = 86, // Wrong medium type
973 OVERFLOW = 87, // Value too large to be stored in data type
974 CANCELED = 88, // Operation canceled
975 IDRM = 89, // Identifier removed
976 NOMSG = 90, // No message of desired type
977 NOTSUP = 91, // Not supported
978 BADMSG = 92, // Bad or Corrupt message
979 NOTRECOVERABLE = 93, // State not recoverable
980 OWNERDEAD = 94, // Previous owner died
981 PROTO = 95, // Protocol error
982
983 _,
984};
985
986const _MAX_PAGE_SHIFT = switch (builtin.cpu.arch) {
987 .i386 => 12,
988 .sparcv9 => 13,
989};
990pub const MINSIGSTKSZ = 1 << _MAX_PAGE_SHIFT;
991pub const SIGSTKSZ = MINSIGSTKSZ + (1 << _MAX_PAGE_SHIFT) * 4;
992
993pub const SS_ONSTACK = 0x0001;
994pub const SS_DISABLE = 0x0004;
995
996pub const stack_t = extern struct {
997 ss_sp: [*]u8,
998 ss_size: usize,
999 ss_flags: c_int,
1000};
1001
1002pub const S_IFMT = 0o170000;
1003
1004pub const S_IFIFO = 0o010000;
1005pub const S_IFCHR = 0o020000;
1006pub const S_IFDIR = 0o040000;
1007pub const S_IFBLK = 0o060000;
1008pub const S_IFREG = 0o100000;
1009pub const S_IFLNK = 0o120000;
1010pub const S_IFSOCK = 0o140000;
1011
1012pub const S_ISUID = 0o4000;
1013pub const S_ISGID = 0o2000;
1014pub const S_ISVTX = 0o1000;
1015pub const S_IRWXU = 0o700;
1016pub const S_IRUSR = 0o400;
1017pub const S_IWUSR = 0o200;
1018pub const S_IXUSR = 0o100;
1019pub const S_IRWXG = 0o070;
1020pub const S_IRGRP = 0o040;
1021pub const S_IWGRP = 0o020;
1022pub const S_IXGRP = 0o010;
1023pub const S_IRWXO = 0o007;
1024pub const S_IROTH = 0o004;
1025pub const S_IWOTH = 0o002;
1026pub const S_IXOTH = 0o001;
1027
1028pub fn S_ISFIFO(m: u32) bool {
1029 return m & S_IFMT == S_IFIFO;
1030}
1031
1032pub fn S_ISCHR(m: u32) bool {
1033 return m & S_IFMT == S_IFCHR;
1034}
1035
1036pub fn S_ISDIR(m: u32) bool {
1037 return m & S_IFMT == S_IFDIR;
1038}
1039
1040pub fn S_ISBLK(m: u32) bool {
1041 return m & S_IFMT == S_IFBLK;
1042}
1043
1044pub fn S_ISREG(m: u32) bool {
1045 return m & S_IFMT == S_IFREG;
1046}
1047
1048pub fn S_ISLNK(m: u32) bool {
1049 return m & S_IFMT == S_IFLNK;
1050}
1051
1052pub fn S_ISSOCK(m: u32) bool {
1053 return m & S_IFMT == S_IFSOCK;
1054}
1055
1056/// Magic value that specify the use of the current working directory
1057/// to determine the target of relative file paths in the openat() and
1058/// similar syscalls.
1059pub const AT_FDCWD = -100;
1060
1061/// Check access using effective user and group ID
1062pub const AT_EACCESS = 0x01;
1063
1064/// Do not follow symbolic links
1065pub const AT_SYMLINK_NOFOLLOW = 0x02;
1066
1067/// Follow symbolic link
1068pub const AT_SYMLINK_FOLLOW = 0x04;
1069
1070/// Remove directory instead of file
1071pub const AT_REMOVEDIR = 0x08;
1072
1073pub const HOST_NAME_MAX = 255;
1074
1075/// dummy for IP
1076pub const IPPROTO_IP = 0;
1077
1078/// IP6 hop-by-hop options
1079pub const IPPROTO_HOPOPTS = IPPROTO_IP;
1080
1081/// control message protocol
1082pub const IPPROTO_ICMP = 1;
1083
1084/// group mgmt protocol
1085pub const IPPROTO_IGMP = 2;
1086
1087/// gateway^2 (deprecated)
1088pub const IPPROTO_GGP = 3;
1089
1090/// IP header
1091pub const IPPROTO_IPV4 = IPPROTO_IPIP;
1092
1093/// IP inside IP
1094pub const IPPROTO_IPIP = 4;
1095
1096/// tcp
1097pub const IPPROTO_TCP = 6;
1098
1099/// exterior gateway protocol
1100pub const IPPROTO_EGP = 8;
1101
1102/// pup
1103pub const IPPROTO_PUP = 12;
1104
1105/// user datagram protocol
1106pub const IPPROTO_UDP = 17;
1107
1108/// xns idp
1109pub const IPPROTO_IDP = 22;
1110
1111/// tp-4 w/ class negotiation
1112pub const IPPROTO_TP = 29;
1113
1114/// IP6 header
1115pub const IPPROTO_IPV6 = 41;
1116
1117/// IP6 routing header
1118pub const IPPROTO_ROUTING = 43;
1119
1120/// IP6 fragmentation header
1121pub const IPPROTO_FRAGMENT = 44;
1122
1123/// resource reservation
1124pub const IPPROTO_RSVP = 46;
1125
1126/// GRE encaps RFC 1701
1127pub const IPPROTO_GRE = 47;
1128
1129/// encap. security payload
1130pub const IPPROTO_ESP = 50;
1131
1132/// authentication header
1133pub const IPPROTO_AH = 51;
1134
1135/// IP Mobility RFC 2004
1136pub const IPPROTO_MOBILE = 55;
1137
1138/// IPv6 ICMP
1139pub const IPPROTO_IPV6_ICMP = 58;
1140
1141/// ICMP6
1142pub const IPPROTO_ICMPV6 = 58;
1143
1144/// IP6 no next header
1145pub const IPPROTO_NONE = 59;
1146
1147/// IP6 destination option
1148pub const IPPROTO_DSTOPTS = 60;
1149
1150/// ISO cnlp
1151pub const IPPROTO_EON = 80;
1152
1153/// Ethernet-in-IP
1154pub const IPPROTO_ETHERIP = 97;
1155
1156/// encapsulation header
1157pub const IPPROTO_ENCAP = 98;
1158
1159/// Protocol indep. multicast
1160pub const IPPROTO_PIM = 103;
1161
1162/// IP Payload Comp. Protocol
1163pub const IPPROTO_IPCOMP = 108;
1164
1165/// VRRP RFC 2338
1166pub const IPPROTO_VRRP = 112;
1167
1168/// Common Address Resolution Protocol
1169pub const IPPROTO_CARP = 112;
1170
1171/// PFSYNC
1172pub const IPPROTO_PFSYNC = 240;
1173
1174/// raw IP packet
1175pub const IPPROTO_RAW = 255;
1176
1177pub const rlimit_resource = enum(c_int) {
1178 CPU,
1179 FSIZE,
1180 DATA,
1181 STACK,
1182 CORE,
1183 RSS,
1184 MEMLOCK,
1185 NPROC,
1186 NOFILE,
1187
1188 _,
1189};
1190
1191pub const rlim_t = u64;
1192
1193/// No limit
1194pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
1195
1196pub const RLIM_SAVED_MAX = RLIM_INFINITY;
1197pub const RLIM_SAVED_CUR = RLIM_INFINITY;
1198
1199pub const rlimit = extern struct {
1200 /// Soft limit
1201 cur: rlim_t,
1202 /// Hard limit
1203 max: rlim_t,
1204};
1205
1206pub const SHUT_RD = 0;
1207pub const SHUT_WR = 1;
1208pub const SHUT_RDWR = 2;
1209
1210pub const nfds_t = c_uint;
1211
1212pub const pollfd = extern struct {
1213 fd: fd_t,
1214 events: c_short,
1215 revents: c_short,
1216};
1217
1218pub const POLLIN = 0x0001;
1219pub const POLLPRI = 0x0002;
1220pub const POLLOUT = 0x0004;
1221pub const POLLERR = 0x0008;
1222pub const POLLHUP = 0x0010;
1223pub const POLLNVAL = 0x0020;
1224pub const POLLRDNORM = 0x0040;
1225pub const POLLNORM = POLLRDNORM;
1226pub const POLLWRNORM = POLLOUT;
1227pub const POLLRDBAND = 0x0080;
1228pub const POLLWRBAND = 0x0100;
1229
1230// sysctl mib
1231pub const CTL_UNSPEC = 0;
1232pub const CTL_KERN = 1;
1233pub const CTL_VM = 2;
1234pub const CTL_FS = 3;
1235pub const CTL_NET = 4;
1236pub const CTL_DEBUG = 5;
1237pub const CTL_HW = 6;
1238pub const CTL_MACHDEP = 7;
1239
1240pub const CTL_DDB = 9;
1241pub const CTL_VFS = 10;
1242
1243pub const KERN_OSTYPE = 1;
1244pub const KERN_OSRELEASE = 2;
1245pub const KERN_OSREV = 3;
1246pub const KERN_VERSION = 4;
1247pub const KERN_MAXVNODES = 5;
1248pub const KERN_MAXPROC = 6;
1249pub const KERN_MAXFILES = 7;
1250pub const KERN_ARGMAX = 8;
1251pub const KERN_SECURELVL = 9;
1252pub const KERN_HOSTNAME = 10;
1253pub const KERN_HOSTID = 11;
1254pub const KERN_CLOCKRATE = 12;
1255
1256pub const KERN_PROF = 16;
1257pub const KERN_POSIX1 = 17;
1258pub const KERN_NGROUPS = 18;
1259pub const KERN_JOB_CONTROL = 19;
1260pub const KERN_SAVED_IDS = 20;
1261pub const KERN_BOOTTIME = 21;
1262pub const KERN_DOMAINNAME = 22;
1263pub const KERN_MAXPARTITIONS = 23;
1264pub const KERN_RAWPARTITION = 24;
1265pub const KERN_MAXTHREAD = 25;
1266pub const KERN_NTHREADS = 26;
1267pub const KERN_OSVERSION = 27;
1268pub const KERN_SOMAXCONN = 28;
1269pub const KERN_SOMINCONN = 29;
1270
1271pub const KERN_NOSUIDCOREDUMP = 32;
1272pub const KERN_FSYNC = 33;
1273pub const KERN_SYSVMSG = 34;
1274pub const KERN_SYSVSEM = 35;
1275pub const KERN_SYSVSHM = 36;
1276
1277pub const KERN_MSGBUFSIZE = 38;
1278pub const KERN_MALLOCSTATS = 39;
1279pub const KERN_CPTIME = 40;
1280pub const KERN_NCHSTATS = 41;
1281pub const KERN_FORKSTAT = 42;
1282pub const KERN_NSELCOLL = 43;
1283pub const KERN_TTY = 44;
1284pub const KERN_CCPU = 45;
1285pub const KERN_FSCALE = 46;
1286pub const KERN_NPROCS = 47;
1287pub const KERN_MSGBUF = 48;
1288pub const KERN_POOL = 49;
1289pub const KERN_STACKGAPRANDOM = 50;
1290pub const KERN_SYSVIPC_INFO = 51;
1291pub const KERN_ALLOWKMEM = 52;
1292pub const KERN_WITNESSWATCH = 53;
1293pub const KERN_SPLASSERT = 54;
1294pub const KERN_PROC_ARGS = 55;
1295pub const KERN_NFILES = 56;
1296pub const KERN_TTYCOUNT = 57;
1297pub const KERN_NUMVNODES = 58;
1298pub const KERN_MBSTAT = 59;
1299pub const KERN_WITNESS = 60;
1300pub const KERN_SEMINFO = 61;
1301pub const KERN_SHMINFO = 62;
1302pub const KERN_INTRCNT = 63;
1303pub const KERN_WATCHDOG = 64;
1304pub const KERN_ALLOWDT = 65;
1305pub const KERN_PROC = 66;
1306pub const KERN_MAXCLUSTERS = 67;
1307pub const KERN_EVCOUNT = 68;
1308pub const KERN_TIMECOUNTER = 69;
1309pub const KERN_MAXLOCKSPERUID = 70;
1310pub const KERN_CPTIME2 = 71;
1311pub const KERN_CACHEPCT = 72;
1312pub const KERN_FILE = 73;
1313pub const KERN_WXABORT = 74;
1314pub const KERN_CONSDEV = 75;
1315pub const KERN_NETLIVELOCKS = 76;
1316pub const KERN_POOL_DEBUG = 77;
1317pub const KERN_PROC_CWD = 78;
1318pub const KERN_PROC_NOBROADCASTKILL = 79;
1319pub const KERN_PROC_VMMAP = 80;
1320pub const KERN_GLOBAL_PTRACE = 81;
1321pub const KERN_CONSBUFSIZE = 82;
1322pub const KERN_CONSBUF = 83;
1323pub const KERN_AUDIO = 84;
1324pub const KERN_CPUSTATS = 85;
1325pub const KERN_PFSTATUS = 86;
1326pub const KERN_TIMEOUT_STATS = 87;
1327pub const KERN_UTC_OFFSET = 88;
1328pub const KERN_VIDEO = 89;
1329
1330pub const HW_MACHINE = 1;
1331pub const HW_MODEL = 2;
1332pub const HW_NCPU = 3;
1333pub const HW_BYTEORDER = 4;
1334pub const HW_PHYSMEM = 5;
1335pub const HW_USERMEM = 6;
1336pub const HW_PAGESIZE = 7;
1337pub const HW_DISKNAMES = 8;
1338pub const HW_DISKSTATS = 9;
1339pub const HW_DISKCOUNT = 10;
1340pub const HW_SENSORS = 11;
1341pub const HW_CPUSPEED = 12;
1342pub const HW_SETPERF = 13;
1343pub const HW_VENDOR = 14;
1344pub const HW_PRODUCT = 15;
1345pub const HW_VERSION = 16;
1346pub const HW_SERIALNO = 17;
1347pub const HW_UUID = 18;
1348pub const HW_PHYSMEM64 = 19;
1349pub const HW_USERMEM64 = 20;
1350pub const HW_NCPUFOUND = 21;
1351pub const HW_ALLOWPOWERDOWN = 22;
1352pub const HW_PERFPOLICY = 23;
1353pub const HW_SMT = 24;
1354pub const HW_NCPUONLINE = 25;
1355
1356pub const KERN_PROC_ALL = 0;
1357pub const KERN_PROC_PID = 1;
1358pub const KERN_PROC_PGRP = 2;
1359pub const KERN_PROC_SESSION = 3;
1360pub const KERN_PROC_TTY = 4;
1361pub const KERN_PROC_UID = 5;
1362pub const KERN_PROC_RUID = 6;
1363pub const KERN_PROC_KTHREAD = 7;
1364pub const KERN_PROC_SHOW_THREADS = 0x40000000;
1365
1366pub const KERN_PROC_ARGV = 1;
1367pub const KERN_PROC_NARGV = 2;
1368pub const KERN_PROC_ENV = 3;
1369pub const KERN_PROC_NENV = 4;
lib/std/c/wasi.zig+26-1
...@@ -4,12 +4,13 @@ pub fn _errno() *c_int {...@@ -4,12 +4,13 @@ pub fn _errno() *c_int {
4 return &errno;4 return &errno;
5}5}
66
7pub const fd_t = c_int;
7pub const pid_t = c_int;8pub const pid_t = c_int;
8pub const uid_t = u32;9pub const uid_t = u32;
9pub const gid_t = u32;10pub const gid_t = u32;
10pub const off_t = i64;11pub const off_t = i64;
1112
12pub const libc_stat = extern struct {13pub const Stat = extern struct {
13 dev: i32,14 dev: i32,
14 ino: ino_t,15 ino: ino_t,
15 nlink: u64,16 nlink: u64,
...@@ -51,3 +52,27 @@ pub const libc_stat = extern struct {...@@ -51,3 +52,27 @@ pub const libc_stat = extern struct {
51 };52 };
52 }53 }
53};54};
55
56/// Derived from
57/// https://github.com/WebAssembly/wasi-libc/blob/main/expected/wasm32-wasi/predefined-macros.txt
58pub const O = struct {
59 pub const ACCMODE = (EXEC | RDWR | SEARCH);
60 pub const APPEND = FDFLAG_APPEND;
61 pub const CLOEXEC = (0);
62 pub const CREAT = ((1 << 0) << 12); // = __WASI_OFLAGS_CREAT << 12
63 pub const DIRECTORY = ((1 << 1) << 12); // = __WASI_OFLAGS_DIRECTORY << 12
64 pub const DSYNC = FDFLAG_DSYNC;
65 pub const EXCL = ((1 << 2) << 12); // = __WASI_OFLAGS_EXCL << 12
66 pub const EXEC = (0x02000000);
67 pub const NOCTTY = (0);
68 pub const NOFOLLOW = (0x01000000);
69 pub const NONBLOCK = (1 << FDFLAG_NONBLOCK);
70 pub const RDONLY = (0x04000000);
71 pub const RDWR = (RDONLY | WRONLY);
72 pub const RSYNC = (1 << FDFLAG_RSYNC);
73 pub const SEARCH = (0x08000000);
74 pub const SYNC = (1 << FDFLAG_SYNC);
75 pub const TRUNC = ((1 << 3) << 12); // = __WASI_OFLAGS_TRUNC << 12
76 pub const TTY_INIT = (0);
77 pub const WRONLY = (0x10000000);
78};
lib/std/c/windows.zig+340
...@@ -1,3 +1,343 @@...@@ -1,3 +1,343 @@
1//! The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime).
2
3const ws2_32 = @import("../os/windows/ws2_32.zig");
4
1pub extern "c" fn _errno() *c_int;5pub extern "c" fn _errno() *c_int;
26
3pub extern "c" fn _msize(memblock: ?*c_void) usize;7pub extern "c" fn _msize(memblock: ?*c_void) usize;
8
9// TODO: copied the else case and removed the socket function (because its in ws2_32)
10// need to verify which of these is actually supported on windows
11pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
12pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
13pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
14pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
15pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
16pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
17pub extern "c" fn sched_yield() c_int;
18pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
19pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
20pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
21pub extern "c" fn sigfillset(set: ?*sigset_t) void;
22pub extern "c" fn alarm(seconds: c_uint) c_uint;
23pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
24
25pub const fd_t = HANDLE;
26pub const ino_t = LARGE_INTEGER;
27pub const pid_t = HANDLE;
28pub const mode_t = u0;
29
30pub const PATH_MAX = 260;
31
32pub const time_t = c_longlong;
33
34pub const timespec = extern struct {
35 tv_sec: time_t,
36 tv_nsec: c_long,
37};
38
39pub const timeval = extern struct {
40 tv_sec: c_long,
41 tv_usec: c_long,
42};
43
44pub const sig_atomic_t = c_int;
45
46/// maximum signal number + 1
47pub const NSIG = 23;
48
49// Signal types
50
51/// interrupt
52pub const SIGINT = 2;
53
54/// illegal instruction - invalid function image
55pub const SIGILL = 4;
56
57/// floating point exception
58pub const SIGFPE = 8;
59
60/// segment violation
61pub const SIGSEGV = 11;
62
63/// Software termination signal from kill
64pub const SIGTERM = 15;
65
66/// Ctrl-Break sequence
67pub const SIGBREAK = 21;
68
69/// abnormal termination triggered by abort call
70pub const SIGABRT = 22;
71
72/// SIGABRT compatible with other platforms, same as SIGABRT
73pub const SIGABRT_COMPAT = 6;
74
75// Signal action codes
76
77/// default signal action
78pub const SIG_DFL = 0;
79
80/// ignore signal
81pub const SIG_IGN = 1;
82
83/// return current value
84pub const SIG_GET = 2;
85
86/// signal gets error
87pub const SIG_SGE = 3;
88
89/// acknowledge
90pub const SIG_ACK = 4;
91
92/// Signal error value (returned by signal call on error)
93pub const SIG_ERR = -1;
94
95pub const SEEK_SET = 0;
96pub const SEEK_CUR = 1;
97pub const SEEK_END = 2;
98
99pub const E = enum(u16) {
100 /// No error occurred.
101 SUCCESS = 0,
102 PERM = 1,
103 NOENT = 2,
104 SRCH = 3,
105 INTR = 4,
106 IO = 5,
107 NXIO = 6,
108 @"2BIG" = 7,
109 NOEXEC = 8,
110 BADF = 9,
111 CHILD = 10,
112 AGAIN = 11,
113 NOMEM = 12,
114 ACCES = 13,
115 FAULT = 14,
116 BUSY = 16,
117 EXIST = 17,
118 XDEV = 18,
119 NODEV = 19,
120 NOTDIR = 20,
121 ISDIR = 21,
122 NFILE = 23,
123 MFILE = 24,
124 NOTTY = 25,
125 FBIG = 27,
126 NOSPC = 28,
127 SPIPE = 29,
128 ROFS = 30,
129 MLINK = 31,
130 PIPE = 32,
131 DOM = 33,
132 /// Also means `DEADLOCK`.
133 DEADLK = 36,
134 NAMETOOLONG = 38,
135 NOLCK = 39,
136 NOSYS = 40,
137 NOTEMPTY = 41,
138
139 INVAL = 22,
140 RANGE = 34,
141 ILSEQ = 42,
142
143 // POSIX Supplement
144 ADDRINUSE = 100,
145 ADDRNOTAVAIL = 101,
146 AFNOSUPPORT = 102,
147 ALREADY = 103,
148 BADMSG = 104,
149 CANCELED = 105,
150 CONNABORTED = 106,
151 CONNREFUSED = 107,
152 CONNRESET = 108,
153 DESTADDRREQ = 109,
154 HOSTUNREACH = 110,
155 IDRM = 111,
156 INPROGRESS = 112,
157 ISCONN = 113,
158 LOOP = 114,
159 MSGSIZE = 115,
160 NETDOWN = 116,
161 NETRESET = 117,
162 NETUNREACH = 118,
163 NOBUFS = 119,
164 NODATA = 120,
165 NOLINK = 121,
166 NOMSG = 122,
167 NOPROTOOPT = 123,
168 NOSR = 124,
169 NOSTR = 125,
170 NOTCONN = 126,
171 NOTRECOVERABLE = 127,
172 NOTSOCK = 128,
173 NOTSUP = 129,
174 OPNOTSUPP = 130,
175 OTHER = 131,
176 OVERFLOW = 132,
177 OWNERDEAD = 133,
178 PROTO = 134,
179 PROTONOSUPPORT = 135,
180 PROTOTYPE = 136,
181 TIME = 137,
182 TIMEDOUT = 138,
183 TXTBSY = 139,
184 WOULDBLOCK = 140,
185 DQUOT = 10069,
186 _,
187};
188
189pub const STRUNCATE = 80;
190
191pub const F_OK = 0;
192
193/// Remove directory instead of unlinking file
194pub const AT_REMOVEDIR = 0x200;
195
196pub const in_port_t = u16;
197pub const sa_family_t = ws2_32.ADDRESS_FAMILY;
198pub const socklen_t = ws2_32.socklen_t;
199
200pub const sockaddr = ws2_32.sockaddr;
201pub const sockaddr_in = ws2_32.sockaddr_in;
202pub const sockaddr_in6 = ws2_32.sockaddr_in6;
203pub const sockaddr_un = ws2_32.sockaddr_un;
204
205pub const in6_addr = [16]u8;
206pub const in_addr = u32;
207
208pub const addrinfo = ws2_32.addrinfo;
209
210pub const AF_UNSPEC = ws2_32.AF_UNSPEC;
211pub const AF_UNIX = ws2_32.AF_UNIX;
212pub const AF_INET = ws2_32.AF_INET;
213pub const AF_IMPLINK = ws2_32.AF_IMPLINK;
214pub const AF_PUP = ws2_32.AF_PUP;
215pub const AF_CHAOS = ws2_32.AF_CHAOS;
216pub const AF_NS = ws2_32.AF_NS;
217pub const AF_IPX = ws2_32.AF_IPX;
218pub const AF_ISO = ws2_32.AF_ISO;
219pub const AF_OSI = ws2_32.AF_OSI;
220pub const AF_ECMA = ws2_32.AF_ECMA;
221pub const AF_DATAKIT = ws2_32.AF_DATAKIT;
222pub const AF_CCITT = ws2_32.AF_CCITT;
223pub const AF_SNA = ws2_32.AF_SNA;
224pub const AF_DECnet = ws2_32.AF_DECnet;
225pub const AF_DLI = ws2_32.AF_DLI;
226pub const AF_LAT = ws2_32.AF_LAT;
227pub const AF_HYLINK = ws2_32.AF_HYLINK;
228pub const AF_APPLETALK = ws2_32.AF_APPLETALK;
229pub const AF_NETBIOS = ws2_32.AF_NETBIOS;
230pub const AF_VOICEVIEW = ws2_32.AF_VOICEVIEW;
231pub const AF_FIREFOX = ws2_32.AF_FIREFOX;
232pub const AF_UNKNOWN1 = ws2_32.AF_UNKNOWN1;
233pub const AF_BAN = ws2_32.AF_BAN;
234pub const AF_ATM = ws2_32.AF_ATM;
235pub const AF_INET6 = ws2_32.AF_INET6;
236pub const AF_CLUSTER = ws2_32.AF_CLUSTER;
237pub const AF_12844 = ws2_32.AF_12844;
238pub const AF_IRDA = ws2_32.AF_IRDA;
239pub const AF_NETDES = ws2_32.AF_NETDES;
240pub const AF_TCNPROCESS = ws2_32.AF_TCNPROCESS;
241pub const AF_TCNMESSAGE = ws2_32.AF_TCNMESSAGE;
242pub const AF_ICLFXBM = ws2_32.AF_ICLFXBM;
243pub const AF_BTH = ws2_32.AF_BTH;
244pub const AF_MAX = ws2_32.AF_MAX;
245
246pub const SOCK_STREAM = ws2_32.SOCK_STREAM;
247pub const SOCK_DGRAM = ws2_32.SOCK_DGRAM;
248pub const SOCK_RAW = ws2_32.SOCK_RAW;
249pub const SOCK_RDM = ws2_32.SOCK_RDM;
250pub const SOCK_SEQPACKET = ws2_32.SOCK_SEQPACKET;
251
252/// WARNING: this flag is not supported by windows socket functions directly,
253/// it is only supported by std.os.socket. Be sure that this value does
254/// not share any bits with any of the SOCK_* values.
255pub const SOCK_CLOEXEC = 0x10000;
256/// WARNING: this flag is not supported by windows socket functions directly,
257/// it is only supported by std.os.socket. Be sure that this value does
258/// not share any bits with any of the SOCK_* values.
259pub const SOCK_NONBLOCK = 0x20000;
260
261pub const IPPROTO_ICMP = ws2_32.IPPROTO_ICMP;
262pub const IPPROTO_IGMP = ws2_32.IPPROTO_IGMP;
263pub const BTHPROTO_RFCOMM = ws2_32.BTHPROTO_RFCOMM;
264pub const IPPROTO_TCP = ws2_32.IPPROTO_TCP;
265pub const IPPROTO_UDP = ws2_32.IPPROTO_UDP;
266pub const IPPROTO_ICMPV6 = ws2_32.IPPROTO_ICMPV6;
267pub const IPPROTO_RM = ws2_32.IPPROTO_RM;
268
269pub const nfds_t = c_ulong;
270pub const pollfd = ws2_32.pollfd;
271
272pub const POLLRDNORM = ws2_32.POLLRDNORM;
273pub const POLLRDBAND = ws2_32.POLLRDBAND;
274pub const POLLIN = ws2_32.POLLIN;
275pub const POLLPRI = ws2_32.POLLPRI;
276pub const POLLWRNORM = ws2_32.POLLWRNORM;
277pub const POLLOUT = ws2_32.POLLOUT;
278pub const POLLWRBAND = ws2_32.POLLWRBAND;
279pub const POLLERR = ws2_32.POLLERR;
280pub const POLLHUP = ws2_32.POLLHUP;
281pub const POLLNVAL = ws2_32.POLLNVAL;
282
283pub const SOL_SOCKET = ws2_32.SOL_SOCKET;
284
285pub const SO_DEBUG = ws2_32.SO_DEBUG;
286pub const SO_ACCEPTCONN = ws2_32.SO_ACCEPTCONN;
287pub const SO_REUSEADDR = ws2_32.SO_REUSEADDR;
288pub const SO_KEEPALIVE = ws2_32.SO_KEEPALIVE;
289pub const SO_DONTROUTE = ws2_32.SO_DONTROUTE;
290pub const SO_BROADCAST = ws2_32.SO_BROADCAST;
291pub const SO_USELOOPBACK = ws2_32.SO_USELOOPBACK;
292pub const SO_LINGER = ws2_32.SO_LINGER;
293pub const SO_OOBINLINE = ws2_32.SO_OOBINLINE;
294
295pub const SO_DONTLINGER = ws2_32.SO_DONTLINGER;
296pub const SO_EXCLUSIVEADDRUSE = ws2_32.SO_EXCLUSIVEADDRUSE;
297
298pub const SO_SNDBUF = ws2_32.SO_SNDBUF;
299pub const SO_RCVBUF = ws2_32.SO_RCVBUF;
300pub const SO_SNDLOWAT = ws2_32.SO_SNDLOWAT;
301pub const SO_RCVLOWAT = ws2_32.SO_RCVLOWAT;
302pub const SO_SNDTIMEO = ws2_32.SO_SNDTIMEO;
303pub const SO_RCVTIMEO = ws2_32.SO_RCVTIMEO;
304pub const SO_ERROR = ws2_32.SO_ERROR;
305pub const SO_TYPE = ws2_32.SO_TYPE;
306
307pub const SO_GROUP_ID = ws2_32.SO_GROUP_ID;
308pub const SO_GROUP_PRIORITY = ws2_32.SO_GROUP_PRIORITY;
309pub const SO_MAX_MSG_SIZE = ws2_32.SO_MAX_MSG_SIZE;
310pub const SO_PROTOCOL_INFOA = ws2_32.SO_PROTOCOL_INFOA;
311pub const SO_PROTOCOL_INFOW = ws2_32.SO_PROTOCOL_INFOW;
312
313pub const PVD_CONFIG = ws2_32.PVD_CONFIG;
314pub const SO_CONDITIONAL_ACCEPT = ws2_32.SO_CONDITIONAL_ACCEPT;
315
316pub const TCP_NODELAY = ws2_32.TCP_NODELAY;
317
318pub const O_RDONLY = 0o0;
319pub const O_WRONLY = 0o1;
320pub const O_RDWR = 0o2;
321
322pub const O_CREAT = 0o100;
323pub const O_EXCL = 0o200;
324pub const O_NOCTTY = 0o400;
325pub const O_TRUNC = 0o1000;
326pub const O_APPEND = 0o2000;
327pub const O_NONBLOCK = 0o4000;
328pub const O_DSYNC = 0o10000;
329pub const O_SYNC = 0o4010000;
330pub const O_RSYNC = 0o4010000;
331pub const O_DIRECTORY = 0o200000;
332pub const O_NOFOLLOW = 0o400000;
333pub const O_CLOEXEC = 0o2000000;
334
335pub const O_ASYNC = 0o20000;
336pub const O_DIRECT = 0o40000;
337pub const O_LARGEFILE = 0;
338pub const O_NOATIME = 0o1000000;
339pub const O_PATH = 0o10000000;
340pub const O_TMPFILE = 0o20200000;
341pub const O_NDELAY = O_NONBLOCK;
342
343pub const IFNAMESIZE = 30;
lib/std/fs.zig+1-1
...@@ -471,7 +471,7 @@ pub const Dir = struct {...@@ -471,7 +471,7 @@ pub const Dir = struct {
471 continue :start_over;471 continue :start_over;
472 }472 }
473473
474 var stat_info: os.libc_stat = undefined;474 var stat_info: os.Stat = undefined;
475 _ = os.system._kern_read_stat(475 _ = os.system._kern_read_stat(
476 self.dir.fd,476 self.dir.fd,
477 &haiku_entry.d_name,477 &haiku_entry.d_name,
lib/std/os.zig+58-85
...@@ -40,15 +40,10 @@ comptime {...@@ -40,15 +40,10 @@ comptime {
40}40}
4141
42test {42test {
43 _ = darwin;
44 _ = freebsd;
45 _ = linux;43 _ = linux;
46 _ = netbsd;
47 _ = openbsd;
48 _ = uefi;44 _ = uefi;
49 _ = wasi;45 _ = wasi;
50 _ = windows;46 _ = windows;
51 _ = haiku;
5247
53 _ = @import("os/test.zig");48 _ = @import("os/test.zig");
54}49}
...@@ -61,85 +56,68 @@ pub const system = if (@hasDecl(root, "os") and root.os != @This())...@@ -61,85 +56,68 @@ pub const system = if (@hasDecl(root, "os") and root.os != @This())
61else if (builtin.link_libc)56else if (builtin.link_libc)
62 std.c57 std.c
63else switch (builtin.os.tag) {58else switch (builtin.os.tag) {
64 .macos, .ios, .watchos, .tvos => darwin,
65 .freebsd => freebsd,
66 .haiku => haiku,
67 .linux => linux,59 .linux => linux,
68 .netbsd => netbsd,
69 .openbsd => openbsd,
70 .dragonfly => dragonfly,
71 .wasi => wasi,60 .wasi => wasi,
72 .windows => windows,61 .windows => windows,
62 .uefi => uefi,
73 else => struct {},63 else => struct {},
74};64};
7565pub const ARCH = system.ARCH;
76const bits = switch (builtin.os.tag) {66pub const AT = system.AT;
77 .macos, .ios, .tvos, .watchos => std.c,67pub const CLOCK = system.CLOCK;
78 .dragonfly => @import("os/bits/dragonfly.zig"),68pub const E = system.E;
79 .freebsd => @import("os/bits/freebsd.zig"),69pub const Elf_Symndx = system.Elf_Symndx;
80 .haiku => @import("os/bits/haiku.zig"),70pub const F = system.F;
81 .linux => linux,71pub const Flock = system.Flock;
82 .netbsd => @import("os/bits/netbsd.zig"),72pub const IOV_MAX = system.IOV_MAX;
83 .openbsd => @import("os/bits/openbsd.zig"),73pub const LOCK = system.LOCK;
84 .wasi => @import("os/bits/wasi.zig"),74pub const MAP = system.MAP;
85 .windows => @import("os/bits/windows.zig"),75pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN;
86 else => struct {},76pub const MMAP2_UNIT = system.MMAP2_UNIT;
87};77pub const NAME_MAX = system.NAME_MAX;
88pub const E = bits.E;78pub const O = system.O;
89pub const ARCH = bits.ARCH;79pub const PATH_MAX = system.PATH_MAX;
90pub const Elf_Symndx = bits.Elf_Symndx;80pub const PROT = system.PROT;
91pub const F = bits.F;81pub const REG = system.REG;
92pub const Flock = bits.Flock;82pub const S = system.S;
93pub const LOCK = bits.LOCK;83pub const SA = system.SA;
94pub const MAP = bits.MAP;84pub const SC = system.SC;
95pub const MMAP2_UNIT = bits.MMAP2_UNIT;85pub const SIG = system.SIG;
96pub const O = bits.O;86pub const STDERR_FILENO = system.STDIN_FILENO;
97pub const REG = bits.REG;87pub const STDIN_FILENO = system.STDIN_FILENO;
98pub const SC = bits.SC;88pub const STDOUT_FILENO = system.STDIN_FILENO;
99pub const SYS = bits.SYS;89pub const SYS = system.SYS;
100pub const VDSO = bits.VDSO;90pub const Sigaction = system.Sigaction;
101pub const blkcnt_t = bits.blkcnt_t;91pub const Stat = system.Stat;
102pub const blksize_t = bits.blksize_t;92pub const VDSO = system.VDSO;
103pub const dev_t = bits.dev_t;93pub const blkcnt_t = system.blkcnt_t;
104pub const ino_t = bits.ino_t;94pub const blksize_t = system.blksize_t;
105pub const kernel_stat = bits.kernel_stat;95pub const clock_t = system.clock_t;
106pub const libc_stat = bits.libc_stat;96pub const dev_t = system.dev_t;
107pub const mcontext_t = bits.mcontext_t;97pub const dl_phdr_info = system.dl_phdr_info;
108pub const mode_t = bits.mode_t;98pub const empty_sigset = system.empty_sigset;
109pub const msghdr = bits.msghdr;99pub const fd_t = system.fd_t;
110pub const msghdr_const = bits.msghdr_const;100pub const gid_t = system.gid_t;
111pub const nlink_t = bits.nlink_t;101pub const ino_t = system.ino_t;
112pub const off_t = bits.off_t;102pub const mcontext_t = system.mcontext_t;
113pub const time_t = bits.time_t;103pub const mode_t = system.mode_t;
114pub const timespec = bits.timespec;104pub const msghdr = system.msghdr;
115pub const timeval = bits.timeval;105pub const msghdr_const = system.msghdr_const;
116pub const timezone = bits.timezone;106pub const nlink_t = system.nlink_t;
117pub const ucontext_t = bits.ucontext_t;107pub const off_t = system.off_t;
118pub const user_desc = bits.user_desc;108pub const pid_t = system.pid_t;
119pub const pid_t = bits.pid_t;109pub const pollfd = system.pollfd;
120pub const fd_t = bits.fd_t;110pub const rlimit = system.rlimit;
121pub const uid_t = bits.uid_t;111pub const rlimit_resource = system.rlimit_resource;
122pub const gid_t = bits.gid_t;112pub const siginfo_t = system.siginfo_t;
123pub const clock_t = bits.clock_t;113pub const sigset_t = system.sigset_t;
124pub const NAME_MAX = bits.NAME_MAX;114pub const time_t = system.time_t;
125pub const PATH_MAX = bits.PATH_MAX;115pub const timespec = system.timespec;
126pub const IOV_MAX = bits.IOV_MAX;116pub const timeval = system.timeval;
127pub const MAX_ADDR_LEN = bits.MAX_ADDR_LEN;117pub const timezone = system.timezone;
128pub const STDIN_FILENO = bits.STDIN_FILENO;118pub const ucontext_t = system.ucontext_t;
129pub const STDOUT_FILENO = bits.STDIN_FILENO;119pub const uid_t = system.uid_t;
130pub const STDERR_FILENO = bits.STDIN_FILENO;120pub const user_desc = system.user_desc;
131pub const AT = bits.AT;
132pub const PROT = bits.PROT;
133pub const CLOCK = bits.CLOCK;
134pub const dl_phdr_info = bits.dl_phdr_info;
135pub const Sigaction = bits.Sigaction;
136pub const rlimit_resource = bits.rlimit_resource;
137pub const SIG = bits.SIG;
138pub const rlimit = bits.rlimit;
139pub const empty_sigset = bits.empty_sigset;
140pub const S = bits.S;
141pub const siginfo_t = bits.siginfo_t;
142pub const SA = bits.SA;
143121
144pub const iovec = extern struct {122pub const iovec = extern struct {
145 iov_base: [*]u8,123 iov_base: [*]u8,
...@@ -334,7 +312,7 @@ pub fn raise(sig: u8) RaiseError!void {...@@ -334,7 +312,7 @@ pub fn raise(sig: u8) RaiseError!void {
334 }312 }
335313
336 if (builtin.os.tag == .linux) {314 if (builtin.os.tag == .linux) {
337 var set: bits.sigset_t = undefined;315 var set: sigset_t = undefined;
338 // block application signals316 // block application signals
339 _ = linux.sigprocmask(SIG.BLOCK, &linux.app_mask, &set);317 _ = linux.sigprocmask(SIG.BLOCK, &linux.app_mask, &set);
340318
...@@ -3558,11 +3536,6 @@ pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {...@@ -3558,11 +3536,6 @@ pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {
3558 }3536 }
3559}3537}
35603538
3561pub const Stat = if (builtin.link_libc)
3562 system.libc_stat
3563else
3564 system.kernel_stat;
3565
3566pub const FStatError = error{3539pub const FStatError = error{
3567 SystemResources,3540 SystemResources,
35683541
lib/std/os/bits/darwin.zig deleted-1783
...@@ -1,1783 +0,0 @@
1const std = @import("../../std.zig");
2const assert = std.debug.assert;
3const maxInt = std.math.maxInt;
4
5// See: https://opensource.apple.com/source/xnu/xnu-6153.141.1/bsd/sys/_types.h.auto.html
6// TODO: audit mode_t/pid_t, should likely be u16/i32
7pub const fd_t = c_int;
8pub const pid_t = c_int;
9pub const mode_t = c_uint;
10pub const uid_t = u32;
11pub const gid_t = u32;
12
13pub const in_port_t = u16;
14pub const sa_family_t = u8;
15pub const socklen_t = u32;
16pub const sockaddr = extern struct {
17 len: u8,
18 family: sa_family_t,
19 data: [14]u8,
20};
21pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
22pub const sockaddr_in = extern struct {
23 len: u8 = @sizeOf(sockaddr_in),
24 family: sa_family_t = AF_INET,
25 port: in_port_t,
26 addr: u32,
27 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
28};
29pub const sockaddr_in6 = extern struct {
30 len: u8 = @sizeOf(sockaddr_in6),
31 family: sa_family_t = AF_INET6,
32 port: in_port_t,
33 flowinfo: u32,
34 addr: [16]u8,
35 scope_id: u32,
36};
37
38/// UNIX domain socket
39pub const sockaddr_un = extern struct {
40 len: u8 = @sizeOf(sockaddr_un),
41 family: sa_family_t = AF_UNIX,
42 path: [104]u8,
43};
44
45pub const timeval = extern struct {
46 tv_sec: c_long,
47 tv_usec: i32,
48};
49
50pub const timezone = extern struct {
51 tz_minuteswest: i32,
52 tz_dsttime: i32,
53};
54
55pub const mach_timebase_info_data = extern struct {
56 numer: u32,
57 denom: u32,
58};
59
60pub const off_t = i64;
61pub const ino_t = u64;
62
63pub const Flock = extern struct {
64 l_start: off_t,
65 l_len: off_t,
66 l_pid: pid_t,
67 l_type: i16,
68 l_whence: i16,
69};
70
71pub const libc_stat = extern struct {
72 dev: i32,
73 mode: u16,
74 nlink: u16,
75 ino: ino_t,
76 uid: uid_t,
77 gid: gid_t,
78 rdev: i32,
79 atimesec: isize,
80 atimensec: isize,
81 mtimesec: isize,
82 mtimensec: isize,
83 ctimesec: isize,
84 ctimensec: isize,
85 birthtimesec: isize,
86 birthtimensec: isize,
87 size: off_t,
88 blocks: i64,
89 blksize: i32,
90 flags: u32,
91 gen: u32,
92 lspare: i32,
93 qspare: [2]i64,
94
95 pub fn atime(self: @This()) timespec {
96 return timespec{
97 .tv_sec = self.atimesec,
98 .tv_nsec = self.atimensec,
99 };
100 }
101
102 pub fn mtime(self: @This()) timespec {
103 return timespec{
104 .tv_sec = self.mtimesec,
105 .tv_nsec = self.mtimensec,
106 };
107 }
108
109 pub fn ctime(self: @This()) timespec {
110 return timespec{
111 .tv_sec = self.ctimesec,
112 .tv_nsec = self.ctimensec,
113 };
114 }
115};
116
117pub const timespec = extern struct {
118 tv_sec: isize,
119 tv_nsec: isize,
120};
121
122pub const sigset_t = u32;
123pub const empty_sigset: sigset_t = 0;
124
125pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
126pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
127pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
128pub const SIG_HOLD = @intToPtr(?Sigaction.sigaction_fn, 5);
129
130pub const siginfo_t = extern struct {
131 signo: c_int,
132 errno: c_int,
133 code: c_int,
134 pid: pid_t,
135 uid: uid_t,
136 status: c_int,
137 addr: *c_void,
138 value: extern union {
139 int: c_int,
140 ptr: *c_void,
141 },
142 si_band: c_long,
143 _pad: [7]c_ulong,
144};
145
146/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
147pub const Sigaction = extern struct {
148 pub const handler_fn = fn (c_int) callconv(.C) void;
149 pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void;
150
151 handler: extern union {
152 handler: ?handler_fn,
153 sigaction: ?sigaction_fn,
154 },
155 mask: sigset_t,
156 flags: c_uint,
157};
158
159pub const dirent = extern struct {
160 d_ino: usize,
161 d_seekoff: usize,
162 d_reclen: u16,
163 d_namlen: u16,
164 d_type: u8,
165 d_name: u8, // field address is address of first byte of name
166
167 pub fn reclen(self: dirent) u16 {
168 return self.d_reclen;
169 }
170};
171
172/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
173pub const Kevent = extern struct {
174 ident: usize,
175 filter: i16,
176 flags: u16,
177 fflags: u32,
178 data: isize,
179 udata: usize,
180};
181
182// sys/types.h on macos uses #pragma pack(4) so these checks are
183// to make sure the struct is laid out the same. These values were
184// produced from C code using the offsetof macro.
185comptime {
186 assert(@offsetOf(Kevent, "ident") == 0);
187 assert(@offsetOf(Kevent, "filter") == 8);
188 assert(@offsetOf(Kevent, "flags") == 10);
189 assert(@offsetOf(Kevent, "fflags") == 12);
190 assert(@offsetOf(Kevent, "data") == 16);
191 assert(@offsetOf(Kevent, "udata") == 24);
192}
193
194pub const kevent64_s = extern struct {
195 ident: u64,
196 filter: i16,
197 flags: u16,
198 fflags: u32,
199 data: i64,
200 udata: u64,
201 ext: [2]u64,
202};
203
204// sys/types.h on macos uses #pragma pack() so these checks are
205// to make sure the struct is laid out the same. These values were
206// produced from C code using the offsetof macro.
207comptime {
208 assert(@offsetOf(kevent64_s, "ident") == 0);
209 assert(@offsetOf(kevent64_s, "filter") == 8);
210 assert(@offsetOf(kevent64_s, "flags") == 10);
211 assert(@offsetOf(kevent64_s, "fflags") == 12);
212 assert(@offsetOf(kevent64_s, "data") == 16);
213 assert(@offsetOf(kevent64_s, "udata") == 24);
214 assert(@offsetOf(kevent64_s, "ext") == 32);
215}
216
217pub const mach_port_t = c_uint;
218pub const clock_serv_t = mach_port_t;
219pub const clock_res_t = c_int;
220pub const mach_port_name_t = natural_t;
221pub const natural_t = c_uint;
222pub const mach_timespec_t = extern struct {
223 tv_sec: c_uint,
224 tv_nsec: clock_res_t,
225};
226pub const kern_return_t = c_int;
227pub const host_t = mach_port_t;
228pub const CALENDAR_CLOCK = 1;
229
230pub const PATH_MAX = 1024;
231pub const IOV_MAX = 16;
232
233pub const STDIN_FILENO = 0;
234pub const STDOUT_FILENO = 1;
235pub const STDERR_FILENO = 2;
236
237/// [MC2] no permissions
238pub const PROT_NONE = 0x00;
239
240/// [MC2] pages can be read
241pub const PROT_READ = 0x01;
242
243/// [MC2] pages can be written
244pub const PROT_WRITE = 0x02;
245
246/// [MC2] pages can be executed
247pub const PROT_EXEC = 0x04;
248
249/// allocated from memory, swap space
250pub const MAP_ANONYMOUS = 0x1000;
251
252/// map from file (default)
253pub const MAP_FILE = 0x0000;
254
255/// interpret addr exactly
256pub const MAP_FIXED = 0x0010;
257
258/// region may contain semaphores
259pub const MAP_HASSEMAPHORE = 0x0200;
260
261/// changes are private
262pub const MAP_PRIVATE = 0x0002;
263
264/// share changes
265pub const MAP_SHARED = 0x0001;
266
267/// don't cache pages for this mapping
268pub const MAP_NOCACHE = 0x0400;
269
270/// don't reserve needed swap area
271pub const MAP_NORESERVE = 0x0040;
272pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
273
274/// [XSI] no hang in wait/no child to reap
275pub const WNOHANG = 0x00000001;
276
277/// [XSI] notify on stop, untraced child
278pub const WUNTRACED = 0x00000002;
279
280/// take signal on signal stack
281pub const SA_ONSTACK = 0x0001;
282
283/// restart system on signal return
284pub const SA_RESTART = 0x0002;
285
286/// reset to SIG_DFL when taking signal
287pub const SA_RESETHAND = 0x0004;
288
289/// do not generate SIGCHLD on child stop
290pub const SA_NOCLDSTOP = 0x0008;
291
292/// don't mask the signal we're delivering
293pub const SA_NODEFER = 0x0010;
294
295/// don't keep zombies around
296pub const SA_NOCLDWAIT = 0x0020;
297
298/// signal handler with SA_SIGINFO args
299pub const SA_SIGINFO = 0x0040;
300
301/// do not bounce off kernel's sigtramp
302pub const SA_USERTRAMP = 0x0100;
303
304/// signal handler with SA_SIGINFO args with 64bit regs information
305pub const SA_64REGSET = 0x0200;
306
307pub const O_PATH = 0x0000;
308
309pub const F_OK = 0;
310pub const X_OK = 1;
311pub const W_OK = 2;
312pub const R_OK = 4;
313
314/// open for reading only
315pub const O_RDONLY = 0x0000;
316
317/// open for writing only
318pub const O_WRONLY = 0x0001;
319
320/// open for reading and writing
321pub const O_RDWR = 0x0002;
322
323/// do not block on open or for data to become available
324pub const O_NONBLOCK = 0x0004;
325
326/// append on each write
327pub const O_APPEND = 0x0008;
328
329/// create file if it does not exist
330pub const O_CREAT = 0x0200;
331
332/// truncate size to 0
333pub const O_TRUNC = 0x0400;
334
335/// error if O_CREAT and the file exists
336pub const O_EXCL = 0x0800;
337
338/// atomically obtain a shared lock
339pub const O_SHLOCK = 0x0010;
340
341/// atomically obtain an exclusive lock
342pub const O_EXLOCK = 0x0020;
343
344/// do not follow symlinks
345pub const O_NOFOLLOW = 0x0100;
346
347/// allow open of symlinks
348pub const O_SYMLINK = 0x200000;
349
350/// descriptor requested for event notifications only
351pub const O_EVTONLY = 0x8000;
352
353/// mark as close-on-exec
354pub const O_CLOEXEC = 0x1000000;
355
356pub const O_ACCMODE = 3;
357pub const O_ALERT = 536870912;
358pub const O_ASYNC = 64;
359pub const O_DIRECTORY = 1048576;
360pub const O_DP_GETRAWENCRYPTED = 1;
361pub const O_DP_GETRAWUNENCRYPTED = 2;
362pub const O_DSYNC = 4194304;
363pub const O_FSYNC = O_SYNC;
364pub const O_NOCTTY = 131072;
365pub const O_POPUP = 2147483648;
366pub const O_SYNC = 128;
367
368pub const SEEK_SET = 0x0;
369pub const SEEK_CUR = 0x1;
370pub const SEEK_END = 0x2;
371
372pub const DT_UNKNOWN = 0;
373pub const DT_FIFO = 1;
374pub const DT_CHR = 2;
375pub const DT_DIR = 4;
376pub const DT_BLK = 6;
377pub const DT_REG = 8;
378pub const DT_LNK = 10;
379pub const DT_SOCK = 12;
380pub const DT_WHT = 14;
381
382/// block specified signal set
383pub const SIG_BLOCK = 1;
384
385/// unblock specified signal set
386pub const SIG_UNBLOCK = 2;
387
388/// set specified signal set
389pub const SIG_SETMASK = 3;
390
391/// hangup
392pub const SIGHUP = 1;
393
394/// interrupt
395pub const SIGINT = 2;
396
397/// quit
398pub const SIGQUIT = 3;
399
400/// illegal instruction (not reset when caught)
401pub const SIGILL = 4;
402
403/// trace trap (not reset when caught)
404pub const SIGTRAP = 5;
405
406/// abort()
407pub const SIGABRT = 6;
408
409/// pollable event ([XSR] generated, not supported)
410pub const SIGPOLL = 7;
411
412/// compatibility
413pub const SIGIOT = SIGABRT;
414
415/// EMT instruction
416pub const SIGEMT = 7;
417
418/// floating point exception
419pub const SIGFPE = 8;
420
421/// kill (cannot be caught or ignored)
422pub const SIGKILL = 9;
423
424/// bus error
425pub const SIGBUS = 10;
426
427/// segmentation violation
428pub const SIGSEGV = 11;
429
430/// bad argument to system call
431pub const SIGSYS = 12;
432
433/// write on a pipe with no one to read it
434pub const SIGPIPE = 13;
435
436/// alarm clock
437pub const SIGALRM = 14;
438
439/// software termination signal from kill
440pub const SIGTERM = 15;
441
442/// urgent condition on IO channel
443pub const SIGURG = 16;
444
445/// sendable stop signal not from tty
446pub const SIGSTOP = 17;
447
448/// stop signal from tty
449pub const SIGTSTP = 18;
450
451/// continue a stopped process
452pub const SIGCONT = 19;
453
454/// to parent on child stop or exit
455pub const SIGCHLD = 20;
456
457/// to readers pgrp upon background tty read
458pub const SIGTTIN = 21;
459
460/// like TTIN for output if (tp->t_local&LTOSTOP)
461pub const SIGTTOU = 22;
462
463/// input/output possible signal
464pub const SIGIO = 23;
465
466/// exceeded CPU time limit
467pub const SIGXCPU = 24;
468
469/// exceeded file size limit
470pub const SIGXFSZ = 25;
471
472/// virtual time alarm
473pub const SIGVTALRM = 26;
474
475/// profiling time alarm
476pub const SIGPROF = 27;
477
478/// window size changes
479pub const SIGWINCH = 28;
480
481/// information request
482pub const SIGINFO = 29;
483
484/// user defined signal 1
485pub const SIGUSR1 = 30;
486
487/// user defined signal 2
488pub const SIGUSR2 = 31;
489
490/// no flag value
491pub const KEVENT_FLAG_NONE = 0x000;
492
493/// immediate timeout
494pub const KEVENT_FLAG_IMMEDIATE = 0x001;
495
496/// output events only include change
497pub const KEVENT_FLAG_ERROR_EVENTS = 0x002;
498
499/// add event to kq (implies enable)
500pub const EV_ADD = 0x0001;
501
502/// delete event from kq
503pub const EV_DELETE = 0x0002;
504
505/// enable event
506pub const EV_ENABLE = 0x0004;
507
508/// disable event (not reported)
509pub const EV_DISABLE = 0x0008;
510
511/// only report one occurrence
512pub const EV_ONESHOT = 0x0010;
513
514/// clear event state after reporting
515pub const EV_CLEAR = 0x0020;
516
517/// force immediate event output
518/// ... with or without EV_ERROR
519/// ... use KEVENT_FLAG_ERROR_EVENTS
520/// on syscalls supporting flags
521pub const EV_RECEIPT = 0x0040;
522
523/// disable event after reporting
524pub const EV_DISPATCH = 0x0080;
525
526/// unique kevent per udata value
527pub const EV_UDATA_SPECIFIC = 0x0100;
528
529/// ... in combination with EV_DELETE
530/// will defer delete until udata-specific
531/// event enabled. EINPROGRESS will be
532/// returned to indicate the deferral
533pub const EV_DISPATCH2 = EV_DISPATCH | EV_UDATA_SPECIFIC;
534
535/// report that source has vanished
536/// ... only valid with EV_DISPATCH2
537pub const EV_VANISHED = 0x0200;
538
539/// reserved by system
540pub const EV_SYSFLAGS = 0xF000;
541
542/// filter-specific flag
543pub const EV_FLAG0 = 0x1000;
544
545/// filter-specific flag
546pub const EV_FLAG1 = 0x2000;
547
548/// EOF detected
549pub const EV_EOF = 0x8000;
550
551/// error, data contains errno
552pub const EV_ERROR = 0x4000;
553
554pub const EV_POLL = EV_FLAG0;
555pub const EV_OOBAND = EV_FLAG1;
556
557pub const EVFILT_READ = -1;
558pub const EVFILT_WRITE = -2;
559
560/// attached to aio requests
561pub const EVFILT_AIO = -3;
562
563/// attached to vnodes
564pub const EVFILT_VNODE = -4;
565
566/// attached to struct proc
567pub const EVFILT_PROC = -5;
568
569/// attached to struct proc
570pub const EVFILT_SIGNAL = -6;
571
572/// timers
573pub const EVFILT_TIMER = -7;
574
575/// Mach portsets
576pub const EVFILT_MACHPORT = -8;
577
578/// Filesystem events
579pub const EVFILT_FS = -9;
580
581/// User events
582pub const EVFILT_USER = -10;
583
584/// Virtual memory events
585pub const EVFILT_VM = -12;
586
587/// Exception events
588pub const EVFILT_EXCEPT = -15;
589
590pub const EVFILT_SYSCOUNT = 17;
591
592/// On input, NOTE_TRIGGER causes the event to be triggered for output.
593pub const NOTE_TRIGGER = 0x01000000;
594
595/// ignore input fflags
596pub const NOTE_FFNOP = 0x00000000;
597
598/// and fflags
599pub const NOTE_FFAND = 0x40000000;
600
601/// or fflags
602pub const NOTE_FFOR = 0x80000000;
603
604/// copy fflags
605pub const NOTE_FFCOPY = 0xc0000000;
606
607/// mask for operations
608pub const NOTE_FFCTRLMASK = 0xc0000000;
609pub const NOTE_FFLAGSMASK = 0x00ffffff;
610
611/// low water mark
612pub const NOTE_LOWAT = 0x00000001;
613
614/// OOB data
615pub const NOTE_OOB = 0x00000002;
616
617/// vnode was removed
618pub const NOTE_DELETE = 0x00000001;
619
620/// data contents changed
621pub const NOTE_WRITE = 0x00000002;
622
623/// size increased
624pub const NOTE_EXTEND = 0x00000004;
625
626/// attributes changed
627pub const NOTE_ATTRIB = 0x00000008;
628
629/// link count changed
630pub const NOTE_LINK = 0x00000010;
631
632/// vnode was renamed
633pub const NOTE_RENAME = 0x00000020;
634
635/// vnode access was revoked
636pub const NOTE_REVOKE = 0x00000040;
637
638/// No specific vnode event: to test for EVFILT_READ activation
639pub const NOTE_NONE = 0x00000080;
640
641/// vnode was unlocked by flock(2)
642pub const NOTE_FUNLOCK = 0x00000100;
643
644/// process exited
645pub const NOTE_EXIT = 0x80000000;
646
647/// process forked
648pub const NOTE_FORK = 0x40000000;
649
650/// process exec'd
651pub const NOTE_EXEC = 0x20000000;
652
653/// shared with EVFILT_SIGNAL
654pub const NOTE_SIGNAL = 0x08000000;
655
656/// exit status to be returned, valid for child process only
657pub const NOTE_EXITSTATUS = 0x04000000;
658
659/// provide details on reasons for exit
660pub const NOTE_EXIT_DETAIL = 0x02000000;
661
662/// mask for signal & exit status
663pub const NOTE_PDATAMASK = 0x000fffff;
664pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
665
666pub const NOTE_EXIT_DETAIL_MASK = 0x00070000;
667pub const NOTE_EXIT_DECRYPTFAIL = 0x00010000;
668pub const NOTE_EXIT_MEMORY = 0x00020000;
669pub const NOTE_EXIT_CSERROR = 0x00040000;
670
671/// will react on memory pressure
672pub const NOTE_VM_PRESSURE = 0x80000000;
673
674/// will quit on memory pressure, possibly after cleaning up dirty state
675pub const NOTE_VM_PRESSURE_TERMINATE = 0x40000000;
676
677/// will quit immediately on memory pressure
678pub const NOTE_VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000;
679
680/// there was an error
681pub const NOTE_VM_ERROR = 0x10000000;
682
683/// data is seconds
684pub const NOTE_SECONDS = 0x00000001;
685
686/// data is microseconds
687pub const NOTE_USECONDS = 0x00000002;
688
689/// data is nanoseconds
690pub const NOTE_NSECONDS = 0x00000004;
691
692/// absolute timeout
693pub const NOTE_ABSOLUTE = 0x00000008;
694
695/// ext[1] holds leeway for power aware timers
696pub const NOTE_LEEWAY = 0x00000010;
697
698/// system does minimal timer coalescing
699pub const NOTE_CRITICAL = 0x00000020;
700
701/// system does maximum timer coalescing
702pub const NOTE_BACKGROUND = 0x00000040;
703pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080;
704
705/// data is mach absolute time units
706pub const NOTE_MACHTIME = 0x00000100;
707
708pub const AF_UNSPEC = 0;
709pub const AF_LOCAL = 1;
710pub const AF_UNIX = AF_LOCAL;
711pub const AF_INET = 2;
712pub const AF_SYS_CONTROL = 2;
713pub const AF_IMPLINK = 3;
714pub const AF_PUP = 4;
715pub const AF_CHAOS = 5;
716pub const AF_NS = 6;
717pub const AF_ISO = 7;
718pub const AF_OSI = AF_ISO;
719pub const AF_ECMA = 8;
720pub const AF_DATAKIT = 9;
721pub const AF_CCITT = 10;
722pub const AF_SNA = 11;
723pub const AF_DECnet = 12;
724pub const AF_DLI = 13;
725pub const AF_LAT = 14;
726pub const AF_HYLINK = 15;
727pub const AF_APPLETALK = 16;
728pub const AF_ROUTE = 17;
729pub const AF_LINK = 18;
730pub const AF_XTP = 19;
731pub const AF_COIP = 20;
732pub const AF_CNT = 21;
733pub const AF_RTIP = 22;
734pub const AF_IPX = 23;
735pub const AF_SIP = 24;
736pub const AF_PIP = 25;
737pub const AF_ISDN = 28;
738pub const AF_E164 = AF_ISDN;
739pub const AF_KEY = 29;
740pub const AF_INET6 = 30;
741pub const AF_NATM = 31;
742pub const AF_SYSTEM = 32;
743pub const AF_NETBIOS = 33;
744pub const AF_PPP = 34;
745pub const AF_MAX = 40;
746
747pub const PF_UNSPEC = AF_UNSPEC;
748pub const PF_LOCAL = AF_LOCAL;
749pub const PF_UNIX = PF_LOCAL;
750pub const PF_INET = AF_INET;
751pub const PF_IMPLINK = AF_IMPLINK;
752pub const PF_PUP = AF_PUP;
753pub const PF_CHAOS = AF_CHAOS;
754pub const PF_NS = AF_NS;
755pub const PF_ISO = AF_ISO;
756pub const PF_OSI = AF_ISO;
757pub const PF_ECMA = AF_ECMA;
758pub const PF_DATAKIT = AF_DATAKIT;
759pub const PF_CCITT = AF_CCITT;
760pub const PF_SNA = AF_SNA;
761pub const PF_DECnet = AF_DECnet;
762pub const PF_DLI = AF_DLI;
763pub const PF_LAT = AF_LAT;
764pub const PF_HYLINK = AF_HYLINK;
765pub const PF_APPLETALK = AF_APPLETALK;
766pub const PF_ROUTE = AF_ROUTE;
767pub const PF_LINK = AF_LINK;
768pub const PF_XTP = AF_XTP;
769pub const PF_COIP = AF_COIP;
770pub const PF_CNT = AF_CNT;
771pub const PF_SIP = AF_SIP;
772pub const PF_IPX = AF_IPX;
773pub const PF_RTIP = AF_RTIP;
774pub const PF_PIP = AF_PIP;
775pub const PF_ISDN = AF_ISDN;
776pub const PF_KEY = AF_KEY;
777pub const PF_INET6 = AF_INET6;
778pub const PF_NATM = AF_NATM;
779pub const PF_SYSTEM = AF_SYSTEM;
780pub const PF_NETBIOS = AF_NETBIOS;
781pub const PF_PPP = AF_PPP;
782pub const PF_MAX = AF_MAX;
783
784pub const SYSPROTO_EVENT = 1;
785pub const SYSPROTO_CONTROL = 2;
786
787pub const SOCK_STREAM = 1;
788pub const SOCK_DGRAM = 2;
789pub const SOCK_RAW = 3;
790pub const SOCK_RDM = 4;
791pub const SOCK_SEQPACKET = 5;
792pub const SOCK_MAXADDRLEN = 255;
793
794/// Not actually supported by Darwin, but Zig supplies a shim.
795/// This numerical value is not ABI-stable. It need only not conflict
796/// with any other "SOCK_" bits.
797pub const SOCK_CLOEXEC = 1 << 15;
798/// Not actually supported by Darwin, but Zig supplies a shim.
799/// This numerical value is not ABI-stable. It need only not conflict
800/// with any other "SOCK_" bits.
801pub const SOCK_NONBLOCK = 1 << 16;
802
803pub const IPPROTO_ICMP = 1;
804pub const IPPROTO_ICMPV6 = 58;
805pub const IPPROTO_TCP = 6;
806pub const IPPROTO_UDP = 17;
807pub const IPPROTO_IP = 0;
808pub const IPPROTO_IPV6 = 41;
809
810pub const SOL_SOCKET = 0xffff;
811
812pub const SO_DEBUG = 0x0001;
813pub const SO_ACCEPTCONN = 0x0002;
814pub const SO_REUSEADDR = 0x0004;
815pub const SO_KEEPALIVE = 0x0008;
816pub const SO_DONTROUTE = 0x0010;
817pub const SO_BROADCAST = 0x0020;
818pub const SO_USELOOPBACK = 0x0040;
819pub const SO_LINGER = 0x1080;
820pub const SO_OOBINLINE = 0x0100;
821pub const SO_REUSEPORT = 0x0200;
822pub const SO_ACCEPTFILTER = 0x1000;
823pub const SO_SNDBUF = 0x1001;
824pub const SO_RCVBUF = 0x1002;
825pub const SO_SNDLOWAT = 0x1003;
826pub const SO_RCVLOWAT = 0x1004;
827pub const SO_SNDTIMEO = 0x1005;
828pub const SO_RCVTIMEO = 0x1006;
829pub const SO_ERROR = 0x1007;
830pub const SO_TYPE = 0x1008;
831
832pub const SO_NREAD = 0x1020;
833pub const SO_NKE = 0x1021;
834pub const SO_NOSIGPIPE = 0x1022;
835pub const SO_NOADDRERR = 0x1023;
836pub const SO_NWRITE = 0x1024;
837pub const SO_REUSESHAREUID = 0x1025;
838
839fn wstatus(x: u32) u32 {
840 return x & 0o177;
841}
842const wstopped = 0o177;
843pub fn WEXITSTATUS(x: u32) u8 {
844 return @intCast(u8, x >> 8);
845}
846pub fn WTERMSIG(x: u32) u32 {
847 return wstatus(x);
848}
849pub fn WSTOPSIG(x: u32) u32 {
850 return x >> 8;
851}
852pub fn WIFEXITED(x: u32) bool {
853 return wstatus(x) == 0;
854}
855pub fn WIFSTOPPED(x: u32) bool {
856 return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13;
857}
858pub fn WIFSIGNALED(x: u32) bool {
859 return wstatus(x) != wstopped and wstatus(x) != 0;
860}
861
862pub const E = enum(u16) {
863 /// No error occurred.
864 SUCCESS = 0,
865
866 /// Operation not permitted
867 PERM = 1,
868
869 /// No such file or directory
870 NOENT = 2,
871
872 /// No such process
873 SRCH = 3,
874
875 /// Interrupted system call
876 INTR = 4,
877
878 /// Input/output error
879 IO = 5,
880
881 /// Device not configured
882 NXIO = 6,
883
884 /// Argument list too long
885 @"2BIG" = 7,
886
887 /// Exec format error
888 NOEXEC = 8,
889
890 /// Bad file descriptor
891 BADF = 9,
892
893 /// No child processes
894 CHILD = 10,
895
896 /// Resource deadlock avoided
897 DEADLK = 11,
898
899 /// Cannot allocate memory
900 NOMEM = 12,
901
902 /// Permission denied
903 ACCES = 13,
904
905 /// Bad address
906 FAULT = 14,
907
908 /// Block device required
909 NOTBLK = 15,
910
911 /// Device / Resource busy
912 BUSY = 16,
913
914 /// File exists
915 EXIST = 17,
916
917 /// Cross-device link
918 XDEV = 18,
919
920 /// Operation not supported by device
921 NODEV = 19,
922
923 /// Not a directory
924 NOTDIR = 20,
925
926 /// Is a directory
927 ISDIR = 21,
928
929 /// Invalid argument
930 INVAL = 22,
931
932 /// Too many open files in system
933 NFILE = 23,
934
935 /// Too many open files
936 MFILE = 24,
937
938 /// Inappropriate ioctl for device
939 NOTTY = 25,
940
941 /// Text file busy
942 TXTBSY = 26,
943
944 /// File too large
945 FBIG = 27,
946
947 /// No space left on device
948 NOSPC = 28,
949
950 /// Illegal seek
951 SPIPE = 29,
952
953 /// Read-only file system
954 ROFS = 30,
955
956 /// Too many links
957 MLINK = 31,
958
959 /// Broken pipe
960 PIPE = 32,
961
962 // math software
963
964 /// Numerical argument out of domain
965 DOM = 33,
966
967 /// Result too large
968 RANGE = 34,
969
970 // non-blocking and interrupt i/o
971
972 /// Resource temporarily unavailable
973 /// This is the same code used for `WOULDBLOCK`.
974 AGAIN = 35,
975
976 /// Operation now in progress
977 INPROGRESS = 36,
978
979 /// Operation already in progress
980 ALREADY = 37,
981
982 // ipc/network software -- argument errors
983
984 /// Socket operation on non-socket
985 NOTSOCK = 38,
986
987 /// Destination address required
988 DESTADDRREQ = 39,
989
990 /// Message too long
991 MSGSIZE = 40,
992
993 /// Protocol wrong type for socket
994 PROTOTYPE = 41,
995
996 /// Protocol not available
997 NOPROTOOPT = 42,
998
999 /// Protocol not supported
1000 PROTONOSUPPORT = 43,
1001
1002 /// Socket type not supported
1003 SOCKTNOSUPPORT = 44,
1004
1005 /// Operation not supported
1006 /// The same code is used for `NOTSUP`.
1007 OPNOTSUPP = 45,
1008
1009 /// Protocol family not supported
1010 PFNOSUPPORT = 46,
1011
1012 /// Address family not supported by protocol family
1013 AFNOSUPPORT = 47,
1014
1015 /// Address already in use
1016 ADDRINUSE = 48,
1017 /// Can't assign requested address
1018
1019 // ipc/network software -- operational errors
1020 ADDRNOTAVAIL = 49,
1021
1022 /// Network is down
1023 NETDOWN = 50,
1024
1025 /// Network is unreachable
1026 NETUNREACH = 51,
1027
1028 /// Network dropped connection on reset
1029 NETRESET = 52,
1030
1031 /// Software caused connection abort
1032 CONNABORTED = 53,
1033
1034 /// Connection reset by peer
1035 CONNRESET = 54,
1036
1037 /// No buffer space available
1038 NOBUFS = 55,
1039
1040 /// Socket is already connected
1041 ISCONN = 56,
1042
1043 /// Socket is not connected
1044 NOTCONN = 57,
1045
1046 /// Can't send after socket shutdown
1047 SHUTDOWN = 58,
1048
1049 /// Too many references: can't splice
1050 TOOMANYREFS = 59,
1051
1052 /// Operation timed out
1053 TIMEDOUT = 60,
1054
1055 /// Connection refused
1056 CONNREFUSED = 61,
1057
1058 /// Too many levels of symbolic links
1059 LOOP = 62,
1060
1061 /// File name too long
1062 NAMETOOLONG = 63,
1063
1064 /// Host is down
1065 HOSTDOWN = 64,
1066
1067 /// No route to host
1068 HOSTUNREACH = 65,
1069 /// Directory not empty
1070
1071 // quotas & mush
1072 NOTEMPTY = 66,
1073
1074 /// Too many processes
1075 PROCLIM = 67,
1076
1077 /// Too many users
1078 USERS = 68,
1079 /// Disc quota exceeded
1080
1081 // Network File System
1082 DQUOT = 69,
1083
1084 /// Stale NFS file handle
1085 STALE = 70,
1086
1087 /// Too many levels of remote in path
1088 REMOTE = 71,
1089
1090 /// RPC struct is bad
1091 BADRPC = 72,
1092
1093 /// RPC version wrong
1094 RPCMISMATCH = 73,
1095
1096 /// RPC prog. not avail
1097 PROGUNAVAIL = 74,
1098
1099 /// Program version wrong
1100 PROGMISMATCH = 75,
1101
1102 /// Bad procedure for program
1103 PROCUNAVAIL = 76,
1104
1105 /// No locks available
1106 NOLCK = 77,
1107
1108 /// Function not implemented
1109 NOSYS = 78,
1110
1111 /// Inappropriate file type or format
1112 FTYPE = 79,
1113
1114 /// Authentication error
1115 AUTH = 80,
1116
1117 /// Need authenticator
1118 NEEDAUTH = 81,
1119
1120 // Intelligent device errors
1121
1122 /// Device power is off
1123 PWROFF = 82,
1124
1125 /// Device error, e.g. paper out
1126 DEVERR = 83,
1127
1128 /// Value too large to be stored in data type
1129 OVERFLOW = 84,
1130
1131 // Program loading errors
1132
1133 /// Bad executable
1134 BADEXEC = 85,
1135
1136 /// Bad CPU type in executable
1137 BADARCH = 86,
1138
1139 /// Shared library version mismatch
1140 SHLIBVERS = 87,
1141
1142 /// Malformed Macho file
1143 BADMACHO = 88,
1144
1145 /// Operation canceled
1146 CANCELED = 89,
1147
1148 /// Identifier removed
1149 IDRM = 90,
1150
1151 /// No message of desired type
1152 NOMSG = 91,
1153
1154 /// Illegal byte sequence
1155 ILSEQ = 92,
1156
1157 /// Attribute not found
1158 NOATTR = 93,
1159
1160 /// Bad message
1161 BADMSG = 94,
1162
1163 /// Reserved
1164 MULTIHOP = 95,
1165
1166 /// No message available on STREAM
1167 NODATA = 96,
1168
1169 /// Reserved
1170 NOLINK = 97,
1171
1172 /// No STREAM resources
1173 NOSR = 98,
1174
1175 /// Not a STREAM
1176 NOSTR = 99,
1177
1178 /// Protocol error
1179 PROTO = 100,
1180
1181 /// STREAM ioctl timeout
1182 TIME = 101,
1183
1184 /// No such policy registered
1185 NOPOLICY = 103,
1186
1187 /// State not recoverable
1188 NOTRECOVERABLE = 104,
1189
1190 /// Previous owner died
1191 OWNERDEAD = 105,
1192
1193 /// Interface output queue is full
1194 QFULL = 106,
1195
1196 _,
1197};
1198
1199pub const SIGSTKSZ = 131072;
1200pub const MINSIGSTKSZ = 32768;
1201
1202pub const SS_ONSTACK = 1;
1203pub const SS_DISABLE = 4;
1204
1205pub const stack_t = extern struct {
1206 ss_sp: [*]u8,
1207 ss_size: isize,
1208 ss_flags: i32,
1209};
1210
1211pub const S_IFMT = 0o170000;
1212
1213pub const S_IFIFO = 0o010000;
1214pub const S_IFCHR = 0o020000;
1215pub const S_IFDIR = 0o040000;
1216pub const S_IFBLK = 0o060000;
1217pub const S_IFREG = 0o100000;
1218pub const S_IFLNK = 0o120000;
1219pub const S_IFSOCK = 0o140000;
1220pub const S_IFWHT = 0o160000;
1221
1222pub const S_ISUID = 0o4000;
1223pub const S_ISGID = 0o2000;
1224pub const S_ISVTX = 0o1000;
1225pub const S_IRWXU = 0o700;
1226pub const S_IRUSR = 0o400;
1227pub const S_IWUSR = 0o200;
1228pub const S_IXUSR = 0o100;
1229pub const S_IRWXG = 0o070;
1230pub const S_IRGRP = 0o040;
1231pub const S_IWGRP = 0o020;
1232pub const S_IXGRP = 0o010;
1233pub const S_IRWXO = 0o007;
1234pub const S_IROTH = 0o004;
1235pub const S_IWOTH = 0o002;
1236pub const S_IXOTH = 0o001;
1237
1238pub fn S_ISFIFO(m: u32) bool {
1239 return m & S_IFMT == S_IFIFO;
1240}
1241
1242pub fn S_ISCHR(m: u32) bool {
1243 return m & S_IFMT == S_IFCHR;
1244}
1245
1246pub fn S_ISDIR(m: u32) bool {
1247 return m & S_IFMT == S_IFDIR;
1248}
1249
1250pub fn S_ISBLK(m: u32) bool {
1251 return m & S_IFMT == S_IFBLK;
1252}
1253
1254pub fn S_ISREG(m: u32) bool {
1255 return m & S_IFMT == S_IFREG;
1256}
1257
1258pub fn S_ISLNK(m: u32) bool {
1259 return m & S_IFMT == S_IFLNK;
1260}
1261
1262pub fn S_ISSOCK(m: u32) bool {
1263 return m & S_IFMT == S_IFSOCK;
1264}
1265
1266pub fn S_IWHT(m: u32) bool {
1267 return m & S_IFMT == S_IFWHT;
1268}
1269
1270pub const HOST_NAME_MAX = 72;
1271
1272pub const AT_FDCWD = -2;
1273
1274/// Use effective ids in access check
1275pub const AT_EACCESS = 0x0010;
1276
1277/// Act on the symlink itself not the target
1278pub const AT_SYMLINK_NOFOLLOW = 0x0020;
1279
1280/// Act on target of symlink
1281pub const AT_SYMLINK_FOLLOW = 0x0040;
1282
1283/// Path refers to directory
1284pub const AT_REMOVEDIR = 0x0080;
1285
1286pub const addrinfo = extern struct {
1287 flags: i32,
1288 family: i32,
1289 socktype: i32,
1290 protocol: i32,
1291 addrlen: socklen_t,
1292 canonname: ?[*:0]u8,
1293 addr: ?*sockaddr,
1294 next: ?*addrinfo,
1295};
1296
1297pub const RTLD_LAZY = 0x1;
1298pub const RTLD_NOW = 0x2;
1299pub const RTLD_LOCAL = 0x4;
1300pub const RTLD_GLOBAL = 0x8;
1301pub const RTLD_NOLOAD = 0x10;
1302pub const RTLD_NODELETE = 0x80;
1303pub const RTLD_FIRST = 0x100;
1304
1305pub const RTLD_NEXT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -1)));
1306pub const RTLD_DEFAULT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -2)));
1307pub const RTLD_SELF = @intToPtr(*c_void, @bitCast(usize, @as(isize, -3)));
1308pub const RTLD_MAIN_ONLY = @intToPtr(*c_void, @bitCast(usize, @as(isize, -5)));
1309
1310/// duplicate file descriptor
1311pub const F_DUPFD = 0;
1312
1313/// get file descriptor flags
1314pub const F_GETFD = 1;
1315
1316/// set file descriptor flags
1317pub const F_SETFD = 2;
1318
1319/// get file status flags
1320pub const F_GETFL = 3;
1321
1322/// set file status flags
1323pub const F_SETFL = 4;
1324
1325/// get SIGIO/SIGURG proc/pgrp
1326pub const F_GETOWN = 5;
1327
1328/// set SIGIO/SIGURG proc/pgrp
1329pub const F_SETOWN = 6;
1330
1331/// get record locking information
1332pub const F_GETLK = 7;
1333
1334/// set record locking information
1335pub const F_SETLK = 8;
1336
1337/// F_SETLK; wait if blocked
1338pub const F_SETLKW = 9;
1339
1340/// F_SETLK; wait if blocked, return on timeout
1341pub const F_SETLKWTIMEOUT = 10;
1342pub const F_FLUSH_DATA = 40;
1343
1344/// Used for regression test
1345pub const F_CHKCLEAN = 41;
1346
1347/// Preallocate storage
1348pub const F_PREALLOCATE = 42;
1349
1350/// Truncate a file without zeroing space
1351pub const F_SETSIZE = 43;
1352
1353/// Issue an advisory read async with no copy to user
1354pub const F_RDADVISE = 44;
1355
1356/// turn read ahead off/on for this fd
1357pub const F_RDAHEAD = 45;
1358
1359/// turn data caching off/on for this fd
1360pub const F_NOCACHE = 48;
1361
1362/// file offset to device offset
1363pub const F_LOG2PHYS = 49;
1364
1365/// return the full path of the fd
1366pub const F_GETPATH = 50;
1367
1368/// fsync + ask the drive to flush to the media
1369pub const F_FULLFSYNC = 51;
1370
1371/// find which component (if any) is a package
1372pub const F_PATHPKG_CHECK = 52;
1373
1374/// "freeze" all fs operations
1375pub const F_FREEZE_FS = 53;
1376
1377/// "thaw" all fs operations
1378pub const F_THAW_FS = 54;
1379
1380/// turn data caching off/on (globally) for this file
1381pub const F_GLOBAL_NOCACHE = 55;
1382
1383/// add detached signatures
1384pub const F_ADDSIGS = 59;
1385
1386/// add signature from same file (used by dyld for shared libs)
1387pub const F_ADDFILESIGS = 61;
1388
1389/// used in conjunction with F_NOCACHE to indicate that DIRECT, synchonous writes
1390/// should not be used (i.e. its ok to temporaily create cached pages)
1391pub const F_NODIRECT = 62;
1392
1393///Get the protection class of a file from the EA, returns int
1394pub const F_GETPROTECTIONCLASS = 63;
1395
1396///Set the protection class of a file for the EA, requires int
1397pub const F_SETPROTECTIONCLASS = 64;
1398
1399///file offset to device offset, extended
1400pub const F_LOG2PHYS_EXT = 65;
1401
1402///get record locking information, per-process
1403pub const F_GETLKPID = 66;
1404
1405///Mark the file as being the backing store for another filesystem
1406pub const F_SETBACKINGSTORE = 70;
1407
1408///return the full path of the FD, but error in specific mtmd circumstances
1409pub const F_GETPATH_MTMINFO = 71;
1410
1411///Returns the code directory, with associated hashes, to the caller
1412pub const F_GETCODEDIR = 72;
1413
1414///No SIGPIPE generated on EPIPE
1415pub const F_SETNOSIGPIPE = 73;
1416
1417///Status of SIGPIPE for this fd
1418pub const F_GETNOSIGPIPE = 74;
1419
1420///For some cases, we need to rewrap the key for AKS/MKB
1421pub const F_TRANSCODEKEY = 75;
1422
1423///file being written to a by single writer... if throttling enabled, writes
1424///may be broken into smaller chunks with throttling in between
1425pub const F_SINGLE_WRITER = 76;
1426
1427///Get the protection version number for this filesystem
1428pub const F_GETPROTECTIONLEVEL = 77;
1429
1430///Add detached code signatures (used by dyld for shared libs)
1431pub const F_FINDSIGS = 78;
1432
1433///Add signature from same file, only if it is signed by Apple (used by dyld for simulator)
1434pub const F_ADDFILESIGS_FOR_DYLD_SIM = 83;
1435
1436///fsync + issue barrier to drive
1437pub const F_BARRIERFSYNC = 85;
1438
1439///Add signature from same file, return end offset in structure on success
1440pub const F_ADDFILESIGS_RETURN = 97;
1441
1442///Check if Library Validation allows this Mach-O file to be mapped into the calling process
1443pub const F_CHECK_LV = 98;
1444
1445///Deallocate a range of the file
1446pub const F_PUNCHHOLE = 99;
1447
1448///Trim an active file
1449pub const F_TRIM_ACTIVE_FILE = 100;
1450
1451pub const FCNTL_FS_SPECIFIC_BASE = 0x00010000;
1452
1453///mark the dup with FD_CLOEXEC
1454pub const F_DUPFD_CLOEXEC = 67;
1455
1456///close-on-exec flag
1457pub const FD_CLOEXEC = 1;
1458
1459/// shared or read lock
1460pub const F_RDLCK = 1;
1461
1462/// unlock
1463pub const F_UNLCK = 2;
1464
1465/// exclusive or write lock
1466pub const F_WRLCK = 3;
1467
1468pub const LOCK_SH = 1;
1469pub const LOCK_EX = 2;
1470pub const LOCK_UN = 8;
1471pub const LOCK_NB = 4;
1472
1473pub const nfds_t = u32;
1474pub const pollfd = extern struct {
1475 fd: fd_t,
1476 events: i16,
1477 revents: i16,
1478};
1479
1480pub const POLLIN = 0x001;
1481pub const POLLPRI = 0x002;
1482pub const POLLOUT = 0x004;
1483pub const POLLRDNORM = 0x040;
1484pub const POLLWRNORM = POLLOUT;
1485pub const POLLRDBAND = 0x080;
1486pub const POLLWRBAND = 0x100;
1487
1488pub const POLLEXTEND = 0x0200;
1489pub const POLLATTRIB = 0x0400;
1490pub const POLLNLINK = 0x0800;
1491pub const POLLWRITE = 0x1000;
1492
1493pub const POLLERR = 0x008;
1494pub const POLLHUP = 0x010;
1495pub const POLLNVAL = 0x020;
1496
1497pub const POLLSTANDARD = POLLIN | POLLPRI | POLLOUT | POLLRDNORM | POLLRDBAND | POLLWRBAND | POLLERR | POLLHUP | POLLNVAL;
1498
1499pub const CLOCK_REALTIME = 0;
1500pub const CLOCK_MONOTONIC = 6;
1501pub const CLOCK_MONOTONIC_RAW = 4;
1502pub const CLOCK_MONOTONIC_RAW_APPROX = 5;
1503pub const CLOCK_UPTIME_RAW = 8;
1504pub const CLOCK_UPTIME_RAW_APPROX = 9;
1505pub const CLOCK_PROCESS_CPUTIME_ID = 12;
1506pub const CLOCK_THREAD_CPUTIME_ID = 16;
1507
1508/// Max open files per process
1509/// https://opensource.apple.com/source/xnu/xnu-4903.221.2/bsd/sys/syslimits.h.auto.html
1510pub const OPEN_MAX = 10240;
1511pub const RUSAGE_SELF = 0;
1512pub const RUSAGE_CHILDREN = -1;
1513
1514pub const rusage = extern struct {
1515 utime: timeval,
1516 stime: timeval,
1517 maxrss: isize,
1518 ixrss: isize,
1519 idrss: isize,
1520 isrss: isize,
1521 minflt: isize,
1522 majflt: isize,
1523 nswap: isize,
1524 inblock: isize,
1525 oublock: isize,
1526 msgsnd: isize,
1527 msgrcv: isize,
1528 nsignals: isize,
1529 nvcsw: isize,
1530 nivcsw: isize,
1531};
1532
1533pub const rlimit_resource = enum(c_int) {
1534 CPU = 0,
1535 FSIZE = 1,
1536 DATA = 2,
1537 STACK = 3,
1538 CORE = 4,
1539 RSS = 5,
1540 MEMLOCK = 6,
1541 NPROC = 7,
1542 NOFILE = 8,
1543 _,
1544
1545 pub const AS: rlimit_resource = .RSS;
1546};
1547
1548pub const rlim_t = u64;
1549
1550/// No limit
1551pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
1552
1553pub const RLIM_SAVED_MAX = RLIM_INFINITY;
1554pub const RLIM_SAVED_CUR = RLIM_INFINITY;
1555
1556pub const rlimit = extern struct {
1557 /// Soft limit
1558 cur: rlim_t,
1559 /// Hard limit
1560 max: rlim_t,
1561};
1562
1563pub const SHUT_RD = 0;
1564pub const SHUT_WR = 1;
1565pub const SHUT_RDWR = 2;
1566
1567// Term
1568pub const VEOF = 0;
1569pub const VEOL = 1;
1570pub const VEOL2 = 2;
1571pub const VERASE = 3;
1572pub const VWERASE = 4;
1573pub const VKILL = 5;
1574pub const VREPRINT = 6;
1575pub const VINTR = 8;
1576pub const VQUIT = 9;
1577pub const VSUSP = 10;
1578pub const VDSUSP = 11;
1579pub const VSTART = 12;
1580pub const VSTOP = 13;
1581pub const VLNEXT = 14;
1582pub const VDISCARD = 15;
1583pub const VMIN = 16;
1584pub const VTIME = 17;
1585pub const VSTATUS = 18;
1586pub const NCCS = 20; // 2 spares (7, 19)
1587
1588pub const IGNBRK = 0x00000001; // ignore BREAK condition
1589pub const BRKINT = 0x00000002; // map BREAK to SIGINTR
1590pub const IGNPAR = 0x00000004; // ignore (discard) parity errors
1591pub const PARMRK = 0x00000008; // mark parity and framing errors
1592pub const INPCK = 0x00000010; // enable checking of parity errors
1593pub const ISTRIP = 0x00000020; // strip 8th bit off chars
1594pub const INLCR = 0x00000040; // map NL into CR
1595pub const IGNCR = 0x00000080; // ignore CR
1596pub const ICRNL = 0x00000100; // map CR to NL (ala CRMOD)
1597pub const IXON = 0x00000200; // enable output flow control
1598pub const IXOFF = 0x00000400; // enable input flow control
1599pub const IXANY = 0x00000800; // any char will restart after stop
1600pub const IMAXBEL = 0x00002000; // ring bell on input queue full
1601pub const IUTF8 = 0x00004000; // maintain state for UTF-8 VERASE
1602
1603pub const OPOST = 0x00000001; //enable following output processing
1604pub const ONLCR = 0x00000002; // map NL to CR-NL (ala CRMOD)
1605pub const OXTABS = 0x00000004; // expand tabs to spaces
1606pub const ONOEOT = 0x00000008; // discard EOT's (^D) on output)
1607
1608pub const OCRNL = 0x00000010; // map CR to NL on output
1609pub const ONOCR = 0x00000020; // no CR output at column 0
1610pub const ONLRET = 0x00000040; // NL performs CR function
1611pub const OFILL = 0x00000080; // use fill characters for delay
1612pub const NLDLY = 0x00000300; // \n delay
1613pub const TABDLY = 0x00000c04; // horizontal tab delay
1614pub const CRDLY = 0x00003000; // \r delay
1615pub const FFDLY = 0x00004000; // form feed delay
1616pub const BSDLY = 0x00008000; // \b delay
1617pub const VTDLY = 0x00010000; // vertical tab delay
1618pub const OFDEL = 0x00020000; // fill is DEL, else NUL
1619
1620pub const NL0 = 0x00000000;
1621pub const NL1 = 0x00000100;
1622pub const NL2 = 0x00000200;
1623pub const NL3 = 0x00000300;
1624pub const TAB0 = 0x00000000;
1625pub const TAB1 = 0x00000400;
1626pub const TAB2 = 0x00000800;
1627pub const TAB3 = 0x00000004;
1628pub const CR0 = 0x00000000;
1629pub const CR1 = 0x00001000;
1630pub const CR2 = 0x00002000;
1631pub const CR3 = 0x00003000;
1632pub const FF0 = 0x00000000;
1633pub const FF1 = 0x00004000;
1634pub const BS0 = 0x00000000;
1635pub const BS1 = 0x00008000;
1636pub const VT0 = 0x00000000;
1637pub const VT1 = 0x00010000;
1638
1639pub const CIGNORE = 0x00000001; // ignore control flags
1640pub const CSIZE = 0x00000300; // character size mask
1641pub const CS5 = 0x00000000; // 5 bits (pseudo)
1642pub const CS6 = 0x00000100; // 6 bits
1643pub const CS7 = 0x00000200; // 7 bits
1644pub const CS8 = 0x00000300; // 8 bits
1645pub const CSTOPB = 0x0000040; // send 2 stop bits
1646pub const CREAD = 0x00000800; // enable receiver
1647pub const PARENB = 0x00001000; // parity enable
1648pub const PARODD = 0x00002000; // odd parity, else even
1649pub const HUPCL = 0x00004000; // hang up on last close
1650pub const CLOCAL = 0x00008000; // ignore modem status lines
1651pub const CCTS_OFLOW = 0x00010000; // CTS flow control of output
1652pub const CRTSCTS = (CCTS_OFLOW | CRTS_IFLOW);
1653pub const CRTS_IFLOW = 0x00020000; // RTS flow control of input
1654pub const CDTR_IFLOW = 0x00040000; // DTR flow control of input
1655pub const CDSR_OFLOW = 0x00080000; // DSR flow control of output
1656pub const CCAR_OFLOW = 0x00100000; // DCD flow control of output
1657pub const MDMBUF = 0x00100000; // old name for CCAR_OFLOW
1658
1659pub const ECHOKE = 0x00000001; // visual erase for line kill
1660pub const ECHOE = 0x00000002; // visually erase chars
1661pub const ECHOK = 0x00000004; // echo NL after line kill
1662pub const ECHO = 0x00000008; // enable echoing
1663pub const ECHONL = 0x00000010; // echo NL even if ECHO is off
1664pub const ECHOPRT = 0x00000020; // visual erase mode for hardcopy
1665pub const ECHOCTL = 0x00000040; // echo control chars as ^(Char)
1666pub const ISIG = 0x00000080; // enable signals INTR, QUIT, [D]SUSP
1667pub const ICANON = 0x00000100; // canonicalize input lines
1668pub const ALTWERASE = 0x00000200; // use alternate WERASE algorithm
1669pub const IEXTEN = 0x00000400; // enable DISCARD and LNEXT
1670pub const EXTPROC = 0x00000800; // external processing
1671pub const TOSTOP = 0x00400000; // stop background jobs from output
1672pub const FLUSHO = 0x00800000; // output being flushed (state)
1673pub const NOKERNINFO = 0x02000000; // no kernel output from VSTATUS
1674pub const PENDIN = 0x20000000; // XXX retype pending input (state)
1675pub const NOFLSH = 0x80000000; // don't flush after interrupt
1676
1677pub const TCSANOW = 0; // make change immediate
1678pub const TCSADRAIN = 1; // drain output, then change
1679pub const TCSAFLUSH = 2; // drain output, flush input
1680pub const TCSASOFT = 0x10; // flag - don't alter h.w. state
1681pub const TCSA = enum(c_uint) {
1682 NOW,
1683 DRAIN,
1684 FLUSH,
1685 _,
1686};
1687
1688pub const B0 = 0;
1689pub const B50 = 50;
1690pub const B75 = 75;
1691pub const B110 = 110;
1692pub const B134 = 134;
1693pub const B150 = 150;
1694pub const B200 = 200;
1695pub const B300 = 300;
1696pub const B600 = 600;
1697pub const B1200 = 1200;
1698pub const B1800 = 1800;
1699pub const B2400 = 2400;
1700pub const B4800 = 4800;
1701pub const B9600 = 9600;
1702pub const B19200 = 19200;
1703pub const B38400 = 38400;
1704pub const B7200 = 7200;
1705pub const B14400 = 14400;
1706pub const B28800 = 28800;
1707pub const B57600 = 57600;
1708pub const B76800 = 76800;
1709pub const B115200 = 115200;
1710pub const B230400 = 230400;
1711pub const EXTA = 19200;
1712pub const EXTB = 38400;
1713
1714pub const TCIFLUSH = 1;
1715pub const TCOFLUSH = 2;
1716pub const TCIOFLUSH = 3;
1717pub const TCOOFF = 1;
1718pub const TCOON = 2;
1719pub const TCIOFF = 3;
1720pub const TCION = 4;
1721
1722pub const cc_t = u8;
1723pub const speed_t = u64;
1724pub const tcflag_t = u64;
1725
1726pub const termios = extern struct {
1727 iflag: tcflag_t, // input flags
1728 oflag: tcflag_t, // output flags
1729 cflag: tcflag_t, // control flags
1730 lflag: tcflag_t, // local flags
1731 cc: [NCCS]cc_t, // control chars
1732 ispeed: speed_t align(8), // input speed
1733 ospeed: speed_t, // output speed
1734};
1735
1736pub const winsize = extern struct {
1737 ws_row: u16,
1738 ws_col: u16,
1739 ws_xpixel: u16,
1740 ws_ypixel: u16,
1741};
1742
1743pub const TIOCGWINSZ = ior(0x40000000, 't', 104, @sizeOf(winsize));
1744pub const IOCPARM_MASK = 0x1fff;
1745
1746fn ior(inout: u32, group: usize, num: usize, len: usize) usize {
1747 return (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num));
1748}
1749
1750// CPU families mapping
1751pub const CPUFAMILY = enum(u32) {
1752 UNKNOWN = 0,
1753 POWERPC_G3 = 0xcee41549,
1754 POWERPC_G4 = 0x77c184ae,
1755 POWERPC_G5 = 0xed76d8aa,
1756 INTEL_6_13 = 0xaa33392b,
1757 INTEL_PENRYN = 0x78ea4fbc,
1758 INTEL_NEHALEM = 0x6b5a4cd2,
1759 INTEL_WESTMERE = 0x573b5eec,
1760 INTEL_SANDYBRIDGE = 0x5490b78c,
1761 INTEL_IVYBRIDGE = 0x1f65e835,
1762 INTEL_HASWELL = 0x10b282dc,
1763 INTEL_BROADWELL = 0x582ed09c,
1764 INTEL_SKYLAKE = 0x37fc219f,
1765 INTEL_KABYLAKE = 0x0f817246,
1766 ARM_9 = 0xe73283ae,
1767 ARM_11 = 0x8ff620d8,
1768 ARM_XSCALE = 0x53b005f5,
1769 ARM_12 = 0xbd1b0ae9,
1770 ARM_13 = 0x0cc90e64,
1771 ARM_14 = 0x96077ef1,
1772 ARM_15 = 0xa8511bca,
1773 ARM_SWIFT = 0x1e2d6381,
1774 ARM_CYCLONE = 0x37a09642,
1775 ARM_TYPHOON = 0x2c91a47e,
1776 ARM_TWISTER = 0x92fb37c8,
1777 ARM_HURRICANE = 0x67ceee93,
1778 ARM_MONSOON_MISTRAL = 0xe81e7ef6,
1779 ARM_VORTEX_TEMPEST = 0x07d34b9f,
1780 ARM_LIGHTNING_THUNDER = 0x462504d2,
1781 ARM_FIRESTORM_ICESTORM = 0x1b588bb3,
1782 _,
1783};
lib/std/os/bits/dragonfly.zig deleted-1031
...@@ -1,1031 +0,0 @@
1const std = @import("../../std.zig");
2const maxInt = std.math.maxInt;
3
4pub fn S_ISCHR(m: u32) bool {
5 return m & S_IFMT == S_IFCHR;
6}
7
8// See:
9// - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/include/unistd.h
10// - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/sys/sys/types.h
11// TODO: mode_t should probably be changed to a u16, audit pid_t/off_t as well
12pub const fd_t = c_int;
13pub const pid_t = c_int;
14pub const off_t = c_long;
15pub const mode_t = c_uint;
16pub const uid_t = u32;
17pub const gid_t = u32;
18pub const time_t = isize;
19pub const suseconds_t = c_long;
20
21pub const E = enum(u16) {
22 /// No error occurred.
23 SUCCESS = 0,
24
25 PERM = 1,
26 NOENT = 2,
27 SRCH = 3,
28 INTR = 4,
29 IO = 5,
30 NXIO = 6,
31 @"2BIG" = 7,
32 NOEXEC = 8,
33 BADF = 9,
34 CHILD = 10,
35 DEADLK = 11,
36 NOMEM = 12,
37 ACCES = 13,
38 FAULT = 14,
39 NOTBLK = 15,
40 BUSY = 16,
41 EXIST = 17,
42 XDEV = 18,
43 NODEV = 19,
44 NOTDIR = 20,
45 ISDIR = 21,
46 INVAL = 22,
47 NFILE = 23,
48 MFILE = 24,
49 NOTTY = 25,
50 TXTBSY = 26,
51 FBIG = 27,
52 NOSPC = 28,
53 SPIPE = 29,
54 ROFS = 30,
55 MLINK = 31,
56 PIPE = 32,
57 DOM = 33,
58 RANGE = 34,
59 /// This code is also used for `WOULDBLOCK`.
60 AGAIN = 35,
61 INPROGRESS = 36,
62 ALREADY = 37,
63 NOTSOCK = 38,
64 DESTADDRREQ = 39,
65 MSGSIZE = 40,
66 PROTOTYPE = 41,
67 NOPROTOOPT = 42,
68 PROTONOSUPPORT = 43,
69 SOCKTNOSUPPORT = 44,
70 /// This code is also used for `NOTSUP`.
71 OPNOTSUPP = 45,
72 PFNOSUPPORT = 46,
73 AFNOSUPPORT = 47,
74 ADDRINUSE = 48,
75 ADDRNOTAVAIL = 49,
76 NETDOWN = 50,
77 NETUNREACH = 51,
78 NETRESET = 52,
79 CONNABORTED = 53,
80 CONNRESET = 54,
81 NOBUFS = 55,
82 ISCONN = 56,
83 NOTCONN = 57,
84 SHUTDOWN = 58,
85 TOOMANYREFS = 59,
86 TIMEDOUT = 60,
87 CONNREFUSED = 61,
88 LOOP = 62,
89 NAMETOOLONG = 63,
90 HOSTDOWN = 64,
91 HOSTUNREACH = 65,
92 NOTEMPTY = 66,
93 PROCLIM = 67,
94 USERS = 68,
95 DQUOT = 69,
96 STALE = 70,
97 REMOTE = 71,
98 BADRPC = 72,
99 RPCMISMATCH = 73,
100 PROGUNAVAIL = 74,
101 PROGMISMATCH = 75,
102 PROCUNAVAIL = 76,
103 NOLCK = 77,
104 NOSYS = 78,
105 FTYPE = 79,
106 AUTH = 80,
107 NEEDAUTH = 81,
108 IDRM = 82,
109 NOMSG = 83,
110 OVERFLOW = 84,
111 CANCELED = 85,
112 ILSEQ = 86,
113 NOATTR = 87,
114 DOOFUS = 88,
115 BADMSG = 89,
116 MULTIHOP = 90,
117 NOLINK = 91,
118 PROTO = 92,
119 NOMEDIUM = 93,
120 ASYNC = 99,
121 _,
122};
123
124pub const STDIN_FILENO = 0;
125pub const STDOUT_FILENO = 1;
126pub const STDERR_FILENO = 2;
127
128pub const PROT_NONE = 0;
129pub const PROT_READ = 1;
130pub const PROT_WRITE = 2;
131pub const PROT_EXEC = 4;
132
133pub const MAP_FILE = 0;
134pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
135pub const MAP_ANONYMOUS = MAP_ANON;
136pub const MAP_COPY = MAP_PRIVATE;
137pub const MAP_SHARED = 1;
138pub const MAP_PRIVATE = 2;
139pub const MAP_FIXED = 16;
140pub const MAP_RENAME = 32;
141pub const MAP_NORESERVE = 64;
142pub const MAP_INHERIT = 128;
143pub const MAP_NOEXTEND = 256;
144pub const MAP_HASSEMAPHORE = 512;
145pub const MAP_STACK = 1024;
146pub const MAP_NOSYNC = 2048;
147pub const MAP_ANON = 4096;
148pub const MAP_VPAGETABLE = 8192;
149pub const MAP_TRYFIXED = 65536;
150pub const MAP_NOCORE = 131072;
151pub const MAP_SIZEALIGN = 262144;
152
153pub const WNOHANG = 0x0001;
154pub const WUNTRACED = 0x0002;
155pub const WCONTINUED = 0x0004;
156pub const WSTOPPED = WUNTRACED;
157pub const WNOWAIT = 0x0008;
158pub const WEXITED = 0x0010;
159pub const WTRAPPED = 0x0020;
160
161pub const SA_ONSTACK = 0x0001;
162pub const SA_RESTART = 0x0002;
163pub const SA_RESETHAND = 0x0004;
164pub const SA_NODEFER = 0x0010;
165pub const SA_NOCLDWAIT = 0x0020;
166pub const SA_SIGINFO = 0x0040;
167
168pub const PATH_MAX = 1024;
169pub const IOV_MAX = KERN_IOV_MAX;
170
171pub const ino_t = c_ulong;
172
173pub const libc_stat = extern struct {
174 ino: ino_t,
175 nlink: c_uint,
176 dev: c_uint,
177 mode: c_ushort,
178 padding1: u16,
179 uid: uid_t,
180 gid: gid_t,
181 rdev: c_uint,
182 atim: timespec,
183 mtim: timespec,
184 ctim: timespec,
185 size: c_ulong,
186 blocks: i64,
187 blksize: u32,
188 flags: u32,
189 gen: u32,
190 lspare: i32,
191 qspare1: i64,
192 qspare2: i64,
193 pub fn atime(self: @This()) timespec {
194 return self.atim;
195 }
196
197 pub fn mtime(self: @This()) timespec {
198 return self.mtim;
199 }
200
201 pub fn ctime(self: @This()) timespec {
202 return self.ctim;
203 }
204};
205
206pub const timespec = extern struct {
207 tv_sec: c_long,
208 tv_nsec: c_long,
209};
210
211pub const timeval = extern struct {
212 /// seconds
213 tv_sec: time_t,
214 /// microseconds
215 tv_usec: suseconds_t,
216};
217
218pub const CTL_UNSPEC = 0;
219pub const CTL_KERN = 1;
220pub const CTL_VM = 2;
221pub const CTL_VFS = 3;
222pub const CTL_NET = 4;
223pub const CTL_DEBUG = 5;
224pub const CTL_HW = 6;
225pub const CTL_MACHDEP = 7;
226pub const CTL_USER = 8;
227pub const CTL_LWKT = 10;
228pub const CTL_MAXID = 11;
229pub const CTL_MAXNAME = 12;
230
231pub const KERN_PROC_ALL = 0;
232pub const KERN_OSTYPE = 1;
233pub const KERN_PROC_PID = 1;
234pub const KERN_OSRELEASE = 2;
235pub const KERN_PROC_PGRP = 2;
236pub const KERN_OSREV = 3;
237pub const KERN_PROC_SESSION = 3;
238pub const KERN_VERSION = 4;
239pub const KERN_PROC_TTY = 4;
240pub const KERN_MAXVNODES = 5;
241pub const KERN_PROC_UID = 5;
242pub const KERN_MAXPROC = 6;
243pub const KERN_PROC_RUID = 6;
244pub const KERN_MAXFILES = 7;
245pub const KERN_PROC_ARGS = 7;
246pub const KERN_ARGMAX = 8;
247pub const KERN_PROC_CWD = 8;
248pub const KERN_PROC_PATHNAME = 9;
249pub const KERN_SECURELVL = 9;
250pub const KERN_PROC_SIGTRAMP = 10;
251pub const KERN_HOSTNAME = 10;
252pub const KERN_HOSTID = 11;
253pub const KERN_CLOCKRATE = 12;
254pub const KERN_VNODE = 13;
255pub const KERN_PROC = 14;
256pub const KERN_FILE = 15;
257pub const KERN_PROC_FLAGMASK = 16;
258pub const KERN_PROF = 16;
259pub const KERN_PROC_FLAG_LWP = 16;
260pub const KERN_POSIX1 = 17;
261pub const KERN_NGROUPS = 18;
262pub const KERN_JOB_CONTROL = 19;
263pub const KERN_SAVED_IDS = 20;
264pub const KERN_BOOTTIME = 21;
265pub const KERN_NISDOMAINNAME = 22;
266pub const KERN_UPDATEINTERVAL = 23;
267pub const KERN_OSRELDATE = 24;
268pub const KERN_NTP_PLL = 25;
269pub const KERN_BOOTFILE = 26;
270pub const KERN_MAXFILESPERPROC = 27;
271pub const KERN_MAXPROCPERUID = 28;
272pub const KERN_DUMPDEV = 29;
273pub const KERN_IPC = 30;
274pub const KERN_DUMMY = 31;
275pub const KERN_PS_STRINGS = 32;
276pub const KERN_USRSTACK = 33;
277pub const KERN_LOGSIGEXIT = 34;
278pub const KERN_IOV_MAX = 35;
279pub const KERN_MAXPOSIXLOCKSPERUID = 36;
280pub const KERN_MAXID = 37;
281
282pub const HOST_NAME_MAX = 255;
283
284// access function
285pub const F_OK = 0; // test for existence of file
286pub const X_OK = 1; // test for execute or search permission
287pub const W_OK = 2; // test for write permission
288pub const R_OK = 4; // test for read permission
289
290pub const O_RDONLY = 0;
291pub const O_NDELAY = O_NONBLOCK;
292pub const O_WRONLY = 1;
293pub const O_RDWR = 2;
294pub const O_ACCMODE = 3;
295pub const O_NONBLOCK = 4;
296pub const O_APPEND = 8;
297pub const O_SHLOCK = 16;
298pub const O_EXLOCK = 32;
299pub const O_ASYNC = 64;
300pub const O_FSYNC = 128;
301pub const O_SYNC = 128;
302pub const O_NOFOLLOW = 256;
303pub const O_CREAT = 512;
304pub const O_TRUNC = 1024;
305pub const O_EXCL = 2048;
306pub const O_NOCTTY = 32768;
307pub const O_DIRECT = 65536;
308pub const O_CLOEXEC = 131072;
309pub const O_FBLOCKING = 262144;
310pub const O_FNONBLOCKING = 524288;
311pub const O_FAPPEND = 1048576;
312pub const O_FOFFSET = 2097152;
313pub const O_FSYNCWRITE = 4194304;
314pub const O_FASYNCWRITE = 8388608;
315pub const O_DIRECTORY = 134217728;
316
317pub const SEEK_SET = 0;
318pub const SEEK_CUR = 1;
319pub const SEEK_END = 2;
320pub const SEEK_DATA = 3;
321pub const SEEK_HOLE = 4;
322
323pub const F_ULOCK = 0;
324pub const F_LOCK = 1;
325pub const F_TLOCK = 2;
326pub const F_TEST = 3;
327
328pub const FD_CLOEXEC = 1;
329
330pub const AT_FDCWD = -328243;
331pub const AT_SYMLINK_NOFOLLOW = 1;
332pub const AT_REMOVEDIR = 2;
333pub const AT_EACCESS = 4;
334pub const AT_SYMLINK_FOLLOW = 8;
335
336pub fn WEXITSTATUS(s: u32) u8 {
337 return @intCast(u8, (s & 0xff00) >> 8);
338}
339pub fn WTERMSIG(s: u32) u32 {
340 return s & 0x7f;
341}
342pub fn WSTOPSIG(s: u32) u32 {
343 return WEXITSTATUS(s);
344}
345pub fn WIFEXITED(s: u32) bool {
346 return WTERMSIG(s) == 0;
347}
348pub fn WIFSTOPPED(s: u32) bool {
349 return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
350}
351pub fn WIFSIGNALED(s: u32) bool {
352 return (s & 0xffff) -% 1 < 0xff;
353}
354
355pub const dirent = extern struct {
356 d_fileno: c_ulong,
357 d_namlen: u16,
358 d_type: u8,
359 d_unused1: u8,
360 d_unused2: u32,
361 d_name: [256]u8,
362
363 pub fn reclen(self: dirent) u16 {
364 return (@offsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~@as(u16, 7);
365 }
366};
367
368pub const DT_UNKNOWN = 0;
369pub const DT_FIFO = 1;
370pub const DT_CHR = 2;
371pub const DT_DIR = 4;
372pub const DT_BLK = 6;
373pub const DT_REG = 8;
374pub const DT_LNK = 10;
375pub const DT_SOCK = 12;
376pub const DT_WHT = 14;
377pub const DT_DBF = 15;
378
379pub const CLOCK_REALTIME = 0;
380pub const CLOCK_VIRTUAL = 1;
381pub const CLOCK_PROF = 2;
382pub const CLOCK_MONOTONIC = 4;
383pub const CLOCK_UPTIME = 5;
384pub const CLOCK_UPTIME_PRECISE = 7;
385pub const CLOCK_UPTIME_FAST = 8;
386pub const CLOCK_REALTIME_PRECISE = 9;
387pub const CLOCK_REALTIME_FAST = 10;
388pub const CLOCK_MONOTONIC_PRECISE = 11;
389pub const CLOCK_MONOTONIC_FAST = 12;
390pub const CLOCK_SECOND = 13;
391pub const CLOCK_THREAD_CPUTIME_ID = 14;
392pub const CLOCK_PROCESS_CPUTIME_ID = 15;
393
394pub const sockaddr = extern struct {
395 len: u8,
396 family: u8,
397 data: [14]u8,
398};
399
400pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
401
402pub const Kevent = extern struct {
403 ident: usize,
404 filter: c_short,
405 flags: c_ushort,
406 fflags: c_uint,
407 data: isize,
408 udata: usize,
409};
410
411pub const EVFILT_FS = -10;
412pub const EVFILT_USER = -9;
413pub const EVFILT_EXCEPT = -8;
414pub const EVFILT_TIMER = -7;
415pub const EVFILT_SIGNAL = -6;
416pub const EVFILT_PROC = -5;
417pub const EVFILT_VNODE = -4;
418pub const EVFILT_AIO = -3;
419pub const EVFILT_WRITE = -2;
420pub const EVFILT_READ = -1;
421pub const EVFILT_SYSCOUNT = 10;
422pub const EVFILT_MARKER = 15;
423
424pub const EV_ADD = 1;
425pub const EV_DELETE = 2;
426pub const EV_ENABLE = 4;
427pub const EV_DISABLE = 8;
428pub const EV_ONESHOT = 16;
429pub const EV_CLEAR = 32;
430pub const EV_RECEIPT = 64;
431pub const EV_DISPATCH = 128;
432pub const EV_NODATA = 4096;
433pub const EV_FLAG1 = 8192;
434pub const EV_ERROR = 16384;
435pub const EV_EOF = 32768;
436pub const EV_SYSFLAGS = 61440;
437
438pub const NOTE_FFNOP = 0;
439pub const NOTE_TRACK = 1;
440pub const NOTE_DELETE = 1;
441pub const NOTE_LOWAT = 1;
442pub const NOTE_TRACKERR = 2;
443pub const NOTE_OOB = 2;
444pub const NOTE_WRITE = 2;
445pub const NOTE_EXTEND = 4;
446pub const NOTE_CHILD = 4;
447pub const NOTE_ATTRIB = 8;
448pub const NOTE_LINK = 16;
449pub const NOTE_RENAME = 32;
450pub const NOTE_REVOKE = 64;
451pub const NOTE_PDATAMASK = 1048575;
452pub const NOTE_FFLAGSMASK = 16777215;
453pub const NOTE_TRIGGER = 16777216;
454pub const NOTE_EXEC = 536870912;
455pub const NOTE_FFAND = 1073741824;
456pub const NOTE_FORK = 1073741824;
457pub const NOTE_EXIT = 2147483648;
458pub const NOTE_FFOR = 2147483648;
459pub const NOTE_FFCTRLMASK = 3221225472;
460pub const NOTE_FFCOPY = 3221225472;
461pub const NOTE_PCTRLMASK = 4026531840;
462
463pub const stack_t = extern struct {
464 ss_sp: [*]u8,
465 ss_size: isize,
466 ss_flags: i32,
467};
468
469pub const S_IREAD = S_IRUSR;
470pub const S_IEXEC = S_IXUSR;
471pub const S_IWRITE = S_IWUSR;
472pub const S_IXOTH = 1;
473pub const S_IWOTH = 2;
474pub const S_IROTH = 4;
475pub const S_IRWXO = 7;
476pub const S_IXGRP = 8;
477pub const S_IWGRP = 16;
478pub const S_IRGRP = 32;
479pub const S_IRWXG = 56;
480pub const S_IXUSR = 64;
481pub const S_IWUSR = 128;
482pub const S_IRUSR = 256;
483pub const S_IRWXU = 448;
484pub const S_ISTXT = 512;
485pub const S_BLKSIZE = 512;
486pub const S_ISVTX = 512;
487pub const S_ISGID = 1024;
488pub const S_ISUID = 2048;
489pub const S_IFIFO = 4096;
490pub const S_IFCHR = 8192;
491pub const S_IFDIR = 16384;
492pub const S_IFBLK = 24576;
493pub const S_IFREG = 32768;
494pub const S_IFDB = 36864;
495pub const S_IFLNK = 40960;
496pub const S_IFSOCK = 49152;
497pub const S_IFWHT = 57344;
498pub const S_IFMT = 61440;
499
500pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
501pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
502pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
503pub const BADSIG = SIG_ERR;
504
505pub const SIG_BLOCK = 1;
506pub const SIG_UNBLOCK = 2;
507pub const SIG_SETMASK = 3;
508
509pub const SIGIOT = SIGABRT;
510pub const SIGHUP = 1;
511pub const SIGINT = 2;
512pub const SIGQUIT = 3;
513pub const SIGILL = 4;
514pub const SIGTRAP = 5;
515pub const SIGABRT = 6;
516pub const SIGEMT = 7;
517pub const SIGFPE = 8;
518pub const SIGKILL = 9;
519pub const SIGBUS = 10;
520pub const SIGSEGV = 11;
521pub const SIGSYS = 12;
522pub const SIGPIPE = 13;
523pub const SIGALRM = 14;
524pub const SIGTERM = 15;
525pub const SIGURG = 16;
526pub const SIGSTOP = 17;
527pub const SIGTSTP = 18;
528pub const SIGCONT = 19;
529pub const SIGCHLD = 20;
530pub const SIGTTIN = 21;
531pub const SIGTTOU = 22;
532pub const SIGIO = 23;
533pub const SIGXCPU = 24;
534pub const SIGXFSZ = 25;
535pub const SIGVTALRM = 26;
536pub const SIGPROF = 27;
537pub const SIGWINCH = 28;
538pub const SIGINFO = 29;
539pub const SIGUSR1 = 30;
540pub const SIGUSR2 = 31;
541pub const SIGTHR = 32;
542pub const SIGCKPT = 33;
543pub const SIGCKPTEXIT = 34;
544
545pub const siginfo_t = extern struct {
546 signo: c_int,
547 errno: c_int,
548 code: c_int,
549 pid: c_int,
550 uid: uid_t,
551 status: c_int,
552 addr: ?*c_void,
553 value: sigval,
554 band: c_long,
555 __spare__: [7]c_int,
556};
557
558pub const sigval = extern union {
559 sival_int: c_int,
560 sival_ptr: ?*c_void,
561};
562
563pub const _SIG_WORDS = 4;
564
565pub const sigset_t = extern struct {
566 __bits: [_SIG_WORDS]c_uint,
567};
568
569pub const empty_sigset = sigset_t{ .__bits = [_]c_uint{0} ** _SIG_WORDS };
570
571pub const sig_atomic_t = c_int;
572
573pub const Sigaction = extern struct {
574 pub const handler_fn = fn (c_int) callconv(.C) void;
575 pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void;
576
577 /// signal handler
578 handler: extern union {
579 handler: ?handler_fn,
580 sigaction: ?sigaction_fn,
581 },
582 flags: c_uint,
583 mask: sigset_t,
584};
585
586pub const sig_t = [*c]fn (c_int) callconv(.C) void;
587
588pub const SOCK_STREAM = 1;
589pub const SOCK_DGRAM = 2;
590pub const SOCK_RAW = 3;
591pub const SOCK_RDM = 4;
592pub const SOCK_SEQPACKET = 5;
593pub const SOCK_MAXADDRLEN = 255;
594pub const SOCK_CLOEXEC = 0x10000000;
595pub const SOCK_NONBLOCK = 0x20000000;
596
597pub const SO_DEBUG = 0x0001;
598pub const SO_ACCEPTCONN = 0x0002;
599pub const SO_REUSEADDR = 0x0004;
600pub const SO_KEEPALIVE = 0x0008;
601pub const SO_DONTROUTE = 0x0010;
602pub const SO_BROADCAST = 0x0020;
603pub const SO_USELOOPBACK = 0x0040;
604pub const SO_LINGER = 0x0080;
605pub const SO_OOBINLINE = 0x0100;
606pub const SO_REUSEPORT = 0x0200;
607pub const SO_TIMESTAMP = 0x0400;
608pub const SO_NOSIGPIPE = 0x0800;
609pub const SO_ACCEPTFILTER = 0x1000;
610pub const SO_RERROR = 0x2000;
611pub const SO_PASSCRED = 0x4000;
612
613pub const SO_SNDBUF = 0x1001;
614pub const SO_RCVBUF = 0x1002;
615pub const SO_SNDLOWAT = 0x1003;
616pub const SO_RCVLOWAT = 0x1004;
617pub const SO_SNDTIMEO = 0x1005;
618pub const SO_RCVTIMEO = 0x1006;
619pub const SO_ERROR = 0x1007;
620pub const SO_TYPE = 0x1008;
621pub const SO_SNDSPACE = 0x100a;
622pub const SO_CPUHINT = 0x1030;
623
624pub const SOL_SOCKET = 0xffff;
625
626pub const PF_INET6 = AF_INET6;
627pub const PF_IMPLINK = AF_IMPLINK;
628pub const PF_ROUTE = AF_ROUTE;
629pub const PF_ISO = AF_ISO;
630pub const PF_PIP = pseudo_AF_PIP;
631pub const PF_CHAOS = AF_CHAOS;
632pub const PF_DATAKIT = AF_DATAKIT;
633pub const PF_INET = AF_INET;
634pub const PF_APPLETALK = AF_APPLETALK;
635pub const PF_SIP = AF_SIP;
636pub const PF_OSI = AF_ISO;
637pub const PF_CNT = AF_CNT;
638pub const PF_LINK = AF_LINK;
639pub const PF_HYLINK = AF_HYLINK;
640pub const PF_MAX = AF_MAX;
641pub const PF_KEY = pseudo_AF_KEY;
642pub const PF_PUP = AF_PUP;
643pub const PF_COIP = AF_COIP;
644pub const PF_SNA = AF_SNA;
645pub const PF_LOCAL = AF_LOCAL;
646pub const PF_NETBIOS = AF_NETBIOS;
647pub const PF_NATM = AF_NATM;
648pub const PF_BLUETOOTH = AF_BLUETOOTH;
649pub const PF_UNSPEC = AF_UNSPEC;
650pub const PF_NETGRAPH = AF_NETGRAPH;
651pub const PF_ECMA = AF_ECMA;
652pub const PF_IPX = AF_IPX;
653pub const PF_DLI = AF_DLI;
654pub const PF_ATM = AF_ATM;
655pub const PF_CCITT = AF_CCITT;
656pub const PF_ISDN = AF_ISDN;
657pub const PF_RTIP = pseudo_AF_RTIP;
658pub const PF_LAT = AF_LAT;
659pub const PF_UNIX = PF_LOCAL;
660pub const PF_XTP = pseudo_AF_XTP;
661pub const PF_DECnet = AF_DECnet;
662
663pub const AF_UNSPEC = 0;
664pub const AF_OSI = AF_ISO;
665pub const AF_UNIX = AF_LOCAL;
666pub const AF_LOCAL = 1;
667pub const AF_INET = 2;
668pub const AF_IMPLINK = 3;
669pub const AF_PUP = 4;
670pub const AF_CHAOS = 5;
671pub const AF_NETBIOS = 6;
672pub const AF_ISO = 7;
673pub const AF_ECMA = 8;
674pub const AF_DATAKIT = 9;
675pub const AF_CCITT = 10;
676pub const AF_SNA = 11;
677pub const AF_DLI = 13;
678pub const AF_LAT = 14;
679pub const AF_HYLINK = 15;
680pub const AF_APPLETALK = 16;
681pub const AF_ROUTE = 17;
682pub const AF_LINK = 18;
683pub const AF_COIP = 20;
684pub const AF_CNT = 21;
685pub const AF_IPX = 23;
686pub const AF_SIP = 24;
687pub const AF_ISDN = 26;
688pub const AF_INET6 = 28;
689pub const AF_NATM = 29;
690pub const AF_ATM = 30;
691pub const AF_NETGRAPH = 32;
692pub const AF_BLUETOOTH = 33;
693pub const AF_MPLS = 34;
694pub const AF_MAX = 36;
695
696pub const in_port_t = u16;
697pub const sa_family_t = u8;
698pub const socklen_t = u32;
699
700pub const sockaddr_in = extern struct {
701 len: u8 = @sizeOf(sockaddr_in),
702 family: sa_family_t = AF_INET,
703 port: in_port_t,
704 addr: u32,
705 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
706};
707
708pub const sockaddr_in6 = extern struct {
709 len: u8 = @sizeOf(sockaddr_in6),
710 family: sa_family_t = AF_INET6,
711 port: in_port_t,
712 flowinfo: u32,
713 addr: [16]u8,
714 scope_id: u32,
715};
716
717pub const EAI = enum(c_int) {
718 ADDRFAMILY = 1,
719 AGAIN = 2,
720 BADFLAGS = 3,
721 FAIL = 4,
722 FAMILY = 5,
723 MEMORY = 6,
724 NODATA = 7,
725 NONAME = 8,
726 SERVICE = 9,
727 SOCKTYPE = 10,
728 SYSTEM = 11,
729 BADHINTS = 12,
730 PROTOCOL = 13,
731 OVERFLOW = 14,
732 _,
733};
734
735pub const AI_PASSIVE = 0x00000001;
736pub const AI_CANONNAME = 0x00000002;
737pub const AI_NUMERICHOST = 0x00000004;
738pub const AI_NUMERICSERV = 0x00000008;
739pub const AI_MASK = AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | AI_ADDRCONFIG;
740pub const AI_ALL = 0x00000100;
741pub const AI_V4MAPPED_CFG = 0x00000200;
742pub const AI_ADDRCONFIG = 0x00000400;
743pub const AI_V4MAPPED = 0x00000800;
744pub const AI_DEFAULT = AI_V4MAPPED_CFG | AI_ADDRCONFIG;
745
746pub const RTLD_LAZY = 1;
747pub const RTLD_NOW = 2;
748pub const RTLD_MODEMASK = 0x3;
749pub const RTLD_GLOBAL = 0x100;
750pub const RTLD_LOCAL = 0;
751pub const RTLD_TRACE = 0x200;
752pub const RTLD_NODELETE = 0x01000;
753pub const RTLD_NOLOAD = 0x02000;
754
755pub const RTLD_NEXT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -1)));
756pub const RTLD_DEFAULT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -2)));
757pub const RTLD_SELF = @intToPtr(*c_void, @bitCast(usize, @as(isize, -3)));
758pub const RTLD_ALL = @intToPtr(*c_void, @bitCast(usize, @as(isize, -4)));
759
760pub const dl_phdr_info = extern struct {
761 dlpi_addr: usize,
762 dlpi_name: ?[*:0]const u8,
763 dlpi_phdr: [*]std.elf.Phdr,
764 dlpi_phnum: u16,
765};
766pub const cmsghdr = extern struct {
767 cmsg_len: socklen_t,
768 cmsg_level: c_int,
769 cmsg_type: c_int,
770};
771pub const msghdr = extern struct {
772 msg_name: ?*c_void,
773 msg_namelen: socklen_t,
774 msg_iov: [*c]iovec,
775 msg_iovlen: c_int,
776 msg_control: ?*c_void,
777 msg_controllen: socklen_t,
778 msg_flags: c_int,
779};
780pub const cmsgcred = extern struct {
781 cmcred_pid: pid_t,
782 cmcred_uid: uid_t,
783 cmcred_euid: uid_t,
784 cmcred_gid: gid_t,
785 cmcred_ngroups: c_short,
786 cmcred_groups: [16]gid_t,
787};
788pub const sf_hdtr = extern struct {
789 headers: [*c]iovec,
790 hdr_cnt: c_int,
791 trailers: [*c]iovec,
792 trl_cnt: c_int,
793};
794
795pub const MS_SYNC = 0;
796pub const MS_ASYNC = 1;
797pub const MS_INVALIDATE = 2;
798
799pub const POSIX_MADV_SEQUENTIAL = 2;
800pub const POSIX_MADV_RANDOM = 1;
801pub const POSIX_MADV_DONTNEED = 4;
802pub const POSIX_MADV_NORMAL = 0;
803pub const POSIX_MADV_WILLNEED = 3;
804
805pub const MADV_SEQUENTIAL = 2;
806pub const MADV_CONTROL_END = MADV_SETMAP;
807pub const MADV_DONTNEED = 4;
808pub const MADV_RANDOM = 1;
809pub const MADV_WILLNEED = 3;
810pub const MADV_NORMAL = 0;
811pub const MADV_CONTROL_START = MADV_INVAL;
812pub const MADV_FREE = 5;
813pub const MADV_NOSYNC = 6;
814pub const MADV_AUTOSYNC = 7;
815pub const MADV_NOCORE = 8;
816pub const MADV_CORE = 9;
817pub const MADV_INVAL = 10;
818pub const MADV_SETMAP = 11;
819
820pub const F_DUPFD = 0;
821pub const F_GETFD = 1;
822pub const F_RDLCK = 1;
823pub const F_SETFD = 2;
824pub const F_UNLCK = 2;
825pub const F_WRLCK = 3;
826pub const F_GETFL = 3;
827pub const F_SETFL = 4;
828pub const F_GETOWN = 5;
829pub const F_SETOWN = 6;
830pub const F_GETLK = 7;
831pub const F_SETLK = 8;
832pub const F_SETLKW = 9;
833pub const F_DUP2FD = 10;
834pub const F_DUPFD_CLOEXEC = 17;
835pub const F_DUP2FD_CLOEXEC = 18;
836
837pub const LOCK_SH = 1;
838pub const LOCK_EX = 2;
839pub const LOCK_UN = 8;
840pub const LOCK_NB = 4;
841
842pub const Flock = extern struct {
843 l_start: off_t,
844 l_len: off_t,
845 l_pid: pid_t,
846 l_type: c_short,
847 l_whence: c_short,
848};
849
850pub const addrinfo = extern struct {
851 flags: i32,
852 family: i32,
853 socktype: i32,
854 protocol: i32,
855 addrlen: socklen_t,
856 canonname: ?[*:0]u8,
857 addr: ?*sockaddr,
858 next: ?*addrinfo,
859};
860
861pub const IPPROTO_IP = 0;
862pub const IPPROTO_ICMP = 1;
863pub const IPPROTO_TCP = 6;
864pub const IPPROTO_UDP = 17;
865pub const IPPROTO_IPV6 = 41;
866pub const IPPROTO_RAW = 255;
867pub const IPPROTO_HOPOPTS = 0;
868pub const IPPROTO_IGMP = 2;
869pub const IPPROTO_GGP = 3;
870pub const IPPROTO_IPV4 = 4;
871pub const IPPROTO_IPIP = IPPROTO_IPV4;
872pub const IPPROTO_ST = 7;
873pub const IPPROTO_EGP = 8;
874pub const IPPROTO_PIGP = 9;
875pub const IPPROTO_RCCMON = 10;
876pub const IPPROTO_NVPII = 11;
877pub const IPPROTO_PUP = 12;
878pub const IPPROTO_ARGUS = 13;
879pub const IPPROTO_EMCON = 14;
880pub const IPPROTO_XNET = 15;
881pub const IPPROTO_CHAOS = 16;
882pub const IPPROTO_MUX = 18;
883pub const IPPROTO_MEAS = 19;
884pub const IPPROTO_HMP = 20;
885pub const IPPROTO_PRM = 21;
886pub const IPPROTO_IDP = 22;
887pub const IPPROTO_TRUNK1 = 23;
888pub const IPPROTO_TRUNK2 = 24;
889pub const IPPROTO_LEAF1 = 25;
890pub const IPPROTO_LEAF2 = 26;
891pub const IPPROTO_RDP = 27;
892pub const IPPROTO_IRTP = 28;
893pub const IPPROTO_TP = 29;
894pub const IPPROTO_BLT = 30;
895pub const IPPROTO_NSP = 31;
896pub const IPPROTO_INP = 32;
897pub const IPPROTO_SEP = 33;
898pub const IPPROTO_3PC = 34;
899pub const IPPROTO_IDPR = 35;
900pub const IPPROTO_XTP = 36;
901pub const IPPROTO_DDP = 37;
902pub const IPPROTO_CMTP = 38;
903pub const IPPROTO_TPXX = 39;
904pub const IPPROTO_IL = 40;
905pub const IPPROTO_SDRP = 42;
906pub const IPPROTO_ROUTING = 43;
907pub const IPPROTO_FRAGMENT = 44;
908pub const IPPROTO_IDRP = 45;
909pub const IPPROTO_RSVP = 46;
910pub const IPPROTO_GRE = 47;
911pub const IPPROTO_MHRP = 48;
912pub const IPPROTO_BHA = 49;
913pub const IPPROTO_ESP = 50;
914pub const IPPROTO_AH = 51;
915pub const IPPROTO_INLSP = 52;
916pub const IPPROTO_SWIPE = 53;
917pub const IPPROTO_NHRP = 54;
918pub const IPPROTO_MOBILE = 55;
919pub const IPPROTO_TLSP = 56;
920pub const IPPROTO_SKIP = 57;
921pub const IPPROTO_ICMPV6 = 58;
922pub const IPPROTO_NONE = 59;
923pub const IPPROTO_DSTOPTS = 60;
924pub const IPPROTO_AHIP = 61;
925pub const IPPROTO_CFTP = 62;
926pub const IPPROTO_HELLO = 63;
927pub const IPPROTO_SATEXPAK = 64;
928pub const IPPROTO_KRYPTOLAN = 65;
929pub const IPPROTO_RVD = 66;
930pub const IPPROTO_IPPC = 67;
931pub const IPPROTO_ADFS = 68;
932pub const IPPROTO_SATMON = 69;
933pub const IPPROTO_VISA = 70;
934pub const IPPROTO_IPCV = 71;
935pub const IPPROTO_CPNX = 72;
936pub const IPPROTO_CPHB = 73;
937pub const IPPROTO_WSN = 74;
938pub const IPPROTO_PVP = 75;
939pub const IPPROTO_BRSATMON = 76;
940pub const IPPROTO_ND = 77;
941pub const IPPROTO_WBMON = 78;
942pub const IPPROTO_WBEXPAK = 79;
943pub const IPPROTO_EON = 80;
944pub const IPPROTO_VMTP = 81;
945pub const IPPROTO_SVMTP = 82;
946pub const IPPROTO_VINES = 83;
947pub const IPPROTO_TTP = 84;
948pub const IPPROTO_IGP = 85;
949pub const IPPROTO_DGP = 86;
950pub const IPPROTO_TCF = 87;
951pub const IPPROTO_IGRP = 88;
952pub const IPPROTO_OSPFIGP = 89;
953pub const IPPROTO_SRPC = 90;
954pub const IPPROTO_LARP = 91;
955pub const IPPROTO_MTP = 92;
956pub const IPPROTO_AX25 = 93;
957pub const IPPROTO_IPEIP = 94;
958pub const IPPROTO_MICP = 95;
959pub const IPPROTO_SCCSP = 96;
960pub const IPPROTO_ETHERIP = 97;
961pub const IPPROTO_ENCAP = 98;
962pub const IPPROTO_APES = 99;
963pub const IPPROTO_GMTP = 100;
964pub const IPPROTO_IPCOMP = 108;
965pub const IPPROTO_PIM = 103;
966pub const IPPROTO_CARP = 112;
967pub const IPPROTO_PGM = 113;
968pub const IPPROTO_PFSYNC = 240;
969pub const IPPROTO_DIVERT = 254;
970pub const IPPROTO_MAX = 256;
971pub const IPPROTO_DONE = 257;
972pub const IPPROTO_UNKNOWN = 258;
973
974pub const rlimit_resource = enum(c_int) {
975 CPU = 0,
976 FSIZE = 1,
977 DATA = 2,
978 STACK = 3,
979 CORE = 4,
980 RSS = 5,
981 MEMLOCK = 6,
982 NPROC = 7,
983 NOFILE = 8,
984 SBSIZE = 9,
985 VMEM = 10,
986 POSIXLOCKS = 11,
987 _,
988
989 pub const AS: rlimit_resource = .VMEM;
990};
991
992pub const rlim_t = i64;
993
994/// No limit
995pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
996
997pub const RLIM_SAVED_MAX = RLIM_INFINITY;
998pub const RLIM_SAVED_CUR = RLIM_INFINITY;
999
1000pub const rlimit = extern struct {
1001 /// Soft limit
1002 cur: rlim_t,
1003 /// Hard limit
1004 max: rlim_t,
1005};
1006
1007pub const SHUT_RD = 0;
1008pub const SHUT_WR = 1;
1009pub const SHUT_RDWR = 2;
1010
1011pub const nfds_t = u32;
1012
1013pub const pollfd = extern struct {
1014 fd: fd_t,
1015 events: i16,
1016 revents: i16,
1017};
1018
1019/// Requestable events.
1020pub const POLLIN = 0x0001;
1021pub const POLLPRI = 0x0002;
1022pub const POLLOUT = 0x0004;
1023pub const POLLRDNORM = 0x0040;
1024pub const POLLWRNORM = POLLOUT;
1025pub const POLLRDBAND = 0x0080;
1026pub const POLLWRBAND = 0x0100;
1027
1028/// These events are set if they occur regardless of whether they were requested.
1029pub const POLLERR = 0x0008;
1030pub const POLLHUP = 0x0010;
1031pub const POLLNVAL = 0x0020;
lib/std/os/bits/freebsd.zig deleted-1540
...@@ -1,1540 +0,0 @@
1const std = @import("../../std.zig");
2const builtin = @import("builtin");
3const maxInt = std.math.maxInt;
4
5pub const blksize_t = i32;
6pub const blkcnt_t = i64;
7pub const clockid_t = i32;
8pub const fsblkcnt_t = u64;
9pub const fsfilcnt_t = u64;
10pub const nlink_t = u64;
11pub const fd_t = i32;
12pub const pid_t = i32;
13pub const uid_t = u32;
14pub const gid_t = u32;
15pub const mode_t = u16;
16pub const off_t = i64;
17pub const ino_t = u64;
18pub const dev_t = u64;
19pub const time_t = i64;
20// The signedness is not constant across different architectures.
21pub const clock_t = isize;
22
23pub const socklen_t = u32;
24pub const suseconds_t = c_long;
25
26/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
27pub const Kevent = extern struct {
28 ident: usize,
29 filter: i16,
30 flags: u16,
31 fflags: u32,
32 data: i64,
33 udata: usize,
34 // TODO ext
35};
36
37// Modes and flags for dlopen()
38// include/dlfcn.h
39
40/// Bind function calls lazily.
41pub const RTLD_LAZY = 1;
42
43/// Bind function calls immediately.
44pub const RTLD_NOW = 2;
45
46pub const RTLD_MODEMASK = 0x3;
47
48/// Make symbols globally available.
49pub const RTLD_GLOBAL = 0x100;
50
51/// Opposite of RTLD_GLOBAL, and the default.
52pub const RTLD_LOCAL = 0;
53
54/// Trace loaded objects and exit.
55pub const RTLD_TRACE = 0x200;
56
57/// Do not remove members.
58pub const RTLD_NODELETE = 0x01000;
59
60/// Do not load if not already loaded.
61pub const RTLD_NOLOAD = 0x02000;
62
63pub const dl_phdr_info = extern struct {
64 dlpi_addr: usize,
65 dlpi_name: ?[*:0]const u8,
66 dlpi_phdr: [*]std.elf.Phdr,
67 dlpi_phnum: u16,
68};
69
70pub const Flock = extern struct {
71 l_start: off_t,
72 l_len: off_t,
73 l_pid: pid_t,
74 l_type: i16,
75 l_whence: i16,
76 l_sysid: i32,
77 __unused: [4]u8,
78};
79
80pub const msghdr = extern struct {
81 /// optional address
82 msg_name: ?*sockaddr,
83
84 /// size of address
85 msg_namelen: socklen_t,
86
87 /// scatter/gather array
88 msg_iov: [*]iovec,
89
90 /// # elements in msg_iov
91 msg_iovlen: i32,
92
93 /// ancillary data
94 msg_control: ?*c_void,
95
96 /// ancillary data buffer len
97 msg_controllen: socklen_t,
98
99 /// flags on received message
100 msg_flags: i32,
101};
102
103pub const msghdr_const = extern struct {
104 /// optional address
105 msg_name: ?*const sockaddr,
106
107 /// size of address
108 msg_namelen: socklen_t,
109
110 /// scatter/gather array
111 msg_iov: [*]iovec_const,
112
113 /// # elements in msg_iov
114 msg_iovlen: i32,
115
116 /// ancillary data
117 msg_control: ?*c_void,
118
119 /// ancillary data buffer len
120 msg_controllen: socklen_t,
121
122 /// flags on received message
123 msg_flags: i32,
124};
125
126pub const libc_stat = extern struct {
127 dev: dev_t,
128 ino: ino_t,
129 nlink: nlink_t,
130
131 mode: mode_t,
132 __pad0: u16,
133 uid: uid_t,
134 gid: gid_t,
135 __pad1: u32,
136 rdev: dev_t,
137
138 atim: timespec,
139 mtim: timespec,
140 ctim: timespec,
141 birthtim: timespec,
142
143 size: off_t,
144 blocks: i64,
145 blksize: isize,
146 flags: u32,
147 gen: u64,
148 __spare: [10]u64,
149
150 pub fn atime(self: @This()) timespec {
151 return self.atim;
152 }
153
154 pub fn mtime(self: @This()) timespec {
155 return self.mtim;
156 }
157
158 pub fn ctime(self: @This()) timespec {
159 return self.ctim;
160 }
161};
162
163pub const timespec = extern struct {
164 tv_sec: isize,
165 tv_nsec: isize,
166};
167
168pub const timeval = extern struct {
169 /// seconds
170 tv_sec: time_t,
171 /// microseconds
172 tv_usec: suseconds_t,
173};
174
175pub const dirent = extern struct {
176 d_fileno: usize,
177 d_off: i64,
178 d_reclen: u16,
179 d_type: u8,
180 d_pad0: u8,
181 d_namlen: u16,
182 d_pad1: u16,
183 d_name: [256]u8,
184
185 pub fn reclen(self: dirent) u16 {
186 return self.d_reclen;
187 }
188};
189
190pub const in_port_t = u16;
191pub const sa_family_t = u8;
192
193pub const sockaddr = extern struct {
194 /// total length
195 len: u8,
196
197 /// address family
198 family: sa_family_t,
199
200 /// actually longer; address value
201 data: [14]u8,
202};
203
204pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
205
206pub const sockaddr_in = extern struct {
207 len: u8 = @sizeOf(sockaddr_in),
208 family: sa_family_t = AF_INET,
209 port: in_port_t,
210 addr: u32,
211 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
212};
213
214pub const sockaddr_in6 = extern struct {
215 len: u8 = @sizeOf(sockaddr_in6),
216 family: sa_family_t = AF_INET6,
217 port: in_port_t,
218 flowinfo: u32,
219 addr: [16]u8,
220 scope_id: u32,
221};
222
223pub const sockaddr_un = extern struct {
224 len: u8 = @sizeOf(sockaddr_un),
225 family: sa_family_t = AF_UNIX,
226 path: [104]u8,
227};
228
229pub const CTL_KERN = 1;
230pub const CTL_DEBUG = 5;
231
232pub const KERN_PROC = 14; // struct: process entries
233pub const KERN_PROC_PATHNAME = 12; // path to executable
234pub const KERN_IOV_MAX = 35;
235
236pub const PATH_MAX = 1024;
237pub const IOV_MAX = KERN_IOV_MAX;
238
239pub const STDIN_FILENO = 0;
240pub const STDOUT_FILENO = 1;
241pub const STDERR_FILENO = 2;
242
243pub const PROT_NONE = 0;
244pub const PROT_READ = 1;
245pub const PROT_WRITE = 2;
246pub const PROT_EXEC = 4;
247
248pub const CLOCK_REALTIME = 0;
249pub const CLOCK_VIRTUAL = 1;
250pub const CLOCK_PROF = 2;
251pub const CLOCK_MONOTONIC = 4;
252pub const CLOCK_UPTIME = 5;
253pub const CLOCK_UPTIME_PRECISE = 7;
254pub const CLOCK_UPTIME_FAST = 8;
255pub const CLOCK_REALTIME_PRECISE = 9;
256pub const CLOCK_REALTIME_FAST = 10;
257pub const CLOCK_MONOTONIC_PRECISE = 11;
258pub const CLOCK_MONOTONIC_FAST = 12;
259pub const CLOCK_SECOND = 13;
260pub const CLOCK_THREAD_CPUTIME_ID = 14;
261pub const CLOCK_PROCESS_CPUTIME_ID = 15;
262
263pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
264pub const MAP_SHARED = 0x0001;
265pub const MAP_PRIVATE = 0x0002;
266pub const MAP_FIXED = 0x0010;
267pub const MAP_STACK = 0x0400;
268pub const MAP_NOSYNC = 0x0800;
269pub const MAP_ANON = 0x1000;
270pub const MAP_ANONYMOUS = MAP_ANON;
271pub const MAP_FILE = 0;
272
273pub const MAP_GUARD = 0x00002000;
274pub const MAP_EXCL = 0x00004000;
275pub const MAP_NOCORE = 0x00020000;
276pub const MAP_PREFAULT_READ = 0x00040000;
277pub const MAP_32BIT = 0x00080000;
278
279pub const WNOHANG = 1;
280pub const WUNTRACED = 2;
281pub const WSTOPPED = WUNTRACED;
282pub const WCONTINUED = 4;
283pub const WNOWAIT = 8;
284pub const WEXITED = 16;
285pub const WTRAPPED = 32;
286
287pub const SA_ONSTACK = 0x0001;
288pub const SA_RESTART = 0x0002;
289pub const SA_RESETHAND = 0x0004;
290pub const SA_NOCLDSTOP = 0x0008;
291pub const SA_NODEFER = 0x0010;
292pub const SA_NOCLDWAIT = 0x0020;
293pub const SA_SIGINFO = 0x0040;
294
295pub const SIGHUP = 1;
296pub const SIGINT = 2;
297pub const SIGQUIT = 3;
298pub const SIGILL = 4;
299pub const SIGTRAP = 5;
300pub const SIGABRT = 6;
301pub const SIGIOT = SIGABRT;
302pub const SIGEMT = 7;
303pub const SIGFPE = 8;
304pub const SIGKILL = 9;
305pub const SIGBUS = 10;
306pub const SIGSEGV = 11;
307pub const SIGSYS = 12;
308pub const SIGPIPE = 13;
309pub const SIGALRM = 14;
310pub const SIGTERM = 15;
311pub const SIGURG = 16;
312pub const SIGSTOP = 17;
313pub const SIGTSTP = 18;
314pub const SIGCONT = 19;
315pub const SIGCHLD = 20;
316pub const SIGTTIN = 21;
317pub const SIGTTOU = 22;
318pub const SIGIO = 23;
319pub const SIGXCPU = 24;
320pub const SIGXFSZ = 25;
321pub const SIGVTALRM = 26;
322pub const SIGPROF = 27;
323pub const SIGWINCH = 28;
324pub const SIGINFO = 29;
325pub const SIGUSR1 = 30;
326pub const SIGUSR2 = 31;
327pub const SIGTHR = 32;
328pub const SIGLWP = SIGTHR;
329pub const SIGLIBRT = 33;
330
331pub const SIGRTMIN = 65;
332pub const SIGRTMAX = 126;
333
334// access function
335pub const F_OK = 0; // test for existence of file
336pub const X_OK = 1; // test for execute or search permission
337pub const W_OK = 2; // test for write permission
338pub const R_OK = 4; // test for read permission
339
340pub const O_RDONLY = 0x0000;
341pub const O_WRONLY = 0x0001;
342pub const O_RDWR = 0x0002;
343pub const O_ACCMODE = 0x0003;
344
345pub const O_SHLOCK = 0x0010;
346pub const O_EXLOCK = 0x0020;
347
348pub const O_CREAT = 0x0200;
349pub const O_EXCL = 0x0800;
350pub const O_NOCTTY = 0x8000;
351pub const O_TRUNC = 0x0400;
352pub const O_APPEND = 0x0008;
353pub const O_NONBLOCK = 0x0004;
354pub const O_DSYNC = 0o10000;
355pub const O_SYNC = 0x0080;
356pub const O_RSYNC = 0o4010000;
357pub const O_DIRECTORY = 0x20000;
358pub const O_NOFOLLOW = 0x0100;
359pub const O_CLOEXEC = 0x00100000;
360
361pub const O_ASYNC = 0x0040;
362pub const O_DIRECT = 0x00010000;
363pub const O_NOATIME = 0o1000000;
364pub const O_PATH = 0o10000000;
365pub const O_TMPFILE = 0o20200000;
366pub const O_NDELAY = O_NONBLOCK;
367
368pub const F_DUPFD = 0;
369pub const F_GETFD = 1;
370pub const F_SETFD = 2;
371pub const F_GETFL = 3;
372pub const F_SETFL = 4;
373
374pub const F_GETOWN = 5;
375pub const F_SETOWN = 6;
376
377pub const F_GETLK = 11;
378pub const F_SETLK = 12;
379pub const F_SETLKW = 13;
380
381pub const F_RDLCK = 1;
382pub const F_WRLCK = 3;
383pub const F_UNLCK = 2;
384
385pub const LOCK_SH = 1;
386pub const LOCK_EX = 2;
387pub const LOCK_UN = 8;
388pub const LOCK_NB = 4;
389
390pub const F_SETOWN_EX = 15;
391pub const F_GETOWN_EX = 16;
392
393pub const F_GETOWNER_UIDS = 17;
394
395pub const FD_CLOEXEC = 1;
396
397pub const SEEK_SET = 0;
398pub const SEEK_CUR = 1;
399pub const SEEK_END = 2;
400
401pub const SIG_BLOCK = 1;
402pub const SIG_UNBLOCK = 2;
403pub const SIG_SETMASK = 3;
404
405pub const SOCK_STREAM = 1;
406pub const SOCK_DGRAM = 2;
407pub const SOCK_RAW = 3;
408pub const SOCK_RDM = 4;
409pub const SOCK_SEQPACKET = 5;
410
411pub const SOCK_CLOEXEC = 0x10000000;
412pub const SOCK_NONBLOCK = 0x20000000;
413
414pub const SO_DEBUG = 0x00000001;
415pub const SO_ACCEPTCONN = 0x00000002;
416pub const SO_REUSEADDR = 0x00000004;
417pub const SO_KEEPALIVE = 0x00000008;
418pub const SO_DONTROUTE = 0x00000010;
419pub const SO_BROADCAST = 0x00000020;
420pub const SO_USELOOPBACK = 0x00000040;
421pub const SO_LINGER = 0x00000080;
422pub const SO_OOBINLINE = 0x00000100;
423pub const SO_REUSEPORT = 0x00000200;
424pub const SO_TIMESTAMP = 0x00000400;
425pub const SO_NOSIGPIPE = 0x00000800;
426pub const SO_ACCEPTFILTER = 0x00001000;
427pub const SO_BINTIME = 0x00002000;
428pub const SO_NO_OFFLOAD = 0x00004000;
429pub const SO_NO_DDP = 0x00008000;
430pub const SO_REUSEPORT_LB = 0x00010000;
431
432pub const SO_SNDBUF = 0x1001;
433pub const SO_RCVBUF = 0x1002;
434pub const SO_SNDLOWAT = 0x1003;
435pub const SO_RCVLOWAT = 0x1004;
436pub const SO_SNDTIMEO = 0x1005;
437pub const SO_RCVTIMEO = 0x1006;
438pub const SO_ERROR = 0x1007;
439pub const SO_TYPE = 0x1008;
440pub const SO_LABEL = 0x1009;
441pub const SO_PEERLABEL = 0x1010;
442pub const SO_LISTENQLIMIT = 0x1011;
443pub const SO_LISTENQLEN = 0x1012;
444pub const SO_LISTENINCQLEN = 0x1013;
445pub const SO_SETFIB = 0x1014;
446pub const SO_USER_COOKIE = 0x1015;
447pub const SO_PROTOCOL = 0x1016;
448pub const SO_PROTOTYPE = SO_PROTOCOL;
449pub const SO_TS_CLOCK = 0x1017;
450pub const SO_MAX_PACING_RATE = 0x1018;
451pub const SO_DOMAIN = 0x1019;
452
453pub const SOL_SOCKET = 0xffff;
454
455pub const PF_UNSPEC = AF_UNSPEC;
456pub const PF_LOCAL = AF_LOCAL;
457pub const PF_UNIX = PF_LOCAL;
458pub const PF_INET = AF_INET;
459pub const PF_IMPLINK = AF_IMPLINK;
460pub const PF_PUP = AF_PUP;
461pub const PF_CHAOS = AF_CHAOS;
462pub const PF_NETBIOS = AF_NETBIOS;
463pub const PF_ISO = AF_ISO;
464pub const PF_OSI = AF_ISO;
465pub const PF_ECMA = AF_ECMA;
466pub const PF_DATAKIT = AF_DATAKIT;
467pub const PF_CCITT = AF_CCITT;
468pub const PF_DECnet = AF_DECnet;
469pub const PF_DLI = AF_DLI;
470pub const PF_LAT = AF_LAT;
471pub const PF_HYLINK = AF_HYLINK;
472pub const PF_APPLETALK = AF_APPLETALK;
473pub const PF_ROUTE = AF_ROUTE;
474pub const PF_LINK = AF_LINK;
475pub const PF_XTP = pseudo_AF_XTP;
476pub const PF_COIP = AF_COIP;
477pub const PF_CNT = AF_CNT;
478pub const PF_SIP = AF_SIP;
479pub const PF_IPX = AF_IPX;
480pub const PF_RTIP = pseudo_AF_RTIP;
481pub const PF_PIP = psuedo_AF_PIP;
482pub const PF_ISDN = AF_ISDN;
483pub const PF_KEY = pseudo_AF_KEY;
484pub const PF_INET6 = pseudo_AF_INET6;
485pub const PF_NATM = AF_NATM;
486pub const PF_ATM = AF_ATM;
487pub const PF_NETGRAPH = AF_NETGRAPH;
488pub const PF_SLOW = AF_SLOW;
489pub const PF_SCLUSTER = AF_SCLUSTER;
490pub const PF_ARP = AF_ARP;
491pub const PF_BLUETOOTH = AF_BLUETOOTH;
492pub const PF_IEEE80211 = AF_IEEE80211;
493pub const PF_INET_SDP = AF_INET_SDP;
494pub const PF_INET6_SDP = AF_INET6_SDP;
495pub const PF_MAX = AF_MAX;
496
497pub const AF_UNSPEC = 0;
498pub const AF_UNIX = 1;
499pub const AF_LOCAL = AF_UNIX;
500pub const AF_FILE = AF_LOCAL;
501pub const AF_INET = 2;
502pub const AF_IMPLINK = 3;
503pub const AF_PUP = 4;
504pub const AF_CHAOS = 5;
505pub const AF_NETBIOS = 6;
506pub const AF_ISO = 7;
507pub const AF_OSI = AF_ISO;
508pub const AF_ECMA = 8;
509pub const AF_DATAKIT = 9;
510pub const AF_CCITT = 10;
511pub const AF_SNA = 11;
512pub const AF_DECnet = 12;
513pub const AF_DLI = 13;
514pub const AF_LAT = 14;
515pub const AF_HYLINK = 15;
516pub const AF_APPLETALK = 16;
517pub const AF_ROUTE = 17;
518pub const AF_LINK = 18;
519pub const pseudo_AF_XTP = 19;
520pub const AF_COIP = 20;
521pub const AF_CNT = 21;
522pub const pseudo_AF_RTIP = 22;
523pub const AF_IPX = 23;
524pub const AF_SIP = 24;
525pub const pseudo_AF_PIP = 25;
526pub const AF_ISDN = 26;
527pub const AF_E164 = AF_ISDN;
528pub const pseudo_AF_KEY = 27;
529pub const AF_INET6 = 28;
530pub const AF_NATM = 29;
531pub const AF_ATM = 30;
532pub const pseudo_AF_HDRCMPLT = 31;
533pub const AF_NETGRAPH = 32;
534pub const AF_SLOW = 33;
535pub const AF_SCLUSTER = 34;
536pub const AF_ARP = 35;
537pub const AF_BLUETOOTH = 36;
538pub const AF_IEEE80211 = 37;
539pub const AF_INET_SDP = 40;
540pub const AF_INET6_SDP = 42;
541pub const AF_MAX = 42;
542
543pub const DT_UNKNOWN = 0;
544pub const DT_FIFO = 1;
545pub const DT_CHR = 2;
546pub const DT_DIR = 4;
547pub const DT_BLK = 6;
548pub const DT_REG = 8;
549pub const DT_LNK = 10;
550pub const DT_SOCK = 12;
551pub const DT_WHT = 14;
552
553/// add event to kq (implies enable)
554pub const EV_ADD = 0x0001;
555
556/// delete event from kq
557pub const EV_DELETE = 0x0002;
558
559/// enable event
560pub const EV_ENABLE = 0x0004;
561
562/// disable event (not reported)
563pub const EV_DISABLE = 0x0008;
564
565/// only report one occurrence
566pub const EV_ONESHOT = 0x0010;
567
568/// clear event state after reporting
569pub const EV_CLEAR = 0x0020;
570
571/// error, event data contains errno
572pub const EV_ERROR = 0x4000;
573
574/// force immediate event output
575/// ... with or without EV_ERROR
576/// ... use KEVENT_FLAG_ERROR_EVENTS
577/// on syscalls supporting flags
578pub const EV_RECEIPT = 0x0040;
579
580/// disable event after reporting
581pub const EV_DISPATCH = 0x0080;
582
583pub const EVFILT_READ = -1;
584pub const EVFILT_WRITE = -2;
585
586/// attached to aio requests
587pub const EVFILT_AIO = -3;
588
589/// attached to vnodes
590pub const EVFILT_VNODE = -4;
591
592/// attached to struct proc
593pub const EVFILT_PROC = -5;
594
595/// attached to struct proc
596pub const EVFILT_SIGNAL = -6;
597
598/// timers
599pub const EVFILT_TIMER = -7;
600
601/// Process descriptors
602pub const EVFILT_PROCDESC = -8;
603
604/// Filesystem events
605pub const EVFILT_FS = -9;
606
607pub const EVFILT_LIO = -10;
608
609/// User events
610pub const EVFILT_USER = -11;
611
612/// Sendfile events
613pub const EVFILT_SENDFILE = -12;
614
615pub const EVFILT_EMPTY = -13;
616
617/// On input, NOTE_TRIGGER causes the event to be triggered for output.
618pub const NOTE_TRIGGER = 0x01000000;
619
620/// ignore input fflags
621pub const NOTE_FFNOP = 0x00000000;
622
623/// and fflags
624pub const NOTE_FFAND = 0x40000000;
625
626/// or fflags
627pub const NOTE_FFOR = 0x80000000;
628
629/// copy fflags
630pub const NOTE_FFCOPY = 0xc0000000;
631
632/// mask for operations
633pub const NOTE_FFCTRLMASK = 0xc0000000;
634pub const NOTE_FFLAGSMASK = 0x00ffffff;
635
636/// low water mark
637pub const NOTE_LOWAT = 0x00000001;
638
639/// behave like poll()
640pub const NOTE_FILE_POLL = 0x00000002;
641
642/// vnode was removed
643pub const NOTE_DELETE = 0x00000001;
644
645/// data contents changed
646pub const NOTE_WRITE = 0x00000002;
647
648/// size increased
649pub const NOTE_EXTEND = 0x00000004;
650
651/// attributes changed
652pub const NOTE_ATTRIB = 0x00000008;
653
654/// link count changed
655pub const NOTE_LINK = 0x00000010;
656
657/// vnode was renamed
658pub const NOTE_RENAME = 0x00000020;
659
660/// vnode access was revoked
661pub const NOTE_REVOKE = 0x00000040;
662
663/// vnode was opened
664pub const NOTE_OPEN = 0x00000080;
665
666/// file closed, fd did not allow write
667pub const NOTE_CLOSE = 0x00000100;
668
669/// file closed, fd did allow write
670pub const NOTE_CLOSE_WRITE = 0x00000200;
671
672/// file was read
673pub const NOTE_READ = 0x00000400;
674
675/// process exited
676pub const NOTE_EXIT = 0x80000000;
677
678/// process forked
679pub const NOTE_FORK = 0x40000000;
680
681/// process exec'd
682pub const NOTE_EXEC = 0x20000000;
683
684/// mask for signal & exit status
685pub const NOTE_PDATAMASK = 0x000fffff;
686pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
687
688/// data is seconds
689pub const NOTE_SECONDS = 0x00000001;
690
691/// data is milliseconds
692pub const NOTE_MSECONDS = 0x00000002;
693
694/// data is microseconds
695pub const NOTE_USECONDS = 0x00000004;
696
697/// data is nanoseconds
698pub const NOTE_NSECONDS = 0x00000008;
699
700/// timeout is absolute
701pub const NOTE_ABSTIME = 0x00000010;
702
703pub const TIOCEXCL = 0x2000740d;
704pub const TIOCNXCL = 0x2000740e;
705pub const TIOCSCTTY = 0x20007461;
706pub const TIOCGPGRP = 0x40047477;
707pub const TIOCSPGRP = 0x80047476;
708pub const TIOCOUTQ = 0x40047473;
709pub const TIOCSTI = 0x80017472;
710pub const TIOCGWINSZ = 0x40087468;
711pub const TIOCSWINSZ = 0x80087467;
712pub const TIOCMGET = 0x4004746a;
713pub const TIOCMBIS = 0x8004746c;
714pub const TIOCMBIC = 0x8004746b;
715pub const TIOCMSET = 0x8004746d;
716pub const FIONREAD = 0x4004667f;
717pub const TIOCCONS = 0x80047462;
718pub const TIOCPKT = 0x80047470;
719pub const FIONBIO = 0x8004667e;
720pub const TIOCNOTTY = 0x20007471;
721pub const TIOCSETD = 0x8004741b;
722pub const TIOCGETD = 0x4004741a;
723pub const TIOCSBRK = 0x2000747b;
724pub const TIOCCBRK = 0x2000747a;
725pub const TIOCGSID = 0x40047463;
726pub const TIOCGPTN = 0x4004740f;
727pub const TIOCSIG = 0x2004745f;
728
729pub fn WEXITSTATUS(s: u32) u8 {
730 return @intCast(u8, (s & 0xff00) >> 8);
731}
732pub fn WTERMSIG(s: u32) u32 {
733 return s & 0x7f;
734}
735pub fn WSTOPSIG(s: u32) u32 {
736 return WEXITSTATUS(s);
737}
738pub fn WIFEXITED(s: u32) bool {
739 return WTERMSIG(s) == 0;
740}
741pub fn WIFSTOPPED(s: u32) bool {
742 return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
743}
744pub fn WIFSIGNALED(s: u32) bool {
745 return (s & 0xffff) -% 1 < 0xff;
746}
747
748pub const winsize = extern struct {
749 ws_row: u16,
750 ws_col: u16,
751 ws_xpixel: u16,
752 ws_ypixel: u16,
753};
754
755const NSIG = 32;
756
757pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
758pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
759pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
760
761/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
762pub const Sigaction = extern struct {
763 pub const handler_fn = fn (c_int) callconv(.C) void;
764 pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void;
765
766 /// signal handler
767 handler: extern union {
768 handler: ?handler_fn,
769 sigaction: ?sigaction_fn,
770 },
771
772 /// see signal options
773 flags: c_uint,
774
775 /// signal mask to apply
776 mask: sigset_t,
777};
778
779pub const siginfo_t = extern struct {
780 signo: c_int,
781 errno: c_int,
782 code: c_int,
783 pid: pid_t,
784 uid: uid_t,
785 status: c_int,
786 addr: ?*c_void,
787 value: sigval,
788 reason: extern union {
789 fault: extern struct {
790 trapno: c_int,
791 },
792 timer: extern struct {
793 timerid: c_int,
794 overrun: c_int,
795 },
796 mesgq: extern struct {
797 mqd: c_int,
798 },
799 poll: extern struct {
800 band: c_long,
801 },
802 spare: extern struct {
803 spare1: c_long,
804 spare2: [7]c_int,
805 },
806 },
807};
808
809pub const sigval = extern union {
810 int: c_int,
811 ptr: ?*c_void,
812};
813
814pub const _SIG_WORDS = 4;
815pub const _SIG_MAXSIG = 128;
816
817pub inline fn _SIG_IDX(sig: usize) usize {
818 return sig - 1;
819}
820pub inline fn _SIG_WORD(sig: usize) usize {
821 return_SIG_IDX(sig) >> 5;
822}
823pub inline fn _SIG_BIT(sig: usize) usize {
824 return 1 << (_SIG_IDX(sig) & 31);
825}
826pub inline fn _SIG_VALID(sig: usize) usize {
827 return sig <= _SIG_MAXSIG and sig > 0;
828}
829
830pub const sigset_t = extern struct {
831 __bits: [_SIG_WORDS]u32,
832};
833
834pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** _SIG_WORDS };
835
836pub usingnamespace switch (builtin.target.cpu.arch) {
837 .x86_64 => struct {
838 pub const ucontext_t = extern struct {
839 sigmask: sigset_t,
840 mcontext: mcontext_t,
841 link: ?*ucontext_t,
842 stack: stack_t,
843 flags: c_int,
844 __spare__: [4]c_int,
845 };
846
847 /// XXX x86_64 specific
848 pub const mcontext_t = extern struct {
849 onstack: u64,
850 rdi: u64,
851 rsi: u64,
852 rdx: u64,
853 rcx: u64,
854 r8: u64,
855 r9: u64,
856 rax: u64,
857 rbx: u64,
858 rbp: u64,
859 r10: u64,
860 r11: u64,
861 r12: u64,
862 r13: u64,
863 r14: u64,
864 r15: u64,
865 trapno: u32,
866 fs: u16,
867 gs: u16,
868 addr: u64,
869 flags: u32,
870 es: u16,
871 ds: u16,
872 err: u64,
873 rip: u64,
874 cs: u64,
875 rflags: u64,
876 rsp: u64,
877 ss: u64,
878 };
879 },
880 else => struct {},
881};
882
883pub const E = enum(u16) {
884 /// No error occurred.
885 SUCCESS = 0,
886
887 PERM = 1, // Operation not permitted
888 NOENT = 2, // No such file or directory
889 SRCH = 3, // No such process
890 INTR = 4, // Interrupted system call
891 IO = 5, // Input/output error
892 NXIO = 6, // Device not configured
893 @"2BIG" = 7, // Argument list too long
894 NOEXEC = 8, // Exec format error
895 BADF = 9, // Bad file descriptor
896 CHILD = 10, // No child processes
897 DEADLK = 11, // Resource deadlock avoided
898 // 11 was AGAIN
899 NOMEM = 12, // Cannot allocate memory
900 ACCES = 13, // Permission denied
901 FAULT = 14, // Bad address
902 NOTBLK = 15, // Block device required
903 BUSY = 16, // Device busy
904 EXIST = 17, // File exists
905 XDEV = 18, // Cross-device link
906 NODEV = 19, // Operation not supported by device
907 NOTDIR = 20, // Not a directory
908 ISDIR = 21, // Is a directory
909 INVAL = 22, // Invalid argument
910 NFILE = 23, // Too many open files in system
911 MFILE = 24, // Too many open files
912 NOTTY = 25, // Inappropriate ioctl for device
913 TXTBSY = 26, // Text file busy
914 FBIG = 27, // File too large
915 NOSPC = 28, // No space left on device
916 SPIPE = 29, // Illegal seek
917 ROFS = 30, // Read-only filesystem
918 MLINK = 31, // Too many links
919 PIPE = 32, // Broken pipe
920
921 // math software
922 DOM = 33, // Numerical argument out of domain
923 RANGE = 34, // Result too large
924
925 // non-blocking and interrupt i/o
926
927 /// Resource temporarily unavailable
928 /// This code is also used for `WOULDBLOCK`: operation would block.
929 AGAIN = 35,
930 INPROGRESS = 36, // Operation now in progress
931 ALREADY = 37, // Operation already in progress
932
933 // ipc/network software -- argument errors
934 NOTSOCK = 38, // Socket operation on non-socket
935 DESTADDRREQ = 39, // Destination address required
936 MSGSIZE = 40, // Message too long
937 PROTOTYPE = 41, // Protocol wrong type for socket
938 NOPROTOOPT = 42, // Protocol not available
939 PROTONOSUPPORT = 43, // Protocol not supported
940 SOCKTNOSUPPORT = 44, // Socket type not supported
941 /// Operation not supported
942 /// This code is also used for `NOTSUP`.
943 OPNOTSUPP = 45,
944 PFNOSUPPORT = 46, // Protocol family not supported
945 AFNOSUPPORT = 47, // Address family not supported by protocol family
946 ADDRINUSE = 48, // Address already in use
947 ADDRNOTAVAIL = 49, // Can't assign requested address
948
949 // ipc/network software -- operational errors
950 NETDOWN = 50, // Network is down
951 NETUNREACH = 51, // Network is unreachable
952 NETRESET = 52, // Network dropped connection on reset
953 CONNABORTED = 53, // Software caused connection abort
954 CONNRESET = 54, // Connection reset by peer
955 NOBUFS = 55, // No buffer space available
956 ISCONN = 56, // Socket is already connected
957 NOTCONN = 57, // Socket is not connected
958 SHUTDOWN = 58, // Can't send after socket shutdown
959 TOOMANYREFS = 59, // Too many references: can't splice
960 TIMEDOUT = 60, // Operation timed out
961 CONNREFUSED = 61, // Connection refused
962
963 LOOP = 62, // Too many levels of symbolic links
964 NAMETOOLONG = 63, // File name too long
965
966 // should be rearranged
967 HOSTDOWN = 64, // Host is down
968 HOSTUNREACH = 65, // No route to host
969 NOTEMPTY = 66, // Directory not empty
970
971 // quotas & mush
972 PROCLIM = 67, // Too many processes
973 USERS = 68, // Too many users
974 DQUOT = 69, // Disc quota exceeded
975
976 // Network File System
977 STALE = 70, // Stale NFS file handle
978 REMOTE = 71, // Too many levels of remote in path
979 BADRPC = 72, // RPC struct is bad
980 RPCMISMATCH = 73, // RPC version wrong
981 PROGUNAVAIL = 74, // RPC prog. not avail
982 PROGMISMATCH = 75, // Program version wrong
983 PROCUNAVAIL = 76, // Bad procedure for program
984
985 NOLCK = 77, // No locks available
986 NOSYS = 78, // Function not implemented
987
988 FTYPE = 79, // Inappropriate file type or format
989 AUTH = 80, // Authentication error
990 NEEDAUTH = 81, // Need authenticator
991 IDRM = 82, // Identifier removed
992 NOMSG = 83, // No message of desired type
993 OVERFLOW = 84, // Value too large to be stored in data type
994 CANCELED = 85, // Operation canceled
995 ILSEQ = 86, // Illegal byte sequence
996 NOATTR = 87, // Attribute not found
997
998 DOOFUS = 88, // Programming error
999
1000 BADMSG = 89, // Bad message
1001 MULTIHOP = 90, // Multihop attempted
1002 NOLINK = 91, // Link has been severed
1003 PROTO = 92, // Protocol error
1004
1005 NOTCAPABLE = 93, // Capabilities insufficient
1006 CAPMODE = 94, // Not permitted in capability mode
1007 NOTRECOVERABLE = 95, // State not recoverable
1008 OWNERDEAD = 96, // Previous owner died
1009 _,
1010};
1011
1012pub const MINSIGSTKSZ = switch (builtin.target.cpu.arch) {
1013 .i386, .x86_64 => 2048,
1014 .arm, .aarch64 => 4096,
1015 else => @compileError("MINSIGSTKSZ not defined for this architecture"),
1016};
1017pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
1018
1019pub const SS_ONSTACK = 1;
1020pub const SS_DISABLE = 4;
1021
1022pub const stack_t = extern struct {
1023 ss_sp: [*]u8,
1024 ss_size: isize,
1025 ss_flags: i32,
1026};
1027
1028pub const S_IFMT = 0o170000;
1029
1030pub const S_IFIFO = 0o010000;
1031pub const S_IFCHR = 0o020000;
1032pub const S_IFDIR = 0o040000;
1033pub const S_IFBLK = 0o060000;
1034pub const S_IFREG = 0o100000;
1035pub const S_IFLNK = 0o120000;
1036pub const S_IFSOCK = 0o140000;
1037pub const S_IFWHT = 0o160000;
1038
1039pub const S_ISUID = 0o4000;
1040pub const S_ISGID = 0o2000;
1041pub const S_ISVTX = 0o1000;
1042pub const S_IRWXU = 0o700;
1043pub const S_IRUSR = 0o400;
1044pub const S_IWUSR = 0o200;
1045pub const S_IXUSR = 0o100;
1046pub const S_IRWXG = 0o070;
1047pub const S_IRGRP = 0o040;
1048pub const S_IWGRP = 0o020;
1049pub const S_IXGRP = 0o010;
1050pub const S_IRWXO = 0o007;
1051pub const S_IROTH = 0o004;
1052pub const S_IWOTH = 0o002;
1053pub const S_IXOTH = 0o001;
1054
1055pub fn S_ISFIFO(m: u32) bool {
1056 return m & S_IFMT == S_IFIFO;
1057}
1058
1059pub fn S_ISCHR(m: u32) bool {
1060 return m & S_IFMT == S_IFCHR;
1061}
1062
1063pub fn S_ISDIR(m: u32) bool {
1064 return m & S_IFMT == S_IFDIR;
1065}
1066
1067pub fn S_ISBLK(m: u32) bool {
1068 return m & S_IFMT == S_IFBLK;
1069}
1070
1071pub fn S_ISREG(m: u32) bool {
1072 return m & S_IFMT == S_IFREG;
1073}
1074
1075pub fn S_ISLNK(m: u32) bool {
1076 return m & S_IFMT == S_IFLNK;
1077}
1078
1079pub fn S_ISSOCK(m: u32) bool {
1080 return m & S_IFMT == S_IFSOCK;
1081}
1082
1083pub fn S_IWHT(m: u32) bool {
1084 return m & S_IFMT == S_IFWHT;
1085}
1086
1087pub const HOST_NAME_MAX = 255;
1088
1089/// Magic value that specify the use of the current working directory
1090/// to determine the target of relative file paths in the openat() and
1091/// similar syscalls.
1092pub const AT_FDCWD = -100;
1093
1094/// Check access using effective user and group ID
1095pub const AT_EACCESS = 0x0100;
1096
1097/// Do not follow symbolic links
1098pub const AT_SYMLINK_NOFOLLOW = 0x0200;
1099
1100/// Follow symbolic link
1101pub const AT_SYMLINK_FOLLOW = 0x0400;
1102
1103/// Remove directory instead of file
1104pub const AT_REMOVEDIR = 0x0800;
1105
1106pub const addrinfo = extern struct {
1107 flags: i32,
1108 family: i32,
1109 socktype: i32,
1110 protocol: i32,
1111 addrlen: socklen_t,
1112 canonname: ?[*:0]u8,
1113 addr: ?*sockaddr,
1114 next: ?*addrinfo,
1115};
1116
1117/// Fail if not under dirfd
1118pub const AT_BENEATH = 0x1000;
1119
1120/// dummy for IP
1121pub const IPPROTO_IP = 0;
1122
1123/// control message protocol
1124pub const IPPROTO_ICMP = 1;
1125
1126/// tcp
1127pub const IPPROTO_TCP = 6;
1128
1129/// user datagram protocol
1130pub const IPPROTO_UDP = 17;
1131
1132/// IP6 header
1133pub const IPPROTO_IPV6 = 41;
1134
1135/// raw IP packet
1136pub const IPPROTO_RAW = 255;
1137
1138/// IP6 hop-by-hop options
1139pub const IPPROTO_HOPOPTS = 0;
1140
1141/// group mgmt protocol
1142pub const IPPROTO_IGMP = 2;
1143
1144/// gateway^2 (deprecated)
1145pub const IPPROTO_GGP = 3;
1146
1147/// IPv4 encapsulation
1148pub const IPPROTO_IPV4 = 4;
1149
1150/// for compatibility
1151pub const IPPROTO_IPIP = IPPROTO_IPV4;
1152
1153/// Stream protocol II
1154pub const IPPROTO_ST = 7;
1155
1156/// exterior gateway protocol
1157pub const IPPROTO_EGP = 8;
1158
1159/// private interior gateway
1160pub const IPPROTO_PIGP = 9;
1161
1162/// BBN RCC Monitoring
1163pub const IPPROTO_RCCMON = 10;
1164
1165/// network voice protocol
1166pub const IPPROTO_NVPII = 11;
1167
1168/// pup
1169pub const IPPROTO_PUP = 12;
1170
1171/// Argus
1172pub const IPPROTO_ARGUS = 13;
1173
1174/// EMCON
1175pub const IPPROTO_EMCON = 14;
1176
1177/// Cross Net Debugger
1178pub const IPPROTO_XNET = 15;
1179
1180/// Chaos
1181pub const IPPROTO_CHAOS = 16;
1182
1183/// Multiplexing
1184pub const IPPROTO_MUX = 18;
1185
1186/// DCN Measurement Subsystems
1187pub const IPPROTO_MEAS = 19;
1188
1189/// Host Monitoring
1190pub const IPPROTO_HMP = 20;
1191
1192/// Packet Radio Measurement
1193pub const IPPROTO_PRM = 21;
1194
1195/// xns idp
1196pub const IPPROTO_IDP = 22;
1197
1198/// Trunk-1
1199pub const IPPROTO_TRUNK1 = 23;
1200
1201/// Trunk-2
1202pub const IPPROTO_TRUNK2 = 24;
1203
1204/// Leaf-1
1205pub const IPPROTO_LEAF1 = 25;
1206
1207/// Leaf-2
1208pub const IPPROTO_LEAF2 = 26;
1209
1210/// Reliable Data
1211pub const IPPROTO_RDP = 27;
1212
1213/// Reliable Transaction
1214pub const IPPROTO_IRTP = 28;
1215
1216/// tp-4 w/ class negotiation
1217pub const IPPROTO_TP = 29;
1218
1219/// Bulk Data Transfer
1220pub const IPPROTO_BLT = 30;
1221
1222/// Network Services
1223pub const IPPROTO_NSP = 31;
1224
1225/// Merit Internodal
1226pub const IPPROTO_INP = 32;
1227
1228/// Datagram Congestion Control Protocol
1229pub const IPPROTO_DCCP = 33;
1230
1231/// Third Party Connect
1232pub const IPPROTO_3PC = 34;
1233
1234/// InterDomain Policy Routing
1235pub const IPPROTO_IDPR = 35;
1236
1237/// XTP
1238pub const IPPROTO_XTP = 36;
1239
1240/// Datagram Delivery
1241pub const IPPROTO_DDP = 37;
1242
1243/// Control Message Transport
1244pub const IPPROTO_CMTP = 38;
1245
1246/// TP++ Transport
1247pub const IPPROTO_TPXX = 39;
1248
1249/// IL transport protocol
1250pub const IPPROTO_IL = 40;
1251
1252/// Source Demand Routing
1253pub const IPPROTO_SDRP = 42;
1254
1255/// IP6 routing header
1256pub const IPPROTO_ROUTING = 43;
1257
1258/// IP6 fragmentation header
1259pub const IPPROTO_FRAGMENT = 44;
1260
1261/// InterDomain Routing
1262pub const IPPROTO_IDRP = 45;
1263
1264/// resource reservation
1265pub const IPPROTO_RSVP = 46;
1266
1267/// General Routing Encap.
1268pub const IPPROTO_GRE = 47;
1269
1270/// Mobile Host Routing
1271pub const IPPROTO_MHRP = 48;
1272
1273/// BHA
1274pub const IPPROTO_BHA = 49;
1275
1276/// IP6 Encap Sec. Payload
1277pub const IPPROTO_ESP = 50;
1278
1279/// IP6 Auth Header
1280pub const IPPROTO_AH = 51;
1281
1282/// Integ. Net Layer Security
1283pub const IPPROTO_INLSP = 52;
1284
1285/// IP with encryption
1286pub const IPPROTO_SWIPE = 53;
1287
1288/// Next Hop Resolution
1289pub const IPPROTO_NHRP = 54;
1290
1291/// IP Mobility
1292pub const IPPROTO_MOBILE = 55;
1293
1294/// Transport Layer Security
1295pub const IPPROTO_TLSP = 56;
1296
1297/// SKIP
1298pub const IPPROTO_SKIP = 57;
1299
1300/// ICMP6
1301pub const IPPROTO_ICMPV6 = 58;
1302
1303/// IP6 no next header
1304pub const IPPROTO_NONE = 59;
1305
1306/// IP6 destination option
1307pub const IPPROTO_DSTOPTS = 60;
1308
1309/// any host internal protocol
1310pub const IPPROTO_AHIP = 61;
1311
1312/// CFTP
1313pub const IPPROTO_CFTP = 62;
1314
1315/// "hello" routing protocol
1316pub const IPPROTO_HELLO = 63;
1317
1318/// SATNET/Backroom EXPAK
1319pub const IPPROTO_SATEXPAK = 64;
1320
1321/// Kryptolan
1322pub const IPPROTO_KRYPTOLAN = 65;
1323
1324/// Remote Virtual Disk
1325pub const IPPROTO_RVD = 66;
1326
1327/// Pluribus Packet Core
1328pub const IPPROTO_IPPC = 67;
1329
1330/// Any distributed FS
1331pub const IPPROTO_ADFS = 68;
1332
1333/// Satnet Monitoring
1334pub const IPPROTO_SATMON = 69;
1335
1336/// VISA Protocol
1337pub const IPPROTO_VISA = 70;
1338
1339/// Packet Core Utility
1340pub const IPPROTO_IPCV = 71;
1341
1342/// Comp. Prot. Net. Executive
1343pub const IPPROTO_CPNX = 72;
1344
1345/// Comp. Prot. HeartBeat
1346pub const IPPROTO_CPHB = 73;
1347
1348/// Wang Span Network
1349pub const IPPROTO_WSN = 74;
1350
1351/// Packet Video Protocol
1352pub const IPPROTO_PVP = 75;
1353
1354/// BackRoom SATNET Monitoring
1355pub const IPPROTO_BRSATMON = 76;
1356
1357/// Sun net disk proto (temp.)
1358pub const IPPROTO_ND = 77;
1359
1360/// WIDEBAND Monitoring
1361pub const IPPROTO_WBMON = 78;
1362
1363/// WIDEBAND EXPAK
1364pub const IPPROTO_WBEXPAK = 79;
1365
1366/// ISO cnlp
1367pub const IPPROTO_EON = 80;
1368
1369/// VMTP
1370pub const IPPROTO_VMTP = 81;
1371
1372/// Secure VMTP
1373pub const IPPROTO_SVMTP = 82;
1374
1375/// Banyon VINES
1376pub const IPPROTO_VINES = 83;
1377
1378/// TTP
1379pub const IPPROTO_TTP = 84;
1380
1381/// NSFNET-IGP
1382pub const IPPROTO_IGP = 85;
1383
1384/// dissimilar gateway prot.
1385pub const IPPROTO_DGP = 86;
1386
1387/// TCF
1388pub const IPPROTO_TCF = 87;
1389
1390/// Cisco/GXS IGRP
1391pub const IPPROTO_IGRP = 88;
1392
1393/// OSPFIGP
1394pub const IPPROTO_OSPFIGP = 89;
1395
1396/// Strite RPC protocol
1397pub const IPPROTO_SRPC = 90;
1398
1399/// Locus Address Resoloution
1400pub const IPPROTO_LARP = 91;
1401
1402/// Multicast Transport
1403pub const IPPROTO_MTP = 92;
1404
1405/// AX.25 Frames
1406pub const IPPROTO_AX25 = 93;
1407
1408/// IP encapsulated in IP
1409pub const IPPROTO_IPEIP = 94;
1410
1411/// Mobile Int.ing control
1412pub const IPPROTO_MICP = 95;
1413
1414/// Semaphore Comm. security
1415pub const IPPROTO_SCCSP = 96;
1416
1417/// Ethernet IP encapsulation
1418pub const IPPROTO_ETHERIP = 97;
1419
1420/// encapsulation header
1421pub const IPPROTO_ENCAP = 98;
1422
1423/// any private encr. scheme
1424pub const IPPROTO_APES = 99;
1425
1426/// GMTP
1427pub const IPPROTO_GMTP = 100;
1428
1429/// payload compression (IPComp)
1430pub const IPPROTO_IPCOMP = 108;
1431
1432/// SCTP
1433pub const IPPROTO_SCTP = 132;
1434
1435/// IPv6 Mobility Header
1436pub const IPPROTO_MH = 135;
1437
1438/// UDP-Lite
1439pub const IPPROTO_UDPLITE = 136;
1440
1441/// IP6 Host Identity Protocol
1442pub const IPPROTO_HIP = 139;
1443
1444/// IP6 Shim6 Protocol
1445pub const IPPROTO_SHIM6 = 140;
1446
1447/// Protocol Independent Mcast
1448pub const IPPROTO_PIM = 103;
1449
1450/// CARP
1451pub const IPPROTO_CARP = 112;
1452
1453/// PGM
1454pub const IPPROTO_PGM = 113;
1455
1456/// MPLS-in-IP
1457pub const IPPROTO_MPLS = 137;
1458
1459/// PFSYNC
1460pub const IPPROTO_PFSYNC = 240;
1461
1462/// Reserved
1463pub const IPPROTO_RESERVED_253 = 253;
1464
1465/// Reserved
1466pub const IPPROTO_RESERVED_254 = 254;
1467
1468pub const rlimit_resource = enum(c_int) {
1469 CPU = 0,
1470 FSIZE = 1,
1471 DATA = 2,
1472 STACK = 3,
1473 CORE = 4,
1474 RSS = 5,
1475 MEMLOCK = 6,
1476 NPROC = 7,
1477 NOFILE = 8,
1478 SBSIZE = 9,
1479 VMEM = 10,
1480 NPTS = 11,
1481 SWAP = 12,
1482 KQUEUES = 13,
1483 UMTXP = 14,
1484 _,
1485
1486 pub const AS: rlimit_resource = .VMEM;
1487};
1488
1489pub const rlim_t = i64;
1490
1491/// No limit
1492pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
1493
1494pub const RLIM_SAVED_MAX = RLIM_INFINITY;
1495pub const RLIM_SAVED_CUR = RLIM_INFINITY;
1496
1497pub const rlimit = extern struct {
1498 /// Soft limit
1499 cur: rlim_t,
1500 /// Hard limit
1501 max: rlim_t,
1502};
1503
1504pub const SHUT_RD = 0;
1505pub const SHUT_WR = 1;
1506pub const SHUT_RDWR = 2;
1507
1508pub const nfds_t = u32;
1509
1510pub const pollfd = extern struct {
1511 fd: fd_t,
1512 events: i16,
1513 revents: i16,
1514};
1515
1516/// any readable data available.
1517pub const POLLIN = 0x0001;
1518/// OOB/Urgent readable data.
1519pub const POLLPRI = 0x0002;
1520/// file descriptor is writeable.
1521pub const POLLOUT = 0x0004;
1522/// non-OOB/URG data available.
1523pub const POLLRDNORM = 0x0040;
1524/// no write type differentiation.
1525pub const POLLWRNORM = POLLOUT;
1526/// OOB/Urgent readable data.
1527pub const POLLRDBAND = 0x0080;
1528/// OOB/Urgent data can be written.
1529pub const POLLWRBAND = 0x0100;
1530/// like POLLIN, except ignore EOF.
1531pub const POLLINIGNEOF = 0x2000;
1532/// some poll error occurred.
1533pub const POLLERR = 0x0008;
1534/// file descriptor was "hung up".
1535pub const POLLHUP = 0x0010;
1536/// requested events "invalid".
1537pub const POLLNVAL = 0x0020;
1538
1539pub const POLLSTANDARD = POLLIN | POLLPRI | POLLOUT | POLLRDNORM | POLLRDBAND |
1540 POLLWRBAND | POLLERR | POLLHUP | POLLNVAL;
lib/std/os/bits/haiku.zig deleted-1373
...@@ -1,1373 +0,0 @@
1const std = @import("../../std.zig");
2const maxInt = std.math.maxInt;
3
4pub const fd_t = c_int;
5pub const pid_t = c_int;
6pub const uid_t = u32;
7pub const gid_t = u32;
8pub const mode_t = c_uint;
9
10pub const socklen_t = u32;
11
12/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
13pub const Kevent = extern struct {
14 ident: usize,
15 filter: i16,
16 flags: u16,
17 fflags: u32,
18 data: i64,
19 udata: usize,
20 // TODO ext
21};
22
23// Modes and flags for dlopen()
24// include/dlfcn.h
25
26pub const POLLIN = 0x0001;
27pub const POLLERR = 0x0004;
28pub const POLLNVAL = 0x1000;
29pub const POLLHUP = 0x0080;
30
31/// Bind function calls lazily.
32pub const RTLD_LAZY = 1;
33
34/// Bind function calls immediately.
35pub const RTLD_NOW = 2;
36
37pub const RTLD_MODEMASK = 0x3;
38
39/// Make symbols globally available.
40pub const RTLD_GLOBAL = 0x100;
41
42/// Opposite of RTLD_GLOBAL, and the default.
43pub const RTLD_LOCAL = 0;
44
45/// Trace loaded objects and exit.
46pub const RTLD_TRACE = 0x200;
47
48/// Do not remove members.
49pub const RTLD_NODELETE = 0x01000;
50
51/// Do not load if not already loaded.
52pub const RTLD_NOLOAD = 0x02000;
53
54pub const dl_phdr_info = extern struct {
55 dlpi_addr: usize,
56 dlpi_name: ?[*:0]const u8,
57 dlpi_phdr: [*]std.elf.Phdr,
58 dlpi_phnum: u16,
59};
60
61pub const Flock = extern struct {
62 l_start: off_t,
63 l_len: off_t,
64 l_pid: pid_t,
65 l_type: i16,
66 l_whence: i16,
67 l_sysid: i32,
68 __unused: [4]u8,
69};
70
71pub const msghdr = extern struct {
72 /// optional address
73 msg_name: ?*sockaddr,
74
75 /// size of address
76 msg_namelen: socklen_t,
77
78 /// scatter/gather array
79 msg_iov: [*]iovec,
80
81 /// # elements in msg_iov
82 msg_iovlen: i32,
83
84 /// ancillary data
85 msg_control: ?*c_void,
86
87 /// ancillary data buffer len
88 msg_controllen: socklen_t,
89
90 /// flags on received message
91 msg_flags: i32,
92};
93
94pub const msghdr_const = extern struct {
95 /// optional address
96 msg_name: ?*const sockaddr,
97
98 /// size of address
99 msg_namelen: socklen_t,
100
101 /// scatter/gather array
102 msg_iov: [*]iovec_const,
103
104 /// # elements in msg_iov
105 msg_iovlen: i32,
106
107 /// ancillary data
108 msg_control: ?*c_void,
109
110 /// ancillary data buffer len
111 msg_controllen: socklen_t,
112
113 /// flags on received message
114 msg_flags: i32,
115};
116
117pub const off_t = i64;
118pub const ino_t = u64;
119
120pub const nfds_t = u32;
121
122pub const pollfd = extern struct {
123 fd: i32,
124 events: i16,
125 revents: i16,
126};
127
128pub const libc_stat = extern struct {
129 dev: i32,
130 ino: u64,
131 mode: u32,
132 nlink: i32,
133 uid: i32,
134 gid: i32,
135 size: i64,
136 rdev: i32,
137 blksize: i32,
138 atim: timespec,
139 mtim: timespec,
140 ctim: timespec,
141 crtim: timespec,
142 st_type: u32,
143 blocks: i64,
144
145 pub fn atime(self: @This()) timespec {
146 return self.atim;
147 }
148 pub fn mtime(self: @This()) timespec {
149 return self.mtim;
150 }
151 pub fn ctime(self: @This()) timespec {
152 return self.ctim;
153 }
154 pub fn crtime(self: @This()) timespec {
155 return self.crtim;
156 }
157};
158
159pub const timespec = extern struct {
160 tv_sec: isize,
161 tv_nsec: isize,
162};
163
164pub const dirent = extern struct {
165 d_dev: i32,
166 d_pdev: i32,
167 d_ino: i64,
168 d_pino: i64,
169 d_reclen: u16,
170 d_name: [256]u8,
171
172 pub fn reclen(self: dirent) u16 {
173 return self.d_reclen;
174 }
175};
176
177pub const image_info = extern struct {
178 id: u32,
179 type: u32,
180 sequence: i32,
181 init_order: i32,
182 init_routine: *c_void,
183 term_routine: *c_void,
184 device: i32,
185 node: i32,
186 name: [1024]u8,
187 text: *c_void,
188 data: *c_void,
189 text_size: i32,
190 data_size: i32,
191 api_version: i32,
192 abi: i32,
193};
194
195pub const system_info = extern struct {
196 boot_time: i64,
197 cpu_count: u32,
198 max_pages: u64,
199 used_pages: u64,
200 cached_pages: u64,
201 block_cache_pages: u64,
202 ignored_pages: u64,
203 needed_memory: u64,
204 free_memory: u64,
205 max_swap_pages: u64,
206 free_swap_pages: u64,
207 page_faults: u32,
208 max_sems: u32,
209 used_sems: u32,
210 max_ports: u32,
211 used_ports: u32,
212 max_threads: u32,
213 used_threads: u32,
214 max_teams: u32,
215 used_teams: u32,
216 kernel_name: [256]u8,
217 kernel_build_date: [32]u8,
218 kernel_build_time: [32]u8,
219 kernel_version: i64,
220 abi: u32,
221};
222
223pub const in_port_t = u16;
224pub const sa_family_t = u8;
225
226pub const sockaddr = extern struct {
227 /// total length
228 len: u8,
229
230 /// address family
231 family: sa_family_t,
232
233 /// actually longer; address value
234 data: [14]u8,
235};
236
237pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
238
239pub const sockaddr_in = extern struct {
240 len: u8 = @sizeOf(sockaddr_in),
241 family: sa_family_t = AF_INET,
242 port: in_port_t,
243 addr: u32,
244 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
245};
246
247pub const sockaddr_in6 = extern struct {
248 len: u8 = @sizeOf(sockaddr_in6),
249 family: sa_family_t = AF_INET6,
250 port: in_port_t,
251 flowinfo: u32,
252 addr: [16]u8,
253 scope_id: u32,
254};
255
256pub const sockaddr_un = extern struct {
257 len: u8 = @sizeOf(sockaddr_un),
258 family: sa_family_t = AF_UNIX,
259 path: [104]u8,
260};
261
262pub const CTL_KERN = 1;
263pub const CTL_DEBUG = 5;
264
265pub const KERN_PROC = 14; // struct: process entries
266pub const KERN_PROC_PATHNAME = 12; // path to executable
267
268pub const PATH_MAX = 1024;
269
270pub const STDIN_FILENO = 0;
271pub const STDOUT_FILENO = 1;
272pub const STDERR_FILENO = 2;
273
274pub const PROT_NONE = 0;
275pub const PROT_READ = 1;
276pub const PROT_WRITE = 2;
277pub const PROT_EXEC = 4;
278
279pub const CLOCK_MONOTONIC = 0;
280pub const CLOCK_REALTIME = -1;
281pub const CLOCK_PROCESS_CPUTIME_ID = -2;
282pub const CLOCK_THREAD_CPUTIME_ID = -3;
283
284pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
285pub const MAP_SHARED = 0x0001;
286pub const MAP_PRIVATE = 0x0002;
287pub const MAP_FIXED = 0x0010;
288pub const MAP_STACK = 0x0400;
289pub const MAP_NOSYNC = 0x0800;
290pub const MAP_ANON = 0x1000;
291pub const MAP_ANONYMOUS = MAP_ANON;
292pub const MAP_FILE = 0;
293
294pub const MAP_GUARD = 0x00002000;
295pub const MAP_EXCL = 0x00004000;
296pub const MAP_NOCORE = 0x00020000;
297pub const MAP_PREFAULT_READ = 0x00040000;
298pub const MAP_32BIT = 0x00080000;
299
300pub const WNOHANG = 0x1;
301pub const WUNTRACED = 0x2;
302pub const WSTOPPED = 0x10;
303pub const WCONTINUED = 0x4;
304pub const WNOWAIT = 0x20;
305pub const WEXITED = 0x08;
306
307pub const SA_ONSTACK = 0x20;
308pub const SA_RESTART = 0x10;
309pub const SA_RESETHAND = 0x04;
310pub const SA_NOCLDSTOP = 0x01;
311pub const SA_NODEFER = 0x08;
312pub const SA_NOCLDWAIT = 0x02;
313pub const SA_SIGINFO = 0x40;
314pub const SA_NOMASK = SA_NODEFER;
315pub const SA_STACK = SA_ONSTACK;
316pub const SA_ONESHOT = SA_RESETHAND;
317
318pub const SIGHUP = 1;
319pub const SIGINT = 2;
320pub const SIGQUIT = 3;
321pub const SIGILL = 4;
322pub const SIGCHLD = 5;
323pub const SIGABRT = 6;
324pub const SIGIOT = SIGABRT;
325pub const SIGPIPE = 7;
326pub const SIGFPE = 8;
327pub const SIGKILL = 9;
328pub const SIGSTOP = 10;
329pub const SIGSEGV = 11;
330pub const SIGCONT = 12;
331pub const SIGTSTP = 13;
332pub const SIGALRM = 14;
333pub const SIGTERM = 15;
334pub const SIGTTIN = 16;
335pub const SIGTTOU = 17;
336pub const SIGUSR1 = 18;
337pub const SIGUSR2 = 19;
338pub const SIGWINCH = 20;
339pub const SIGKILLTHR = 21;
340pub const SIGTRAP = 22;
341pub const SIGPOLL = 23;
342pub const SIGPROF = 24;
343pub const SIGSYS = 25;
344pub const SIGURG = 26;
345pub const SIGVTALRM = 27;
346pub const SIGXCPU = 28;
347pub const SIGXFSZ = 29;
348pub const SIGBUS = 30;
349pub const SIGRESERVED1 = 31;
350pub const SIGRESERVED2 = 32;
351
352// TODO: check
353pub const SIGRTMIN = 65;
354pub const SIGRTMAX = 126;
355
356// access function
357pub const F_OK = 0; // test for existence of file
358pub const X_OK = 1; // test for execute or search permission
359pub const W_OK = 2; // test for write permission
360pub const R_OK = 4; // test for read permission
361
362pub const O_RDONLY = 0x0000;
363pub const O_WRONLY = 0x0001;
364pub const O_RDWR = 0x0002;
365pub const O_ACCMODE = 0x0003;
366
367pub const O_SHLOCK = 0x0010;
368pub const O_EXLOCK = 0x0020;
369
370pub const O_CREAT = 0x0200;
371pub const O_EXCL = 0x0800;
372pub const O_NOCTTY = 0x8000;
373pub const O_TRUNC = 0x0400;
374pub const O_APPEND = 0x0008;
375pub const O_NONBLOCK = 0x0004;
376pub const O_DSYNC = 0o10000;
377pub const O_SYNC = 0x0080;
378pub const O_RSYNC = 0o4010000;
379pub const O_DIRECTORY = 0x20000;
380pub const O_NOFOLLOW = 0x0100;
381pub const O_CLOEXEC = 0x00100000;
382
383pub const O_ASYNC = 0x0040;
384pub const O_DIRECT = 0x00010000;
385pub const O_NOATIME = 0o1000000;
386pub const O_PATH = 0o10000000;
387pub const O_TMPFILE = 0o20200000;
388pub const O_NDELAY = O_NONBLOCK;
389
390pub const F_DUPFD = 0;
391pub const F_GETFD = 1;
392pub const F_SETFD = 2;
393pub const F_GETFL = 3;
394pub const F_SETFL = 4;
395
396pub const F_GETOWN = 5;
397pub const F_SETOWN = 6;
398
399pub const F_GETLK = 11;
400pub const F_SETLK = 12;
401pub const F_SETLKW = 13;
402
403pub const F_RDLCK = 1;
404pub const F_WRLCK = 3;
405pub const F_UNLCK = 2;
406
407pub const LOCK_SH = 1;
408pub const LOCK_EX = 2;
409pub const LOCK_UN = 8;
410pub const LOCK_NB = 4;
411
412pub const F_SETOWN_EX = 15;
413pub const F_GETOWN_EX = 16;
414
415pub const F_GETOWNER_UIDS = 17;
416
417pub const FD_CLOEXEC = 1;
418
419pub const SEEK_SET = 0;
420pub const SEEK_CUR = 1;
421pub const SEEK_END = 2;
422
423pub const SIG_BLOCK = 1;
424pub const SIG_UNBLOCK = 2;
425pub const SIG_SETMASK = 3;
426
427pub const SOCK_STREAM = 1;
428pub const SOCK_DGRAM = 2;
429pub const SOCK_RAW = 3;
430pub const SOCK_RDM = 4;
431pub const SOCK_SEQPACKET = 5;
432
433pub const SOCK_CLOEXEC = 0x10000000;
434pub const SOCK_NONBLOCK = 0x20000000;
435
436pub const SO_DEBUG = 0x00000001;
437pub const SO_ACCEPTCONN = 0x00000002;
438pub const SO_REUSEADDR = 0x00000004;
439pub const SO_KEEPALIVE = 0x00000008;
440pub const SO_DONTROUTE = 0x00000010;
441pub const SO_BROADCAST = 0x00000020;
442pub const SO_USELOOPBACK = 0x00000040;
443pub const SO_LINGER = 0x00000080;
444pub const SO_OOBINLINE = 0x00000100;
445pub const SO_REUSEPORT = 0x00000200;
446pub const SO_TIMESTAMP = 0x00000400;
447pub const SO_NOSIGPIPE = 0x00000800;
448pub const SO_ACCEPTFILTER = 0x00001000;
449pub const SO_BINTIME = 0x00002000;
450pub const SO_NO_OFFLOAD = 0x00004000;
451pub const SO_NO_DDP = 0x00008000;
452pub const SO_REUSEPORT_LB = 0x00010000;
453
454pub const SO_SNDBUF = 0x1001;
455pub const SO_RCVBUF = 0x1002;
456pub const SO_SNDLOWAT = 0x1003;
457pub const SO_RCVLOWAT = 0x1004;
458pub const SO_SNDTIMEO = 0x1005;
459pub const SO_RCVTIMEO = 0x1006;
460pub const SO_ERROR = 0x1007;
461pub const SO_TYPE = 0x1008;
462pub const SO_LABEL = 0x1009;
463pub const SO_PEERLABEL = 0x1010;
464pub const SO_LISTENQLIMIT = 0x1011;
465pub const SO_LISTENQLEN = 0x1012;
466pub const SO_LISTENINCQLEN = 0x1013;
467pub const SO_SETFIB = 0x1014;
468pub const SO_USER_COOKIE = 0x1015;
469pub const SO_PROTOCOL = 0x1016;
470pub const SO_PROTOTYPE = SO_PROTOCOL;
471pub const SO_TS_CLOCK = 0x1017;
472pub const SO_MAX_PACING_RATE = 0x1018;
473pub const SO_DOMAIN = 0x1019;
474
475pub const SOL_SOCKET = 0xffff;
476
477pub const PF_UNSPEC = AF_UNSPEC;
478pub const PF_LOCAL = AF_LOCAL;
479pub const PF_UNIX = PF_LOCAL;
480pub const PF_INET = AF_INET;
481pub const PF_IMPLINK = AF_IMPLINK;
482pub const PF_PUP = AF_PUP;
483pub const PF_CHAOS = AF_CHAOS;
484pub const PF_NETBIOS = AF_NETBIOS;
485pub const PF_ISO = AF_ISO;
486pub const PF_OSI = AF_ISO;
487pub const PF_ECMA = AF_ECMA;
488pub const PF_DATAKIT = AF_DATAKIT;
489pub const PF_CCITT = AF_CCITT;
490pub const PF_DECnet = AF_DECnet;
491pub const PF_DLI = AF_DLI;
492pub const PF_LAT = AF_LAT;
493pub const PF_HYLINK = AF_HYLINK;
494pub const PF_APPLETALK = AF_APPLETALK;
495pub const PF_ROUTE = AF_ROUTE;
496pub const PF_LINK = AF_LINK;
497pub const PF_XTP = pseudo_AF_XTP;
498pub const PF_COIP = AF_COIP;
499pub const PF_CNT = AF_CNT;
500pub const PF_SIP = AF_SIP;
501pub const PF_IPX = AF_IPX;
502pub const PF_RTIP = pseudo_AF_RTIP;
503pub const PF_PIP = psuedo_AF_PIP;
504pub const PF_ISDN = AF_ISDN;
505pub const PF_KEY = pseudo_AF_KEY;
506pub const PF_INET6 = pseudo_AF_INET6;
507pub const PF_NATM = AF_NATM;
508pub const PF_ATM = AF_ATM;
509pub const PF_NETGRAPH = AF_NETGRAPH;
510pub const PF_SLOW = AF_SLOW;
511pub const PF_SCLUSTER = AF_SCLUSTER;
512pub const PF_ARP = AF_ARP;
513pub const PF_BLUETOOTH = AF_BLUETOOTH;
514pub const PF_IEEE80211 = AF_IEEE80211;
515pub const PF_INET_SDP = AF_INET_SDP;
516pub const PF_INET6_SDP = AF_INET6_SDP;
517pub const PF_MAX = AF_MAX;
518
519pub const AF_UNSPEC = 0;
520pub const AF_UNIX = 1;
521pub const AF_LOCAL = AF_UNIX;
522pub const AF_FILE = AF_LOCAL;
523pub const AF_INET = 2;
524pub const AF_IMPLINK = 3;
525pub const AF_PUP = 4;
526pub const AF_CHAOS = 5;
527pub const AF_NETBIOS = 6;
528pub const AF_ISO = 7;
529pub const AF_OSI = AF_ISO;
530pub const AF_ECMA = 8;
531pub const AF_DATAKIT = 9;
532pub const AF_CCITT = 10;
533pub const AF_SNA = 11;
534pub const AF_DECnet = 12;
535pub const AF_DLI = 13;
536pub const AF_LAT = 14;
537pub const AF_HYLINK = 15;
538pub const AF_APPLETALK = 16;
539pub const AF_ROUTE = 17;
540pub const AF_LINK = 18;
541pub const pseudo_AF_XTP = 19;
542pub const AF_COIP = 20;
543pub const AF_CNT = 21;
544pub const pseudo_AF_RTIP = 22;
545pub const AF_IPX = 23;
546pub const AF_SIP = 24;
547pub const pseudo_AF_PIP = 25;
548pub const AF_ISDN = 26;
549pub const AF_E164 = AF_ISDN;
550pub const pseudo_AF_KEY = 27;
551pub const AF_INET6 = 28;
552pub const AF_NATM = 29;
553pub const AF_ATM = 30;
554pub const pseudo_AF_HDRCMPLT = 31;
555pub const AF_NETGRAPH = 32;
556pub const AF_SLOW = 33;
557pub const AF_SCLUSTER = 34;
558pub const AF_ARP = 35;
559pub const AF_BLUETOOTH = 36;
560pub const AF_IEEE80211 = 37;
561pub const AF_INET_SDP = 40;
562pub const AF_INET6_SDP = 42;
563pub const AF_MAX = 42;
564
565pub const DT_UNKNOWN = 0;
566pub const DT_FIFO = 1;
567pub const DT_CHR = 2;
568pub const DT_DIR = 4;
569pub const DT_BLK = 6;
570pub const DT_REG = 8;
571pub const DT_LNK = 10;
572pub const DT_SOCK = 12;
573pub const DT_WHT = 14;
574
575/// add event to kq (implies enable)
576pub const EV_ADD = 0x0001;
577
578/// delete event from kq
579pub const EV_DELETE = 0x0002;
580
581/// enable event
582pub const EV_ENABLE = 0x0004;
583
584/// disable event (not reported)
585pub const EV_DISABLE = 0x0008;
586
587/// only report one occurrence
588pub const EV_ONESHOT = 0x0010;
589
590/// clear event state after reporting
591pub const EV_CLEAR = 0x0020;
592
593/// force immediate event output
594/// ... with or without EV_ERROR
595/// ... use KEVENT_FLAG_ERROR_EVENTS
596/// on syscalls supporting flags
597pub const EV_RECEIPT = 0x0040;
598
599/// disable event after reporting
600pub const EV_DISPATCH = 0x0080;
601
602pub const EVFILT_READ = -1;
603pub const EVFILT_WRITE = -2;
604
605/// attached to aio requests
606pub const EVFILT_AIO = -3;
607
608/// attached to vnodes
609pub const EVFILT_VNODE = -4;
610
611/// attached to struct proc
612pub const EVFILT_PROC = -5;
613
614/// attached to struct proc
615pub const EVFILT_SIGNAL = -6;
616
617/// timers
618pub const EVFILT_TIMER = -7;
619
620/// Process descriptors
621pub const EVFILT_PROCDESC = -8;
622
623/// Filesystem events
624pub const EVFILT_FS = -9;
625
626pub const EVFILT_LIO = -10;
627
628/// User events
629pub const EVFILT_USER = -11;
630
631/// Sendfile events
632pub const EVFILT_SENDFILE = -12;
633
634pub const EVFILT_EMPTY = -13;
635
636pub const TCGETA = 0x8000;
637pub const TCSETA = 0x8001;
638pub const TCSETAW = 0x8004;
639pub const TCSETAF = 0x8003;
640pub const TCSBRK = 08005;
641pub const TCXONC = 0x8007;
642pub const TCFLSH = 0x8006;
643
644pub const TIOCSCTTY = 0x8017;
645pub const TIOCGPGRP = 0x8015;
646pub const TIOCSPGRP = 0x8016;
647pub const TIOCGWINSZ = 0x8012;
648pub const TIOCSWINSZ = 0x8013;
649pub const TIOCMGET = 0x8018;
650pub const TIOCMBIS = 0x8022;
651pub const TIOCMBIC = 0x8023;
652pub const TIOCMSET = 0x8019;
653pub const FIONREAD = 0xbe000001;
654pub const FIONBIO = 0xbe000000;
655pub const TIOCSBRK = 0x8020;
656pub const TIOCCBRK = 0x8021;
657pub const TIOCGSID = 0x8024;
658
659pub fn WEXITSTATUS(s: u32) u8 {
660 return @intCast(u8, s & 0xff);
661}
662
663pub fn WTERMSIG(s: u32) u32 {
664 return (s >> 8) & 0xff;
665}
666
667pub fn WSTOPSIG(s: u32) u32 {
668 return WEXITSTATUS(s);
669}
670
671pub fn WIFEXITED(s: u32) bool {
672 return WTERMSIG(s) == 0;
673}
674
675pub fn WIFSTOPPED(s: u32) bool {
676 return ((s >> 16) & 0xff) != 0;
677}
678
679pub fn WIFSIGNALED(s: u32) bool {
680 return ((s >> 8) & 0xff) != 0;
681}
682
683pub const winsize = extern struct {
684 ws_row: u16,
685 ws_col: u16,
686 ws_xpixel: u16,
687 ws_ypixel: u16,
688};
689
690const NSIG = 32;
691
692pub const SIG_ERR = @intToPtr(fn (i32) callconv(.C) void, maxInt(usize));
693pub const SIG_DFL = @intToPtr(fn (i32) callconv(.C) void, 0);
694pub const SIG_IGN = @intToPtr(fn (i32) callconv(.C) void, 1);
695
696/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
697pub const Sigaction = extern struct {
698 /// signal handler
699 __sigaction_u: extern union {
700 __sa_handler: fn (i32) callconv(.C) void,
701 __sa_sigaction: fn (i32, *__siginfo, usize) callconv(.C) void,
702 },
703
704 /// see signal options
705 sa_flags: u32,
706
707 /// signal mask to apply
708 sa_mask: sigset_t,
709};
710
711pub const _SIG_WORDS = 4;
712pub const _SIG_MAXSIG = 128;
713pub inline fn _SIG_IDX(sig: usize) usize {
714 return sig - 1;
715}
716pub inline fn _SIG_WORD(sig: usize) usize {
717 return_SIG_IDX(sig) >> 5;
718}
719pub inline fn _SIG_BIT(sig: usize) usize {
720 return 1 << (_SIG_IDX(sig) & 31);
721}
722pub inline fn _SIG_VALID(sig: usize) usize {
723 return sig <= _SIG_MAXSIG and sig > 0;
724}
725
726pub const sigset_t = extern struct {
727 __bits: [_SIG_WORDS]u32,
728};
729
730pub const E = enum(i32) {
731 /// No error occurred.
732 SUCCESS = 0,
733 PERM = -0x7ffffff1, // Operation not permitted
734 NOENT = -0x7fff9ffd, // No such file or directory
735 SRCH = -0x7fff8ff3, // No such process
736 INTR = -0x7ffffff6, // Interrupted system call
737 IO = -0x7fffffff, // Input/output error
738 NXIO = -0x7fff8ff5, // Device not configured
739 @"2BIG" = -0x7fff8fff, // Argument list too long
740 NOEXEC = -0x7fffecfe, // Exec format error
741 CHILD = -0x7fff8ffe, // No child processes
742 DEADLK = -0x7fff8ffd, // Resource deadlock avoided
743 NOMEM = -0x80000000, // Cannot allocate memory
744 ACCES = -0x7ffffffe, // Permission denied
745 FAULT = -0x7fffecff, // Bad address
746 BUSY = -0x7ffffff2, // Device busy
747 EXIST = -0x7fff9ffe, // File exists
748 XDEV = -0x7fff9ff5, // Cross-device link
749 NODEV = -0x7fff8ff9, // Operation not supported by device
750 NOTDIR = -0x7fff9ffb, // Not a directory
751 ISDIR = -0x7fff9ff7, // Is a directory
752 INVAL = -0x7ffffffb, // Invalid argument
753 NFILE = -0x7fff8ffa, // Too many open files in system
754 MFILE = -0x7fff9ff6, // Too many open files
755 NOTTY = -0x7fff8ff6, // Inappropriate ioctl for device
756 TXTBSY = -0x7fff8fc5, // Text file busy
757 FBIG = -0x7fff8ffc, // File too large
758 NOSPC = -0x7fff9ff9, // No space left on device
759 SPIPE = -0x7fff8ff4, // Illegal seek
760 ROFS = -0x7fff9ff8, // Read-only filesystem
761 MLINK = -0x7fff8ffb, // Too many links
762 PIPE = -0x7fff9ff3, // Broken pipe
763 BADF = -0x7fffa000, // Bad file descriptor
764
765 // math software
766 DOM = 33, // Numerical argument out of domain
767 RANGE = 34, // Result too large
768
769 // non-blocking and interrupt i/o
770
771 /// Also used for `WOULDBLOCK`.
772 AGAIN = -0x7ffffff5,
773 INPROGRESS = -0x7fff8fdc,
774 ALREADY = -0x7fff8fdb,
775
776 // ipc/network software -- argument errors
777 NOTSOCK = 38, // Socket operation on non-socket
778 DESTADDRREQ = 39, // Destination address required
779 MSGSIZE = 40, // Message too long
780 PROTOTYPE = 41, // Protocol wrong type for socket
781 NOPROTOOPT = 42, // Protocol not available
782 PROTONOSUPPORT = 43, // Protocol not supported
783 SOCKTNOSUPPORT = 44, // Socket type not supported
784 /// Also used for `NOTSUP`.
785 OPNOTSUPP = 45, // Operation not supported
786 PFNOSUPPORT = 46, // Protocol family not supported
787 AFNOSUPPORT = 47, // Address family not supported by protocol family
788 ADDRINUSE = 48, // Address already in use
789 ADDRNOTAVAIL = 49, // Can't assign requested address
790
791 // ipc/network software -- operational errors
792 NETDOWN = 50, // Network is down
793 NETUNREACH = 51, // Network is unreachable
794 NETRESET = 52, // Network dropped connection on reset
795 CONNABORTED = 53, // Software caused connection abort
796 CONNRESET = 54, // Connection reset by peer
797 NOBUFS = 55, // No buffer space available
798 ISCONN = 56, // Socket is already connected
799 NOTCONN = 57, // Socket is not connected
800 SHUTDOWN = 58, // Can't send after socket shutdown
801 TOOMANYREFS = 59, // Too many references: can't splice
802 TIMEDOUT = 60, // Operation timed out
803 CONNREFUSED = 61, // Connection refused
804
805 LOOP = 62, // Too many levels of symbolic links
806 NAMETOOLONG = 63, // File name too long
807
808 // should be rearranged
809 HOSTDOWN = 64, // Host is down
810 HOSTUNREACH = 65, // No route to host
811 NOTEMPTY = 66, // Directory not empty
812
813 // quotas & mush
814 PROCLIM = 67, // Too many processes
815 USERS = 68, // Too many users
816 DQUOT = 69, // Disc quota exceeded
817
818 // Network File System
819 STALE = 70, // Stale NFS file handle
820 REMOTE = 71, // Too many levels of remote in path
821 BADRPC = 72, // RPC struct is bad
822 RPCMISMATCH = 73, // RPC version wrong
823 PROGUNAVAIL = 74, // RPC prog. not avail
824 PROGMISMATCH = 75, // Program version wrong
825 PROCUNAVAIL = 76, // Bad procedure for program
826
827 NOLCK = 77, // No locks available
828 NOSYS = 78, // Function not implemented
829
830 FTYPE = 79, // Inappropriate file type or format
831 AUTH = 80, // Authentication error
832 NEEDAUTH = 81, // Need authenticator
833 IDRM = 82, // Identifier removed
834 NOMSG = 83, // No message of desired type
835 OVERFLOW = 84, // Value too large to be stored in data type
836 CANCELED = 85, // Operation canceled
837 ILSEQ = 86, // Illegal byte sequence
838 NOATTR = 87, // Attribute not found
839
840 DOOFUS = 88, // Programming error
841
842 BADMSG = 89, // Bad message
843 MULTIHOP = 90, // Multihop attempted
844 NOLINK = 91, // Link has been severed
845 PROTO = 92, // Protocol error
846
847 NOTCAPABLE = 93, // Capabilities insufficient
848 CAPMODE = 94, // Not permitted in capability mode
849 NOTRECOVERABLE = 95, // State not recoverable
850 OWNERDEAD = 96, // Previous owner died
851
852 _,
853};
854
855pub const MINSIGSTKSZ = switch (builtin.cpu.arch) {
856 .i386, .x86_64 => 2048,
857 .arm, .aarch64 => 4096,
858 else => @compileError("MINSIGSTKSZ not defined for this architecture"),
859};
860pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
861
862pub const SS_ONSTACK = 1;
863pub const SS_DISABLE = 4;
864
865pub const stack_t = extern struct {
866 ss_sp: [*]u8,
867 ss_size: isize,
868 ss_flags: i32,
869};
870
871pub const S_IFMT = 0o170000;
872
873pub const S_IFIFO = 0o010000;
874pub const S_IFCHR = 0o020000;
875pub const S_IFDIR = 0o040000;
876pub const S_IFBLK = 0o060000;
877pub const S_IFREG = 0o100000;
878pub const S_IFLNK = 0o120000;
879pub const S_IFSOCK = 0o140000;
880pub const S_IFWHT = 0o160000;
881
882pub const S_ISUID = 0o4000;
883pub const S_ISGID = 0o2000;
884pub const S_ISVTX = 0o1000;
885pub const S_IRWXU = 0o700;
886pub const S_IRUSR = 0o400;
887pub const S_IWUSR = 0o200;
888pub const S_IXUSR = 0o100;
889pub const S_IRWXG = 0o070;
890pub const S_IRGRP = 0o040;
891pub const S_IWGRP = 0o020;
892pub const S_IXGRP = 0o010;
893pub const S_IRWXO = 0o007;
894pub const S_IROTH = 0o004;
895pub const S_IWOTH = 0o002;
896pub const S_IXOTH = 0o001;
897
898pub fn S_ISFIFO(m: u32) bool {
899 return m & S_IFMT == S_IFIFO;
900}
901
902pub fn S_ISCHR(m: u32) bool {
903 return m & S_IFMT == S_IFCHR;
904}
905
906pub fn S_ISDIR(m: u32) bool {
907 return m & S_IFMT == S_IFDIR;
908}
909
910pub fn S_ISBLK(m: u32) bool {
911 return m & S_IFMT == S_IFBLK;
912}
913
914pub fn S_ISREG(m: u32) bool {
915 return m & S_IFMT == S_IFREG;
916}
917
918pub fn S_ISLNK(m: u32) bool {
919 return m & S_IFMT == S_IFLNK;
920}
921
922pub fn S_ISSOCK(m: u32) bool {
923 return m & S_IFMT == S_IFSOCK;
924}
925
926pub fn S_IWHT(m: u32) bool {
927 return m & S_IFMT == S_IFWHT;
928}
929
930pub const HOST_NAME_MAX = 255;
931
932/// Magic value that specify the use of the current working directory
933/// to determine the target of relative file paths in the openat() and
934/// similar syscalls.
935pub const AT_FDCWD = -100;
936
937/// Check access using effective user and group ID
938pub const AT_EACCESS = 0x0100;
939
940/// Do not follow symbolic links
941pub const AT_SYMLINK_NOFOLLOW = 0x0200;
942
943/// Follow symbolic link
944pub const AT_SYMLINK_FOLLOW = 0x0400;
945
946/// Remove directory instead of file
947pub const AT_REMOVEDIR = 0x0800;
948
949pub const addrinfo = extern struct {
950 flags: i32,
951 family: i32,
952 socktype: i32,
953 protocol: i32,
954 addrlen: socklen_t,
955 canonname: ?[*:0]u8,
956 addr: ?*sockaddr,
957 next: ?*addrinfo,
958};
959
960/// Fail if not under dirfd
961pub const AT_BENEATH = 0x1000;
962
963/// dummy for IP
964pub const IPPROTO_IP = 0;
965
966/// control message protocol
967pub const IPPROTO_ICMP = 1;
968
969/// tcp
970pub const IPPROTO_TCP = 6;
971
972/// user datagram protocol
973pub const IPPROTO_UDP = 17;
974
975/// IP6 header
976pub const IPPROTO_IPV6 = 41;
977
978/// raw IP packet
979pub const IPPROTO_RAW = 255;
980
981/// IP6 hop-by-hop options
982pub const IPPROTO_HOPOPTS = 0;
983
984/// group mgmt protocol
985pub const IPPROTO_IGMP = 2;
986
987/// gateway^2 (deprecated)
988pub const IPPROTO_GGP = 3;
989
990/// IPv4 encapsulation
991pub const IPPROTO_IPV4 = 4;
992
993/// for compatibility
994pub const IPPROTO_IPIP = IPPROTO_IPV4;
995
996/// Stream protocol II
997pub const IPPROTO_ST = 7;
998
999/// exterior gateway protocol
1000pub const IPPROTO_EGP = 8;
1001
1002/// private interior gateway
1003pub const IPPROTO_PIGP = 9;
1004
1005/// BBN RCC Monitoring
1006pub const IPPROTO_RCCMON = 10;
1007
1008/// network voice protocol
1009pub const IPPROTO_NVPII = 11;
1010
1011/// pup
1012pub const IPPROTO_PUP = 12;
1013
1014/// Argus
1015pub const IPPROTO_ARGUS = 13;
1016
1017/// EMCON
1018pub const IPPROTO_EMCON = 14;
1019
1020/// Cross Net Debugger
1021pub const IPPROTO_XNET = 15;
1022
1023/// Chaos
1024pub const IPPROTO_CHAOS = 16;
1025
1026/// Multiplexing
1027pub const IPPROTO_MUX = 18;
1028
1029/// DCN Measurement Subsystems
1030pub const IPPROTO_MEAS = 19;
1031
1032/// Host Monitoring
1033pub const IPPROTO_HMP = 20;
1034
1035/// Packet Radio Measurement
1036pub const IPPROTO_PRM = 21;
1037
1038/// xns idp
1039pub const IPPROTO_IDP = 22;
1040
1041/// Trunk-1
1042pub const IPPROTO_TRUNK1 = 23;
1043
1044/// Trunk-2
1045pub const IPPROTO_TRUNK2 = 24;
1046
1047/// Leaf-1
1048pub const IPPROTO_LEAF1 = 25;
1049
1050/// Leaf-2
1051pub const IPPROTO_LEAF2 = 26;
1052
1053/// Reliable Data
1054pub const IPPROTO_RDP = 27;
1055
1056/// Reliable Transaction
1057pub const IPPROTO_IRTP = 28;
1058
1059/// tp-4 w/ class negotiation
1060pub const IPPROTO_TP = 29;
1061
1062/// Bulk Data Transfer
1063pub const IPPROTO_BLT = 30;
1064
1065/// Network Services
1066pub const IPPROTO_NSP = 31;
1067
1068/// Merit Internodal
1069pub const IPPROTO_INP = 32;
1070
1071/// Datagram Congestion Control Protocol
1072pub const IPPROTO_DCCP = 33;
1073
1074/// Third Party Connect
1075pub const IPPROTO_3PC = 34;
1076
1077/// InterDomain Policy Routing
1078pub const IPPROTO_IDPR = 35;
1079
1080/// XTP
1081pub const IPPROTO_XTP = 36;
1082
1083/// Datagram Delivery
1084pub const IPPROTO_DDP = 37;
1085
1086/// Control Message Transport
1087pub const IPPROTO_CMTP = 38;
1088
1089/// TP++ Transport
1090pub const IPPROTO_TPXX = 39;
1091
1092/// IL transport protocol
1093pub const IPPROTO_IL = 40;
1094
1095/// Source Demand Routing
1096pub const IPPROTO_SDRP = 42;
1097
1098/// IP6 routing header
1099pub const IPPROTO_ROUTING = 43;
1100
1101/// IP6 fragmentation header
1102pub const IPPROTO_FRAGMENT = 44;
1103
1104/// InterDomain Routing
1105pub const IPPROTO_IDRP = 45;
1106
1107/// resource reservation
1108pub const IPPROTO_RSVP = 46;
1109
1110/// General Routing Encap.
1111pub const IPPROTO_GRE = 47;
1112
1113/// Mobile Host Routing
1114pub const IPPROTO_MHRP = 48;
1115
1116/// BHA
1117pub const IPPROTO_BHA = 49;
1118
1119/// IP6 Encap Sec. Payload
1120pub const IPPROTO_ESP = 50;
1121
1122/// IP6 Auth Header
1123pub const IPPROTO_AH = 51;
1124
1125/// Integ. Net Layer Security
1126pub const IPPROTO_INLSP = 52;
1127
1128/// IP with encryption
1129pub const IPPROTO_SWIPE = 53;
1130
1131/// Next Hop Resolution
1132pub const IPPROTO_NHRP = 54;
1133
1134/// IP Mobility
1135pub const IPPROTO_MOBILE = 55;
1136
1137/// Transport Layer Security
1138pub const IPPROTO_TLSP = 56;
1139
1140/// SKIP
1141pub const IPPROTO_SKIP = 57;
1142
1143/// ICMP6
1144pub const IPPROTO_ICMPV6 = 58;
1145
1146/// IP6 no next header
1147pub const IPPROTO_NONE = 59;
1148
1149/// IP6 destination option
1150pub const IPPROTO_DSTOPTS = 60;
1151
1152/// any host internal protocol
1153pub const IPPROTO_AHIP = 61;
1154
1155/// CFTP
1156pub const IPPROTO_CFTP = 62;
1157
1158/// "hello" routing protocol
1159pub const IPPROTO_HELLO = 63;
1160
1161/// SATNET/Backroom EXPAK
1162pub const IPPROTO_SATEXPAK = 64;
1163
1164/// Kryptolan
1165pub const IPPROTO_KRYPTOLAN = 65;
1166
1167/// Remote Virtual Disk
1168pub const IPPROTO_RVD = 66;
1169
1170/// Pluribus Packet Core
1171pub const IPPROTO_IPPC = 67;
1172
1173/// Any distributed FS
1174pub const IPPROTO_ADFS = 68;
1175
1176/// Satnet Monitoring
1177pub const IPPROTO_SATMON = 69;
1178
1179/// VISA Protocol
1180pub const IPPROTO_VISA = 70;
1181
1182/// Packet Core Utility
1183pub const IPPROTO_IPCV = 71;
1184
1185/// Comp. Prot. Net. Executive
1186pub const IPPROTO_CPNX = 72;
1187
1188/// Comp. Prot. HeartBeat
1189pub const IPPROTO_CPHB = 73;
1190
1191/// Wang Span Network
1192pub const IPPROTO_WSN = 74;
1193
1194/// Packet Video Protocol
1195pub const IPPROTO_PVP = 75;
1196
1197/// BackRoom SATNET Monitoring
1198pub const IPPROTO_BRSATMON = 76;
1199
1200/// Sun net disk proto (temp.)
1201pub const IPPROTO_ND = 77;
1202
1203/// WIDEBAND Monitoring
1204pub const IPPROTO_WBMON = 78;
1205
1206/// WIDEBAND EXPAK
1207pub const IPPROTO_WBEXPAK = 79;
1208
1209/// ISO cnlp
1210pub const IPPROTO_EON = 80;
1211
1212/// VMTP
1213pub const IPPROTO_VMTP = 81;
1214
1215/// Secure VMTP
1216pub const IPPROTO_SVMTP = 82;
1217
1218/// Banyon VINES
1219pub const IPPROTO_VINES = 83;
1220
1221/// TTP
1222pub const IPPROTO_TTP = 84;
1223
1224/// NSFNET-IGP
1225pub const IPPROTO_IGP = 85;
1226
1227/// dissimilar gateway prot.
1228pub const IPPROTO_DGP = 86;
1229
1230/// TCF
1231pub const IPPROTO_TCF = 87;
1232
1233/// Cisco/GXS IGRP
1234pub const IPPROTO_IGRP = 88;
1235
1236/// OSPFIGP
1237pub const IPPROTO_OSPFIGP = 89;
1238
1239/// Strite RPC protocol
1240pub const IPPROTO_SRPC = 90;
1241
1242/// Locus Address Resoloution
1243pub const IPPROTO_LARP = 91;
1244
1245/// Multicast Transport
1246pub const IPPROTO_MTP = 92;
1247
1248/// AX.25 Frames
1249pub const IPPROTO_AX25 = 93;
1250
1251/// IP encapsulated in IP
1252pub const IPPROTO_IPEIP = 94;
1253
1254/// Mobile Int.ing control
1255pub const IPPROTO_MICP = 95;
1256
1257/// Semaphore Comm. security
1258pub const IPPROTO_SCCSP = 96;
1259
1260/// Ethernet IP encapsulation
1261pub const IPPROTO_ETHERIP = 97;
1262
1263/// encapsulation header
1264pub const IPPROTO_ENCAP = 98;
1265
1266/// any private encr. scheme
1267pub const IPPROTO_APES = 99;
1268
1269/// GMTP
1270pub const IPPROTO_GMTP = 100;
1271
1272/// payload compression (IPComp)
1273pub const IPPROTO_IPCOMP = 108;
1274
1275/// SCTP
1276pub const IPPROTO_SCTP = 132;
1277
1278/// IPv6 Mobility Header
1279pub const IPPROTO_MH = 135;
1280
1281/// UDP-Lite
1282pub const IPPROTO_UDPLITE = 136;
1283
1284/// IP6 Host Identity Protocol
1285pub const IPPROTO_HIP = 139;
1286
1287/// IP6 Shim6 Protocol
1288pub const IPPROTO_SHIM6 = 140;
1289
1290/// Protocol Independent Mcast
1291pub const IPPROTO_PIM = 103;
1292
1293/// CARP
1294pub const IPPROTO_CARP = 112;
1295
1296/// PGM
1297pub const IPPROTO_PGM = 113;
1298
1299/// MPLS-in-IP
1300pub const IPPROTO_MPLS = 137;
1301
1302/// PFSYNC
1303pub const IPPROTO_PFSYNC = 240;
1304
1305/// Reserved
1306pub const IPPROTO_RESERVED_253 = 253;
1307
1308/// Reserved
1309pub const IPPROTO_RESERVED_254 = 254;
1310
1311pub const rlimit_resource = enum(c_int) {
1312 CPU = 0,
1313 FSIZE = 1,
1314 DATA = 2,
1315 STACK = 3,
1316 CORE = 4,
1317 RSS = 5,
1318 MEMLOCK = 6,
1319 NPROC = 7,
1320 NOFILE = 8,
1321 SBSIZE = 9,
1322 VMEM = 10,
1323 NPTS = 11,
1324 SWAP = 12,
1325 KQUEUES = 13,
1326 UMTXP = 14,
1327 _,
1328
1329 pub const AS: rlimit_resource = .VMEM;
1330};
1331
1332pub const rlim_t = i64;
1333
1334/// No limit
1335pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
1336
1337pub const RLIM_SAVED_MAX = RLIM_INFINITY;
1338pub const RLIM_SAVED_CUR = RLIM_INFINITY;
1339
1340pub const rlimit = extern struct {
1341 /// Soft limit
1342 cur: rlim_t,
1343 /// Hard limit
1344 max: rlim_t,
1345};
1346
1347pub const SHUT_RD = 0;
1348pub const SHUT_WR = 1;
1349pub const SHUT_RDWR = 2;
1350
1351// TODO fill out if needed
1352pub const directory_which = enum(c_int) {
1353 B_USER_SETTINGS_DIRECTORY = 0xbbe,
1354
1355 _,
1356};
1357
1358pub const cc_t = u8;
1359pub const speed_t = u8;
1360pub const tcflag_t = u32;
1361
1362pub const NCCS = 32;
1363
1364pub const termios = extern struct {
1365 c_iflag: tcflag_t,
1366 c_oflag: tcflag_t,
1367 c_cflag: tcflag_t,
1368 c_lflag: tcflag_t,
1369 c_line: cc_t,
1370 c_ispeed: speed_t,
1371 c_ospeed: speed_t,
1372 cc_t: [NCCS]cc_t,
1373};
lib/std/os/bits/linux/arm-eabi.zig+1-4
...@@ -551,7 +551,7 @@ pub const dev_t = u64;...@@ -551,7 +551,7 @@ pub const dev_t = u64;
551pub const blkcnt_t = i64;551pub const blkcnt_t = i64;
552552
553// The `stat` definition used by the Linux kernel.553// The `stat` definition used by the Linux kernel.
554pub const kernel_stat = extern struct {554pub const Stat = extern struct {
555 dev: dev_t,555 dev: dev_t,
556 __dev_padding: u32,556 __dev_padding: u32,
557 __ino_truncated: u32,557 __ino_truncated: u32,
...@@ -582,9 +582,6 @@ pub const kernel_stat = extern struct {...@@ -582,9 +582,6 @@ pub const kernel_stat = extern struct {
582 }582 }
583};583};
584584
585// The `stat64` definition used by the libc.
586pub const libc_stat = kernel_stat;
587
588pub const timespec = extern struct {585pub const timespec = extern struct {
589 tv_sec: i32,586 tv_sec: i32,
590 tv_nsec: i32,587 tv_nsec: i32,
lib/std/os/bits/linux/arm64.zig+1-4
...@@ -424,7 +424,7 @@ pub const dev_t = usize;...@@ -424,7 +424,7 @@ pub const dev_t = usize;
424pub const blkcnt_t = isize;424pub const blkcnt_t = isize;
425425
426// The `stat` definition used by the Linux kernel.426// The `stat` definition used by the Linux kernel.
427pub const kernel_stat = extern struct {427pub const Stat = extern struct {
428 dev: dev_t,428 dev: dev_t,
429 ino: ino_t,429 ino: ino_t,
430 mode: mode_t,430 mode: mode_t,
...@@ -455,9 +455,6 @@ pub const kernel_stat = extern struct {...@@ -455,9 +455,6 @@ pub const kernel_stat = extern struct {
455 }455 }
456};456};
457457
458// The `stat64` definition used by the libc.
459pub const libc_stat = kernel_stat;
460
461pub const timespec = extern struct {458pub const timespec = extern struct {
462 tv_sec: time_t,459 tv_sec: time_t,
463 tv_nsec: isize,460 tv_nsec: isize,
lib/std/os/bits/linux/i386.zig+1-4
...@@ -599,7 +599,7 @@ pub const dev_t = u64;...@@ -599,7 +599,7 @@ pub const dev_t = u64;
599pub const blkcnt_t = i64;599pub const blkcnt_t = i64;
600600
601// The `stat` definition used by the Linux kernel.601// The `stat` definition used by the Linux kernel.
602pub const kernel_stat = extern struct {602pub const Stat = extern struct {
603 dev: dev_t,603 dev: dev_t,
604 __dev_padding: u32,604 __dev_padding: u32,
605 __ino_truncated: u32,605 __ino_truncated: u32,
...@@ -630,9 +630,6 @@ pub const kernel_stat = extern struct {...@@ -630,9 +630,6 @@ pub const kernel_stat = extern struct {
630 }630 }
631};631};
632632
633// The `stat64` definition used by the libc.
634pub const libc_stat = kernel_stat;
635
636pub const timespec = extern struct {633pub const timespec = extern struct {
637 tv_sec: i32,634 tv_sec: i32,
638 tv_nsec: i32,635 tv_nsec: i32,
lib/std/os/bits/linux/mips.zig+1-33
...@@ -540,7 +540,7 @@ pub const dev_t = u64;...@@ -540,7 +540,7 @@ pub const dev_t = u64;
540pub const blkcnt_t = i64;540pub const blkcnt_t = i64;
541541
542// The `stat` definition used by the Linux kernel.542// The `stat` definition used by the Linux kernel.
543pub const kernel_stat = extern struct {543pub const Stat = extern struct {
544 dev: u32,544 dev: u32,
545 __pad0: [3]u32, // Reserved for st_dev expansion545 __pad0: [3]u32, // Reserved for st_dev expansion
546 ino: ino_t,546 ino: ino_t,
...@@ -572,38 +572,6 @@ pub const kernel_stat = extern struct {...@@ -572,38 +572,6 @@ pub const kernel_stat = extern struct {
572 }572 }
573};573};
574574
575pub const libc_stat = extern struct {
576 dev: dev_t,
577 __pad0: [2]u32,
578 ino: ino_t,
579 mode: mode_t,
580 nlink: nlink_t,
581 uid: uid_t,
582 gid: gid_t,
583 rdev: dev_t,
584 __pad1: [2]u32,
585 size: off_t,
586 atim: timespec,
587 mtim: timespec,
588 ctim: timespec,
589 blksize: blksize_t,
590 __pad3: u32,
591 blocks: blkcnt_t,
592 __pad4: [14]u32,
593
594 pub fn atime(self: @This()) timespec {
595 return self.atim;
596 }
597
598 pub fn mtime(self: @This()) timespec {
599 return self.mtim;
600 }
601
602 pub fn ctime(self: @This()) timespec {
603 return self.ctim;
604 }
605};
606
607pub const timespec = extern struct {575pub const timespec = extern struct {
608 tv_sec: isize,576 tv_sec: isize,
609 tv_nsec: isize,577 tv_nsec: isize,
lib/std/os/bits/linux/powerpc.zig+1-4
...@@ -539,7 +539,7 @@ pub const dev_t = u64;...@@ -539,7 +539,7 @@ pub const dev_t = u64;
539pub const blkcnt_t = i64;539pub const blkcnt_t = i64;
540540
541// The `stat` definition used by the Linux kernel.541// The `stat` definition used by the Linux kernel.
542pub const kernel_stat = extern struct {542pub const Stat = extern struct {
543 dev: dev_t,543 dev: dev_t,
544 ino: ino_t,544 ino: ino_t,
545 mode: mode_t,545 mode: mode_t,
...@@ -569,9 +569,6 @@ pub const kernel_stat = extern struct {...@@ -569,9 +569,6 @@ pub const kernel_stat = extern struct {
569 }569 }
570};570};
571571
572// The `stat64` definition used by the libc.
573pub const libc_stat = kernel_stat;
574
575pub const timespec = extern struct {572pub const timespec = extern struct {
576 tv_sec: time_t,573 tv_sec: time_t,
577 tv_nsec: isize,574 tv_nsec: isize,
lib/std/os/bits/linux/powerpc64.zig+1-4
...@@ -515,7 +515,7 @@ pub const dev_t = u64;...@@ -515,7 +515,7 @@ pub const dev_t = u64;
515pub const blkcnt_t = i64;515pub const blkcnt_t = i64;
516516
517// The `stat` definition used by the Linux kernel.517// The `stat` definition used by the Linux kernel.
518pub const kernel_stat = extern struct {518pub const Stat = extern struct {
519 dev: dev_t,519 dev: dev_t,
520 ino: ino_t,520 ino: ino_t,
521 nlink: nlink_t,521 nlink: nlink_t,
...@@ -544,9 +544,6 @@ pub const kernel_stat = extern struct {...@@ -544,9 +544,6 @@ pub const kernel_stat = extern struct {
544 }544 }
545};545};
546546
547// The `stat64` definition used by the libc.
548pub const libc_stat = kernel_stat;
549
550pub const timespec = extern struct {547pub const timespec = extern struct {
551 tv_sec: time_t,548 tv_sec: time_t,
552 tv_nsec: isize,549 tv_nsec: isize,
lib/std/os/bits/linux/riscv64.zig+1-4
...@@ -386,7 +386,7 @@ pub const Flock = extern struct {...@@ -386,7 +386,7 @@ pub const Flock = extern struct {
386};386};
387387
388// The `stat` definition used by the Linux kernel.388// The `stat` definition used by the Linux kernel.
389pub const kernel_stat = extern struct {389pub const Stat = extern struct {
390 dev: dev_t,390 dev: dev_t,
391 ino: ino_t,391 ino: ino_t,
392 mode: mode_t,392 mode: mode_t,
...@@ -417,7 +417,4 @@ pub const kernel_stat = extern struct {...@@ -417,7 +417,4 @@ pub const kernel_stat = extern struct {
417 }417 }
418};418};
419419
420// The `stat64` definition used by the libc.
421pub const libc_stat = kernel_stat;
422
423pub const Elf_Symndx = u32;420pub const Elf_Symndx = u32;
lib/std/os/bits/linux/sparc64.zig+1-35
...@@ -489,42 +489,8 @@ pub const off_t = i64;...@@ -489,42 +489,8 @@ pub const off_t = i64;
489pub const ino_t = u64;489pub const ino_t = u64;
490pub const mode_t = u32;490pub const mode_t = u32;
491491
492// The `stat64` definition used by the libc.
493pub const libc_stat = extern struct {
494 dev: u64,
495 ino: ino_t,
496 mode: u32,
497 nlink: usize,
498
499 uid: u32,
500 gid: u32,
501 rdev: u64,
502 __pad0: u32,
503
504 size: off_t,
505 blksize: isize,
506 blocks: i64,
507
508 atim: timespec,
509 mtim: timespec,
510 ctim: timespec,
511 __unused: [2]isize,
512
513 pub fn atime(self: libc_stat) timespec {
514 return self.atim;
515 }
516
517 pub fn mtime(self: libc_stat) timespec {
518 return self.mtim;
519 }
520
521 pub fn ctime(self: libc_stat) timespec {
522 return self.ctim;
523 }
524};
525
526// The `stat64` definition used by the kernel.492// The `stat64` definition used by the kernel.
527pub const kernel_stat = extern struct {493pub const Stat = extern struct {
528 dev: u64,494 dev: u64,
529 ino: u64,495 ino: u64,
530 nlink: u64,496 nlink: u64,
lib/std/os/bits/netbsd.zig deleted-1326
...@@ -1,1326 +0,0 @@
1const std = @import("../../std.zig");
2const builtin = std.builtin;
3const maxInt = std.math.maxInt;
4
5pub const blkcnt_t = i64;
6pub const blksize_t = i32;
7pub const clock_t = u32;
8pub const dev_t = u64;
9pub const fd_t = i32;
10pub const gid_t = u32;
11pub const ino_t = u64;
12pub const mode_t = u32;
13pub const nlink_t = u32;
14pub const off_t = i64;
15pub const pid_t = i32;
16pub const socklen_t = u32;
17pub const time_t = i64;
18pub const uid_t = u32;
19pub const lwpid_t = i32;
20pub const suseconds_t = c_int;
21
22/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
23pub const Kevent = extern struct {
24 ident: usize,
25 filter: i32,
26 flags: u32,
27 fflags: u32,
28 data: i64,
29 udata: usize,
30};
31
32pub const RTLD_LAZY = 1;
33pub const RTLD_NOW = 2;
34pub const RTLD_GLOBAL = 0x100;
35pub const RTLD_LOCAL = 0x200;
36pub const RTLD_NODELETE = 0x01000;
37pub const RTLD_NOLOAD = 0x02000;
38
39pub const RTLD_NEXT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -1)));
40pub const RTLD_DEFAULT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -2)));
41pub const RTLD_SELF = @intToPtr(*c_void, @bitCast(usize, @as(isize, -3)));
42
43pub const dl_phdr_info = extern struct {
44 dlpi_addr: usize,
45 dlpi_name: ?[*:0]const u8,
46 dlpi_phdr: [*]std.elf.Phdr,
47 dlpi_phnum: u16,
48};
49
50pub const Flock = extern struct {
51 l_start: off_t,
52 l_len: off_t,
53 l_pid: pid_t,
54 l_type: i16,
55 l_whence: i16,
56};
57
58pub const addrinfo = extern struct {
59 flags: i32,
60 family: i32,
61 socktype: i32,
62 protocol: i32,
63 addrlen: socklen_t,
64 canonname: ?[*:0]u8,
65 addr: ?*sockaddr,
66 next: ?*addrinfo,
67};
68
69pub const EAI = enum(c_int) {
70 /// address family for hostname not supported
71 ADDRFAMILY = 1,
72
73 /// name could not be resolved at this time
74 AGAIN = 2,
75
76 /// flags parameter had an invalid value
77 BADFLAGS = 3,
78
79 /// non-recoverable failure in name resolution
80 FAIL = 4,
81
82 /// address family not recognized
83 FAMILY = 5,
84
85 /// memory allocation failure
86 MEMORY = 6,
87
88 /// no address associated with hostname
89 NODATA = 7,
90
91 /// name does not resolve
92 NONAME = 8,
93
94 /// service not recognized for socket type
95 SERVICE = 9,
96
97 /// intended socket type was not recognized
98 SOCKTYPE = 10,
99
100 /// system error returned in errno
101 SYSTEM = 11,
102
103 /// invalid value for hints
104 BADHINTS = 12,
105
106 /// resolved protocol is unknown
107 PROTOCOL = 13,
108
109 /// argument buffer overflow
110 OVERFLOW = 14,
111
112 _,
113};
114
115pub const EAI_MAX = 15;
116
117pub const msghdr = extern struct {
118 /// optional address
119 msg_name: ?*sockaddr,
120
121 /// size of address
122 msg_namelen: socklen_t,
123
124 /// scatter/gather array
125 msg_iov: [*]iovec,
126
127 /// # elements in msg_iov
128 msg_iovlen: i32,
129
130 /// ancillary data
131 msg_control: ?*c_void,
132
133 /// ancillary data buffer len
134 msg_controllen: socklen_t,
135
136 /// flags on received message
137 msg_flags: i32,
138};
139
140pub const msghdr_const = extern struct {
141 /// optional address
142 msg_name: ?*const sockaddr,
143
144 /// size of address
145 msg_namelen: socklen_t,
146
147 /// scatter/gather array
148 msg_iov: [*]iovec_const,
149
150 /// # elements in msg_iov
151 msg_iovlen: i32,
152
153 /// ancillary data
154 msg_control: ?*c_void,
155
156 /// ancillary data buffer len
157 msg_controllen: socklen_t,
158
159 /// flags on received message
160 msg_flags: i32,
161};
162
163pub const libc_stat = extern struct {
164 dev: dev_t,
165 mode: mode_t,
166 ino: ino_t,
167 nlink: nlink_t,
168 uid: uid_t,
169 gid: gid_t,
170 rdev: dev_t,
171 atim: timespec,
172 mtim: timespec,
173 ctim: timespec,
174 birthtim: timespec,
175 size: off_t,
176 blocks: blkcnt_t,
177 blksize: blksize_t,
178 flags: u32,
179 gen: u32,
180 __spare: [2]u32,
181
182 pub fn atime(self: @This()) timespec {
183 return self.atim;
184 }
185
186 pub fn mtime(self: @This()) timespec {
187 return self.mtim;
188 }
189
190 pub fn ctime(self: @This()) timespec {
191 return self.ctim;
192 }
193};
194
195pub const timespec = extern struct {
196 tv_sec: i64,
197 tv_nsec: isize,
198};
199
200pub const timeval = extern struct {
201 /// seconds
202 tv_sec: time_t,
203 /// microseconds
204 tv_usec: suseconds_t,
205};
206
207pub const MAXNAMLEN = 511;
208
209pub const dirent = extern struct {
210 d_fileno: ino_t,
211 d_reclen: u16,
212 d_namlen: u16,
213 d_type: u8,
214 d_name: [MAXNAMLEN:0]u8,
215
216 pub fn reclen(self: dirent) u16 {
217 return self.d_reclen;
218 }
219};
220
221pub const SOCK_STREAM = 1;
222pub const SOCK_DGRAM = 2;
223pub const SOCK_RAW = 3;
224pub const SOCK_RDM = 4;
225pub const SOCK_SEQPACKET = 5;
226pub const SOCK_CONN_DGRAM = 6;
227pub const SOCK_DCCP = SOCK_CONN_DGRAM;
228
229pub const SOCK_CLOEXEC = 0x10000000;
230pub const SOCK_NONBLOCK = 0x20000000;
231pub const SOCK_NOSIGPIPE = 0x40000000;
232pub const SOCK_FLAGS_MASK = 0xf0000000;
233
234pub const SO_DEBUG = 0x0001;
235pub const SO_ACCEPTCONN = 0x0002;
236pub const SO_REUSEADDR = 0x0004;
237pub const SO_KEEPALIVE = 0x0008;
238pub const SO_DONTROUTE = 0x0010;
239pub const SO_BROADCAST = 0x0020;
240pub const SO_USELOOPBACK = 0x0040;
241pub const SO_LINGER = 0x0080;
242pub const SO_OOBINLINE = 0x0100;
243pub const SO_REUSEPORT = 0x0200;
244pub const SO_NOSIGPIPE = 0x0800;
245pub const SO_ACCEPTFILTER = 0x1000;
246pub const SO_TIMESTAMP = 0x2000;
247pub const SO_RERROR = 0x4000;
248
249pub const SO_SNDBUF = 0x1001;
250pub const SO_RCVBUF = 0x1002;
251pub const SO_SNDLOWAT = 0x1003;
252pub const SO_RCVLOWAT = 0x1004;
253pub const SO_ERROR = 0x1007;
254pub const SO_TYPE = 0x1008;
255pub const SO_OVERFLOWED = 0x1009;
256
257pub const SO_NOHEADER = 0x100a;
258pub const SO_SNDTIMEO = 0x100b;
259pub const SO_RCVTIMEO = 0x100c;
260
261pub const SOL_SOCKET = 0xffff;
262
263pub const PF_UNSPEC = AF_UNSPEC;
264pub const PF_LOCAL = AF_LOCAL;
265pub const PF_UNIX = PF_LOCAL;
266pub const PF_INET = AF_INET;
267pub const PF_IMPLINK = AF_IMPLINK;
268pub const PF_PUP = AF_PUP;
269pub const PF_CHAOS = AF_CHAOS;
270pub const PF_NS = AF_NS;
271pub const PF_ISO = AF_ISO;
272pub const PF_OSI = AF_ISO;
273pub const PF_ECMA = AF_ECMA;
274pub const PF_DATAKIT = AF_DATAKIT;
275pub const PF_CCITT = AF_CCITT;
276pub const PF_SNA = AF_SNA;
277pub const PF_DECnet = AF_DECnet;
278pub const PF_DLI = AF_DLI;
279pub const PF_LAT = AF_LAT;
280pub const PF_HYLINK = AF_HYLINK;
281pub const PF_APPLETALK = AF_APPLETALK;
282pub const PF_OROUTE = AF_OROUTE;
283pub const PF_LINK = AF_LINK;
284pub const PF_COIP = AF_COIP;
285pub const PF_CNT = AF_CNT;
286pub const PF_INET6 = AF_INET6;
287pub const PF_IPX = AF_IPX;
288pub const PF_ISDN = AF_ISDN;
289pub const PF_E164 = AF_E164;
290pub const PF_NATM = AF_NATM;
291pub const PF_ARP = AF_ARP;
292pub const PF_BLUETOOTH = AF_BLUETOOTH;
293pub const PF_MPLS = AF_MPLS;
294pub const PF_ROUTE = AF_ROUTE;
295pub const PF_CAN = AF_CAN;
296pub const PF_ETHER = AF_ETHER;
297pub const PF_MAX = AF_MAX;
298
299pub const AF_UNSPEC = 0;
300pub const AF_LOCAL = 1;
301pub const AF_UNIX = AF_LOCAL;
302pub const AF_INET = 2;
303pub const AF_IMPLINK = 3;
304pub const AF_PUP = 4;
305pub const AF_CHAOS = 5;
306pub const AF_NS = 6;
307pub const AF_ISO = 7;
308pub const AF_OSI = AF_ISO;
309pub const AF_ECMA = 8;
310pub const AF_DATAKIT = 9;
311pub const AF_CCITT = 10;
312pub const AF_SNA = 11;
313pub const AF_DECnet = 12;
314pub const AF_DLI = 13;
315pub const AF_LAT = 14;
316pub const AF_HYLINK = 15;
317pub const AF_APPLETALK = 16;
318pub const AF_OROUTE = 17;
319pub const AF_LINK = 18;
320pub const AF_COIP = 20;
321pub const AF_CNT = 21;
322pub const AF_IPX = 23;
323pub const AF_INET6 = 24;
324pub const AF_ISDN = 26;
325pub const AF_E164 = AF_ISDN;
326pub const AF_NATM = 27;
327pub const AF_ARP = 28;
328pub const AF_BLUETOOTH = 31;
329pub const AF_IEEE80211 = 32;
330pub const AF_MPLS = 33;
331pub const AF_ROUTE = 34;
332pub const AF_CAN = 35;
333pub const AF_ETHER = 36;
334pub const AF_MAX = 37;
335
336pub const in_port_t = u16;
337pub const sa_family_t = u8;
338
339pub const sockaddr = extern struct {
340 /// total length
341 len: u8,
342
343 /// address family
344 family: sa_family_t,
345
346 /// actually longer; address value
347 data: [14]u8,
348};
349
350pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
351
352pub const sockaddr_in = extern struct {
353 len: u8 = @sizeOf(sockaddr_in),
354 family: sa_family_t = AF_INET,
355 port: in_port_t,
356 addr: u32,
357 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
358};
359
360pub const sockaddr_in6 = extern struct {
361 len: u8 = @sizeOf(sockaddr_in6),
362 family: sa_family_t = AF_INET6,
363 port: in_port_t,
364 flowinfo: u32,
365 addr: [16]u8,
366 scope_id: u32,
367};
368
369/// Definitions for UNIX IPC domain.
370pub const sockaddr_un = extern struct {
371 /// total sockaddr length
372 len: u8 = @sizeOf(sockaddr_un),
373
374 /// AF_LOCAL
375 family: sa_family_t = AF_LOCAL,
376
377 /// path name
378 path: [104]u8,
379};
380
381/// get address to use bind()
382pub const AI_PASSIVE = 0x00000001;
383
384/// fill ai_canonname
385pub const AI_CANONNAME = 0x00000002;
386
387/// prevent host name resolution
388pub const AI_NUMERICHOST = 0x00000004;
389
390/// prevent service name resolution
391pub const AI_NUMERICSERV = 0x00000008;
392
393/// only if any address is assigned
394pub const AI_ADDRCONFIG = 0x00000400;
395
396pub const CTL_KERN = 1;
397pub const CTL_DEBUG = 5;
398
399pub const KERN_PROC_ARGS = 48; // struct: process argv/env
400pub const KERN_PROC_PATHNAME = 5; // path to executable
401pub const KERN_IOV_MAX = 38;
402
403pub const PATH_MAX = 1024;
404pub const IOV_MAX = KERN_IOV_MAX;
405
406pub const STDIN_FILENO = 0;
407pub const STDOUT_FILENO = 1;
408pub const STDERR_FILENO = 2;
409
410pub const PROT_NONE = 0;
411pub const PROT_READ = 1;
412pub const PROT_WRITE = 2;
413pub const PROT_EXEC = 4;
414
415pub const CLOCK_REALTIME = 0;
416pub const CLOCK_VIRTUAL = 1;
417pub const CLOCK_PROF = 2;
418pub const CLOCK_MONOTONIC = 3;
419pub const CLOCK_THREAD_CPUTIME_ID = 0x20000000;
420pub const CLOCK_PROCESS_CPUTIME_ID = 0x40000000;
421
422pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
423pub const MAP_SHARED = 0x0001;
424pub const MAP_PRIVATE = 0x0002;
425pub const MAP_REMAPDUP = 0x0004;
426pub const MAP_FIXED = 0x0010;
427pub const MAP_RENAME = 0x0020;
428pub const MAP_NORESERVE = 0x0040;
429pub const MAP_INHERIT = 0x0080;
430pub const MAP_HASSEMAPHORE = 0x0200;
431pub const MAP_TRYFIXED = 0x0400;
432pub const MAP_WIRED = 0x0800;
433
434pub const MAP_FILE = 0x0000;
435pub const MAP_NOSYNC = 0x0800;
436pub const MAP_ANON = 0x1000;
437pub const MAP_ANONYMOUS = MAP_ANON;
438pub const MAP_STACK = 0x2000;
439
440pub const WNOHANG = 0x00000001;
441pub const WUNTRACED = 0x00000002;
442pub const WSTOPPED = WUNTRACED;
443pub const WCONTINUED = 0x00000010;
444pub const WNOWAIT = 0x00010000;
445pub const WEXITED = 0x00000020;
446pub const WTRAPPED = 0x00000040;
447
448pub const SA_ONSTACK = 0x0001;
449pub const SA_RESTART = 0x0002;
450pub const SA_RESETHAND = 0x0004;
451pub const SA_NOCLDSTOP = 0x0008;
452pub const SA_NODEFER = 0x0010;
453pub const SA_NOCLDWAIT = 0x0020;
454pub const SA_SIGINFO = 0x0040;
455
456pub const SIGHUP = 1;
457pub const SIGINT = 2;
458pub const SIGQUIT = 3;
459pub const SIGILL = 4;
460pub const SIGTRAP = 5;
461pub const SIGABRT = 6;
462pub const SIGIOT = SIGABRT;
463pub const SIGEMT = 7;
464pub const SIGFPE = 8;
465pub const SIGKILL = 9;
466pub const SIGBUS = 10;
467pub const SIGSEGV = 11;
468pub const SIGSYS = 12;
469pub const SIGPIPE = 13;
470pub const SIGALRM = 14;
471pub const SIGTERM = 15;
472pub const SIGURG = 16;
473pub const SIGSTOP = 17;
474pub const SIGTSTP = 18;
475pub const SIGCONT = 19;
476pub const SIGCHLD = 20;
477pub const SIGTTIN = 21;
478pub const SIGTTOU = 22;
479pub const SIGIO = 23;
480pub const SIGXCPU = 24;
481pub const SIGXFSZ = 25;
482pub const SIGVTALRM = 26;
483pub const SIGPROF = 27;
484pub const SIGWINCH = 28;
485pub const SIGINFO = 29;
486pub const SIGUSR1 = 30;
487pub const SIGUSR2 = 31;
488pub const SIGPWR = 32;
489
490pub const SIGRTMIN = 33;
491pub const SIGRTMAX = 63;
492
493// access function
494pub const F_OK = 0; // test for existence of file
495pub const X_OK = 1; // test for execute or search permission
496pub const W_OK = 2; // test for write permission
497pub const R_OK = 4; // test for read permission
498
499/// open for reading only
500pub const O_RDONLY = 0x00000000;
501
502/// open for writing only
503pub const O_WRONLY = 0x00000001;
504
505/// open for reading and writing
506pub const O_RDWR = 0x00000002;
507
508/// mask for above modes
509pub const O_ACCMODE = 0x00000003;
510
511/// no delay
512pub const O_NONBLOCK = 0x00000004;
513
514/// set append mode
515pub const O_APPEND = 0x00000008;
516
517/// open with shared file lock
518pub const O_SHLOCK = 0x00000010;
519
520/// open with exclusive file lock
521pub const O_EXLOCK = 0x00000020;
522
523/// signal pgrp when data ready
524pub const O_ASYNC = 0x00000040;
525
526/// synchronous writes
527pub const O_SYNC = 0x00000080;
528
529/// don't follow symlinks on the last
530pub const O_NOFOLLOW = 0x00000100;
531
532/// create if nonexistent
533pub const O_CREAT = 0x00000200;
534
535/// truncate to zero length
536pub const O_TRUNC = 0x00000400;
537
538/// error if already exists
539pub const O_EXCL = 0x00000800;
540
541/// don't assign controlling terminal
542pub const O_NOCTTY = 0x00008000;
543
544/// write: I/O data completion
545pub const O_DSYNC = 0x00010000;
546
547/// read: I/O completion as for write
548pub const O_RSYNC = 0x00020000;
549
550/// use alternate i/o semantics
551pub const O_ALT_IO = 0x00040000;
552
553/// direct I/O hint
554pub const O_DIRECT = 0x00080000;
555
556/// fail if not a directory
557pub const O_DIRECTORY = 0x00200000;
558
559/// set close on exec
560pub const O_CLOEXEC = 0x00400000;
561
562/// skip search permission checks
563pub const O_SEARCH = 0x00800000;
564
565pub const F_DUPFD = 0;
566pub const F_GETFD = 1;
567pub const F_SETFD = 2;
568pub const F_GETFL = 3;
569pub const F_SETFL = 4;
570
571pub const F_GETOWN = 5;
572pub const F_SETOWN = 6;
573
574pub const F_GETLK = 7;
575pub const F_SETLK = 8;
576pub const F_SETLKW = 9;
577
578pub const F_RDLCK = 1;
579pub const F_WRLCK = 3;
580pub const F_UNLCK = 2;
581
582pub const LOCK_SH = 1;
583pub const LOCK_EX = 2;
584pub const LOCK_UN = 8;
585pub const LOCK_NB = 4;
586
587pub const FD_CLOEXEC = 1;
588
589pub const SEEK_SET = 0;
590pub const SEEK_CUR = 1;
591pub const SEEK_END = 2;
592
593pub const SIG_BLOCK = 1;
594pub const SIG_UNBLOCK = 2;
595pub const SIG_SETMASK = 3;
596
597pub const DT_UNKNOWN = 0;
598pub const DT_FIFO = 1;
599pub const DT_CHR = 2;
600pub const DT_DIR = 4;
601pub const DT_BLK = 6;
602pub const DT_REG = 8;
603pub const DT_LNK = 10;
604pub const DT_SOCK = 12;
605pub const DT_WHT = 14;
606
607/// add event to kq (implies enable)
608pub const EV_ADD = 0x0001;
609
610/// delete event from kq
611pub const EV_DELETE = 0x0002;
612
613/// enable event
614pub const EV_ENABLE = 0x0004;
615
616/// disable event (not reported)
617pub const EV_DISABLE = 0x0008;
618
619/// only report one occurrence
620pub const EV_ONESHOT = 0x0010;
621
622/// clear event state after reporting
623pub const EV_CLEAR = 0x0020;
624
625/// force immediate event output
626/// ... with or without EV_ERROR
627/// ... use KEVENT_FLAG_ERROR_EVENTS
628/// on syscalls supporting flags
629pub const EV_RECEIPT = 0x0040;
630
631/// disable event after reporting
632pub const EV_DISPATCH = 0x0080;
633
634pub const EVFILT_READ = 0;
635pub const EVFILT_WRITE = 1;
636
637/// attached to aio requests
638pub const EVFILT_AIO = 2;
639
640/// attached to vnodes
641pub const EVFILT_VNODE = 3;
642
643/// attached to struct proc
644pub const EVFILT_PROC = 4;
645
646/// attached to struct proc
647pub const EVFILT_SIGNAL = 5;
648
649/// timers
650pub const EVFILT_TIMER = 6;
651
652/// Filesystem events
653pub const EVFILT_FS = 7;
654
655/// On input, NOTE_TRIGGER causes the event to be triggered for output.
656pub const NOTE_TRIGGER = 0x08000000;
657
658/// low water mark
659pub const NOTE_LOWAT = 0x00000001;
660
661/// vnode was removed
662pub const NOTE_DELETE = 0x00000001;
663
664/// data contents changed
665pub const NOTE_WRITE = 0x00000002;
666
667/// size increased
668pub const NOTE_EXTEND = 0x00000004;
669
670/// attributes changed
671pub const NOTE_ATTRIB = 0x00000008;
672
673/// link count changed
674pub const NOTE_LINK = 0x00000010;
675
676/// vnode was renamed
677pub const NOTE_RENAME = 0x00000020;
678
679/// vnode access was revoked
680pub const NOTE_REVOKE = 0x00000040;
681
682/// process exited
683pub const NOTE_EXIT = 0x80000000;
684
685/// process forked
686pub const NOTE_FORK = 0x40000000;
687
688/// process exec'd
689pub const NOTE_EXEC = 0x20000000;
690
691/// mask for signal & exit status
692pub const NOTE_PDATAMASK = 0x000fffff;
693pub const NOTE_PCTRLMASK = 0xf0000000;
694
695pub const TIOCCBRK = 0x2000747a;
696pub const TIOCCDTR = 0x20007478;
697pub const TIOCCONS = 0x80047462;
698pub const TIOCDCDTIMESTAMP = 0x40107458;
699pub const TIOCDRAIN = 0x2000745e;
700pub const TIOCEXCL = 0x2000740d;
701pub const TIOCEXT = 0x80047460;
702pub const TIOCFLAG_CDTRCTS = 0x10;
703pub const TIOCFLAG_CLOCAL = 0x2;
704pub const TIOCFLAG_CRTSCTS = 0x4;
705pub const TIOCFLAG_MDMBUF = 0x8;
706pub const TIOCFLAG_SOFTCAR = 0x1;
707pub const TIOCFLUSH = 0x80047410;
708pub const TIOCGETA = 0x402c7413;
709pub const TIOCGETD = 0x4004741a;
710pub const TIOCGFLAGS = 0x4004745d;
711pub const TIOCGLINED = 0x40207442;
712pub const TIOCGPGRP = 0x40047477;
713pub const TIOCGQSIZE = 0x40047481;
714pub const TIOCGRANTPT = 0x20007447;
715pub const TIOCGSID = 0x40047463;
716pub const TIOCGSIZE = 0x40087468;
717pub const TIOCGWINSZ = 0x40087468;
718pub const TIOCMBIC = 0x8004746b;
719pub const TIOCMBIS = 0x8004746c;
720pub const TIOCMGET = 0x4004746a;
721pub const TIOCMSET = 0x8004746d;
722pub const TIOCM_CAR = 0x40;
723pub const TIOCM_CD = 0x40;
724pub const TIOCM_CTS = 0x20;
725pub const TIOCM_DSR = 0x100;
726pub const TIOCM_DTR = 0x2;
727pub const TIOCM_LE = 0x1;
728pub const TIOCM_RI = 0x80;
729pub const TIOCM_RNG = 0x80;
730pub const TIOCM_RTS = 0x4;
731pub const TIOCM_SR = 0x10;
732pub const TIOCM_ST = 0x8;
733pub const TIOCNOTTY = 0x20007471;
734pub const TIOCNXCL = 0x2000740e;
735pub const TIOCOUTQ = 0x40047473;
736pub const TIOCPKT = 0x80047470;
737pub const TIOCPKT_DATA = 0x0;
738pub const TIOCPKT_DOSTOP = 0x20;
739pub const TIOCPKT_FLUSHREAD = 0x1;
740pub const TIOCPKT_FLUSHWRITE = 0x2;
741pub const TIOCPKT_IOCTL = 0x40;
742pub const TIOCPKT_NOSTOP = 0x10;
743pub const TIOCPKT_START = 0x8;
744pub const TIOCPKT_STOP = 0x4;
745pub const TIOCPTMGET = 0x40287446;
746pub const TIOCPTSNAME = 0x40287448;
747pub const TIOCRCVFRAME = 0x80087445;
748pub const TIOCREMOTE = 0x80047469;
749pub const TIOCSBRK = 0x2000747b;
750pub const TIOCSCTTY = 0x20007461;
751pub const TIOCSDTR = 0x20007479;
752pub const TIOCSETA = 0x802c7414;
753pub const TIOCSETAF = 0x802c7416;
754pub const TIOCSETAW = 0x802c7415;
755pub const TIOCSETD = 0x8004741b;
756pub const TIOCSFLAGS = 0x8004745c;
757pub const TIOCSIG = 0x2000745f;
758pub const TIOCSLINED = 0x80207443;
759pub const TIOCSPGRP = 0x80047476;
760pub const TIOCSQSIZE = 0x80047480;
761pub const TIOCSSIZE = 0x80087467;
762pub const TIOCSTART = 0x2000746e;
763pub const TIOCSTAT = 0x80047465;
764pub const TIOCSTI = 0x80017472;
765pub const TIOCSTOP = 0x2000746f;
766pub const TIOCSWINSZ = 0x80087467;
767pub const TIOCUCNTL = 0x80047466;
768pub const TIOCXMTFRAME = 0x80087444;
769
770pub fn WEXITSTATUS(s: u32) u8 {
771 return @intCast(u8, (s >> 8) & 0xff);
772}
773pub fn WTERMSIG(s: u32) u32 {
774 return s & 0x7f;
775}
776pub fn WSTOPSIG(s: u32) u32 {
777 return WEXITSTATUS(s);
778}
779pub fn WIFEXITED(s: u32) bool {
780 return WTERMSIG(s) == 0;
781}
782
783pub fn WIFCONTINUED(s: u32) bool {
784 return ((s & 0x7f) == 0xffff);
785}
786
787pub fn WIFSTOPPED(s: u32) bool {
788 return ((s & 0x7f != 0x7f) and !WIFCONTINUED(s));
789}
790
791pub fn WIFSIGNALED(s: u32) bool {
792 return !WIFSTOPPED(s) and !WIFCONTINUED(s) and !WIFEXITED(s);
793}
794
795pub const winsize = extern struct {
796 ws_row: u16,
797 ws_col: u16,
798 ws_xpixel: u16,
799 ws_ypixel: u16,
800};
801
802const NSIG = 32;
803
804pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
805pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
806pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
807
808/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
809pub const Sigaction = extern struct {
810 pub const handler_fn = fn (c_int) callconv(.C) void;
811 pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void;
812
813 /// signal handler
814 handler: extern union {
815 handler: ?handler_fn,
816 sigaction: ?sigaction_fn,
817 },
818 /// signal mask to apply
819 mask: sigset_t,
820 /// signal options
821 flags: c_uint,
822};
823
824pub const sigval_t = extern union {
825 int: i32,
826 ptr: ?*c_void,
827};
828
829pub const siginfo_t = extern union {
830 pad: [128]u8,
831 info: _ksiginfo,
832};
833
834pub const _ksiginfo = extern struct {
835 signo: i32,
836 code: i32,
837 errno: i32,
838 // 64bit architectures insert 4bytes of padding here, this is done by
839 // correctly aligning the reason field
840 reason: extern union {
841 rt: extern struct {
842 pid: pid_t,
843 uid: uid_t,
844 value: sigval_t,
845 },
846 child: extern struct {
847 pid: pid_t,
848 uid: uid_t,
849 status: i32,
850 utime: clock_t,
851 stime: clock_t,
852 },
853 fault: extern struct {
854 addr: ?*c_void,
855 trap: i32,
856 trap2: i32,
857 trap3: i32,
858 },
859 poll: extern struct {
860 band: i32,
861 fd: i32,
862 },
863 syscall: extern struct {
864 sysnum: i32,
865 retval: [2]i32,
866 @"error": i32,
867 args: [8]u64,
868 },
869 ptrace_state: extern struct {
870 pe_report_event: i32,
871 option: extern union {
872 pe_other_pid: pid_t,
873 pe_lwp: lwpid_t,
874 },
875 },
876 } align(@sizeOf(usize)),
877};
878
879pub const _SIG_WORDS = 4;
880pub const _SIG_MAXSIG = 128;
881
882pub inline fn _SIG_IDX(sig: usize) usize {
883 return sig - 1;
884}
885pub inline fn _SIG_WORD(sig: usize) usize {
886 return_SIG_IDX(sig) >> 5;
887}
888pub inline fn _SIG_BIT(sig: usize) usize {
889 return 1 << (_SIG_IDX(sig) & 31);
890}
891pub inline fn _SIG_VALID(sig: usize) usize {
892 return sig <= _SIG_MAXSIG and sig > 0;
893}
894
895pub const sigset_t = extern struct {
896 __bits: [_SIG_WORDS]u32,
897};
898
899pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** _SIG_WORDS };
900
901// XXX x86_64 specific
902pub const mcontext_t = extern struct {
903 gregs: [26]u64,
904 mc_tlsbase: u64,
905 fpregs: [512]u8 align(8),
906};
907
908pub const REG_RBP = 12;
909pub const REG_RIP = 21;
910pub const REG_RSP = 24;
911
912pub const ucontext_t = extern struct {
913 flags: u32,
914 link: ?*ucontext_t,
915 sigmask: sigset_t,
916 stack: stack_t,
917 mcontext: mcontext_t,
918 __pad: [
919 switch (builtin.cpu.arch) {
920 .i386 => 4,
921 .mips, .mipsel, .mips64, .mips64el => 14,
922 .arm, .armeb, .thumb, .thumbeb => 1,
923 .sparc, .sparcel, .sparcv9 => if (@sizeOf(usize) == 4) 43 else 8,
924 else => 0,
925 }
926 ]u32,
927};
928
929pub const E = enum(u16) {
930 /// No error occurred.
931 SUCCESS = 0,
932 PERM = 1, // Operation not permitted
933 NOENT = 2, // No such file or directory
934 SRCH = 3, // No such process
935 INTR = 4, // Interrupted system call
936 IO = 5, // Input/output error
937 NXIO = 6, // Device not configured
938 @"2BIG" = 7, // Argument list too long
939 NOEXEC = 8, // Exec format error
940 BADF = 9, // Bad file descriptor
941 CHILD = 10, // No child processes
942 DEADLK = 11, // Resource deadlock avoided
943 // 11 was AGAIN
944 NOMEM = 12, // Cannot allocate memory
945 ACCES = 13, // Permission denied
946 FAULT = 14, // Bad address
947 NOTBLK = 15, // Block device required
948 BUSY = 16, // Device busy
949 EXIST = 17, // File exists
950 XDEV = 18, // Cross-device link
951 NODEV = 19, // Operation not supported by device
952 NOTDIR = 20, // Not a directory
953 ISDIR = 21, // Is a directory
954 INVAL = 22, // Invalid argument
955 NFILE = 23, // Too many open files in system
956 MFILE = 24, // Too many open files
957 NOTTY = 25, // Inappropriate ioctl for device
958 TXTBSY = 26, // Text file busy
959 FBIG = 27, // File too large
960 NOSPC = 28, // No space left on device
961 SPIPE = 29, // Illegal seek
962 ROFS = 30, // Read-only file system
963 MLINK = 31, // Too many links
964 PIPE = 32, // Broken pipe
965
966 // math software
967 DOM = 33, // Numerical argument out of domain
968 RANGE = 34, // Result too large or too small
969
970 // non-blocking and interrupt i/o
971 // also: WOULDBLOCK: operation would block
972 AGAIN = 35, // Resource temporarily unavailable
973 INPROGRESS = 36, // Operation now in progress
974 ALREADY = 37, // Operation already in progress
975
976 // ipc/network software -- argument errors
977 NOTSOCK = 38, // Socket operation on non-socket
978 DESTADDRREQ = 39, // Destination address required
979 MSGSIZE = 40, // Message too long
980 PROTOTYPE = 41, // Protocol wrong type for socket
981 NOPROTOOPT = 42, // Protocol option not available
982 PROTONOSUPPORT = 43, // Protocol not supported
983 SOCKTNOSUPPORT = 44, // Socket type not supported
984 OPNOTSUPP = 45, // Operation not supported
985 PFNOSUPPORT = 46, // Protocol family not supported
986 AFNOSUPPORT = 47, // Address family not supported by protocol family
987 ADDRINUSE = 48, // Address already in use
988 ADDRNOTAVAIL = 49, // Can't assign requested address
989
990 // ipc/network software -- operational errors
991 NETDOWN = 50, // Network is down
992 NETUNREACH = 51, // Network is unreachable
993 NETRESET = 52, // Network dropped connection on reset
994 CONNABORTED = 53, // Software caused connection abort
995 CONNRESET = 54, // Connection reset by peer
996 NOBUFS = 55, // No buffer space available
997 ISCONN = 56, // Socket is already connected
998 NOTCONN = 57, // Socket is not connected
999 SHUTDOWN = 58, // Can't send after socket shutdown
1000 TOOMANYREFS = 59, // Too many references: can't splice
1001 TIMEDOUT = 60, // Operation timed out
1002 CONNREFUSED = 61, // Connection refused
1003
1004 LOOP = 62, // Too many levels of symbolic links
1005 NAMETOOLONG = 63, // File name too long
1006
1007 // should be rearranged
1008 HOSTDOWN = 64, // Host is down
1009 HOSTUNREACH = 65, // No route to host
1010 NOTEMPTY = 66, // Directory not empty
1011
1012 // quotas & mush
1013 PROCLIM = 67, // Too many processes
1014 USERS = 68, // Too many users
1015 DQUOT = 69, // Disc quota exceeded
1016
1017 // Network File System
1018 STALE = 70, // Stale NFS file handle
1019 REMOTE = 71, // Too many levels of remote in path
1020 BADRPC = 72, // RPC struct is bad
1021 RPCMISMATCH = 73, // RPC version wrong
1022 PROGUNAVAIL = 74, // RPC prog. not avail
1023 PROGMISMATCH = 75, // Program version wrong
1024 PROCUNAVAIL = 76, // Bad procedure for program
1025
1026 NOLCK = 77, // No locks available
1027 NOSYS = 78, // Function not implemented
1028
1029 FTYPE = 79, // Inappropriate file type or format
1030 AUTH = 80, // Authentication error
1031 NEEDAUTH = 81, // Need authenticator
1032
1033 // SystemV IPC
1034 IDRM = 82, // Identifier removed
1035 NOMSG = 83, // No message of desired type
1036 OVERFLOW = 84, // Value too large to be stored in data type
1037
1038 // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
1039 ILSEQ = 85, // Illegal byte sequence
1040
1041 // From IEEE Std 1003.1-2001
1042 // Base, Realtime, Threads or Thread Priority Scheduling option errors
1043 NOTSUP = 86, // Not supported
1044
1045 // Realtime option errors
1046 CANCELED = 87, // Operation canceled
1047
1048 // Realtime, XSI STREAMS option errors
1049 BADMSG = 88, // Bad or Corrupt message
1050
1051 // XSI STREAMS option errors
1052 NODATA = 89, // No message available
1053 NOSR = 90, // No STREAM resources
1054 NOSTR = 91, // Not a STREAM
1055 TIME = 92, // STREAM ioctl timeout
1056
1057 // File system extended attribute errors
1058 NOATTR = 93, // Attribute not found
1059
1060 // Realtime, XSI STREAMS option errors
1061 MULTIHOP = 94, // Multihop attempted
1062 NOLINK = 95, // Link has been severed
1063 PROTO = 96, // Protocol error
1064
1065 _,
1066};
1067
1068pub const MINSIGSTKSZ = 8192;
1069pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
1070
1071pub const SS_ONSTACK = 1;
1072pub const SS_DISABLE = 4;
1073
1074pub const stack_t = extern struct {
1075 ss_sp: [*]u8,
1076 ss_size: isize,
1077 ss_flags: i32,
1078};
1079
1080pub const S_IFMT = 0o170000;
1081
1082pub const S_IFIFO = 0o010000;
1083pub const S_IFCHR = 0o020000;
1084pub const S_IFDIR = 0o040000;
1085pub const S_IFBLK = 0o060000;
1086pub const S_IFREG = 0o100000;
1087pub const S_IFLNK = 0o120000;
1088pub const S_IFSOCK = 0o140000;
1089pub const S_IFWHT = 0o160000;
1090
1091pub const S_ISUID = 0o4000;
1092pub const S_ISGID = 0o2000;
1093pub const S_ISVTX = 0o1000;
1094pub const S_IRWXU = 0o700;
1095pub const S_IRUSR = 0o400;
1096pub const S_IWUSR = 0o200;
1097pub const S_IXUSR = 0o100;
1098pub const S_IRWXG = 0o070;
1099pub const S_IRGRP = 0o040;
1100pub const S_IWGRP = 0o020;
1101pub const S_IXGRP = 0o010;
1102pub const S_IRWXO = 0o007;
1103pub const S_IROTH = 0o004;
1104pub const S_IWOTH = 0o002;
1105pub const S_IXOTH = 0o001;
1106
1107pub fn S_ISFIFO(m: u32) bool {
1108 return m & S_IFMT == S_IFIFO;
1109}
1110
1111pub fn S_ISCHR(m: u32) bool {
1112 return m & S_IFMT == S_IFCHR;
1113}
1114
1115pub fn S_ISDIR(m: u32) bool {
1116 return m & S_IFMT == S_IFDIR;
1117}
1118
1119pub fn S_ISBLK(m: u32) bool {
1120 return m & S_IFMT == S_IFBLK;
1121}
1122
1123pub fn S_ISREG(m: u32) bool {
1124 return m & S_IFMT == S_IFREG;
1125}
1126
1127pub fn S_ISLNK(m: u32) bool {
1128 return m & S_IFMT == S_IFLNK;
1129}
1130
1131pub fn S_ISSOCK(m: u32) bool {
1132 return m & S_IFMT == S_IFSOCK;
1133}
1134
1135pub fn S_IWHT(m: u32) bool {
1136 return m & S_IFMT == S_IFWHT;
1137}
1138
1139/// Magic value that specify the use of the current working directory
1140/// to determine the target of relative file paths in the openat() and
1141/// similar syscalls.
1142pub const AT_FDCWD = -100;
1143
1144/// Check access using effective user and group ID
1145pub const AT_EACCESS = 0x0100;
1146
1147/// Do not follow symbolic links
1148pub const AT_SYMLINK_NOFOLLOW = 0x0200;
1149
1150/// Follow symbolic link
1151pub const AT_SYMLINK_FOLLOW = 0x0400;
1152
1153/// Remove directory instead of file
1154pub const AT_REMOVEDIR = 0x0800;
1155
1156pub const HOST_NAME_MAX = 255;
1157
1158/// dummy for IP
1159pub const IPPROTO_IP = 0;
1160
1161/// IP6 hop-by-hop options
1162pub const IPPROTO_HOPOPTS = 0;
1163
1164/// control message protocol
1165pub const IPPROTO_ICMP = 1;
1166
1167/// group mgmt protocol
1168pub const IPPROTO_IGMP = 2;
1169
1170/// gateway^2 (deprecated)
1171pub const IPPROTO_GGP = 3;
1172
1173/// IP header
1174pub const IPPROTO_IPV4 = 4;
1175
1176/// IP inside IP
1177pub const IPPROTO_IPIP = 4;
1178
1179/// tcp
1180pub const IPPROTO_TCP = 6;
1181
1182/// exterior gateway protocol
1183pub const IPPROTO_EGP = 8;
1184
1185/// pup
1186pub const IPPROTO_PUP = 12;
1187
1188/// user datagram protocol
1189pub const IPPROTO_UDP = 17;
1190
1191/// xns idp
1192pub const IPPROTO_IDP = 22;
1193
1194/// tp-4 w/ class negotiation
1195pub const IPPROTO_TP = 29;
1196
1197/// DCCP
1198pub const IPPROTO_DCCP = 33;
1199
1200/// IP6 header
1201pub const IPPROTO_IPV6 = 41;
1202
1203/// IP6 routing header
1204pub const IPPROTO_ROUTING = 43;
1205
1206/// IP6 fragmentation header
1207pub const IPPROTO_FRAGMENT = 44;
1208
1209/// resource reservation
1210pub const IPPROTO_RSVP = 46;
1211
1212/// GRE encaps RFC 1701
1213pub const IPPROTO_GRE = 47;
1214
1215/// encap. security payload
1216pub const IPPROTO_ESP = 50;
1217
1218/// authentication header
1219pub const IPPROTO_AH = 51;
1220
1221/// IP Mobility RFC 2004
1222pub const IPPROTO_MOBILE = 55;
1223
1224/// IPv6 ICMP
1225pub const IPPROTO_IPV6_ICMP = 58;
1226
1227/// ICMP6
1228pub const IPPROTO_ICMPV6 = 58;
1229
1230/// IP6 no next header
1231pub const IPPROTO_NONE = 59;
1232
1233/// IP6 destination option
1234pub const IPPROTO_DSTOPTS = 60;
1235
1236/// ISO cnlp
1237pub const IPPROTO_EON = 80;
1238
1239/// Ethernet-in-IP
1240pub const IPPROTO_ETHERIP = 97;
1241
1242/// encapsulation header
1243pub const IPPROTO_ENCAP = 98;
1244
1245/// Protocol indep. multicast
1246pub const IPPROTO_PIM = 103;
1247
1248/// IP Payload Comp. Protocol
1249pub const IPPROTO_IPCOMP = 108;
1250
1251/// VRRP RFC 2338
1252pub const IPPROTO_VRRP = 112;
1253
1254/// Common Address Resolution Protocol
1255pub const IPPROTO_CARP = 112;
1256
1257/// L2TPv3
1258pub const IPPROTO_L2TP = 115;
1259
1260/// SCTP
1261pub const IPPROTO_SCTP = 132;
1262
1263/// PFSYNC
1264pub const IPPROTO_PFSYNC = 240;
1265
1266/// raw IP packet
1267pub const IPPROTO_RAW = 255;
1268
1269pub const rlimit_resource = enum(c_int) {
1270 CPU = 0,
1271 FSIZE = 1,
1272 DATA = 2,
1273 STACK = 3,
1274 CORE = 4,
1275 RSS = 5,
1276 MEMLOCK = 6,
1277 NPROC = 7,
1278 NOFILE = 8,
1279 SBSIZE = 9,
1280 VMEM = 10,
1281 NTHR = 11,
1282 _,
1283
1284 pub const AS: rlimit_resource = .VMEM;
1285};
1286
1287pub const rlim_t = u64;
1288
1289/// No limit
1290pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
1291
1292pub const RLIM_SAVED_MAX = RLIM_INFINITY;
1293pub const RLIM_SAVED_CUR = RLIM_INFINITY;
1294
1295pub const rlimit = extern struct {
1296 /// Soft limit
1297 cur: rlim_t,
1298 /// Hard limit
1299 max: rlim_t,
1300};
1301
1302pub const SHUT_RD = 0;
1303pub const SHUT_WR = 1;
1304pub const SHUT_RDWR = 2;
1305
1306pub const nfds_t = u32;
1307
1308pub const pollfd = extern struct {
1309 fd: fd_t,
1310 events: i16,
1311 revents: i16,
1312};
1313
1314/// Testable events (may be specified in events field).
1315pub const POLLIN = 0x0001;
1316pub const POLLPRI = 0x0002;
1317pub const POLLOUT = 0x0004;
1318pub const POLLRDNORM = 0x0040;
1319pub const POLLWRNORM = POLLOUT;
1320pub const POLLRDBAND = 0x0080;
1321pub const POLLWRBAND = 0x0100;
1322
1323/// Non-testable events (may not be specified in events field).
1324pub const POLLERR = 0x0008;
1325pub const POLLHUP = 0x0010;
1326pub const POLLNVAL = 0x0020;
lib/std/os/bits/openbsd.zig deleted-1328
...@@ -1,1328 +0,0 @@
1const std = @import("../../std.zig");
2const builtin = std.builtin;
3const maxInt = std.math.maxInt;
4
5pub const blkcnt_t = i64;
6pub const blksize_t = i32;
7pub const clock_t = i64;
8pub const dev_t = i32;
9pub const fd_t = c_int;
10pub const gid_t = u32;
11pub const ino_t = u64;
12pub const mode_t = u32;
13pub const nlink_t = u32;
14pub const off_t = i64;
15pub const pid_t = i32;
16pub const socklen_t = u32;
17pub const time_t = i64;
18pub const uid_t = u32;
19
20/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
21pub const Kevent = extern struct {
22 ident: usize,
23 filter: c_short,
24 flags: u16,
25 fflags: c_uint,
26 data: i64,
27 udata: usize,
28};
29
30// Modes and flags for dlopen()
31// include/dlfcn.h
32
33/// Bind function calls lazily.
34pub const RTLD_LAZY = 1;
35
36/// Bind function calls immediately.
37pub const RTLD_NOW = 2;
38
39/// Make symbols globally available.
40pub const RTLD_GLOBAL = 0x100;
41
42/// Opposite of RTLD_GLOBAL, and the default.
43pub const RTLD_LOCAL = 0x000;
44
45/// Trace loaded objects and exit.
46pub const RTLD_TRACE = 0x200;
47
48pub const dl_phdr_info = extern struct {
49 dlpi_addr: std.elf.Addr,
50 dlpi_name: ?[*:0]const u8,
51 dlpi_phdr: [*]std.elf.Phdr,
52 dlpi_phnum: std.elf.Half,
53};
54
55pub const Flock = extern struct {
56 l_start: off_t,
57 l_len: off_t,
58 l_pid: pid_t,
59 l_type: c_short,
60 l_whence: c_short,
61};
62
63pub const addrinfo = extern struct {
64 flags: c_int,
65 family: c_int,
66 socktype: c_int,
67 protocol: c_int,
68 addrlen: socklen_t,
69 addr: ?*sockaddr,
70 canonname: ?[*:0]u8,
71 next: ?*addrinfo,
72};
73
74pub const EAI = enum(c_int) {
75 /// address family for hostname not supported
76 ADDRFAMILY = -9,
77
78 /// name could not be resolved at this time
79 AGAIN = -3,
80
81 /// flags parameter had an invalid value
82 BADFLAGS = -1,
83
84 /// non-recoverable failure in name resolution
85 FAIL = -4,
86
87 /// address family not recognized
88 FAMILY = -6,
89
90 /// memory allocation failure
91 MEMORY = -10,
92
93 /// no address associated with hostname
94 NODATA = -5,
95
96 /// name does not resolve
97 NONAME = -2,
98
99 /// service not recognized for socket type
100 SERVICE = -8,
101
102 /// intended socket type was not recognized
103 SOCKTYPE = -7,
104
105 /// system error returned in errno
106 SYSTEM = -11,
107
108 /// invalid value for hints
109 BADHINTS = -12,
110
111 /// resolved protocol is unknown
112 PROTOCOL = -13,
113
114 /// argument buffer overflow
115 OVERFLOW = -14,
116
117 _,
118};
119
120pub const EAI_MAX = 15;
121
122pub const msghdr = extern struct {
123 /// optional address
124 msg_name: ?*sockaddr,
125
126 /// size of address
127 msg_namelen: socklen_t,
128
129 /// scatter/gather array
130 msg_iov: [*]iovec,
131
132 /// # elements in msg_iov
133 msg_iovlen: c_uint,
134
135 /// ancillary data
136 msg_control: ?*c_void,
137
138 /// ancillary data buffer len
139 msg_controllen: socklen_t,
140
141 /// flags on received message
142 msg_flags: c_int,
143};
144
145pub const msghdr_const = extern struct {
146 /// optional address
147 msg_name: ?*const sockaddr,
148
149 /// size of address
150 msg_namelen: socklen_t,
151
152 /// scatter/gather array
153 msg_iov: [*]iovec_const,
154
155 /// # elements in msg_iov
156 msg_iovlen: c_uint,
157
158 /// ancillary data
159 msg_control: ?*c_void,
160
161 /// ancillary data buffer len
162 msg_controllen: socklen_t,
163
164 /// flags on received message
165 msg_flags: c_int,
166};
167
168pub const libc_stat = extern struct {
169 mode: mode_t,
170 dev: dev_t,
171 ino: ino_t,
172 nlink: nlink_t,
173 uid: uid_t,
174 gid: gid_t,
175 rdev: dev_t,
176 atim: timespec,
177 mtim: timespec,
178 ctim: timespec,
179 size: off_t,
180 blocks: blkcnt_t,
181 blksize: blksize_t,
182 flags: u32,
183 gen: u32,
184 birthtim: timespec,
185
186 pub fn atime(self: @This()) timespec {
187 return self.atim;
188 }
189
190 pub fn mtime(self: @This()) timespec {
191 return self.mtim;
192 }
193
194 pub fn ctime(self: @This()) timespec {
195 return self.ctim;
196 }
197};
198
199pub const timespec = extern struct {
200 tv_sec: time_t,
201 tv_nsec: c_long,
202};
203
204pub const timeval = extern struct {
205 tv_sec: time_t,
206 tv_usec: c_long,
207};
208
209pub const timezone = extern struct {
210 tz_minuteswest: c_int,
211 tz_dsttime: c_int,
212};
213
214pub const MAXNAMLEN = 255;
215
216pub const dirent = extern struct {
217 d_fileno: ino_t,
218 d_off: off_t,
219 d_reclen: u16,
220 d_type: u8,
221 d_namlen: u8,
222 __d_padding: [4]u8,
223 d_name: [MAXNAMLEN + 1]u8,
224
225 pub fn reclen(self: dirent) u16 {
226 return self.d_reclen;
227 }
228};
229
230pub const in_port_t = u16;
231pub const sa_family_t = u8;
232
233pub const sockaddr = extern struct {
234 /// total length
235 len: u8,
236
237 /// address family
238 family: sa_family_t,
239
240 /// actually longer; address value
241 data: [14]u8,
242};
243
244pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
245
246pub const sockaddr_in = extern struct {
247 len: u8 = @sizeOf(sockaddr_in),
248 family: sa_family_t = AF_INET,
249 port: in_port_t,
250 addr: u32,
251 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
252};
253
254pub const sockaddr_in6 = extern struct {
255 len: u8 = @sizeOf(sockaddr_in6),
256 family: sa_family_t = AF_INET6,
257 port: in_port_t,
258 flowinfo: u32,
259 addr: [16]u8,
260 scope_id: u32,
261};
262
263/// Definitions for UNIX IPC domain.
264pub const sockaddr_un = extern struct {
265 /// total sockaddr length
266 len: u8 = @sizeOf(sockaddr_un),
267
268 /// AF_LOCAL
269 family: sa_family_t = AF_LOCAL,
270
271 /// path name
272 path: [104]u8,
273};
274
275/// get address to use bind()
276pub const AI_PASSIVE = 1;
277
278/// fill ai_canonname
279pub const AI_CANONNAME = 2;
280
281/// prevent host name resolution
282pub const AI_NUMERICHOST = 4;
283
284/// prevent service name resolution
285pub const AI_NUMERICSERV = 16;
286
287/// only if any address is assigned
288pub const AI_ADDRCONFIG = 64;
289
290pub const PATH_MAX = 1024;
291pub const IOV_MAX = 1024;
292
293pub const STDIN_FILENO = 0;
294pub const STDOUT_FILENO = 1;
295pub const STDERR_FILENO = 2;
296
297pub const PROT_NONE = 0;
298pub const PROT_READ = 1;
299pub const PROT_WRITE = 2;
300pub const PROT_EXEC = 4;
301
302pub const CLOCK_REALTIME = 0;
303pub const CLOCK_PROCESS_CPUTIME_ID = 2;
304pub const CLOCK_MONOTONIC = 3;
305pub const CLOCK_THREAD_CPUTIME_ID = 4;
306
307pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
308pub const MAP_SHARED = 0x0001;
309pub const MAP_PRIVATE = 0x0002;
310pub const MAP_FIXED = 0x0010;
311pub const MAP_RENAME = 0;
312pub const MAP_NORESERVE = 0;
313pub const MAP_INHERIT = 0;
314pub const MAP_HASSEMAPHORE = 0;
315pub const MAP_TRYFIXED = 0;
316
317pub const MAP_FILE = 0;
318pub const MAP_ANON = 0x1000;
319pub const MAP_ANONYMOUS = MAP_ANON;
320pub const MAP_STACK = 0x4000;
321pub const MAP_CONCEAL = 0x8000;
322
323pub const WNOHANG = 1;
324pub const WUNTRACED = 2;
325pub const WCONTINUED = 8;
326
327pub const SA_ONSTACK = 0x0001;
328pub const SA_RESTART = 0x0002;
329pub const SA_RESETHAND = 0x0004;
330pub const SA_NOCLDSTOP = 0x0008;
331pub const SA_NODEFER = 0x0010;
332pub const SA_NOCLDWAIT = 0x0020;
333pub const SA_SIGINFO = 0x0040;
334
335pub const SIGHUP = 1;
336pub const SIGINT = 2;
337pub const SIGQUIT = 3;
338pub const SIGILL = 4;
339pub const SIGTRAP = 5;
340pub const SIGABRT = 6;
341pub const SIGIOT = SIGABRT;
342pub const SIGEMT = 7;
343pub const SIGFPE = 8;
344pub const SIGKILL = 9;
345pub const SIGBUS = 10;
346pub const SIGSEGV = 11;
347pub const SIGSYS = 12;
348pub const SIGPIPE = 13;
349pub const SIGALRM = 14;
350pub const SIGTERM = 15;
351pub const SIGURG = 16;
352pub const SIGSTOP = 17;
353pub const SIGTSTP = 18;
354pub const SIGCONT = 19;
355pub const SIGCHLD = 20;
356pub const SIGTTIN = 21;
357pub const SIGTTOU = 22;
358pub const SIGIO = 23;
359pub const SIGXCPU = 24;
360pub const SIGXFSZ = 25;
361pub const SIGVTALRM = 26;
362pub const SIGPROF = 27;
363pub const SIGWINCH = 28;
364pub const SIGINFO = 29;
365pub const SIGUSR1 = 30;
366pub const SIGUSR2 = 31;
367pub const SIGPWR = 32;
368
369// access function
370pub const F_OK = 0; // test for existence of file
371pub const X_OK = 1; // test for execute or search permission
372pub const W_OK = 2; // test for write permission
373pub const R_OK = 4; // test for read permission
374
375/// open for reading only
376pub const O_RDONLY = 0x00000000;
377
378/// open for writing only
379pub const O_WRONLY = 0x00000001;
380
381/// open for reading and writing
382pub const O_RDWR = 0x00000002;
383
384/// mask for above modes
385pub const O_ACCMODE = 0x00000003;
386
387/// no delay
388pub const O_NONBLOCK = 0x00000004;
389
390/// set append mode
391pub const O_APPEND = 0x00000008;
392
393/// open with shared file lock
394pub const O_SHLOCK = 0x00000010;
395
396/// open with exclusive file lock
397pub const O_EXLOCK = 0x00000020;
398
399/// signal pgrp when data ready
400pub const O_ASYNC = 0x00000040;
401
402/// synchronous writes
403pub const O_SYNC = 0x00000080;
404
405/// don't follow symlinks on the last
406pub const O_NOFOLLOW = 0x00000100;
407
408/// create if nonexistent
409pub const O_CREAT = 0x00000200;
410
411/// truncate to zero length
412pub const O_TRUNC = 0x00000400;
413
414/// error if already exists
415pub const O_EXCL = 0x00000800;
416
417/// don't assign controlling terminal
418pub const O_NOCTTY = 0x00008000;
419
420/// write: I/O data completion
421pub const O_DSYNC = O_SYNC;
422
423/// read: I/O completion as for write
424pub const O_RSYNC = O_SYNC;
425
426/// fail if not a directory
427pub const O_DIRECTORY = 0x20000;
428
429/// set close on exec
430pub const O_CLOEXEC = 0x10000;
431
432pub const F_DUPFD = 0;
433pub const F_GETFD = 1;
434pub const F_SETFD = 2;
435pub const F_GETFL = 3;
436pub const F_SETFL = 4;
437
438pub const F_GETOWN = 5;
439pub const F_SETOWN = 6;
440
441pub const F_GETLK = 7;
442pub const F_SETLK = 8;
443pub const F_SETLKW = 9;
444
445pub const F_RDLCK = 1;
446pub const F_UNLCK = 2;
447pub const F_WRLCK = 3;
448
449pub const LOCK_SH = 0x01;
450pub const LOCK_EX = 0x02;
451pub const LOCK_NB = 0x04;
452pub const LOCK_UN = 0x08;
453
454pub const FD_CLOEXEC = 1;
455
456pub const SEEK_SET = 0;
457pub const SEEK_CUR = 1;
458pub const SEEK_END = 2;
459
460pub const SIG_BLOCK = 1;
461pub const SIG_UNBLOCK = 2;
462pub const SIG_SETMASK = 3;
463
464pub const SOCK_STREAM = 1;
465pub const SOCK_DGRAM = 2;
466pub const SOCK_RAW = 3;
467pub const SOCK_RDM = 4;
468pub const SOCK_SEQPACKET = 5;
469
470pub const SOCK_CLOEXEC = 0x8000;
471pub const SOCK_NONBLOCK = 0x4000;
472
473pub const SO_DEBUG = 0x0001;
474pub const SO_ACCEPTCONN = 0x0002;
475pub const SO_REUSEADDR = 0x0004;
476pub const SO_KEEPALIVE = 0x0008;
477pub const SO_DONTROUTE = 0x0010;
478pub const SO_BROADCAST = 0x0020;
479pub const SO_USELOOPBACK = 0x0040;
480pub const SO_LINGER = 0x0080;
481pub const SO_OOBINLINE = 0x0100;
482pub const SO_REUSEPORT = 0x0200;
483pub const SO_TIMESTAMP = 0x0800;
484pub const SO_BINDANY = 0x1000;
485pub const SO_ZEROIZE = 0x2000;
486pub const SO_SNDBUF = 0x1001;
487pub const SO_RCVBUF = 0x1002;
488pub const SO_SNDLOWAT = 0x1003;
489pub const SO_RCVLOWAT = 0x1004;
490pub const SO_SNDTIMEO = 0x1005;
491pub const SO_RCVTIMEO = 0x1006;
492pub const SO_ERROR = 0x1007;
493pub const SO_TYPE = 0x1008;
494pub const SO_NETPROC = 0x1020;
495pub const SO_RTABLE = 0x1021;
496pub const SO_PEERCRED = 0x1022;
497pub const SO_SPLICE = 0x1023;
498pub const SO_DOMAIN = 0x1024;
499pub const SO_PROTOCOL = 0x1025;
500
501pub const SOL_SOCKET = 0xffff;
502
503pub const PF_UNSPEC = AF_UNSPEC;
504pub const PF_LOCAL = AF_LOCAL;
505pub const PF_UNIX = AF_UNIX;
506pub const PF_INET = AF_INET;
507pub const PF_APPLETALK = AF_APPLETALK;
508pub const PF_INET6 = AF_INET6;
509pub const PF_DECnet = AF_DECnet;
510pub const PF_KEY = AF_KEY;
511pub const PF_ROUTE = AF_ROUTE;
512pub const PF_SNA = AF_SNA;
513pub const PF_MPLS = AF_MPLS;
514pub const PF_BLUETOOTH = AF_BLUETOOTH;
515pub const PF_ISDN = AF_ISDN;
516pub const PF_MAX = AF_MAX;
517
518pub const AF_UNSPEC = 0;
519pub const AF_UNIX = 1;
520pub const AF_LOCAL = AF_UNIX;
521pub const AF_INET = 2;
522pub const AF_APPLETALK = 16;
523pub const AF_INET6 = 24;
524pub const AF_KEY = 30;
525pub const AF_ROUTE = 17;
526pub const AF_SNA = 11;
527pub const AF_MPLS = 33;
528pub const AF_BLUETOOTH = 32;
529pub const AF_ISDN = 26;
530pub const AF_MAX = 36;
531
532pub const DT_UNKNOWN = 0;
533pub const DT_FIFO = 1;
534pub const DT_CHR = 2;
535pub const DT_DIR = 4;
536pub const DT_BLK = 6;
537pub const DT_REG = 8;
538pub const DT_LNK = 10;
539pub const DT_SOCK = 12;
540pub const DT_WHT = 14; // XXX
541
542pub const EV_ADD = 0x0001;
543pub const EV_DELETE = 0x0002;
544pub const EV_ENABLE = 0x0004;
545pub const EV_DISABLE = 0x0008;
546pub const EV_ONESHOT = 0x0010;
547pub const EV_CLEAR = 0x0020;
548pub const EV_RECEIPT = 0x0040;
549pub const EV_DISPATCH = 0x0080;
550pub const EV_FLAG1 = 0x2000;
551pub const EV_ERROR = 0x4000;
552pub const EV_EOF = 0x8000;
553
554pub const EVFILT_READ = -1;
555pub const EVFILT_WRITE = -2;
556pub const EVFILT_AIO = -3;
557pub const EVFILT_VNODE = -4;
558pub const EVFILT_PROC = -5;
559pub const EVFILT_SIGNAL = -6;
560pub const EVFILT_TIMER = -7;
561pub const EVFILT_EXCEPT = -9;
562
563// data/hint flags for EVFILT_{READ|WRITE}
564pub const NOTE_LOWAT = 0x0001;
565pub const NOTE_EOF = 0x0002;
566
567// data/hint flags for EVFILT_EXCEPT and EVFILT_{READ|WRITE}
568pub const NOTE_OOB = 0x0004;
569
570// data/hint flags for EVFILT_VNODE
571pub const NOTE_DELETE = 0x0001;
572pub const NOTE_WRITE = 0x0002;
573pub const NOTE_EXTEND = 0x0004;
574pub const NOTE_ATTRIB = 0x0008;
575pub const NOTE_LINK = 0x0010;
576pub const NOTE_RENAME = 0x0020;
577pub const NOTE_REVOKE = 0x0040;
578pub const NOTE_TRUNCATE = 0x0080;
579
580// data/hint flags for EVFILT_PROC
581pub const NOTE_EXIT = 0x80000000;
582pub const NOTE_FORK = 0x40000000;
583pub const NOTE_EXEC = 0x20000000;
584pub const NOTE_PDATAMASK = 0x000fffff;
585pub const NOTE_PCTRLMASK = 0xf0000000;
586pub const NOTE_TRACK = 0x00000001;
587pub const NOTE_TRACKERR = 0x00000002;
588pub const NOTE_CHILD = 0x00000004;
589
590// data/hint flags for EVFILT_DEVICE
591pub const NOTE_CHANGE = 0x00000001;
592
593pub const TIOCCBRK = 0x2000747a;
594pub const TIOCCDTR = 0x20007478;
595pub const TIOCCONS = 0x80047462;
596pub const TIOCDCDTIMESTAMP = 0x40107458;
597pub const TIOCDRAIN = 0x2000745e;
598pub const TIOCEXCL = 0x2000740d;
599pub const TIOCEXT = 0x80047460;
600pub const TIOCFLAG_CDTRCTS = 0x10;
601pub const TIOCFLAG_CLOCAL = 0x2;
602pub const TIOCFLAG_CRTSCTS = 0x4;
603pub const TIOCFLAG_MDMBUF = 0x8;
604pub const TIOCFLAG_SOFTCAR = 0x1;
605pub const TIOCFLUSH = 0x80047410;
606pub const TIOCGETA = 0x402c7413;
607pub const TIOCGETD = 0x4004741a;
608pub const TIOCGFLAGS = 0x4004745d;
609pub const TIOCGLINED = 0x40207442;
610pub const TIOCGPGRP = 0x40047477;
611pub const TIOCGQSIZE = 0x40047481;
612pub const TIOCGRANTPT = 0x20007447;
613pub const TIOCGSID = 0x40047463;
614pub const TIOCGSIZE = 0x40087468;
615pub const TIOCGWINSZ = 0x40087468;
616pub const TIOCMBIC = 0x8004746b;
617pub const TIOCMBIS = 0x8004746c;
618pub const TIOCMGET = 0x4004746a;
619pub const TIOCMSET = 0x8004746d;
620pub const TIOCM_CAR = 0x40;
621pub const TIOCM_CD = 0x40;
622pub const TIOCM_CTS = 0x20;
623pub const TIOCM_DSR = 0x100;
624pub const TIOCM_DTR = 0x2;
625pub const TIOCM_LE = 0x1;
626pub const TIOCM_RI = 0x80;
627pub const TIOCM_RNG = 0x80;
628pub const TIOCM_RTS = 0x4;
629pub const TIOCM_SR = 0x10;
630pub const TIOCM_ST = 0x8;
631pub const TIOCNOTTY = 0x20007471;
632pub const TIOCNXCL = 0x2000740e;
633pub const TIOCOUTQ = 0x40047473;
634pub const TIOCPKT = 0x80047470;
635pub const TIOCPKT_DATA = 0x0;
636pub const TIOCPKT_DOSTOP = 0x20;
637pub const TIOCPKT_FLUSHREAD = 0x1;
638pub const TIOCPKT_FLUSHWRITE = 0x2;
639pub const TIOCPKT_IOCTL = 0x40;
640pub const TIOCPKT_NOSTOP = 0x10;
641pub const TIOCPKT_START = 0x8;
642pub const TIOCPKT_STOP = 0x4;
643pub const TIOCPTMGET = 0x40287446;
644pub const TIOCPTSNAME = 0x40287448;
645pub const TIOCRCVFRAME = 0x80087445;
646pub const TIOCREMOTE = 0x80047469;
647pub const TIOCSBRK = 0x2000747b;
648pub const TIOCSCTTY = 0x20007461;
649pub const TIOCSDTR = 0x20007479;
650pub const TIOCSETA = 0x802c7414;
651pub const TIOCSETAF = 0x802c7416;
652pub const TIOCSETAW = 0x802c7415;
653pub const TIOCSETD = 0x8004741b;
654pub const TIOCSFLAGS = 0x8004745c;
655pub const TIOCSIG = 0x2000745f;
656pub const TIOCSLINED = 0x80207443;
657pub const TIOCSPGRP = 0x80047476;
658pub const TIOCSQSIZE = 0x80047480;
659pub const TIOCSSIZE = 0x80087467;
660pub const TIOCSTART = 0x2000746e;
661pub const TIOCSTAT = 0x80047465;
662pub const TIOCSTI = 0x80017472;
663pub const TIOCSTOP = 0x2000746f;
664pub const TIOCSWINSZ = 0x80087467;
665pub const TIOCUCNTL = 0x80047466;
666pub const TIOCXMTFRAME = 0x80087444;
667
668pub fn WEXITSTATUS(s: u32) u8 {
669 return @intCast(u8, (s >> 8) & 0xff);
670}
671pub fn WTERMSIG(s: u32) u32 {
672 return (s & 0x7f);
673}
674pub fn WSTOPSIG(s: u32) u32 {
675 return WEXITSTATUS(s);
676}
677pub fn WIFEXITED(s: u32) bool {
678 return WTERMSIG(s) == 0;
679}
680
681pub fn WIFCONTINUED(s: u32) bool {
682 return ((s & 0o177777) == 0o177777);
683}
684
685pub fn WIFSTOPPED(s: u32) bool {
686 return (s & 0xff == 0o177);
687}
688
689pub fn WIFSIGNALED(s: u32) bool {
690 return (((s) & 0o177) != 0o177) and (((s) & 0o177) != 0);
691}
692
693pub const winsize = extern struct {
694 ws_row: c_ushort,
695 ws_col: c_ushort,
696 ws_xpixel: c_ushort,
697 ws_ypixel: c_ushort,
698};
699
700const NSIG = 33;
701
702pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
703pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
704pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
705pub const SIG_CATCH = @intToPtr(?Sigaction.sigaction_fn, 2);
706pub const SIG_HOLD = @intToPtr(?Sigaction.sigaction_fn, 3);
707
708/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
709pub const Sigaction = extern struct {
710 pub const handler_fn = fn (c_int) callconv(.C) void;
711 pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const c_void) callconv(.C) void;
712
713 /// signal handler
714 handler: extern union {
715 handler: ?handler_fn,
716 sigaction: ?sigaction_fn,
717 },
718 /// signal mask to apply
719 mask: sigset_t,
720 /// signal options
721 flags: c_uint,
722};
723
724pub const sigval = extern union {
725 int: c_int,
726 ptr: ?*c_void,
727};
728
729pub const siginfo_t = extern struct {
730 signo: c_int,
731 code: c_int,
732 errno: c_int,
733 data: extern union {
734 proc: extern struct {
735 pid: pid_t,
736 pdata: extern union {
737 kill: extern struct {
738 uid: uid_t,
739 value: sigval,
740 },
741 cld: extern struct {
742 utime: clock_t,
743 stime: clock_t,
744 status: c_int,
745 },
746 },
747 },
748 fault: extern struct {
749 addr: ?*c_void,
750 trapno: c_int,
751 },
752 __pad: [128 - 3 * @sizeOf(c_int)]u8,
753 },
754};
755
756comptime {
757 if (@sizeOf(usize) == 4)
758 std.debug.assert(@sizeOf(siginfo_t) == 128)
759 else
760 // Take into account the padding between errno and data fields.
761 std.debug.assert(@sizeOf(siginfo_t) == 136);
762}
763
764pub usingnamespace switch (builtin.target.cpu.arch) {
765 .x86_64 => struct {
766 pub const ucontext_t = extern struct {
767 sc_rdi: c_long,
768 sc_rsi: c_long,
769 sc_rdx: c_long,
770 sc_rcx: c_long,
771 sc_r8: c_long,
772 sc_r9: c_long,
773 sc_r10: c_long,
774 sc_r11: c_long,
775 sc_r12: c_long,
776 sc_r13: c_long,
777 sc_r14: c_long,
778 sc_r15: c_long,
779 sc_rbp: c_long,
780 sc_rbx: c_long,
781 sc_rax: c_long,
782 sc_gs: c_long,
783 sc_fs: c_long,
784 sc_es: c_long,
785 sc_ds: c_long,
786 sc_trapno: c_long,
787 sc_err: c_long,
788 sc_rip: c_long,
789 sc_cs: c_long,
790 sc_rflags: c_long,
791 sc_rsp: c_long,
792 sc_ss: c_long,
793
794 sc_fpstate: fxsave64,
795 __sc_unused: c_int,
796 sc_mask: c_int,
797 sc_cookie: c_long,
798 };
799
800 pub const fxsave64 = packed struct {
801 fx_fcw: u16,
802 fx_fsw: u16,
803 fx_ftw: u8,
804 fx_unused1: u8,
805 fx_fop: u16,
806 fx_rip: u64,
807 fx_rdp: u64,
808 fx_mxcsr: u32,
809 fx_mxcsr_mask: u32,
810 fx_st: [8][2]u64,
811 fx_xmm: [16][2]u64,
812 fx_unused3: [96]u8,
813 };
814 },
815 else => struct {},
816};
817
818pub const sigset_t = c_uint;
819pub const empty_sigset: sigset_t = 0;
820
821pub const E = enum(u16) {
822 /// No error occurred.
823 SUCCESS = 0,
824 PERM = 1, // Operation not permitted
825 NOENT = 2, // No such file or directory
826 SRCH = 3, // No such process
827 INTR = 4, // Interrupted system call
828 IO = 5, // Input/output error
829 NXIO = 6, // Device not configured
830 @"2BIG" = 7, // Argument list too long
831 NOEXEC = 8, // Exec format error
832 BADF = 9, // Bad file descriptor
833 CHILD = 10, // No child processes
834 DEADLK = 11, // Resource deadlock avoided
835 // 11 was AGAIN
836 NOMEM = 12, // Cannot allocate memory
837 ACCES = 13, // Permission denied
838 FAULT = 14, // Bad address
839 NOTBLK = 15, // Block device required
840 BUSY = 16, // Device busy
841 EXIST = 17, // File exists
842 XDEV = 18, // Cross-device link
843 NODEV = 19, // Operation not supported by device
844 NOTDIR = 20, // Not a directory
845 ISDIR = 21, // Is a directory
846 INVAL = 22, // Invalid argument
847 NFILE = 23, // Too many open files in system
848 MFILE = 24, // Too many open files
849 NOTTY = 25, // Inappropriate ioctl for device
850 TXTBSY = 26, // Text file busy
851 FBIG = 27, // File too large
852 NOSPC = 28, // No space left on device
853 SPIPE = 29, // Illegal seek
854 ROFS = 30, // Read-only file system
855 MLINK = 31, // Too many links
856 PIPE = 32, // Broken pipe
857
858 // math software
859 DOM = 33, // Numerical argument out of domain
860 RANGE = 34, // Result too large or too small
861
862 // non-blocking and interrupt i/o
863 // also: WOULDBLOCK: operation would block
864 AGAIN = 35, // Resource temporarily unavailable
865 INPROGRESS = 36, // Operation now in progress
866 ALREADY = 37, // Operation already in progress
867
868 // ipc/network software -- argument errors
869 NOTSOCK = 38, // Socket operation on non-socket
870 DESTADDRREQ = 39, // Destination address required
871 MSGSIZE = 40, // Message too long
872 PROTOTYPE = 41, // Protocol wrong type for socket
873 NOPROTOOPT = 42, // Protocol option not available
874 PROTONOSUPPORT = 43, // Protocol not supported
875 SOCKTNOSUPPORT = 44, // Socket type not supported
876 OPNOTSUPP = 45, // Operation not supported
877 PFNOSUPPORT = 46, // Protocol family not supported
878 AFNOSUPPORT = 47, // Address family not supported by protocol family
879 ADDRINUSE = 48, // Address already in use
880 ADDRNOTAVAIL = 49, // Can't assign requested address
881
882 // ipc/network software -- operational errors
883 NETDOWN = 50, // Network is down
884 NETUNREACH = 51, // Network is unreachable
885 NETRESET = 52, // Network dropped connection on reset
886 CONNABORTED = 53, // Software caused connection abort
887 CONNRESET = 54, // Connection reset by peer
888 NOBUFS = 55, // No buffer space available
889 ISCONN = 56, // Socket is already connected
890 NOTCONN = 57, // Socket is not connected
891 SHUTDOWN = 58, // Can't send after socket shutdown
892 TOOMANYREFS = 59, // Too many references: can't splice
893 TIMEDOUT = 60, // Operation timed out
894 CONNREFUSED = 61, // Connection refused
895
896 LOOP = 62, // Too many levels of symbolic links
897 NAMETOOLONG = 63, // File name too long
898
899 // should be rearranged
900 HOSTDOWN = 64, // Host is down
901 HOSTUNREACH = 65, // No route to host
902 NOTEMPTY = 66, // Directory not empty
903
904 // quotas & mush
905 PROCLIM = 67, // Too many processes
906 USERS = 68, // Too many users
907 DQUOT = 69, // Disc quota exceeded
908
909 // Network File System
910 STALE = 70, // Stale NFS file handle
911 REMOTE = 71, // Too many levels of remote in path
912 BADRPC = 72, // RPC struct is bad
913 RPCMISMATCH = 73, // RPC version wrong
914 PROGUNAVAIL = 74, // RPC prog. not avail
915 PROGMISMATCH = 75, // Program version wrong
916 PROCUNAVAIL = 76, // Bad procedure for program
917
918 NOLCK = 77, // No locks available
919 NOSYS = 78, // Function not implemented
920
921 FTYPE = 79, // Inappropriate file type or format
922 AUTH = 80, // Authentication error
923 NEEDAUTH = 81, // Need authenticator
924 IPSEC = 82, // IPsec processing failure
925 NOATTR = 83, // Attribute not found
926
927 // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
928 ILSEQ = 84, // Illegal byte sequence
929
930 NOMEDIUM = 85, // No medium found
931 MEDIUMTYPE = 86, // Wrong medium type
932 OVERFLOW = 87, // Value too large to be stored in data type
933 CANCELED = 88, // Operation canceled
934 IDRM = 89, // Identifier removed
935 NOMSG = 90, // No message of desired type
936 NOTSUP = 91, // Not supported
937 BADMSG = 92, // Bad or Corrupt message
938 NOTRECOVERABLE = 93, // State not recoverable
939 OWNERDEAD = 94, // Previous owner died
940 PROTO = 95, // Protocol error
941
942 _,
943};
944
945const _MAX_PAGE_SHIFT = switch (builtin.target.cpu.arch) {
946 .i386 => 12,
947 .sparcv9 => 13,
948};
949pub const MINSIGSTKSZ = 1 << _MAX_PAGE_SHIFT;
950pub const SIGSTKSZ = MINSIGSTKSZ + (1 << _MAX_PAGE_SHIFT) * 4;
951
952pub const SS_ONSTACK = 0x0001;
953pub const SS_DISABLE = 0x0004;
954
955pub const stack_t = extern struct {
956 ss_sp: [*]u8,
957 ss_size: usize,
958 ss_flags: c_int,
959};
960
961pub const S_IFMT = 0o170000;
962
963pub const S_IFIFO = 0o010000;
964pub const S_IFCHR = 0o020000;
965pub const S_IFDIR = 0o040000;
966pub const S_IFBLK = 0o060000;
967pub const S_IFREG = 0o100000;
968pub const S_IFLNK = 0o120000;
969pub const S_IFSOCK = 0o140000;
970
971pub const S_ISUID = 0o4000;
972pub const S_ISGID = 0o2000;
973pub const S_ISVTX = 0o1000;
974pub const S_IRWXU = 0o700;
975pub const S_IRUSR = 0o400;
976pub const S_IWUSR = 0o200;
977pub const S_IXUSR = 0o100;
978pub const S_IRWXG = 0o070;
979pub const S_IRGRP = 0o040;
980pub const S_IWGRP = 0o020;
981pub const S_IXGRP = 0o010;
982pub const S_IRWXO = 0o007;
983pub const S_IROTH = 0o004;
984pub const S_IWOTH = 0o002;
985pub const S_IXOTH = 0o001;
986
987pub fn S_ISFIFO(m: u32) bool {
988 return m & S_IFMT == S_IFIFO;
989}
990
991pub fn S_ISCHR(m: u32) bool {
992 return m & S_IFMT == S_IFCHR;
993}
994
995pub fn S_ISDIR(m: u32) bool {
996 return m & S_IFMT == S_IFDIR;
997}
998
999pub fn S_ISBLK(m: u32) bool {
1000 return m & S_IFMT == S_IFBLK;
1001}
1002
1003pub fn S_ISREG(m: u32) bool {
1004 return m & S_IFMT == S_IFREG;
1005}
1006
1007pub fn S_ISLNK(m: u32) bool {
1008 return m & S_IFMT == S_IFLNK;
1009}
1010
1011pub fn S_ISSOCK(m: u32) bool {
1012 return m & S_IFMT == S_IFSOCK;
1013}
1014
1015/// Magic value that specify the use of the current working directory
1016/// to determine the target of relative file paths in the openat() and
1017/// similar syscalls.
1018pub const AT_FDCWD = -100;
1019
1020/// Check access using effective user and group ID
1021pub const AT_EACCESS = 0x01;
1022
1023/// Do not follow symbolic links
1024pub const AT_SYMLINK_NOFOLLOW = 0x02;
1025
1026/// Follow symbolic link
1027pub const AT_SYMLINK_FOLLOW = 0x04;
1028
1029/// Remove directory instead of file
1030pub const AT_REMOVEDIR = 0x08;
1031
1032pub const HOST_NAME_MAX = 255;
1033
1034/// dummy for IP
1035pub const IPPROTO_IP = 0;
1036
1037/// IP6 hop-by-hop options
1038pub const IPPROTO_HOPOPTS = IPPROTO_IP;
1039
1040/// control message protocol
1041pub const IPPROTO_ICMP = 1;
1042
1043/// group mgmt protocol
1044pub const IPPROTO_IGMP = 2;
1045
1046/// gateway^2 (deprecated)
1047pub const IPPROTO_GGP = 3;
1048
1049/// IP header
1050pub const IPPROTO_IPV4 = IPPROTO_IPIP;
1051
1052/// IP inside IP
1053pub const IPPROTO_IPIP = 4;
1054
1055/// tcp
1056pub const IPPROTO_TCP = 6;
1057
1058/// exterior gateway protocol
1059pub const IPPROTO_EGP = 8;
1060
1061/// pup
1062pub const IPPROTO_PUP = 12;
1063
1064/// user datagram protocol
1065pub const IPPROTO_UDP = 17;
1066
1067/// xns idp
1068pub const IPPROTO_IDP = 22;
1069
1070/// tp-4 w/ class negotiation
1071pub const IPPROTO_TP = 29;
1072
1073/// IP6 header
1074pub const IPPROTO_IPV6 = 41;
1075
1076/// IP6 routing header
1077pub const IPPROTO_ROUTING = 43;
1078
1079/// IP6 fragmentation header
1080pub const IPPROTO_FRAGMENT = 44;
1081
1082/// resource reservation
1083pub const IPPROTO_RSVP = 46;
1084
1085/// GRE encaps RFC 1701
1086pub const IPPROTO_GRE = 47;
1087
1088/// encap. security payload
1089pub const IPPROTO_ESP = 50;
1090
1091/// authentication header
1092pub const IPPROTO_AH = 51;
1093
1094/// IP Mobility RFC 2004
1095pub const IPPROTO_MOBILE = 55;
1096
1097/// IPv6 ICMP
1098pub const IPPROTO_IPV6_ICMP = 58;
1099
1100/// ICMP6
1101pub const IPPROTO_ICMPV6 = 58;
1102
1103/// IP6 no next header
1104pub const IPPROTO_NONE = 59;
1105
1106/// IP6 destination option
1107pub const IPPROTO_DSTOPTS = 60;
1108
1109/// ISO cnlp
1110pub const IPPROTO_EON = 80;
1111
1112/// Ethernet-in-IP
1113pub const IPPROTO_ETHERIP = 97;
1114
1115/// encapsulation header
1116pub const IPPROTO_ENCAP = 98;
1117
1118/// Protocol indep. multicast
1119pub const IPPROTO_PIM = 103;
1120
1121/// IP Payload Comp. Protocol
1122pub const IPPROTO_IPCOMP = 108;
1123
1124/// VRRP RFC 2338
1125pub const IPPROTO_VRRP = 112;
1126
1127/// Common Address Resolution Protocol
1128pub const IPPROTO_CARP = 112;
1129
1130/// PFSYNC
1131pub const IPPROTO_PFSYNC = 240;
1132
1133/// raw IP packet
1134pub const IPPROTO_RAW = 255;
1135
1136pub const rlimit_resource = enum(c_int) {
1137 CPU,
1138 FSIZE,
1139 DATA,
1140 STACK,
1141 CORE,
1142 RSS,
1143 MEMLOCK,
1144 NPROC,
1145 NOFILE,
1146
1147 _,
1148};
1149
1150pub const rlim_t = u64;
1151
1152/// No limit
1153pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
1154
1155pub const RLIM_SAVED_MAX = RLIM_INFINITY;
1156pub const RLIM_SAVED_CUR = RLIM_INFINITY;
1157
1158pub const rlimit = extern struct {
1159 /// Soft limit
1160 cur: rlim_t,
1161 /// Hard limit
1162 max: rlim_t,
1163};
1164
1165pub const SHUT_RD = 0;
1166pub const SHUT_WR = 1;
1167pub const SHUT_RDWR = 2;
1168
1169pub const nfds_t = c_uint;
1170
1171pub const pollfd = extern struct {
1172 fd: fd_t,
1173 events: c_short,
1174 revents: c_short,
1175};
1176
1177pub const POLLIN = 0x0001;
1178pub const POLLPRI = 0x0002;
1179pub const POLLOUT = 0x0004;
1180pub const POLLERR = 0x0008;
1181pub const POLLHUP = 0x0010;
1182pub const POLLNVAL = 0x0020;
1183pub const POLLRDNORM = 0x0040;
1184pub const POLLNORM = POLLRDNORM;
1185pub const POLLWRNORM = POLLOUT;
1186pub const POLLRDBAND = 0x0080;
1187pub const POLLWRBAND = 0x0100;
1188
1189// sysctl mib
1190pub const CTL_UNSPEC = 0;
1191pub const CTL_KERN = 1;
1192pub const CTL_VM = 2;
1193pub const CTL_FS = 3;
1194pub const CTL_NET = 4;
1195pub const CTL_DEBUG = 5;
1196pub const CTL_HW = 6;
1197pub const CTL_MACHDEP = 7;
1198
1199pub const CTL_DDB = 9;
1200pub const CTL_VFS = 10;
1201
1202pub const KERN_OSTYPE = 1;
1203pub const KERN_OSRELEASE = 2;
1204pub const KERN_OSREV = 3;
1205pub const KERN_VERSION = 4;
1206pub const KERN_MAXVNODES = 5;
1207pub const KERN_MAXPROC = 6;
1208pub const KERN_MAXFILES = 7;
1209pub const KERN_ARGMAX = 8;
1210pub const KERN_SECURELVL = 9;
1211pub const KERN_HOSTNAME = 10;
1212pub const KERN_HOSTID = 11;
1213pub const KERN_CLOCKRATE = 12;
1214
1215pub const KERN_PROF = 16;
1216pub const KERN_POSIX1 = 17;
1217pub const KERN_NGROUPS = 18;
1218pub const KERN_JOB_CONTROL = 19;
1219pub const KERN_SAVED_IDS = 20;
1220pub const KERN_BOOTTIME = 21;
1221pub const KERN_DOMAINNAME = 22;
1222pub const KERN_MAXPARTITIONS = 23;
1223pub const KERN_RAWPARTITION = 24;
1224pub const KERN_MAXTHREAD = 25;
1225pub const KERN_NTHREADS = 26;
1226pub const KERN_OSVERSION = 27;
1227pub const KERN_SOMAXCONN = 28;
1228pub const KERN_SOMINCONN = 29;
1229
1230pub const KERN_NOSUIDCOREDUMP = 32;
1231pub const KERN_FSYNC = 33;
1232pub const KERN_SYSVMSG = 34;
1233pub const KERN_SYSVSEM = 35;
1234pub const KERN_SYSVSHM = 36;
1235
1236pub const KERN_MSGBUFSIZE = 38;
1237pub const KERN_MALLOCSTATS = 39;
1238pub const KERN_CPTIME = 40;
1239pub const KERN_NCHSTATS = 41;
1240pub const KERN_FORKSTAT = 42;
1241pub const KERN_NSELCOLL = 43;
1242pub const KERN_TTY = 44;
1243pub const KERN_CCPU = 45;
1244pub const KERN_FSCALE = 46;
1245pub const KERN_NPROCS = 47;
1246pub const KERN_MSGBUF = 48;
1247pub const KERN_POOL = 49;
1248pub const KERN_STACKGAPRANDOM = 50;
1249pub const KERN_SYSVIPC_INFO = 51;
1250pub const KERN_ALLOWKMEM = 52;
1251pub const KERN_WITNESSWATCH = 53;
1252pub const KERN_SPLASSERT = 54;
1253pub const KERN_PROC_ARGS = 55;
1254pub const KERN_NFILES = 56;
1255pub const KERN_TTYCOUNT = 57;
1256pub const KERN_NUMVNODES = 58;
1257pub const KERN_MBSTAT = 59;
1258pub const KERN_WITNESS = 60;
1259pub const KERN_SEMINFO = 61;
1260pub const KERN_SHMINFO = 62;
1261pub const KERN_INTRCNT = 63;
1262pub const KERN_WATCHDOG = 64;
1263pub const KERN_ALLOWDT = 65;
1264pub const KERN_PROC = 66;
1265pub const KERN_MAXCLUSTERS = 67;
1266pub const KERN_EVCOUNT = 68;
1267pub const KERN_TIMECOUNTER = 69;
1268pub const KERN_MAXLOCKSPERUID = 70;
1269pub const KERN_CPTIME2 = 71;
1270pub const KERN_CACHEPCT = 72;
1271pub const KERN_FILE = 73;
1272pub const KERN_WXABORT = 74;
1273pub const KERN_CONSDEV = 75;
1274pub const KERN_NETLIVELOCKS = 76;
1275pub const KERN_POOL_DEBUG = 77;
1276pub const KERN_PROC_CWD = 78;
1277pub const KERN_PROC_NOBROADCASTKILL = 79;
1278pub const KERN_PROC_VMMAP = 80;
1279pub const KERN_GLOBAL_PTRACE = 81;
1280pub const KERN_CONSBUFSIZE = 82;
1281pub const KERN_CONSBUF = 83;
1282pub const KERN_AUDIO = 84;
1283pub const KERN_CPUSTATS = 85;
1284pub const KERN_PFSTATUS = 86;
1285pub const KERN_TIMEOUT_STATS = 87;
1286pub const KERN_UTC_OFFSET = 88;
1287pub const KERN_VIDEO = 89;
1288
1289pub const HW_MACHINE = 1;
1290pub const HW_MODEL = 2;
1291pub const HW_NCPU = 3;
1292pub const HW_BYTEORDER = 4;
1293pub const HW_PHYSMEM = 5;
1294pub const HW_USERMEM = 6;
1295pub const HW_PAGESIZE = 7;
1296pub const HW_DISKNAMES = 8;
1297pub const HW_DISKSTATS = 9;
1298pub const HW_DISKCOUNT = 10;
1299pub const HW_SENSORS = 11;
1300pub const HW_CPUSPEED = 12;
1301pub const HW_SETPERF = 13;
1302pub const HW_VENDOR = 14;
1303pub const HW_PRODUCT = 15;
1304pub const HW_VERSION = 16;
1305pub const HW_SERIALNO = 17;
1306pub const HW_UUID = 18;
1307pub const HW_PHYSMEM64 = 19;
1308pub const HW_USERMEM64 = 20;
1309pub const HW_NCPUFOUND = 21;
1310pub const HW_ALLOWPOWERDOWN = 22;
1311pub const HW_PERFPOLICY = 23;
1312pub const HW_SMT = 24;
1313pub const HW_NCPUONLINE = 25;
1314
1315pub const KERN_PROC_ALL = 0;
1316pub const KERN_PROC_PID = 1;
1317pub const KERN_PROC_PGRP = 2;
1318pub const KERN_PROC_SESSION = 3;
1319pub const KERN_PROC_TTY = 4;
1320pub const KERN_PROC_UID = 5;
1321pub const KERN_PROC_RUID = 6;
1322pub const KERN_PROC_KTHREAD = 7;
1323pub const KERN_PROC_SHOW_THREADS = 0x40000000;
1324
1325pub const KERN_PROC_ARGV = 1;
1326pub const KERN_PROC_NARGV = 2;
1327pub const KERN_PROC_ENV = 3;
1328pub const KERN_PROC_NENV = 4;
lib/std/os/bits/wasi.zig deleted-491
...@@ -1,491 +0,0 @@
1// Convenience types and consts used by std.os module
2const builtin = @import("builtin");
3pub const iovec = posix.iovec;
4pub const iovec_const = posix.iovec_const;
5
6pub const STDIN_FILENO = 0;
7pub const STDOUT_FILENO = 1;
8pub const STDERR_FILENO = 2;
9
10pub const mode_t = u32;
11
12pub const time_t = i64; // match https://github.com/CraneStation/wasi-libc
13
14pub const timespec = struct {
15 tv_sec: time_t,
16 tv_nsec: isize,
17
18 pub fn fromTimestamp(tm: timestamp_t) timespec {
19 const tv_sec: timestamp_t = tm / 1_000_000_000;
20 const tv_nsec = tm - tv_sec * 1_000_000_000;
21 return timespec{
22 .tv_sec = @intCast(time_t, tv_sec),
23 .tv_nsec = @intCast(isize, tv_nsec),
24 };
25 }
26
27 pub fn toTimestamp(ts: timespec) timestamp_t {
28 const tm = @intCast(timestamp_t, ts.tv_sec * 1_000_000_000) + @intCast(timestamp_t, ts.tv_nsec);
29 return tm;
30 }
31};
32
33pub const kernel_stat = struct {
34 dev: device_t,
35 ino: inode_t,
36 mode: mode_t,
37 filetype: filetype_t,
38 nlink: linkcount_t,
39 size: filesize_t,
40 atim: timespec,
41 mtim: timespec,
42 ctim: timespec,
43
44 const Self = @This();
45
46 pub fn fromFilestat(stat: filestat_t) Self {
47 return Self{
48 .dev = stat.dev,
49 .ino = stat.ino,
50 .mode = 0,
51 .filetype = stat.filetype,
52 .nlink = stat.nlink,
53 .size = stat.size,
54 .atim = stat.atime(),
55 .mtim = stat.mtime(),
56 .ctim = stat.ctime(),
57 };
58 }
59
60 pub fn atime(self: Self) timespec {
61 return self.atim;
62 }
63
64 pub fn mtime(self: Self) timespec {
65 return self.mtim;
66 }
67
68 pub fn ctime(self: Self) timespec {
69 return self.ctim;
70 }
71};
72
73pub const IOV_MAX = 1024;
74
75pub const AT_REMOVEDIR: u32 = 0x4;
76pub const AT_FDCWD: fd_t = -2;
77
78// As defined in the wasi_snapshot_preview1 spec file:
79// https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/witx/typenames.witx
80pub const advice_t = u8;
81pub const ADVICE_NORMAL: advice_t = 0;
82pub const ADVICE_SEQUENTIAL: advice_t = 1;
83pub const ADVICE_RANDOM: advice_t = 2;
84pub const ADVICE_WILLNEED: advice_t = 3;
85pub const ADVICE_DONTNEED: advice_t = 4;
86pub const ADVICE_NOREUSE: advice_t = 5;
87
88pub const clockid_t = u32;
89pub const CLOCK = struct {
90 pub const REALTIME: clockid_t = 0;
91 pub const MONOTONIC: clockid_t = 1;
92 pub const PROCESS_CPUTIME_ID: clockid_t = 2;
93 pub const THREAD_CPUTIME_ID: clockid_t = 3;
94};
95
96pub const device_t = u64;
97
98pub const dircookie_t = u64;
99pub const DIRCOOKIE_START: dircookie_t = 0;
100
101pub const dirnamlen_t = u32;
102
103pub const dirent_t = extern struct {
104 d_next: dircookie_t,
105 d_ino: inode_t,
106 d_namlen: dirnamlen_t,
107 d_type: filetype_t,
108};
109
110pub const errno_t = enum(u16) {
111 SUCCESS = 0,
112 @"2BIG" = 1,
113 ACCES = 2,
114 ADDRINUSE = 3,
115 ADDRNOTAVAIL = 4,
116 AFNOSUPPORT = 5,
117 /// This is also the error code used for `WOULDBLOCK`.
118 AGAIN = 6,
119 ALREADY = 7,
120 BADF = 8,
121 BADMSG = 9,
122 BUSY = 10,
123 CANCELED = 11,
124 CHILD = 12,
125 CONNABORTED = 13,
126 CONNREFUSED = 14,
127 CONNRESET = 15,
128 DEADLK = 16,
129 DESTADDRREQ = 17,
130 DOM = 18,
131 DQUOT = 19,
132 EXIST = 20,
133 FAULT = 21,
134 FBIG = 22,
135 HOSTUNREACH = 23,
136 IDRM = 24,
137 ILSEQ = 25,
138 INPROGRESS = 26,
139 INTR = 27,
140 INVAL = 28,
141 IO = 29,
142 ISCONN = 30,
143 ISDIR = 31,
144 LOOP = 32,
145 MFILE = 33,
146 MLINK = 34,
147 MSGSIZE = 35,
148 MULTIHOP = 36,
149 NAMETOOLONG = 37,
150 NETDOWN = 38,
151 NETRESET = 39,
152 NETUNREACH = 40,
153 NFILE = 41,
154 NOBUFS = 42,
155 NODEV = 43,
156 NOENT = 44,
157 NOEXEC = 45,
158 NOLCK = 46,
159 NOLINK = 47,
160 NOMEM = 48,
161 NOMSG = 49,
162 NOPROTOOPT = 50,
163 NOSPC = 51,
164 NOSYS = 52,
165 NOTCONN = 53,
166 NOTDIR = 54,
167 NOTEMPTY = 55,
168 NOTRECOVERABLE = 56,
169 NOTSOCK = 57,
170 /// This is also the code used for `NOTSUP`.
171 OPNOTSUPP = 58,
172 NOTTY = 59,
173 NXIO = 60,
174 OVERFLOW = 61,
175 OWNERDEAD = 62,
176 PERM = 63,
177 PIPE = 64,
178 PROTO = 65,
179 PROTONOSUPPORT = 66,
180 PROTOTYPE = 67,
181 RANGE = 68,
182 ROFS = 69,
183 SPIPE = 70,
184 SRCH = 71,
185 STALE = 72,
186 TIMEDOUT = 73,
187 TXTBSY = 74,
188 XDEV = 75,
189 NOTCAPABLE = 76,
190 _,
191};
192pub const E = errno_t;
193
194pub const event_t = extern struct {
195 userdata: userdata_t,
196 @"error": errno_t,
197 @"type": eventtype_t,
198 fd_readwrite: eventfdreadwrite_t,
199};
200
201pub const eventfdreadwrite_t = extern struct {
202 nbytes: filesize_t,
203 flags: eventrwflags_t,
204};
205
206pub const eventrwflags_t = u16;
207pub const EVENT_FD_READWRITE_HANGUP: eventrwflags_t = 0x0001;
208
209pub const eventtype_t = u8;
210pub const EVENTTYPE_CLOCK: eventtype_t = 0;
211pub const EVENTTYPE_FD_READ: eventtype_t = 1;
212pub const EVENTTYPE_FD_WRITE: eventtype_t = 2;
213
214pub const exitcode_t = u32;
215
216pub const fd_t = if (builtin.link_libc) c_int else u32;
217
218pub const fdflags_t = u16;
219pub const FDFLAG_APPEND: fdflags_t = 0x0001;
220pub const FDFLAG_DSYNC: fdflags_t = 0x0002;
221pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004;
222pub const FDFLAG_RSYNC: fdflags_t = 0x0008;
223pub const FDFLAG_SYNC: fdflags_t = 0x0010;
224
225pub const fdstat_t = extern struct {
226 fs_filetype: filetype_t,
227 fs_flags: fdflags_t,
228 fs_rights_base: rights_t,
229 fs_rights_inheriting: rights_t,
230};
231
232pub const filedelta_t = i64;
233
234pub const filesize_t = u64;
235
236pub const filestat_t = extern struct {
237 dev: device_t,
238 ino: inode_t,
239 filetype: filetype_t,
240 nlink: linkcount_t,
241 size: filesize_t,
242 atim: timestamp_t,
243 mtim: timestamp_t,
244 ctim: timestamp_t,
245
246 pub fn atime(self: filestat_t) timespec {
247 return timespec.fromTimestamp(self.atim);
248 }
249
250 pub fn mtime(self: filestat_t) timespec {
251 return timespec.fromTimestamp(self.mtim);
252 }
253
254 pub fn ctime(self: filestat_t) timespec {
255 return timespec.fromTimestamp(self.ctim);
256 }
257};
258
259pub const filetype_t = u8;
260pub const FILETYPE_UNKNOWN: filetype_t = 0;
261pub const FILETYPE_BLOCK_DEVICE: filetype_t = 1;
262pub const FILETYPE_CHARACTER_DEVICE: filetype_t = 2;
263pub const FILETYPE_DIRECTORY: filetype_t = 3;
264pub const FILETYPE_REGULAR_FILE: filetype_t = 4;
265pub const FILETYPE_SOCKET_DGRAM: filetype_t = 5;
266pub const FILETYPE_SOCKET_STREAM: filetype_t = 6;
267pub const FILETYPE_SYMBOLIC_LINK: filetype_t = 7;
268
269pub const fstflags_t = u16;
270pub const FILESTAT_SET_ATIM: fstflags_t = 0x0001;
271pub const FILESTAT_SET_ATIM_NOW: fstflags_t = 0x0002;
272pub const FILESTAT_SET_MTIM: fstflags_t = 0x0004;
273pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008;
274
275pub const inode_t = u64;
276pub const ino_t = inode_t;
277
278pub const linkcount_t = u64;
279
280pub const lookupflags_t = u32;
281pub const LOOKUP_SYMLINK_FOLLOW: lookupflags_t = 0x00000001;
282
283pub usingnamespace if (builtin.link_libc) struct {
284 // Derived from https://github.com/WebAssembly/wasi-libc/blob/main/expected/wasm32-wasi/predefined-macros.txt
285 pub const O_ACCMODE = (O_EXEC | O_RDWR | O_SEARCH);
286 pub const O_APPEND = FDFLAG_APPEND;
287 pub const O_CLOEXEC = (0);
288 pub const O_CREAT = ((1 << 0) << 12); // = __WASI_OFLAGS_CREAT << 12
289 pub const O_DIRECTORY = ((1 << 1) << 12); // = __WASI_OFLAGS_DIRECTORY << 12
290 pub const O_DSYNC = FDFLAG_DSYNC;
291 pub const O_EXCL = ((1 << 2) << 12); // = __WASI_OFLAGS_EXCL << 12
292 pub const O_EXEC = (0x02000000);
293 pub const O_NOCTTY = (0);
294 pub const O_NOFOLLOW = (0x01000000);
295 pub const O_NONBLOCK = (1 << FDFLAG_NONBLOCK);
296 pub const O_RDONLY = (0x04000000);
297 pub const O_RDWR = (O_RDONLY | O_WRONLY);
298 pub const O_RSYNC = (1 << FDFLAG_RSYNC);
299 pub const O_SEARCH = (0x08000000);
300 pub const O_SYNC = (1 << FDFLAG_SYNC);
301 pub const O_TRUNC = ((1 << 3) << 12); // = __WASI_OFLAGS_TRUNC << 12
302 pub const O_TTY_INIT = (0);
303 pub const O_WRONLY = (0x10000000);
304} else struct {
305 pub const oflags_t = u16;
306 pub const O_CREAT: oflags_t = 0x0001;
307 pub const O_DIRECTORY: oflags_t = 0x0002;
308 pub const O_EXCL: oflags_t = 0x0004;
309 pub const O_TRUNC: oflags_t = 0x0008;
310};
311
312pub const preopentype_t = u8;
313pub const PREOPENTYPE_DIR: preopentype_t = 0;
314
315pub const prestat_t = extern struct {
316 pr_type: preopentype_t,
317 u: prestat_u_t,
318};
319
320pub const prestat_dir_t = extern struct {
321 pr_name_len: usize,
322};
323
324pub const prestat_u_t = extern union {
325 dir: prestat_dir_t,
326};
327
328pub const riflags_t = u16;
329pub const SOCK_RECV_PEEK: riflags_t = 0x0001;
330pub const SOCK_RECV_WAITALL: riflags_t = 0x0002;
331
332pub const rights_t = u64;
333pub const RIGHT_FD_DATASYNC: rights_t = 0x0000000000000001;
334pub const RIGHT_FD_READ: rights_t = 0x0000000000000002;
335pub const RIGHT_FD_SEEK: rights_t = 0x0000000000000004;
336pub const RIGHT_FD_FDSTAT_SET_FLAGS: rights_t = 0x0000000000000008;
337pub const RIGHT_FD_SYNC: rights_t = 0x0000000000000010;
338pub const RIGHT_FD_TELL: rights_t = 0x0000000000000020;
339pub const RIGHT_FD_WRITE: rights_t = 0x0000000000000040;
340pub const RIGHT_FD_ADVISE: rights_t = 0x0000000000000080;
341pub const RIGHT_FD_ALLOCATE: rights_t = 0x0000000000000100;
342pub const RIGHT_PATH_CREATE_DIRECTORY: rights_t = 0x0000000000000200;
343pub const RIGHT_PATH_CREATE_FILE: rights_t = 0x0000000000000400;
344pub const RIGHT_PATH_LINK_SOURCE: rights_t = 0x0000000000000800;
345pub const RIGHT_PATH_LINK_TARGET: rights_t = 0x0000000000001000;
346pub const RIGHT_PATH_OPEN: rights_t = 0x0000000000002000;
347pub const RIGHT_FD_READDIR: rights_t = 0x0000000000004000;
348pub const RIGHT_PATH_READLINK: rights_t = 0x0000000000008000;
349pub const RIGHT_PATH_RENAME_SOURCE: rights_t = 0x0000000000010000;
350pub const RIGHT_PATH_RENAME_TARGET: rights_t = 0x0000000000020000;
351pub const RIGHT_PATH_FILESTAT_GET: rights_t = 0x0000000000040000;
352pub const RIGHT_PATH_FILESTAT_SET_SIZE: rights_t = 0x0000000000080000;
353pub const RIGHT_PATH_FILESTAT_SET_TIMES: rights_t = 0x0000000000100000;
354pub const RIGHT_FD_FILESTAT_GET: rights_t = 0x0000000000200000;
355pub const RIGHT_FD_FILESTAT_SET_SIZE: rights_t = 0x0000000000400000;
356pub const RIGHT_FD_FILESTAT_SET_TIMES: rights_t = 0x0000000000800000;
357pub const RIGHT_PATH_SYMLINK: rights_t = 0x0000000001000000;
358pub const RIGHT_PATH_REMOVE_DIRECTORY: rights_t = 0x0000000002000000;
359pub const RIGHT_PATH_UNLINK_FILE: rights_t = 0x0000000004000000;
360pub const RIGHT_POLL_FD_READWRITE: rights_t = 0x0000000008000000;
361pub const RIGHT_SOCK_SHUTDOWN: rights_t = 0x0000000010000000;
362pub const RIGHT_ALL: rights_t = RIGHT_FD_DATASYNC |
363 RIGHT_FD_READ |
364 RIGHT_FD_SEEK |
365 RIGHT_FD_FDSTAT_SET_FLAGS |
366 RIGHT_FD_SYNC |
367 RIGHT_FD_TELL |
368 RIGHT_FD_WRITE |
369 RIGHT_FD_ADVISE |
370 RIGHT_FD_ALLOCATE |
371 RIGHT_PATH_CREATE_DIRECTORY |
372 RIGHT_PATH_CREATE_FILE |
373 RIGHT_PATH_LINK_SOURCE |
374 RIGHT_PATH_LINK_TARGET |
375 RIGHT_PATH_OPEN |
376 RIGHT_FD_READDIR |
377 RIGHT_PATH_READLINK |
378 RIGHT_PATH_RENAME_SOURCE |
379 RIGHT_PATH_RENAME_TARGET |
380 RIGHT_PATH_FILESTAT_GET |
381 RIGHT_PATH_FILESTAT_SET_SIZE |
382 RIGHT_PATH_FILESTAT_SET_TIMES |
383 RIGHT_FD_FILESTAT_GET |
384 RIGHT_FD_FILESTAT_SET_SIZE |
385 RIGHT_FD_FILESTAT_SET_TIMES |
386 RIGHT_PATH_SYMLINK |
387 RIGHT_PATH_REMOVE_DIRECTORY |
388 RIGHT_PATH_UNLINK_FILE |
389 RIGHT_POLL_FD_READWRITE |
390 RIGHT_SOCK_SHUTDOWN;
391
392pub const roflags_t = u16;
393pub const SOCK_RECV_DATA_TRUNCATED: roflags_t = 0x0001;
394
395pub const sdflags_t = u8;
396pub const SHUT_RD: sdflags_t = 0x01;
397pub const SHUT_WR: sdflags_t = 0x02;
398
399pub const siflags_t = u16;
400
401pub const signal_t = u8;
402pub const SIGNONE: signal_t = 0;
403pub const SIGHUP: signal_t = 1;
404pub const SIGINT: signal_t = 2;
405pub const SIGQUIT: signal_t = 3;
406pub const SIGILL: signal_t = 4;
407pub const SIGTRAP: signal_t = 5;
408pub const SIGABRT: signal_t = 6;
409pub const SIGBUS: signal_t = 7;
410pub const SIGFPE: signal_t = 8;
411pub const SIGKILL: signal_t = 9;
412pub const SIGUSR1: signal_t = 10;
413pub const SIGSEGV: signal_t = 11;
414pub const SIGUSR2: signal_t = 12;
415pub const SIGPIPE: signal_t = 13;
416pub const SIGALRM: signal_t = 14;
417pub const SIGTERM: signal_t = 15;
418pub const SIGCHLD: signal_t = 16;
419pub const SIGCONT: signal_t = 17;
420pub const SIGSTOP: signal_t = 18;
421pub const SIGTSTP: signal_t = 19;
422pub const SIGTTIN: signal_t = 20;
423pub const SIGTTOU: signal_t = 21;
424pub const SIGURG: signal_t = 22;
425pub const SIGXCPU: signal_t = 23;
426pub const SIGXFSZ: signal_t = 24;
427pub const SIGVTALRM: signal_t = 25;
428pub const SIGPROF: signal_t = 26;
429pub const SIGWINCH: signal_t = 27;
430pub const SIGPOLL: signal_t = 28;
431pub const SIGPWR: signal_t = 29;
432pub const SIGSYS: signal_t = 30;
433
434pub const subclockflags_t = u16;
435pub const SUBSCRIPTION_CLOCK_ABSTIME: subclockflags_t = 0x0001;
436
437pub const subscription_t = extern struct {
438 userdata: userdata_t,
439 u: subscription_u_t,
440};
441
442pub const subscription_clock_t = extern struct {
443 id: clockid_t,
444 timeout: timestamp_t,
445 precision: timestamp_t,
446 flags: subclockflags_t,
447};
448
449pub const subscription_fd_readwrite_t = extern struct {
450 fd: fd_t,
451};
452
453pub const subscription_u_t = extern struct {
454 tag: eventtype_t,
455 u: subscription_u_u_t,
456};
457
458pub const subscription_u_u_t = extern union {
459 clock: subscription_clock_t,
460 fd_read: subscription_fd_readwrite_t,
461 fd_write: subscription_fd_readwrite_t,
462};
463
464pub const timestamp_t = u64;
465
466pub const userdata_t = u64;
467
468pub const whence_t = u8;
469pub const WHENCE_SET: whence_t = 0;
470pub const WHENCE_CUR: whence_t = 1;
471pub const WHENCE_END: whence_t = 2;
472
473pub const S_IEXEC = S_IXUSR;
474pub const S_IFBLK = 0x6000;
475pub const S_IFCHR = 0x2000;
476pub const S_IFDIR = 0x4000;
477pub const S_IFIFO = 0xc000;
478pub const S_IFLNK = 0xa000;
479pub const S_IFMT = S_IFBLK | S_IFCHR | S_IFDIR | S_IFIFO | S_IFLNK | S_IFREG | S_IFSOCK;
480pub const S_IFREG = 0x8000;
481// There's no concept of UNIX domain socket but we define this value here in order to line with other OSes.
482pub const S_IFSOCK = 0x1;
483
484pub const SEEK_SET = WHENCE_SET;
485pub const SEEK_CUR = WHENCE_CUR;
486pub const SEEK_END = WHENCE_END;
487
488pub const LOCK_SH = 0x1;
489pub const LOCK_EX = 0x2;
490pub const LOCK_NB = 0x4;
491pub const LOCK_UN = 0x8;
lib/std/os/bits/windows.zig deleted-324
...@@ -1,324 +0,0 @@
1// The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime).
2
3usingnamespace @import("../windows/bits.zig");
4const ws2_32 = @import("../windows/ws2_32.zig");
5
6pub const fd_t = HANDLE;
7pub const ino_t = LARGE_INTEGER;
8pub const pid_t = HANDLE;
9pub const mode_t = u0;
10
11pub const PATH_MAX = 260;
12
13pub const time_t = c_longlong;
14
15pub const timespec = extern struct {
16 tv_sec: time_t,
17 tv_nsec: c_long,
18};
19
20pub const timeval = extern struct {
21 tv_sec: c_long,
22 tv_usec: c_long,
23};
24
25pub const sig_atomic_t = c_int;
26
27/// maximum signal number + 1
28pub const NSIG = 23;
29
30// Signal types
31
32/// interrupt
33pub const SIGINT = 2;
34
35/// illegal instruction - invalid function image
36pub const SIGILL = 4;
37
38/// floating point exception
39pub const SIGFPE = 8;
40
41/// segment violation
42pub const SIGSEGV = 11;
43
44/// Software termination signal from kill
45pub const SIGTERM = 15;
46
47/// Ctrl-Break sequence
48pub const SIGBREAK = 21;
49
50/// abnormal termination triggered by abort call
51pub const SIGABRT = 22;
52
53/// SIGABRT compatible with other platforms, same as SIGABRT
54pub const SIGABRT_COMPAT = 6;
55
56// Signal action codes
57
58/// default signal action
59pub const SIG_DFL = 0;
60
61/// ignore signal
62pub const SIG_IGN = 1;
63
64/// return current value
65pub const SIG_GET = 2;
66
67/// signal gets error
68pub const SIG_SGE = 3;
69
70/// acknowledge
71pub const SIG_ACK = 4;
72
73/// Signal error value (returned by signal call on error)
74pub const SIG_ERR = -1;
75
76pub const SEEK_SET = 0;
77pub const SEEK_CUR = 1;
78pub const SEEK_END = 2;
79
80pub const E = enum(u16) {
81 /// No error occurred.
82 SUCCESS = 0,
83 PERM = 1,
84 NOENT = 2,
85 SRCH = 3,
86 INTR = 4,
87 IO = 5,
88 NXIO = 6,
89 @"2BIG" = 7,
90 NOEXEC = 8,
91 BADF = 9,
92 CHILD = 10,
93 AGAIN = 11,
94 NOMEM = 12,
95 ACCES = 13,
96 FAULT = 14,
97 BUSY = 16,
98 EXIST = 17,
99 XDEV = 18,
100 NODEV = 19,
101 NOTDIR = 20,
102 ISDIR = 21,
103 NFILE = 23,
104 MFILE = 24,
105 NOTTY = 25,
106 FBIG = 27,
107 NOSPC = 28,
108 SPIPE = 29,
109 ROFS = 30,
110 MLINK = 31,
111 PIPE = 32,
112 DOM = 33,
113 /// Also means `DEADLOCK`.
114 DEADLK = 36,
115 NAMETOOLONG = 38,
116 NOLCK = 39,
117 NOSYS = 40,
118 NOTEMPTY = 41,
119
120 INVAL = 22,
121 RANGE = 34,
122 ILSEQ = 42,
123
124 // POSIX Supplement
125 ADDRINUSE = 100,
126 ADDRNOTAVAIL = 101,
127 AFNOSUPPORT = 102,
128 ALREADY = 103,
129 BADMSG = 104,
130 CANCELED = 105,
131 CONNABORTED = 106,
132 CONNREFUSED = 107,
133 CONNRESET = 108,
134 DESTADDRREQ = 109,
135 HOSTUNREACH = 110,
136 IDRM = 111,
137 INPROGRESS = 112,
138 ISCONN = 113,
139 LOOP = 114,
140 MSGSIZE = 115,
141 NETDOWN = 116,
142 NETRESET = 117,
143 NETUNREACH = 118,
144 NOBUFS = 119,
145 NODATA = 120,
146 NOLINK = 121,
147 NOMSG = 122,
148 NOPROTOOPT = 123,
149 NOSR = 124,
150 NOSTR = 125,
151 NOTCONN = 126,
152 NOTRECOVERABLE = 127,
153 NOTSOCK = 128,
154 NOTSUP = 129,
155 OPNOTSUPP = 130,
156 OTHER = 131,
157 OVERFLOW = 132,
158 OWNERDEAD = 133,
159 PROTO = 134,
160 PROTONOSUPPORT = 135,
161 PROTOTYPE = 136,
162 TIME = 137,
163 TIMEDOUT = 138,
164 TXTBSY = 139,
165 WOULDBLOCK = 140,
166 DQUOT = 10069,
167 _,
168};
169
170pub const STRUNCATE = 80;
171
172pub const F_OK = 0;
173
174/// Remove directory instead of unlinking file
175pub const AT_REMOVEDIR = 0x200;
176
177pub const in_port_t = u16;
178pub const sa_family_t = ws2_32.ADDRESS_FAMILY;
179pub const socklen_t = ws2_32.socklen_t;
180
181pub const sockaddr = ws2_32.sockaddr;
182pub const sockaddr_in = ws2_32.sockaddr_in;
183pub const sockaddr_in6 = ws2_32.sockaddr_in6;
184pub const sockaddr_un = ws2_32.sockaddr_un;
185
186pub const in6_addr = [16]u8;
187pub const in_addr = u32;
188
189pub const addrinfo = ws2_32.addrinfo;
190
191pub const AF_UNSPEC = ws2_32.AF_UNSPEC;
192pub const AF_UNIX = ws2_32.AF_UNIX;
193pub const AF_INET = ws2_32.AF_INET;
194pub const AF_IMPLINK = ws2_32.AF_IMPLINK;
195pub const AF_PUP = ws2_32.AF_PUP;
196pub const AF_CHAOS = ws2_32.AF_CHAOS;
197pub const AF_NS = ws2_32.AF_NS;
198pub const AF_IPX = ws2_32.AF_IPX;
199pub const AF_ISO = ws2_32.AF_ISO;
200pub const AF_OSI = ws2_32.AF_OSI;
201pub const AF_ECMA = ws2_32.AF_ECMA;
202pub const AF_DATAKIT = ws2_32.AF_DATAKIT;
203pub const AF_CCITT = ws2_32.AF_CCITT;
204pub const AF_SNA = ws2_32.AF_SNA;
205pub const AF_DECnet = ws2_32.AF_DECnet;
206pub const AF_DLI = ws2_32.AF_DLI;
207pub const AF_LAT = ws2_32.AF_LAT;
208pub const AF_HYLINK = ws2_32.AF_HYLINK;
209pub const AF_APPLETALK = ws2_32.AF_APPLETALK;
210pub const AF_NETBIOS = ws2_32.AF_NETBIOS;
211pub const AF_VOICEVIEW = ws2_32.AF_VOICEVIEW;
212pub const AF_FIREFOX = ws2_32.AF_FIREFOX;
213pub const AF_UNKNOWN1 = ws2_32.AF_UNKNOWN1;
214pub const AF_BAN = ws2_32.AF_BAN;
215pub const AF_ATM = ws2_32.AF_ATM;
216pub const AF_INET6 = ws2_32.AF_INET6;
217pub const AF_CLUSTER = ws2_32.AF_CLUSTER;
218pub const AF_12844 = ws2_32.AF_12844;
219pub const AF_IRDA = ws2_32.AF_IRDA;
220pub const AF_NETDES = ws2_32.AF_NETDES;
221pub const AF_TCNPROCESS = ws2_32.AF_TCNPROCESS;
222pub const AF_TCNMESSAGE = ws2_32.AF_TCNMESSAGE;
223pub const AF_ICLFXBM = ws2_32.AF_ICLFXBM;
224pub const AF_BTH = ws2_32.AF_BTH;
225pub const AF_MAX = ws2_32.AF_MAX;
226
227pub const SOCK_STREAM = ws2_32.SOCK_STREAM;
228pub const SOCK_DGRAM = ws2_32.SOCK_DGRAM;
229pub const SOCK_RAW = ws2_32.SOCK_RAW;
230pub const SOCK_RDM = ws2_32.SOCK_RDM;
231pub const SOCK_SEQPACKET = ws2_32.SOCK_SEQPACKET;
232
233/// WARNING: this flag is not supported by windows socket functions directly,
234/// it is only supported by std.os.socket. Be sure that this value does
235/// not share any bits with any of the SOCK_* values.
236pub const SOCK_CLOEXEC = 0x10000;
237/// WARNING: this flag is not supported by windows socket functions directly,
238/// it is only supported by std.os.socket. Be sure that this value does
239/// not share any bits with any of the SOCK_* values.
240pub const SOCK_NONBLOCK = 0x20000;
241
242pub const IPPROTO_ICMP = ws2_32.IPPROTO_ICMP;
243pub const IPPROTO_IGMP = ws2_32.IPPROTO_IGMP;
244pub const BTHPROTO_RFCOMM = ws2_32.BTHPROTO_RFCOMM;
245pub const IPPROTO_TCP = ws2_32.IPPROTO_TCP;
246pub const IPPROTO_UDP = ws2_32.IPPROTO_UDP;
247pub const IPPROTO_ICMPV6 = ws2_32.IPPROTO_ICMPV6;
248pub const IPPROTO_RM = ws2_32.IPPROTO_RM;
249
250pub const nfds_t = c_ulong;
251pub const pollfd = ws2_32.pollfd;
252
253pub const POLLRDNORM = ws2_32.POLLRDNORM;
254pub const POLLRDBAND = ws2_32.POLLRDBAND;
255pub const POLLIN = ws2_32.POLLIN;
256pub const POLLPRI = ws2_32.POLLPRI;
257pub const POLLWRNORM = ws2_32.POLLWRNORM;
258pub const POLLOUT = ws2_32.POLLOUT;
259pub const POLLWRBAND = ws2_32.POLLWRBAND;
260pub const POLLERR = ws2_32.POLLERR;
261pub const POLLHUP = ws2_32.POLLHUP;
262pub const POLLNVAL = ws2_32.POLLNVAL;
263
264pub const SOL_SOCKET = ws2_32.SOL_SOCKET;
265
266pub const SO_DEBUG = ws2_32.SO_DEBUG;
267pub const SO_ACCEPTCONN = ws2_32.SO_ACCEPTCONN;
268pub const SO_REUSEADDR = ws2_32.SO_REUSEADDR;
269pub const SO_KEEPALIVE = ws2_32.SO_KEEPALIVE;
270pub const SO_DONTROUTE = ws2_32.SO_DONTROUTE;
271pub const SO_BROADCAST = ws2_32.SO_BROADCAST;
272pub const SO_USELOOPBACK = ws2_32.SO_USELOOPBACK;
273pub const SO_LINGER = ws2_32.SO_LINGER;
274pub const SO_OOBINLINE = ws2_32.SO_OOBINLINE;
275
276pub const SO_DONTLINGER = ws2_32.SO_DONTLINGER;
277pub const SO_EXCLUSIVEADDRUSE = ws2_32.SO_EXCLUSIVEADDRUSE;
278
279pub const SO_SNDBUF = ws2_32.SO_SNDBUF;
280pub const SO_RCVBUF = ws2_32.SO_RCVBUF;
281pub const SO_SNDLOWAT = ws2_32.SO_SNDLOWAT;
282pub const SO_RCVLOWAT = ws2_32.SO_RCVLOWAT;
283pub const SO_SNDTIMEO = ws2_32.SO_SNDTIMEO;
284pub const SO_RCVTIMEO = ws2_32.SO_RCVTIMEO;
285pub const SO_ERROR = ws2_32.SO_ERROR;
286pub const SO_TYPE = ws2_32.SO_TYPE;
287
288pub const SO_GROUP_ID = ws2_32.SO_GROUP_ID;
289pub const SO_GROUP_PRIORITY = ws2_32.SO_GROUP_PRIORITY;
290pub const SO_MAX_MSG_SIZE = ws2_32.SO_MAX_MSG_SIZE;
291pub const SO_PROTOCOL_INFOA = ws2_32.SO_PROTOCOL_INFOA;
292pub const SO_PROTOCOL_INFOW = ws2_32.SO_PROTOCOL_INFOW;
293
294pub const PVD_CONFIG = ws2_32.PVD_CONFIG;
295pub const SO_CONDITIONAL_ACCEPT = ws2_32.SO_CONDITIONAL_ACCEPT;
296
297pub const TCP_NODELAY = ws2_32.TCP_NODELAY;
298
299pub const O_RDONLY = 0o0;
300pub const O_WRONLY = 0o1;
301pub const O_RDWR = 0o2;
302
303pub const O_CREAT = 0o100;
304pub const O_EXCL = 0o200;
305pub const O_NOCTTY = 0o400;
306pub const O_TRUNC = 0o1000;
307pub const O_APPEND = 0o2000;
308pub const O_NONBLOCK = 0o4000;
309pub const O_DSYNC = 0o10000;
310pub const O_SYNC = 0o4010000;
311pub const O_RSYNC = 0o4010000;
312pub const O_DIRECTORY = 0o200000;
313pub const O_NOFOLLOW = 0o400000;
314pub const O_CLOEXEC = 0o2000000;
315
316pub const O_ASYNC = 0o20000;
317pub const O_DIRECT = 0o40000;
318pub const O_LARGEFILE = 0;
319pub const O_NOATIME = 0o1000000;
320pub const O_PATH = 0o10000000;
321pub const O_TMPFILE = 0o20200000;
322pub const O_NDELAY = O_NONBLOCK;
323
324pub const IFNAMESIZE = 30;
lib/std/os/linux.zig+36-14
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1// This file provides the system interface functions for Linux matching those1//! This file provides the system interface functions for Linux matching those
2// that are provided by libc, whether or not libc is linked. The following2//! that are provided by libc, whether or not libc is linked. The following
3// abstractions are made:3//! abstractions are made:
4// * Work around kernel bugs and limitations. For example, see sendmmsg.4//! * Work around kernel bugs and limitations. For example, see sendmmsg.
5// * Implement all the syscalls in the same way that libc functions will5//! * Implement all the syscalls in the same way that libc functions will
6// provide `rename` when only the `renameat` syscall exists.6//! provide `rename` when only the `renameat` syscall exists.
7// * Does not support POSIX thread cancellation.7//! * Does not support POSIX thread cancellation.
8const std = @import("../std.zig");8const std = @import("../std.zig");
9const assert = std.debug.assert;9const assert = std.debug.assert;
10const maxInt = std.math.maxInt;10const maxInt = std.math.maxInt;
...@@ -63,8 +63,7 @@ pub const blkcnt_t = arch_bits.blkcnt_t;...@@ -63,8 +63,7 @@ pub const blkcnt_t = arch_bits.blkcnt_t;
63pub const blksize_t = arch_bits.blksize_t;63pub const blksize_t = arch_bits.blksize_t;
64pub const dev_t = arch_bits.dev_t;64pub const dev_t = arch_bits.dev_t;
65pub const ino_t = arch_bits.ino_t;65pub const ino_t = arch_bits.ino_t;
66pub const kernel_stat = arch_bits.kernel_stat;66pub const Stat = arch_bits.Stat;
67pub const libc_stat = arch_bits.libc_stat;
68pub const mcontext_t = arch_bits.mcontext_t;67pub const mcontext_t = arch_bits.mcontext_t;
69pub const mode_t = arch_bits.mode_t;68pub const mode_t = arch_bits.mode_t;
70pub const msghdr = arch_bits.msghdr;69pub const msghdr = arch_bits.msghdr;
...@@ -81,7 +80,30 @@ pub const user_desc = arch_bits.user_desc;...@@ -81,7 +80,30 @@ pub const user_desc = arch_bits.user_desc;
81pub const tls = @import("linux/tls.zig");80pub const tls = @import("linux/tls.zig");
82pub const pie = @import("linux/start_pie.zig");81pub const pie = @import("linux/start_pie.zig");
83pub const BPF = @import("linux/bpf.zig");82pub const BPF = @import("linux/bpf.zig");
84pub usingnamespace @import("linux/io_uring.zig");83
84const io_uring = @import("linux/io_uring.zig");
85pub const IO_Uring = io_uring.IO_Uring;
86pub const SubmissionQueue = io_uring.SubmissionQueue;
87pub const CompletionQueue = io_uring.CompletionQueue;
88pub const io_uring_prep_nop = io_uring.io_uring_prep_nop;
89pub const io_uring_prep_fsync = io_uring.io_uring_prep_fsync;
90pub const io_uring_prep_rw = io_uring.io_uring_prep_rw;
91pub const io_uring_prep_read = io_uring.io_uring_prep_read;
92pub const io_uring_prep_write = io_uring.io_uring_prep_write;
93pub const io_uring_prep_readv = io_uring.io_uring_prep_readv;
94pub const io_uring_prep_writev = io_uring.io_uring_prep_writev;
95pub const io_uring_prep_accept = io_uring.io_uring_prep_accept;
96pub const io_uring_prep_connect = io_uring.io_uring_prep_connect;
97pub const io_uring_prep_epoll_ctl = io_uring.io_uring_prep_epoll_ctl;
98pub const io_uring_prep_recv = io_uring.io_uring_prep_recv;
99pub const io_uring_prep_send = io_uring.io_uring_prep_send;
100pub const io_uring_prep_openat = io_uring.io_uring_prep_openat;
101pub const io_uring_prep_close = io_uring.io_uring_prep_close;
102pub const io_uring_prep_timeout = io_uring.io_uring_prep_timeout;
103pub const io_uring_prep_timeout_remove = io_uring.io_uring_prep_timeout_remove;
104pub const io_uring_prep_poll_add = io_uring.io_uring_prep_poll_add;
105pub const io_uring_prep_poll_remove = io_uring.io_uring_prep_poll_remove;
106pub const io_uring_prep_fallocate = io_uring.io_uring_prep_fallocate;
85107
86/// Set by startup code, used by `getauxval`.108/// Set by startup code, used by `getauxval`.
87pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;109pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;
...@@ -1205,7 +1227,7 @@ pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flag...@@ -1205,7 +1227,7 @@ pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flag
1205 return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags);1227 return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags);
1206}1228}
12071229
1208pub fn fstat(fd: i32, stat_buf: *kernel_stat) usize {1230pub fn fstat(fd: i32, stat_buf: *Stat) usize {
1209 if (@hasField(SYS, "fstat64")) {1231 if (@hasField(SYS, "fstat64")) {
1210 return syscall2(.fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));1232 return syscall2(.fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
1211 } else {1233 } else {
...@@ -1213,7 +1235,7 @@ pub fn fstat(fd: i32, stat_buf: *kernel_stat) usize {...@@ -1213,7 +1235,7 @@ pub fn fstat(fd: i32, stat_buf: *kernel_stat) usize {
1213 }1235 }
1214}1236}
12151237
1216pub fn stat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {1238pub fn stat(pathname: [*:0]const u8, statbuf: *Stat) usize {
1217 if (@hasField(SYS, "stat64")) {1239 if (@hasField(SYS, "stat64")) {
1218 return syscall2(.stat64, @ptrToInt(pathname), @ptrToInt(statbuf));1240 return syscall2(.stat64, @ptrToInt(pathname), @ptrToInt(statbuf));
1219 } else {1241 } else {
...@@ -1221,7 +1243,7 @@ pub fn stat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {...@@ -1221,7 +1243,7 @@ pub fn stat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {
1221 }1243 }
1222}1244}
12231245
1224pub fn lstat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {1246pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize {
1225 if (@hasField(SYS, "lstat64")) {1247 if (@hasField(SYS, "lstat64")) {
1226 return syscall2(.lstat64, @ptrToInt(pathname), @ptrToInt(statbuf));1248 return syscall2(.lstat64, @ptrToInt(pathname), @ptrToInt(statbuf));
1227 } else {1249 } else {
...@@ -1229,7 +1251,7 @@ pub fn lstat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {...@@ -1229,7 +1251,7 @@ pub fn lstat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {
1229 }1251 }
1230}1252}
12311253
1232pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *kernel_stat, flags: u32) usize {1254pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *Stat, flags: u32) usize {
1233 if (@hasField(SYS, "fstatat64")) {1255 if (@hasField(SYS, "fstatat64")) {
1234 return syscall4(.fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);1256 return syscall4(.fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
1235 } else {1257 } else {
lib/std/os/linux/test.zig+1-1
...@@ -82,7 +82,7 @@ test "statx" {...@@ -82,7 +82,7 @@ test "statx" {
82 else => unreachable,82 else => unreachable,
83 }83 }
8484
85 var stat_buf: linux.kernel_stat = undefined;85 var stat_buf: linux.Stat = undefined;
86 switch (linux.getErrno(linux.fstatat(file.handle, "", &stat_buf, linux.AT_EMPTY_PATH))) {86 switch (linux.getErrno(linux.fstatat(file.handle, "", &stat_buf, linux.AT_EMPTY_PATH))) {
87 .SUCCESS => {},87 .SUCCESS => {},
88 else => unreachable,88 else => unreachable,
lib/std/os/linux/x86_64.zig+4-4
...@@ -112,6 +112,9 @@ pub fn restore_rt() callconv(.Naked) void {...@@ -112,6 +112,9 @@ pub fn restore_rt() callconv(.Naked) void {
112112
113pub const mode_t = usize;113pub const mode_t = usize;
114pub const time_t = isize;114pub const time_t = isize;
115pub const nlink_t = usize;
116pub const blksize_t = isize;
117pub const blkcnt_t = isize;
115118
116pub const SYS = enum(usize) {119pub const SYS = enum(usize) {
117 read = 0,120 read = 0,
...@@ -664,7 +667,7 @@ pub const ino_t = u64;...@@ -664,7 +667,7 @@ pub const ino_t = u64;
664pub const dev_t = u64;667pub const dev_t = u64;
665668
666// The `stat` definition used by the Linux kernel.669// The `stat` definition used by the Linux kernel.
667pub const kernel_stat = extern struct {670pub const Stat = extern struct {
668 dev: dev_t,671 dev: dev_t,
669 ino: ino_t,672 ino: ino_t,
670 nlink: usize,673 nlink: usize,
...@@ -696,9 +699,6 @@ pub const kernel_stat = extern struct {...@@ -696,9 +699,6 @@ pub const kernel_stat = extern struct {
696 }699 }
697};700};
698701
699// The `stat64` definition used by the libc.
700pub const libc_stat = kernel_stat;
701
702pub const timespec = extern struct {702pub const timespec = extern struct {
703 tv_sec: isize,703 tv_sec: isize,
704 tv_nsec: isize,704 tv_nsec: isize,
lib/std/os/wasi.zig+468-2
...@@ -15,8 +15,8 @@ comptime {...@@ -15,8 +15,8 @@ comptime {
15 // assert(@alignOf(u64) == 8);15 // assert(@alignOf(u64) == 8);
16}16}
1717
18pub const iovec_t = iovec;18pub const iovec_t = std.os.iovec;
19pub const ciovec_t = iovec_const;19pub const ciovec_t = std.os.iovec_const;
2020
21pub extern "wasi_snapshot_preview1" fn args_get(argv: [*][*:0]u8, argv_buf: [*]u8) errno_t;21pub extern "wasi_snapshot_preview1" fn args_get(argv: [*][*:0]u8, argv_buf: [*]u8) errno_t;
22pub extern "wasi_snapshot_preview1" fn args_sizes_get(argc: *usize, argv_buf_size: *usize) errno_t;22pub extern "wasi_snapshot_preview1" fn args_sizes_get(argc: *usize, argv_buf_size: *usize) errno_t;
...@@ -79,3 +79,469 @@ pub extern "wasi_snapshot_preview1" fn sock_shutdown(sock: fd_t, how: sdflags_t)...@@ -79,3 +79,469 @@ pub extern "wasi_snapshot_preview1" fn sock_shutdown(sock: fd_t, how: sdflags_t)
79pub fn getErrno(r: errno_t) errno_t {79pub fn getErrno(r: errno_t) errno_t {
80 return r;80 return r;
81}81}
82
83pub const STDIN_FILENO = 0;
84pub const STDOUT_FILENO = 1;
85pub const STDERR_FILENO = 2;
86
87pub const mode_t = u32;
88
89pub const time_t = i64; // match https://github.com/CraneStation/wasi-libc
90
91pub const timespec = struct {
92 tv_sec: time_t,
93 tv_nsec: isize,
94
95 pub fn fromTimestamp(tm: timestamp_t) timespec {
96 const tv_sec: timestamp_t = tm / 1_000_000_000;
97 const tv_nsec = tm - tv_sec * 1_000_000_000;
98 return timespec{
99 .tv_sec = @intCast(time_t, tv_sec),
100 .tv_nsec = @intCast(isize, tv_nsec),
101 };
102 }
103
104 pub fn toTimestamp(ts: timespec) timestamp_t {
105 const tm = @intCast(timestamp_t, ts.tv_sec * 1_000_000_000) + @intCast(timestamp_t, ts.tv_nsec);
106 return tm;
107 }
108};
109
110pub const Stat = struct {
111 dev: device_t,
112 ino: inode_t,
113 mode: mode_t,
114 filetype: filetype_t,
115 nlink: linkcount_t,
116 size: filesize_t,
117 atim: timespec,
118 mtim: timespec,
119 ctim: timespec,
120
121 const Self = @This();
122
123 pub fn fromFilestat(stat: filestat_t) Self {
124 return Self{
125 .dev = stat.dev,
126 .ino = stat.ino,
127 .mode = 0,
128 .filetype = stat.filetype,
129 .nlink = stat.nlink,
130 .size = stat.size,
131 .atim = stat.atime(),
132 .mtim = stat.mtime(),
133 .ctim = stat.ctime(),
134 };
135 }
136
137 pub fn atime(self: Self) timespec {
138 return self.atim;
139 }
140
141 pub fn mtime(self: Self) timespec {
142 return self.mtim;
143 }
144
145 pub fn ctime(self: Self) timespec {
146 return self.ctim;
147 }
148};
149
150pub const IOV_MAX = 1024;
151
152pub const AT_REMOVEDIR: u32 = 0x4;
153pub const AT_FDCWD: fd_t = -2;
154
155// As defined in the wasi_snapshot_preview1 spec file:
156// https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/witx/typenames.witx
157pub const advice_t = u8;
158pub const ADVICE_NORMAL: advice_t = 0;
159pub const ADVICE_SEQUENTIAL: advice_t = 1;
160pub const ADVICE_RANDOM: advice_t = 2;
161pub const ADVICE_WILLNEED: advice_t = 3;
162pub const ADVICE_DONTNEED: advice_t = 4;
163pub const ADVICE_NOREUSE: advice_t = 5;
164
165pub const clockid_t = u32;
166pub const CLOCK = struct {
167 pub const REALTIME: clockid_t = 0;
168 pub const MONOTONIC: clockid_t = 1;
169 pub const PROCESS_CPUTIME_ID: clockid_t = 2;
170 pub const THREAD_CPUTIME_ID: clockid_t = 3;
171};
172
173pub const device_t = u64;
174
175pub const dircookie_t = u64;
176pub const DIRCOOKIE_START: dircookie_t = 0;
177
178pub const dirnamlen_t = u32;
179
180pub const dirent_t = extern struct {
181 d_next: dircookie_t,
182 d_ino: inode_t,
183 d_namlen: dirnamlen_t,
184 d_type: filetype_t,
185};
186
187pub const errno_t = enum(u16) {
188 SUCCESS = 0,
189 @"2BIG" = 1,
190 ACCES = 2,
191 ADDRINUSE = 3,
192 ADDRNOTAVAIL = 4,
193 AFNOSUPPORT = 5,
194 /// This is also the error code used for `WOULDBLOCK`.
195 AGAIN = 6,
196 ALREADY = 7,
197 BADF = 8,
198 BADMSG = 9,
199 BUSY = 10,
200 CANCELED = 11,
201 CHILD = 12,
202 CONNABORTED = 13,
203 CONNREFUSED = 14,
204 CONNRESET = 15,
205 DEADLK = 16,
206 DESTADDRREQ = 17,
207 DOM = 18,
208 DQUOT = 19,
209 EXIST = 20,
210 FAULT = 21,
211 FBIG = 22,
212 HOSTUNREACH = 23,
213 IDRM = 24,
214 ILSEQ = 25,
215 INPROGRESS = 26,
216 INTR = 27,
217 INVAL = 28,
218 IO = 29,
219 ISCONN = 30,
220 ISDIR = 31,
221 LOOP = 32,
222 MFILE = 33,
223 MLINK = 34,
224 MSGSIZE = 35,
225 MULTIHOP = 36,
226 NAMETOOLONG = 37,
227 NETDOWN = 38,
228 NETRESET = 39,
229 NETUNREACH = 40,
230 NFILE = 41,
231 NOBUFS = 42,
232 NODEV = 43,
233 NOENT = 44,
234 NOEXEC = 45,
235 NOLCK = 46,
236 NOLINK = 47,
237 NOMEM = 48,
238 NOMSG = 49,
239 NOPROTOOPT = 50,
240 NOSPC = 51,
241 NOSYS = 52,
242 NOTCONN = 53,
243 NOTDIR = 54,
244 NOTEMPTY = 55,
245 NOTRECOVERABLE = 56,
246 NOTSOCK = 57,
247 /// This is also the code used for `NOTSUP`.
248 OPNOTSUPP = 58,
249 NOTTY = 59,
250 NXIO = 60,
251 OVERFLOW = 61,
252 OWNERDEAD = 62,
253 PERM = 63,
254 PIPE = 64,
255 PROTO = 65,
256 PROTONOSUPPORT = 66,
257 PROTOTYPE = 67,
258 RANGE = 68,
259 ROFS = 69,
260 SPIPE = 70,
261 SRCH = 71,
262 STALE = 72,
263 TIMEDOUT = 73,
264 TXTBSY = 74,
265 XDEV = 75,
266 NOTCAPABLE = 76,
267 _,
268};
269pub const E = errno_t;
270
271pub const event_t = extern struct {
272 userdata: userdata_t,
273 @"error": errno_t,
274 @"type": eventtype_t,
275 fd_readwrite: eventfdreadwrite_t,
276};
277
278pub const eventfdreadwrite_t = extern struct {
279 nbytes: filesize_t,
280 flags: eventrwflags_t,
281};
282
283pub const eventrwflags_t = u16;
284pub const EVENT_FD_READWRITE_HANGUP: eventrwflags_t = 0x0001;
285
286pub const eventtype_t = u8;
287pub const EVENTTYPE_CLOCK: eventtype_t = 0;
288pub const EVENTTYPE_FD_READ: eventtype_t = 1;
289pub const EVENTTYPE_FD_WRITE: eventtype_t = 2;
290
291pub const exitcode_t = u32;
292
293pub const fd_t = u32;
294
295pub const fdflags_t = u16;
296pub const FDFLAG_APPEND: fdflags_t = 0x0001;
297pub const FDFLAG_DSYNC: fdflags_t = 0x0002;
298pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004;
299pub const FDFLAG_RSYNC: fdflags_t = 0x0008;
300pub const FDFLAG_SYNC: fdflags_t = 0x0010;
301
302pub const fdstat_t = extern struct {
303 fs_filetype: filetype_t,
304 fs_flags: fdflags_t,
305 fs_rights_base: rights_t,
306 fs_rights_inheriting: rights_t,
307};
308
309pub const filedelta_t = i64;
310
311pub const filesize_t = u64;
312
313pub const filestat_t = extern struct {
314 dev: device_t,
315 ino: inode_t,
316 filetype: filetype_t,
317 nlink: linkcount_t,
318 size: filesize_t,
319 atim: timestamp_t,
320 mtim: timestamp_t,
321 ctim: timestamp_t,
322
323 pub fn atime(self: filestat_t) timespec {
324 return timespec.fromTimestamp(self.atim);
325 }
326
327 pub fn mtime(self: filestat_t) timespec {
328 return timespec.fromTimestamp(self.mtim);
329 }
330
331 pub fn ctime(self: filestat_t) timespec {
332 return timespec.fromTimestamp(self.ctim);
333 }
334};
335
336pub const filetype_t = u8;
337pub const FILETYPE_UNKNOWN: filetype_t = 0;
338pub const FILETYPE_BLOCK_DEVICE: filetype_t = 1;
339pub const FILETYPE_CHARACTER_DEVICE: filetype_t = 2;
340pub const FILETYPE_DIRECTORY: filetype_t = 3;
341pub const FILETYPE_REGULAR_FILE: filetype_t = 4;
342pub const FILETYPE_SOCKET_DGRAM: filetype_t = 5;
343pub const FILETYPE_SOCKET_STREAM: filetype_t = 6;
344pub const FILETYPE_SYMBOLIC_LINK: filetype_t = 7;
345
346pub const fstflags_t = u16;
347pub const FILESTAT_SET_ATIM: fstflags_t = 0x0001;
348pub const FILESTAT_SET_ATIM_NOW: fstflags_t = 0x0002;
349pub const FILESTAT_SET_MTIM: fstflags_t = 0x0004;
350pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008;
351
352pub const inode_t = u64;
353pub const ino_t = inode_t;
354
355pub const linkcount_t = u64;
356
357pub const lookupflags_t = u32;
358pub const LOOKUP_SYMLINK_FOLLOW: lookupflags_t = 0x00000001;
359
360pub const oflags_t = u16;
361pub const O = struct {
362 pub const CREAT: oflags_t = 0x0001;
363 pub const DIRECTORY: oflags_t = 0x0002;
364 pub const EXCL: oflags_t = 0x0004;
365 pub const TRUNC: oflags_t = 0x0008;
366};
367
368pub const preopentype_t = u8;
369pub const PREOPENTYPE_DIR: preopentype_t = 0;
370
371pub const prestat_t = extern struct {
372 pr_type: preopentype_t,
373 u: prestat_u_t,
374};
375
376pub const prestat_dir_t = extern struct {
377 pr_name_len: usize,
378};
379
380pub const prestat_u_t = extern union {
381 dir: prestat_dir_t,
382};
383
384pub const riflags_t = u16;
385pub const SOCK_RECV_PEEK: riflags_t = 0x0001;
386pub const SOCK_RECV_WAITALL: riflags_t = 0x0002;
387
388pub const rights_t = u64;
389pub const RIGHT_FD_DATASYNC: rights_t = 0x0000000000000001;
390pub const RIGHT_FD_READ: rights_t = 0x0000000000000002;
391pub const RIGHT_FD_SEEK: rights_t = 0x0000000000000004;
392pub const RIGHT_FD_FDSTAT_SET_FLAGS: rights_t = 0x0000000000000008;
393pub const RIGHT_FD_SYNC: rights_t = 0x0000000000000010;
394pub const RIGHT_FD_TELL: rights_t = 0x0000000000000020;
395pub const RIGHT_FD_WRITE: rights_t = 0x0000000000000040;
396pub const RIGHT_FD_ADVISE: rights_t = 0x0000000000000080;
397pub const RIGHT_FD_ALLOCATE: rights_t = 0x0000000000000100;
398pub const RIGHT_PATH_CREATE_DIRECTORY: rights_t = 0x0000000000000200;
399pub const RIGHT_PATH_CREATE_FILE: rights_t = 0x0000000000000400;
400pub const RIGHT_PATH_LINK_SOURCE: rights_t = 0x0000000000000800;
401pub const RIGHT_PATH_LINK_TARGET: rights_t = 0x0000000000001000;
402pub const RIGHT_PATH_OPEN: rights_t = 0x0000000000002000;
403pub const RIGHT_FD_READDIR: rights_t = 0x0000000000004000;
404pub const RIGHT_PATH_READLINK: rights_t = 0x0000000000008000;
405pub const RIGHT_PATH_RENAME_SOURCE: rights_t = 0x0000000000010000;
406pub const RIGHT_PATH_RENAME_TARGET: rights_t = 0x0000000000020000;
407pub const RIGHT_PATH_FILESTAT_GET: rights_t = 0x0000000000040000;
408pub const RIGHT_PATH_FILESTAT_SET_SIZE: rights_t = 0x0000000000080000;
409pub const RIGHT_PATH_FILESTAT_SET_TIMES: rights_t = 0x0000000000100000;
410pub const RIGHT_FD_FILESTAT_GET: rights_t = 0x0000000000200000;
411pub const RIGHT_FD_FILESTAT_SET_SIZE: rights_t = 0x0000000000400000;
412pub const RIGHT_FD_FILESTAT_SET_TIMES: rights_t = 0x0000000000800000;
413pub const RIGHT_PATH_SYMLINK: rights_t = 0x0000000001000000;
414pub const RIGHT_PATH_REMOVE_DIRECTORY: rights_t = 0x0000000002000000;
415pub const RIGHT_PATH_UNLINK_FILE: rights_t = 0x0000000004000000;
416pub const RIGHT_POLL_FD_READWRITE: rights_t = 0x0000000008000000;
417pub const RIGHT_SOCK_SHUTDOWN: rights_t = 0x0000000010000000;
418pub const RIGHT_ALL: rights_t = RIGHT_FD_DATASYNC |
419 RIGHT_FD_READ |
420 RIGHT_FD_SEEK |
421 RIGHT_FD_FDSTAT_SET_FLAGS |
422 RIGHT_FD_SYNC |
423 RIGHT_FD_TELL |
424 RIGHT_FD_WRITE |
425 RIGHT_FD_ADVISE |
426 RIGHT_FD_ALLOCATE |
427 RIGHT_PATH_CREATE_DIRECTORY |
428 RIGHT_PATH_CREATE_FILE |
429 RIGHT_PATH_LINK_SOURCE |
430 RIGHT_PATH_LINK_TARGET |
431 RIGHT_PATH_OPEN |
432 RIGHT_FD_READDIR |
433 RIGHT_PATH_READLINK |
434 RIGHT_PATH_RENAME_SOURCE |
435 RIGHT_PATH_RENAME_TARGET |
436 RIGHT_PATH_FILESTAT_GET |
437 RIGHT_PATH_FILESTAT_SET_SIZE |
438 RIGHT_PATH_FILESTAT_SET_TIMES |
439 RIGHT_FD_FILESTAT_GET |
440 RIGHT_FD_FILESTAT_SET_SIZE |
441 RIGHT_FD_FILESTAT_SET_TIMES |
442 RIGHT_PATH_SYMLINK |
443 RIGHT_PATH_REMOVE_DIRECTORY |
444 RIGHT_PATH_UNLINK_FILE |
445 RIGHT_POLL_FD_READWRITE |
446 RIGHT_SOCK_SHUTDOWN;
447
448pub const roflags_t = u16;
449pub const SOCK_RECV_DATA_TRUNCATED: roflags_t = 0x0001;
450
451pub const sdflags_t = u8;
452pub const SHUT_RD: sdflags_t = 0x01;
453pub const SHUT_WR: sdflags_t = 0x02;
454
455pub const siflags_t = u16;
456
457pub const signal_t = u8;
458pub const SIGNONE: signal_t = 0;
459pub const SIGHUP: signal_t = 1;
460pub const SIGINT: signal_t = 2;
461pub const SIGQUIT: signal_t = 3;
462pub const SIGILL: signal_t = 4;
463pub const SIGTRAP: signal_t = 5;
464pub const SIGABRT: signal_t = 6;
465pub const SIGBUS: signal_t = 7;
466pub const SIGFPE: signal_t = 8;
467pub const SIGKILL: signal_t = 9;
468pub const SIGUSR1: signal_t = 10;
469pub const SIGSEGV: signal_t = 11;
470pub const SIGUSR2: signal_t = 12;
471pub const SIGPIPE: signal_t = 13;
472pub const SIGALRM: signal_t = 14;
473pub const SIGTERM: signal_t = 15;
474pub const SIGCHLD: signal_t = 16;
475pub const SIGCONT: signal_t = 17;
476pub const SIGSTOP: signal_t = 18;
477pub const SIGTSTP: signal_t = 19;
478pub const SIGTTIN: signal_t = 20;
479pub const SIGTTOU: signal_t = 21;
480pub const SIGURG: signal_t = 22;
481pub const SIGXCPU: signal_t = 23;
482pub const SIGXFSZ: signal_t = 24;
483pub const SIGVTALRM: signal_t = 25;
484pub const SIGPROF: signal_t = 26;
485pub const SIGWINCH: signal_t = 27;
486pub const SIGPOLL: signal_t = 28;
487pub const SIGPWR: signal_t = 29;
488pub const SIGSYS: signal_t = 30;
489
490pub const subclockflags_t = u16;
491pub const SUBSCRIPTION_CLOCK_ABSTIME: subclockflags_t = 0x0001;
492
493pub const subscription_t = extern struct {
494 userdata: userdata_t,
495 u: subscription_u_t,
496};
497
498pub const subscription_clock_t = extern struct {
499 id: clockid_t,
500 timeout: timestamp_t,
501 precision: timestamp_t,
502 flags: subclockflags_t,
503};
504
505pub const subscription_fd_readwrite_t = extern struct {
506 fd: fd_t,
507};
508
509pub const subscription_u_t = extern struct {
510 tag: eventtype_t,
511 u: subscription_u_u_t,
512};
513
514pub const subscription_u_u_t = extern union {
515 clock: subscription_clock_t,
516 fd_read: subscription_fd_readwrite_t,
517 fd_write: subscription_fd_readwrite_t,
518};
519
520pub const timestamp_t = u64;
521
522pub const userdata_t = u64;
523
524pub const whence_t = u8;
525pub const WHENCE_SET: whence_t = 0;
526pub const WHENCE_CUR: whence_t = 1;
527pub const WHENCE_END: whence_t = 2;
528
529pub const S_IEXEC = S_IXUSR;
530pub const S_IFBLK = 0x6000;
531pub const S_IFCHR = 0x2000;
532pub const S_IFDIR = 0x4000;
533pub const S_IFIFO = 0xc000;
534pub const S_IFLNK = 0xa000;
535pub const S_IFMT = S_IFBLK | S_IFCHR | S_IFDIR | S_IFIFO | S_IFLNK | S_IFREG | S_IFSOCK;
536pub const S_IFREG = 0x8000;
537// There's no concept of UNIX domain socket but we define this value here in order to line with other OSes.
538pub const S_IFSOCK = 0x1;
539
540pub const SEEK_SET = WHENCE_SET;
541pub const SEEK_CUR = WHENCE_CUR;
542pub const SEEK_END = WHENCE_END;
543
544pub const LOCK_SH = 0x1;
545pub const LOCK_EX = 0x2;
546pub const LOCK_NB = 0x4;
547pub const LOCK_UN = 0x8;
lib/std/os/windows/ws2_32.zig-1
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2usingnamespace @import("bits.zig");
32
4pub const SOCKET = *opaque {};3pub const SOCKET = *opaque {};
5pub const INVALID_SOCKET = @intToPtr(SOCKET, ~@as(usize, 0));4pub const INVALID_SOCKET = @intToPtr(SOCKET, ~@as(usize, 0));