authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-10-16 04:03:57-07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-10-16 04:03:57-07:00
loge01bc50a47af4b4a8454d56c292e4d5b0780c513
tree1fdf660be59b6c57aaae96f751fe90d850b5d316
parentbacf7272d5d857641913408d01dbe0871d22ac18
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add netbsd


2 files changed, 1047 insertions(+), 0 deletions(-)

netbsd.zig created+1045
......@@ -0,0 +1,1045 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const arch = builtin.target.cpu.arch;
4
5comptime {
6 std.debug.assert(builtin.target.os.tag == .netbsd);
7 std.debug.assert(@bitSizeOf(usize) == 64);
8}
9
10pub const errno = struct {
11 pub const Error = error{
12 Unexpected,
13 EPERM,
14 ENOENT,
15 ESRCH,
16 EINTR,
17 EIO,
18 ENXIO,
19 E2BIG,
20 ENOEXEC,
21 EBADF,
22 ECHILD,
23 EDEADLK,
24 ENOMEM,
25 EACCES,
26 EFAULT,
27 ENOTBLK,
28 EBUSY,
29 EEXIST,
30 EXDEV,
31 ENODEV,
32 ENOTDIR,
33 EISDIR,
34 EINVAL,
35 ENFILE,
36 EMFILE,
37 ENOTTY,
38 ETXTBSY,
39 EFBIG,
40 ENOSPC,
41 ESPIPE,
42 EROFS,
43 EMLINK,
44 EPIPE,
45 EDOM,
46 ERANGE,
47 EAGAIN,
48 EINPROGRESS,
49 EALREADY,
50 ENOTSOCK,
51 EDESTADDRREQ,
52 EMSGSIZE,
53 EPROTOTYPE,
54 ENOPROTOOPT,
55 EPROTONOSUPPORT,
56 ESOCKTNOSUPPORT,
57 EOPNOTSUPP,
58 EPFNOSUPPORT,
59 EAFNOSUPPORT,
60 EADDRINUSE,
61 EADDRNOTAVAIL,
62 ENETDOWN,
63 ENETUNREACH,
64 ENETRESET,
65 ECONNABORTED,
66 ECONNRESET,
67 ENOBUFS,
68 EISCONN,
69 ENOTCONN,
70 ESHUTDOWN,
71 ETOOMANYREFS,
72 ETIMEDOUT,
73 ECONNREFUSED,
74 ELOOP,
75 ENAMETOOLONG,
76 EHOSTDOWN,
77 EHOSTUNREACH,
78 ENOTEMPTY,
79 EPROCLIM,
80 EUSERS,
81 EDQUOT,
82 ESTALE,
83 EREMOTE,
84 EBADRPC,
85 ERPCMISMATCH,
86 EPROGUNAVAIL,
87 EPROGMISMATCH,
88 EPROCUNAVAIL,
89 ENOLCK,
90 ENOSYS,
91 EFTYPE,
92 EAUTH,
93 ENEEDAUTH,
94 EIDRM,
95 ENOMSG,
96 EOVERFLOW,
97 EILSEQ,
98 ENOTSUP,
99 ECANCELED,
100 EBADMSG,
101 ENODATA,
102 ENOSR,
103 ENOSTR,
104 ETIME,
105 ENOATTR,
106 EMULTIHOP,
107 ENOLINK,
108 EPROTO,
109 EOWNERDEAD,
110 ENOTRECOVERABLE,
111 };
112
113 pub const Enum = enum(c_ushort) {
114 EPERM = 1,
115 ENOENT = 2,
116 ESRCH = 3,
117 EINTR = 4,
118 EIO = 5,
119 ENXIO = 6,
120 E2BIG = 7,
121 ENOEXEC = 8,
122 EBADF = 9,
123 ECHILD = 10,
124 EDEADLK = 11,
125 ENOMEM = 12,
126 EACCES = 13,
127 EFAULT = 14,
128 ENOTBLK = 15,
129 EBUSY = 16,
130 EEXIST = 17,
131 EXDEV = 18,
132 ENODEV = 19,
133 ENOTDIR = 20,
134 EISDIR = 21,
135 EINVAL = 22,
136 ENFILE = 23,
137 EMFILE = 24,
138 ENOTTY = 25,
139 ETXTBSY = 26,
140 EFBIG = 27,
141 ENOSPC = 28,
142 ESPIPE = 29,
143 EROFS = 30,
144 EMLINK = 31,
145 EPIPE = 32,
146 EDOM = 33,
147 ERANGE = 34,
148 EAGAIN = 35,
149 EINPROGRESS = 36,
150 EALREADY = 37,
151 ENOTSOCK = 38,
152 EDESTADDRREQ = 39,
153 EMSGSIZE = 40,
154 EPROTOTYPE = 41,
155 ENOPROTOOPT = 42,
156 EPROTONOSUPPORT = 43,
157 ESOCKTNOSUPPORT = 44,
158 EOPNOTSUPP = 45,
159 EPFNOSUPPORT = 46,
160 EAFNOSUPPORT = 47,
161 EADDRINUSE = 48,
162 EADDRNOTAVAIL = 49,
163 ENETDOWN = 50,
164 ENETUNREACH = 51,
165 ENETRESET = 52,
166 ECONNABORTED = 53,
167 ECONNRESET = 54,
168 ENOBUFS = 55,
169 EISCONN = 56,
170 ENOTCONN = 57,
171 ESHUTDOWN = 58,
172 ETOOMANYREFS = 59,
173 ETIMEDOUT = 60,
174 ECONNREFUSED = 61,
175 ELOOP = 62,
176 ENAMETOOLONG = 63,
177 EHOSTDOWN = 64,
178 EHOSTUNREACH = 65,
179 ENOTEMPTY = 66,
180 EPROCLIM = 67,
181 EUSERS = 68,
182 EDQUOT = 69,
183 ESTALE = 70,
184 EREMOTE = 71,
185 EBADRPC = 72,
186 ERPCMISMATCH = 73,
187 EPROGUNAVAIL = 74,
188 EPROGMISMATCH = 75,
189 EPROCUNAVAIL = 76,
190 ENOLCK = 77,
191 ENOSYS = 78,
192 EFTYPE = 79,
193 EAUTH = 80,
194 ENEEDAUTH = 81,
195 EIDRM = 82,
196 ENOMSG = 83,
197 EOVERFLOW = 84,
198 EILSEQ = 85,
199 ENOTSUP = 86,
200 ECANCELED = 87,
201 EBADMSG = 88,
202 ENODATA = 89,
203 ENOSR = 90,
204 ENOSTR = 91,
205 ETIME = 92,
206 ENOATTR = 93,
207 EMULTIHOP = 94,
208 ENOLINK = 95,
209 EPROTO = 96,
210 EOWNERDEAD = 97,
211 ENOTRECOVERABLE = 98,
212
213 pub const EWOULDBLOCK: Enum = .EAGAIN;
214 };
215
216 comptime {
217 // assert Enum is sequential
218 var value: c_ushort = 0; // SUCCESS
219 for (std.enums.values(Enum)) |val| {
220 std.debug.assert(@intFromEnum(val) > value);
221 value = @intFromEnum(val);
222 }
223 }
224 comptime {
225 // sanity test
226 std.debug.assert(@intFromEnum(Enum.EPERM) == 1);
227 }
228 const list = blk: {
229 const values = std.enums.values(Enum);
230 const len = @intFromEnum(values[values.len - 1]) + 1;
231 var errors: [len]Error = @splat(error.Unexpected);
232 for (values) |f| errors[@intFromEnum(f)] = @field(Error, @tagName(f));
233 const final = errors;
234 break :blk final;
235 };
236 pub fn fromInt(code: c_int) Error {
237 @setRuntimeSafety(false);
238 if (code >= list.len) return error.Unexpected;
239 if (code <= 0) return error.Unexpected;
240 return list[@intCast(code)];
241 }
242 pub fn fromLibC() c_int {
243 return libc.__errno().*;
244 }
245};
246
247pub const eai = struct {
248 pub const Error = error{
249 EAI_ADDRFAMILY,
250 EAI_AGAIN,
251 EAI_BADFLAGS,
252 EAI_FAIL,
253 EAI_FAMILY,
254 EAI_MEMORY,
255 EAI_NODATA,
256 EAI_NONAME,
257 EAI_SERVICE,
258 EAI_SOCKTYPE,
259 EAI_SYSTEM,
260 EAI_BADHINTS,
261 EAI_PROTOCOL,
262 EAI_OVERFLOW,
263 };
264
265 pub const Enum = enum(c_int) {
266 EAI_ADDRFAMILY = 1,
267 EAI_AGAIN = 2,
268 EAI_BADFLAGS = 3,
269 EAI_FAIL = 4,
270 EAI_FAMILY = 5,
271 EAI_MEMORY = 6,
272 EAI_NODATA = 7,
273 EAI_NONAME = 8,
274 EAI_SERVICE = 9,
275 EAI_SOCKTYPE = 10,
276 EAI_SYSTEM = 11,
277 EAI_BADHINTS = 12,
278 EAI_PROTOCOL = 13,
279 EAI_OVERFLOW = 14,
280 };
281
282 pub fn fromInt(code: c_int) Error {
283 return switch (@as(Enum, @enumFromInt(code))) {
284 .EAI_ADDRFAMILY => error.EAI_ADDRFAMILY,
285 .EAI_AGAIN => error.EAI_AGAIN,
286 .EAI_BADFLAGS => error.EAI_BADFLAGS,
287 .EAI_FAIL => error.EAI_FAIL,
288 .EAI_FAMILY => error.EAI_FAMILY,
289 .EAI_MEMORY => error.EAI_MEMORY,
290 .EAI_NODATA => error.EAI_NODATA,
291 .EAI_NONAME => error.EAI_NONAME,
292 .EAI_SERVICE => error.EAI_SERVICE,
293 .EAI_SOCKTYPE => error.EAI_SOCKTYPE,
294 .EAI_SYSTEM => error.EAI_SYSTEM,
295 .EAI_BADHINTS => error.EAI_BADHINTS,
296 .EAI_PROTOCOL => error.EAI_PROTOCOL,
297 .EAI_OVERFLOW => error.EAI_OVERFLOW,
298 };
299 }
300};
301
302pub const libc = struct {
303 pub extern fn __errno() *c_int;
304 pub extern fn pipe2(pipefd: *[2]c_int, flag: c_int) c_int;
305 pub extern fn openat(fd: c_int, file: [*:0]const u8, oflag: c_int, ...) c_int;
306 pub extern fn close(fildes: c_int) c_int;
307 pub extern fn fork() pid_t;
308 pub extern fn dup2(fildes: c_int, fildes2: c_int) c_int;
309 pub extern fn _exit(status: c_int) noreturn;
310 pub extern fn fchdir(fildes: c_int) c_int;
311 pub extern fn execvp(file: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) c_int;
312 pub extern fn kill(pid: pid_t, sig: c_int) c_int;
313 pub extern fn poll(fds: [*]struct_pollfd, nfds: nfds_t, timeout: c_int) c_int;
314 pub extern fn read(fd: c_int, buf: [*]u8, count: usize) isize;
315 pub extern fn write(fd: c_int, buf: *const anyopaque, n: usize) isize;
316 pub extern fn waitpid(pid: pid_t, stat_loc: ?*c_int, options: c_int) pid_t;
317 pub extern fn getenv(name: [*:0]const u8) ?[*:0]const u8;
318 pub extern fn exit(status: c_int) noreturn;
319 pub extern fn mkdirat(fd: c_int, path: [*:0]const u8, mode: mode_t) c_int;
320 pub extern fn fstatat(fd: c_int, noalias path: [*:0]const u8, noalias buf: *struct_stat, flag: c_int) c_int;
321 pub extern fn getaddrinfo(noalias nodename: ?[*:0]const u8, noalias servname: ?[*:0]const u8, noalias hints: ?*const struct_addrinfo, noalias res: **const struct_addrinfo) c_int;
322 pub extern fn freeaddrinfo(ai: *const struct_addrinfo) void;
323 pub extern fn socket(domain: c_int, type: c_int, protocol: c_int) c_int;
324 pub extern fn connect(socket: c_int, address: *const struct_sockaddr, address_len: socklen_t) c_int;
325 pub extern fn getrandom(buf: [*]u8, size: usize, flags: c_uint) isize;
326 pub extern fn arc4random_buf(buf: [*]u8, n: usize) void;
327 pub extern fn pthread_mutex_init(mutex: *pthread_mutex_t, attr: ?*const pthread_mutexattr_t) c_int;
328 pub extern fn pthread_mutex_destroy(mutex: *pthread_mutex_t) c_int;
329 pub extern fn pthread_mutex_lock(mutex: *pthread_mutex_t) c_int;
330 pub extern fn pthread_mutex_trylock(mutex: *pthread_mutex_t) c_int;
331 pub extern fn pthread_mutex_unlock(mutex: *pthread_mutex_t) c_int;
332 pub extern fn pthread_cond_init(noalias cond: *pthread_cond_t, noalias attr: ?*const pthread_condattr_t) c_int;
333 pub extern fn pthread_cond_destroy(cond: *pthread_cond_t) c_int;
334 pub extern fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) c_int;
335 pub extern fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const struct_timespec) c_int;
336 pub extern fn pthread_cond_signal(cond: *pthread_cond_t) c_int;
337 pub extern fn pthread_cond_broadcast(cond: *pthread_cond_t) c_int;
338 pub extern fn pthread_rwlock_init(noalias rwlock: *pthread_rwlock_t, noalias attr: ?*const pthread_rwlockattr_t) c_int;
339 pub extern fn pthread_rwlock_destroy(rwlock: *pthread_rwlock_t) c_int;
340 pub extern fn pthread_rwlock_rdlock(rwlock: *pthread_rwlock_t) c_int;
341 pub extern fn pthread_rwlock_tryrdlock(rwlock: *pthread_rwlock_t) c_int;
342 pub extern fn pthread_rwlock_wrlock(rwlock: *pthread_rwlock_t) c_int;
343 pub extern fn pthread_rwlock_trywrlock(rwlock: *pthread_rwlock_t) c_int;
344 pub extern fn pthread_rwlock_unlock(rwlock: *pthread_rwlock_t) c_int;
345 pub extern fn clock_gettime(clock_id: clockid_t, tp: *struct_timespec) c_int;
346 pub extern fn renameat(oldfd: c_int, old: [*:0]const u8, newfd: c_int, new: [*:0]const u8) c_int;
347 pub extern fn send(fd: c_int, buffer: [*]const u8, length: usize, flags: c_int) isize;
348 pub extern fn recv(fd: c_int, buffer: [*]u8, length: usize, flags: c_int) isize;
349 pub extern fn fstat(fd: c_int, buf: *struct_stat) c_int;
350 pub extern fn mmap(addr: ?*anyopaque, len: usize, prot: c_int, flags: c_int, fd: c_int, offset: off_t) *allowzero anyopaque;
351 pub extern fn writev(fd: c_int, iovec: [*]const struct_iovec, count: c_int) isize;
352 pub extern fn faccessat(fd: c_int, path: [*:0]const u8, amode: c_int, flag: c_int) c_int;
353 pub extern fn readlinkat(fd: c_int, noalias path: [*:0]const u8, noalias buf: [*]u8, len: usize) isize;
354 pub extern fn futimens(fd: c_int, times: *const [2]struct_timespec) c_int;
355 pub extern fn setsockopt(fd: c_int, level: c_int, optname: c_int, optval: *const anyopaque, optlen: socklen_t) c_int;
356 pub extern fn bind(socket: c_int, address: *const struct_sockaddr, address_len: socklen_t) c_int;
357 pub extern fn listen(socket: c_int, backlog: c_int) c_int;
358 pub extern fn getsockname(fd: c_int, noalias addr: *struct_sockaddr, noalias len: *socklen_t) c_int;
359 pub extern fn pthread_attr_init(attr: *pthread_attr_t) c_int;
360 pub extern fn pthread_attr_destroy(attr: *pthread_attr_t) c_int;
361 pub extern fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) c_int;
362 pub extern fn pthread_attr_setstacksize(attr: *pthread_attr_t, stacksize: usize) c_int;
363 pub extern fn pthread_create(noalias newthread: *pthread_t, noalias attr: *const pthread_attr_t, start_routine: *const fn (*anyopaque) callconv(.c) ?*anyopaque, noalias arg: *anyopaque) c_int;
364 pub extern fn pthread_detach(thread: pthread_t) c_int;
365 pub extern fn pthread_join(thread: pthread_t, retval: ?*?*anyopaque) c_int;
366 pub extern fn munmap(addr: *const anyopaque, len: usize) c_int;
367 pub extern fn getdents(dirfd: c_int, buf: [*]u8, nbytes: usize) c_int;
368 pub extern fn accept4(socket: c_int, noalias address: ?*struct_sockaddr, noalias address_len: *socklen_t, flags: c_int) c_int;
369 pub extern fn shutdown(socket: c_int, how: c_int) c_int;
370 pub extern fn unlinkat(fd: c_int, name: [*:0]const u8, flag: c_int) c_int;
371};
372
373pub const pid_t = i32;
374pub const gid_t = u32;
375pub const in_addr_t = u32;
376pub const in_port_t = u16;
377pub const mode_t = u32;
378pub const accmode_t = u32;
379pub const off_t = i64;
380pub const sa_family_t = u8;
381pub const socklen_t = c_uint;
382pub const uid_t = u32;
383pub const fsblkcnt_t = u64;
384pub const fsfilcnt_t = u64;
385pub const struct_pollfd = extern struct { fd: c_int, events: c_short, revents: c_short };
386pub const nfds_t = c_uint;
387pub const struct_stat = extern struct { dev: dev_t, mode: mode_t, ino: ino_t, nlink: nlink_t, uid: uid_t, gid: gid_t, rdev: dev_t, atim: struct_timespec, mtim: struct_timespec, ctim: struct_timespec, birthtim: struct_timespec, size: off_t, blocks: blkcnt_t, blksize: blksize_t, flags: u32, gen: u32, spare: [2]u32 };
388pub const dev_t = u64;
389pub const struct_timespec = extern struct { sec: time_t, nsec: c_long };
390pub const blkcnt_t = i64;
391pub const blksize_t = i32;
392pub const daddr_t = i64;
393pub const fixpt_t = u32;
394pub const ino_t = u64;
395pub const nlink_t = u32;
396pub const lwpid_t = i32;
397pub const rlim_t = u64;
398pub const segsz_t = i32;
399pub const swblk_t = i32;
400pub const mqd_t = c_int;
401pub const cpuid_t = c_ulong;
402pub const psetid_t = c_int;
403pub const time_t = i64;
404pub const struct_iovec = extern struct { base: [*]u8, len: usize };
405pub const struct_in_addr = extern struct { addr: in_addr_t };
406pub const struct_in6_addr = extern struct { addr: extern union { a8: [16]u8, a16: [8]u16, a32: [4]u32 } };
407pub const struct_sockaddr = extern struct { len: u8, family: AF, data: [14]u8 };
408pub const struct_sockaddr_in = extern struct { len: u8 = 16, family: AF = .INET, port: in_port_t, addr: struct_in_addr, zero: [8]u8 = @splat(0) };
409pub const struct_sockaddr_in6 = extern struct { len: u8 = 28, family: AF = .INET6, port: in_port_t, flowinfo: u32, addr: struct_in6_addr, scope_id: u32 };
410pub const struct_sockaddr_un = extern struct { len: u8 = 106, family: AF = .UNIX, path: [104]u8 };
411comptime {
412 std.debug.assert(@sizeOf(struct_sockaddr_in) == 16);
413 std.debug.assert(@sizeOf(struct_sockaddr_in6) == 28);
414 std.debug.assert(@sizeOf(struct_sockaddr_un) == 106);
415}
416pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktype: c_int, protocol: c_int, addrlen: socklen_t, canonname: ?[*:0]u8, addr: ?*struct_sockaddr, next: ?*struct_addrinfo };
417pub const clockid_t = c_int;
418pub const struct_dirent = extern struct { fileno: ino_t, reclen: u16, namlen: u16, type: DT, name: [NAME_MAX + 1]u8 };
419pub const struct_timeval = extern struct { sec: time_t, usec: suseconds_t };
420pub const suseconds_t = c_int;
421pub const useconds_t = c_uint;
422
423const impdef = @cImport({
424 @cInclude("pthread.h");
425});
426pub const pthread_t = impdef.pthread_t;
427pub const pthread_attr_t = impdef.pthread_attr_t;
428pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t;
429pub const pthread_mutex_t = impdef.pthread_mutex_t;
430pub const pthread_condattr_t = impdef.pthread_condattr_t;
431pub const pthread_cond_t = impdef.pthread_cond_t;
432pub const pthread_rwlockattr_t = impdef.pthread_rwlockattr_t;
433pub const pthread_rwlock_t = impdef.pthread_rwlock_t;
434
435pub const INT_MAX = std.math.maxInt(c_int);
436pub const ARG_MAX = (256 * 1024);
437pub const CHILD_MAX = 160;
438pub const GID_MAX = 2147483647;
439pub const LINK_MAX = 32767;
440pub const MAX_CANON = 255;
441pub const MAX_INPUT = 255;
442pub const NAME_MAX = 511;
443pub const NGROUPS_MAX = 16;
444pub const UID_MAX = 2147483647;
445pub const OPEN_MAX = 128;
446pub const PATH_MAX = 1024;
447pub const PIPE_BUF = 512;
448pub const BC_BASE_MAX = INT_MAX;
449pub const BC_DIM_MAX = 65535;
450pub const BC_SCALE_MAX = INT_MAX;
451pub const BC_STRING_MAX = INT_MAX;
452pub const COLL_WEIGHTS_MAX = 2;
453pub const EXPR_NEST_MAX = 32;
454pub const LINE_MAX = 2048;
455pub const RE_DUP_MAX = 255;
456
457pub const O = struct {
458 pub const RDONLY = 0x00000000;
459 pub const WRONLY = 0x00000001;
460 pub const RDWR = 0x00000002;
461 pub const ACCMODE = 0x00000003;
462 pub const NONBLOCK = 0x00000004;
463 pub const APPEND = 0x00000008;
464 pub const SHLOCK = 0x00000010;
465 pub const EXLOCK = 0x00000020;
466 pub const ASYNC = 0x00000040;
467 pub const SYNC = 0x00000080;
468 pub const NOFOLLOW = 0x00000100;
469 pub const CREAT = 0x00000200;
470 pub const TRUNC = 0x00000400;
471 pub const EXCL = 0x00000800;
472 pub const NOCTTY = 0x00008000;
473 pub const DSYNC = 0x00010000;
474 pub const RSYNC = 0x00020000;
475 pub const ALT_IO = 0x00040000;
476 pub const DIRECT = 0x00080000;
477 pub const DIRECTORY = 0x00200000;
478 pub const CLOEXEC = 0x00400000;
479 pub const SEARCH = 0x00800000;
480 pub const NOSIGPIPE = 0x01000000;
481 pub const REGULAR = 0x02000000;
482 pub const EXEC = 0x04000000;
483 pub const CLOFORK = 0x08000000;
484};
485
486pub const AT = struct {
487 pub const FDCWD = -100;
488 pub const EACCESS = 0x100;
489 pub const SYMLINK_NOFOLLOW = 0x200;
490 pub const SYMLINK_FOLLOW = 0x400;
491 pub const REMOVEDIR = 0x800;
492};
493
494pub const SIG = struct {
495 pub const HUP = 1;
496 pub const INT = 2;
497 pub const QUIT = 3;
498 pub const ILL = 4;
499 pub const TRAP = 5;
500 pub const ABRT = 6;
501 pub const IOT = ABRT;
502 pub const EMT = 7;
503 pub const FPE = 8;
504 pub const KILL = 9;
505 pub const BUS = 10;
506 pub const SEGV = 11;
507 pub const SYS = 12;
508 pub const PIPE = 13;
509 pub const ALRM = 14;
510 pub const TERM = 15;
511 pub const URG = 16;
512 pub const STOP = 17;
513 pub const TSTP = 18;
514 pub const CONT = 19;
515 pub const CHLD = 20;
516 pub const TTIN = 21;
517 pub const TTOU = 22;
518 pub const IO = 23;
519 pub const XCPU = 24;
520 pub const XFSZ = 25;
521 pub const VTALRM = 26;
522 pub const PROF = 27;
523 pub const WINCH = 28;
524 pub const INFO = 29;
525 pub const USR1 = 30;
526 pub const USR2 = 31;
527 pub const PWR = 32;
528};
529
530pub const POLL = struct {
531 pub const IN = 0x0001;
532 pub const PRI = 0x0002;
533 pub const OUT = 0x0004;
534 pub const RDNORM = 0x0040;
535 pub const WRNORM = OUT;
536 pub const RDBAND = 0x0080;
537 pub const WRBAND = 0x0100;
538 pub const ERR = 0x0008;
539 pub const HUP = 0x0010;
540 pub const NVAL = 0x0020;
541};
542
543pub const W = struct {
544 pub const NOHANG = 0x00000001;
545 pub const STOPPED = 0x00000002;
546 pub const UNTRACED = STOPPED;
547 pub const CONTINUED = 0x00000010;
548 pub const EXITED = 0x00000020;
549 pub const NOWAIT = 0x00010000;
550 pub const ALTSIG = 0x00000004;
551 pub const ALLSIG = 0x00000008;
552 pub const TRAPPED = 0x00000040;
553 pub const NOZOMBIE = 0x00020000;
554 pub const _STOPPED = 0o177;
555 pub const _CONTINUED = 0xffff;
556 pub const COREFLAG = 0o200;
557
558 pub fn _INT(x: c_int) c_int {
559 return x;
560 }
561 pub fn _STATUS(s: c_int) u8 {
562 return @intCast(_INT(s) & 0o177);
563 }
564 pub fn IFSTOPPED(x: c_int) bool {
565 return _STATUS(x) == _STOPPED and !IFCONTINUED(x);
566 }
567 pub fn IFCONTINUED(x: c_int) bool {
568 return _INT(x) == _CONTINUED;
569 }
570 pub fn STOPSIG(x: c_int) u8 {
571 return @truncate(@as(c_uint, @bitCast(_INT(x) >> 8)));
572 }
573 pub fn IFSIGNALED(x: c_int) bool {
574 return !IFSTOPPED(x) and !IFCONTINUED(x) and !IFEXITED(x);
575 }
576 pub fn TERMSIG(x: c_int) u8 {
577 return _STATUS(x);
578 }
579 pub fn IFEXITED(x: c_int) bool {
580 return _STATUS(x) == 0;
581 }
582 pub fn EXITSTATUS(x: c_int) u8 {
583 return @truncate(@as(c_uint, @bitCast(_INT(x) >> 8)));
584 }
585 pub fn COREDUMP(x: c_int) u8 {
586 return @intCast(_INT(x) & COREFLAG);
587 }
588 pub fn _EXITCODE(r: c_int, s: c_int) c_int {
589 return r << 8 | s;
590 }
591 pub fn _STOPCODE(s: c_int) c_int {
592 return s << 8 | _STOPPED;
593 }
594 pub fn _CONTCODE() c_int {
595 return _CONTINUED;
596 }
597};
598
599pub const S = struct {
600 pub const ISUID = 0o004000;
601 pub const ISGID = 0o002000;
602 pub const ISTXT = 0o001000;
603 pub const IRWXU = 0o000700;
604 pub const IRUSR = 0o000400;
605 pub const IWUSR = 0o000200;
606 pub const IXUSR = 0o000100;
607 pub const IREAD = IRUSR;
608 pub const IWRITE = IWUSR;
609 pub const IEXEC = IXUSR;
610 pub const IRWXG = 0o000070;
611 pub const IRGRP = 0o000040;
612 pub const IWGRP = 0o000020;
613 pub const IXGRP = 0o000010;
614 pub const IRWXO = 0o000007;
615 pub const IROTH = 0o000004;
616 pub const IWOTH = 0o000002;
617 pub const IXOTH = 0o000001;
618 pub const IFMT = 0o170000;
619 pub const IFIFO = 0o010000;
620 pub const IFCHR = 0o020000;
621 pub const IFDIR = 0o040000;
622 pub const IFBLK = 0o060000;
623 pub const IFREG = 0o100000;
624 pub const IFLNK = 0o120000;
625 pub const ISVTX = 0o001000;
626 pub const IFSOCK = 0o140000;
627 pub const IFWHT = 0o160000;
628 pub const ARCH1 = 0o200000;
629 pub const ARCH2 = 0o400000;
630};
631
632pub const AF = enum(sa_family_t) {
633 UNSPEC = 0,
634 LOCAL = 1,
635 INET = 2,
636 IMPLINK = 3,
637 PUP = 4,
638 CHAOS = 5,
639 NS = 6,
640 ISO = 7,
641 ECMA = 8,
642 DATAKIT = 9,
643 CCITT = 10,
644 SNA = 11,
645 DECnet = 12,
646 DLI = 13,
647 LAT = 14,
648 HYLINK = 15,
649 APPLETALK = 16,
650 OROUTE = 17,
651 LINK = 18,
652 XTP = 19,
653 COIP = 20,
654 CNT = 21,
655 RTIP = 22,
656 IPX = 23,
657 INET6 = 24,
658 PIP = 25,
659 ISDN = 26,
660 NATM = 27,
661 ARP = 28,
662 KEY = 29,
663 HDRCMPLT = 30,
664 BLUETOOTH = 31,
665 IEEE80211 = 32,
666 MPLS = 33,
667 ROUTE = 34,
668 CAN = 35,
669 ETHER = 36,
670
671 pub const UNIX: AF = .LOCAL;
672 pub const OSI: AF = .ISO;
673 pub const E164: AF = .ISDN;
674};
675
676pub const SOCK = struct {
677 pub const STREAM = 1;
678 pub const DGRAM = 2;
679 pub const RAW = 3;
680 pub const RDM = 4;
681 pub const SEQPACKET = 5;
682 pub const CONN_DGRAM = 6;
683 pub const DCCP = CONN_DGRAM;
684 pub const CLOEXEC = 0x10000000;
685 pub const NONBLOCK = 0x20000000;
686 pub const NOSIGPIPE = 0x40000000;
687 pub const CLOFORK = 0x80000000;
688 pub const FLAGS_MASK = 0xf0000000;
689};
690
691pub const IPPROTO = struct {
692 pub const IP = 0;
693 pub const HOPOPTS = 0;
694 pub const ICMP = 1;
695 pub const IGMP = 2;
696 pub const GGP = 3;
697 pub const IPV4 = 4;
698 pub const IPIP = 4;
699 pub const TCP = 6;
700 pub const EGP = 8;
701 pub const PUP = 12;
702 pub const UDP = 17;
703 pub const IDP = 22;
704 pub const TP = 29;
705 pub const DCCP = 33;
706 pub const IPV6 = 41;
707 pub const ROUTING = 43;
708 pub const FRAGMENT = 44;
709 pub const RSVP = 46;
710 pub const GRE = 47;
711 pub const ESP = 50;
712 pub const AH = 51;
713 pub const MOBILE = 55;
714 pub const IPV6_ICMP = 58;
715 pub const ICMPV6 = 58;
716 pub const NONE = 59;
717 pub const DSTOPTS = 60;
718 pub const EON = 80;
719 pub const ETHERIP = 97;
720 pub const ENCAP = 98;
721 pub const PIM = 103;
722 pub const IPCOMP = 108;
723 pub const VRRP = 112;
724 pub const CARP = 112;
725 pub const L2TP = 115;
726 pub const SCTP = 132;
727 pub const PFSYNC = 240;
728 pub const RAW = 255;
729};
730
731pub const CLOCK = enum(clockid_t) {
732 REALTIME = 0,
733 VIRTUAL = 1,
734 PROF = 2,
735 MONOTONIC = 3,
736 THREAD_CPUTIME_ID = 0x20000000,
737 PROCESS_CPUTIME_ID = 0x40000000,
738 _,
739};
740
741pub const SOL = struct {
742 pub const SOCKET = 0xffff;
743};
744
745pub const SO = struct {
746 pub const DEBUG = 0x0001;
747 pub const ACCEPTCONN = 0x0002;
748 pub const REUSEADDR = 0x0004;
749 pub const KEEPALIVE = 0x0008;
750 pub const DONTROUTE = 0x0010;
751 pub const BROADCAST = 0x0020;
752 pub const USELOOPBACK = 0x0040;
753 pub const LINGER = 0x0080;
754 pub const OOBINLINE = 0x0100;
755 pub const REUSEPORT = 0x0200;
756 pub const OTIMESTAMP = 0x0400;
757 pub const NOSIGPIPE = 0x0800;
758 pub const ACCEPTFILTER = 0x1000;
759 pub const TIMESTAMP = 0x2000;
760 pub const RERROR = 0x4000;
761 pub const DEFOPTS = (DEBUG | REUSEADDR | KEEPALIVE | DONTROUTE | BROADCAST | USELOOPBACK | LINGER | OOBINLINE | REUSEPORT | NOSIGPIPE | TIMESTAMP | RERROR);
762 pub const SNDBUF = 0x1001;
763 pub const RCVBUF = 0x1002;
764 pub const SNDLOWAT = 0x1003;
765 pub const RCVLOWAT = 0x1004;
766 pub const OSNDTIMEO = 0x1005;
767 pub const ORCVTIMEO = 0x1006;
768 pub const ERROR = 0x1007;
769 pub const TYPE = 0x1008;
770 pub const OVERFLOWED = 0x1009;
771 pub const NOHEADER = 0x100a;
772 pub const SNDTIMEO = 0x100b;
773 pub const RCVTIMEO = 0x100c;
774};
775
776pub const DT = enum(u8) {
777 UNKNOWN = 0,
778 FIFO = 1,
779 CHR = 2,
780 DIR = 4,
781 BLK = 6,
782 REG = 8,
783 LNK = 10,
784 SOCK = 12,
785 WHT = 14,
786};
787
788pub const SHUT = enum(c_int) {
789 RD = 0,
790 WR = 1,
791 RDWR = 2,
792};
793
794pub const MAP = struct {
795 pub const SHARED = 0x0001;
796 pub const PRIVATE = 0x0002;
797 pub const REMAPDUP = 0x0004;
798 pub const FIXED = 0x0010;
799 pub const RENAME = 0x0020;
800 pub const NORESERVE = 0x0040;
801 pub const INHERIT = 0x0080;
802 pub const HASSEMAPHORE = 0x0200;
803 pub const TRYFIXED = 0x0400;
804 pub const WIRED = 0x0800;
805 pub const FILE = 0x0000;
806 pub const ANONYMOUS = 0x1000;
807 pub const ANON = ANONYMOUS;
808 pub const STACK = 0x2000;
809 pub const FAILED = -1;
810};
811
812pub const PROT = struct {
813 pub const NONE = 0x00;
814 pub const READ = 0x01;
815 pub const WRITE = 0x02;
816 pub const EXEC = 0x04;
817};
818
819pub fn pipe2(flag: c_int) ![2]c_int {
820 var fildes: [2]c_int = @splat(-1);
821 const rc = libc.pipe2(&fildes, flag);
822 if (rc == -1) return errno.fromInt(errno.fromLibC());
823 std.debug.assert(rc == 0);
824 return fildes;
825}
826pub fn openat(fd: c_int, file: [*:0]const u8, oflag: c_int) errno.Error!c_int {
827 const rc = libc.openat(fd, file, oflag);
828 if (rc == -1) return errno.fromInt(errno.fromLibC());
829 std.debug.assert(rc >= 0);
830 return rc;
831}
832pub fn openat4(fd: c_int, file: [*:0]const u8, oflag: c_int, mode: mode_t) errno.Error!c_int {
833 const rc = libc.openat(fd, file, oflag, mode);
834 if (rc == -1) return errno.fromInt(errno.fromLibC());
835 return rc;
836}
837pub fn close(fd: c_int) errno.Error!void {
838 const rc = libc.close(fd);
839 if (rc == -1) return errno.fromInt(errno.fromLibC());
840 std.debug.assert(rc == 0);
841}
842pub fn fork() !pid_t {
843 const rc = libc.fork();
844 if (rc == -1) return errno.fromInt(errno.fromLibC());
845 std.debug.assert(rc >= 0);
846 return rc;
847}
848pub fn dup2(fildes: c_int, fildes2: c_int) !void {
849 const rc = libc.dup2(fildes, fildes2);
850 if (rc == -1) return errno.fromInt(errno.fromLibC());
851 std.debug.assert(rc >= 0);
852}
853pub fn fchdir(fildes: c_int) !void {
854 const rc = libc.fchdir(fildes);
855 if (rc == -1) return errno.fromInt(errno.fromLibC());
856 std.debug.assert(rc == 0);
857}
858pub fn execvp(file: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) !noreturn {
859 const rc = libc.execvp(file, argv);
860 std.debug.assert(rc == -1);
861 return errno.fromInt(errno.fromLibC());
862}
863pub fn kill(pid: pid_t, sig: c_int) !void {
864 const rc = libc.kill(pid, sig);
865 if (rc == -1) return errno.fromInt(errno.fromLibC());
866 std.debug.assert(rc == 0);
867}
868pub fn poll(fds: []struct_pollfd, timeout_ms: c_int) !c_int {
869 const rc = libc.poll(fds.ptr, @intCast(fds.len), timeout_ms);
870 if (rc == -1) return errno.fromInt(errno.fromLibC());
871 std.debug.assert(rc >= 0);
872 return rc;
873}
874pub fn read(fd: c_int, buf: []u8) errno.Error!usize {
875 const rc = libc.read(fd, buf.ptr, buf.len);
876 if (rc == -1) return errno.fromInt(errno.fromLibC());
877 std.debug.assert(rc >= 0);
878 return @intCast(rc);
879}
880pub fn write(fd: c_int, buf: []const u8) !usize {
881 const rc = libc.write(fd, buf.ptr, buf.len);
882 if (rc == -1) return errno.fromInt(errno.fromLibC());
883 std.debug.assert(rc >= 0);
884 return @intCast(rc);
885}
886pub fn waitpid(pid: pid_t, options: c_int) !struct { pid_t, c_int } {
887 var status: c_int = 0;
888 const rc = libc.waitpid(pid, &status, options);
889 if (rc == -1) return errno.fromInt(errno.fromLibC());
890 std.debug.assert(rc >= 0);
891 return .{ rc, status };
892}
893pub fn getenv(name: [:0]const u8) ?[:0]const u8 {
894 return std.mem.sliceTo(libc.getenv(name.ptr) orelse return null, 0);
895}
896pub fn exit(status: c_int) noreturn {
897 return libc.exit(status);
898}
899pub fn mkdirat(fd: c_int, path: [*:0]const u8, mode: mode_t) errno.Error!void {
900 const rc = libc.mkdirat(fd, path, mode);
901 if (rc == -1) return errno.fromInt(errno.fromLibC());
902 std.debug.assert(rc == 0);
903}
904pub fn fstatat(fd: c_int, path: [*:0]const u8, flag: c_int) errno.Error!struct_stat {
905 var buf: struct_stat = undefined;
906 const rc = libc.fstatat(fd, path, &buf, flag);
907 if (rc == -1) return errno.fromInt(errno.fromLibC());
908 std.debug.assert(rc == 0);
909 return buf;
910}
911pub fn getaddrinfo(noalias nodename: ?[*:0]const u8, noalias servname: ?[*:0]const u8, noalias req: ?*const struct_addrinfo) eai.Error!*const struct_addrinfo {
912 var pai: *const struct_addrinfo = undefined;
913 var hints = std.mem.zeroes(struct_addrinfo);
914 const rc = libc.getaddrinfo(nodename, servname, req orelse &hints, &pai);
915 if (rc > 0) return eai.fromInt(rc);
916 std.debug.assert(rc == 0);
917 return pai;
918}
919pub fn freeaddrinfo(ai: *const struct_addrinfo) void {
920 return libc.freeaddrinfo(ai);
921}
922pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint {
923 const rc = libc.socket(@intFromEnum(domain), ty, protocol);
924 if (rc == -1) return errno.fromInt(errno.fromLibC());
925 std.debug.assert(rc > 0);
926 return @intCast(rc);
927}
928pub fn connect(socketfd: c_uint, address: *const struct_sockaddr, address_len: socklen_t) errno.Error!void {
929 const rc = libc.connect(@intCast(socketfd), address, address_len);
930 if (rc == -1) return errno.fromInt(errno.fromLibC());
931 std.debug.assert(rc == 0);
932}
933pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 {
934 const rc = libc.getrandom(buf.ptr, buf.len, flags);
935 if (rc == -1) return errno.fromInt(errno.fromLibC());
936 std.debug.assert(rc >= 0);
937 return buf[0..@intCast(rc)];
938}
939pub fn clock_gettime(clock_id: CLOCK) !struct_timespec {
940 var tp: struct_timespec = undefined;
941 const rc = libc.clock_gettime(@intFromEnum(clock_id), &tp);
942 if (rc == -1) return errno.fromInt(errno.fromLibC());
943 std.debug.assert(rc == 0);
944 return tp;
945}
946pub fn renameat(oldfd: c_int, old: [*:0]const u8, newfd: c_int, new: [*:0]const u8) !void {
947 const rc = libc.renameat(oldfd, old, newfd, new);
948 if (rc == -1) return errno.fromInt(errno.fromLibC());
949 std.debug.assert(rc == 0);
950}
951pub fn send(socketfd: c_uint, buffer: []const u8, flags: c_int) errno.Error!usize {
952 const rc = libc.send(@intCast(socketfd), buffer.ptr, buffer.len, flags);
953 if (rc == -1) return errno.fromInt(errno.fromLibC());
954 std.debug.assert(rc >= 0);
955 return @intCast(rc);
956}
957pub fn recv(socketfd: c_uint, buffer: []u8, flags: c_int) errno.Error!usize {
958 const rc = libc.recv(@intCast(socketfd), buffer.ptr, buffer.len, flags);
959 if (rc == -1) return errno.fromInt(errno.fromLibC());
960 std.debug.assert(rc >= 0);
961 return @intCast(rc);
962}
963pub fn fstat(fd: c_int) errno.Error!struct_stat {
964 var buf: struct_stat = undefined;
965 const rc = libc.fstat(fd, &buf);
966 if (rc == -1) return errno.fromInt(errno.fromLibC());
967 std.debug.assert(rc == 0);
968 return buf;
969}
970pub fn mmap(addr: ?*anyopaque, len: usize, prot: c_int, flags: c_int, fd: c_int, offset: off_t) errno.Error![]u8 {
971 const rc = libc.mmap(addr, len, prot, flags, fd, offset);
972 if (@intFromPtr(rc) == MAP.FAILED) return errno.fromInt(errno.fromLibC());
973 const ptr: [*]u8 = @ptrCast(rc);
974 return ptr[0..len];
975}
976pub fn writev(fd: c_int, iovec: []const struct_iovec) !usize {
977 const rc = libc.writev(fd, iovec.ptr, @intCast(iovec.len));
978 if (rc == -1) return errno.fromInt(errno.fromLibC());
979 std.debug.assert(rc >= 0);
980 return @intCast(rc);
981}
982pub fn faccessat(fd: c_int, path: [*:0]const u8, amode: c_int, flag: c_int) !void {
983 const rc = libc.faccessat(fd, path, amode, flag);
984 if (rc == -1) return errno.fromInt(errno.fromLibC());
985 std.debug.assert(rc == 0);
986}
987pub fn readlinkat(dirfd: c_int, noalias path: [*:0]const u8, noalias buf: []u8) ![:0]u8 {
988 const rc = libc.readlinkat(dirfd, path, buf.ptr, buf.len);
989 if (rc == -1) return errno.fromInt(errno.fromLibC());
990 std.debug.assert(rc >= 0);
991 buf[@intCast(rc)] = 0;
992 return buf[0..@intCast(rc) :0];
993}
994pub fn futimens(fd: c_int, times: [2]struct_timespec) !void {
995 const rc = libc.futimens(fd, &times);
996 if (rc == -1) return errno.fromInt(errno.fromLibC());
997 std.debug.assert(rc == 0);
998}
999pub fn setsockopt(socketfd: c_uint, level: c_int, optname: c_int, opaque_opt: []const u8) errno.Error!void {
1000 const rc = libc.setsockopt(@intCast(socketfd), level, optname, opaque_opt.ptr, @intCast(opaque_opt.len));
1001 if (rc == -1) return errno.fromInt(errno.fromLibC());
1002 std.debug.assert(rc == 0);
1003}
1004pub fn bind(socketfd: c_uint, address: *const struct_sockaddr, address_len: socklen_t) errno.Error!void {
1005 const rc = libc.bind(@intCast(socketfd), address, address_len);
1006 if (rc == -1) return errno.fromInt(errno.fromLibC());
1007 std.debug.assert(rc == 0);
1008}
1009pub fn listen(socketfd: c_uint, backlog: c_int) errno.Error!void {
1010 const rc = libc.listen(@intCast(socketfd), backlog);
1011 if (rc == -1) return errno.fromInt(errno.fromLibC());
1012 std.debug.assert(rc == 0);
1013}
1014pub fn getsockname(socketfd: c_uint, noalias address: *struct_sockaddr, noalias address_len: *socklen_t) errno.Error!void {
1015 const rc = libc.getsockname(@intCast(socketfd), address, address_len);
1016 if (rc == -1) return errno.fromInt(errno.fromLibC());
1017 std.debug.assert(rc == 0);
1018}
1019pub fn munmap(addr: *const anyopaque, len: usize) errno.Error!void {
1020 const rc = libc.munmap(addr, len);
1021 if (rc == -1) return errno.fromInt(errno.fromLibC());
1022 std.debug.assert(rc == 0);
1023}
1024pub fn getdents(dirfd: c_int, buf: []u8) errno.Error!usize {
1025 const rc = libc.getdents(dirfd, buf.ptr, buf.len);
1026 if (rc == -1) return errno.fromInt(errno.fromLibC());
1027 std.debug.assert(rc >= 0);
1028 return @intCast(rc);
1029}
1030pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias address_len: *socklen_t, flags: c_int) errno.Error!c_uint {
1031 const rc = libc.accept4(@intCast(socketfd), address, address_len, flags);
1032 if (rc == -1) return errno.fromInt(errno.fromLibC());
1033 std.debug.assert(rc > 0);
1034 return @intCast(rc);
1035}
1036pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void {
1037 const rc = libc.shutdown(@intCast(socketfd), @intFromEnum(how));
1038 if (rc == -1) return errno.fromInt(errno.fromLibC());
1039 std.debug.assert(rc == 0);
1040}
1041pub fn unlinkat(fd: c_int, name: [*:0]const u8, flag: c_int) !void {
1042 const rc = libc.unlinkat(fd, name, flag);
1043 if (rc == -1) return errno.fromInt(errno.fromLibC());
1044 std.debug.assert(rc == 0);
1045}
sys.zig+2
......@@ -5,9 +5,11 @@ pub const impl = switch (builtin.target.os.tag) {
55 .linux => linux,
66 .macos => darwin,
77 .freebsd => freebsd,
8 .netbsd => netbsd,
89 else => unreachable,
910};
1011
1112pub const linux = @import("./linux.zig");
1213pub const darwin = @import("./darwin.zig");
1314pub const freebsd = @import("./freebsd.zig");
15pub const netbsd = @import("./netbsd.zig");