1const std = @import("std");
2const builtin = @import("builtin");
3const arch = builtin.target.cpu.arch;
4
5comptime {
6 std.debug.assert(builtin.target.os.tag == .freebsd);
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 ECANCELED,
98 EILSEQ,
99 ENOATTR,
100 EDOOFUS,
101 EBADMSG,
102 EMULTIHOP,
103 ENOLINK,
104 EPROTO,
105 ENOTCAPABLE,
106 ECAPMODE,
107 ENOTRECOVERABLE,
108 EOWNERDEAD,
109 EINTEGRITY,
110 };
111
112 pub const Enum = enum(c_ushort) {
113 EPERM = 1,
114 ENOENT = 2,
115 ESRCH = 3,
116 EINTR = 4,
117 EIO = 5,
118 ENXIO = 6,
119 E2BIG = 7,
120 ENOEXEC = 8,
121 EBADF = 9,
122 ECHILD = 10,
123 EDEADLK = 11,
124 ENOMEM = 12,
125 EACCES = 13,
126 EFAULT = 14,
127 ENOTBLK = 15,
128 EBUSY = 16,
129 EEXIST = 17,
130 EXDEV = 18,
131 ENODEV = 19,
132 ENOTDIR = 20,
133 EISDIR = 21,
134 EINVAL = 22,
135 ENFILE = 23,
136 EMFILE = 24,
137 ENOTTY = 25,
138 ETXTBSY = 26,
139 EFBIG = 27,
140 ENOSPC = 28,
141 ESPIPE = 29,
142 EROFS = 30,
143 EMLINK = 31,
144 EPIPE = 32,
145 EDOM = 33,
146 ERANGE = 34,
147 EAGAIN = 35,
148 EINPROGRESS = 36,
149 EALREADY = 37,
150 ENOTSOCK = 38,
151 EDESTADDRREQ = 39,
152 EMSGSIZE = 40,
153 EPROTOTYPE = 41,
154 ENOPROTOOPT = 42,
155 EPROTONOSUPPORT = 43,
156 ESOCKTNOSUPPORT = 44,
157 EOPNOTSUPP = 45,
158 EPFNOSUPPORT = 46,
159 EAFNOSUPPORT = 47,
160 EADDRINUSE = 48,
161 EADDRNOTAVAIL = 49,
162 ENETDOWN = 50,
163 ENETUNREACH = 51,
164 ENETRESET = 52,
165 ECONNABORTED = 53,
166 ECONNRESET = 54,
167 ENOBUFS = 55,
168 EISCONN = 56,
169 ENOTCONN = 57,
170 ESHUTDOWN = 58,
171 ETOOMANYREFS = 59,
172 ETIMEDOUT = 60,
173 ECONNREFUSED = 61,
174 ELOOP = 62,
175 ENAMETOOLONG = 63,
176 EHOSTDOWN = 64,
177 EHOSTUNREACH = 65,
178 ENOTEMPTY = 66,
179 EPROCLIM = 67,
180 EUSERS = 68,
181 EDQUOT = 69,
182 ESTALE = 70,
183 EREMOTE = 71,
184 EBADRPC = 72,
185 ERPCMISMATCH = 73,
186 EPROGUNAVAIL = 74,
187 EPROGMISMATCH = 75,
188 EPROCUNAVAIL = 76,
189 ENOLCK = 77,
190 ENOSYS = 78,
191 EFTYPE = 79,
192 EAUTH = 80,
193 ENEEDAUTH = 81,
194 EIDRM = 82,
195 ENOMSG = 83,
196 EOVERFLOW = 84,
197 ECANCELED = 85,
198 EILSEQ = 86,
199 ENOATTR = 87,
200 EDOOFUS = 88,
201 EBADMSG = 89,
202 EMULTIHOP = 90,
203 ENOLINK = 91,
204 EPROTO = 92,
205 ENOTCAPABLE = 93,
206 ECAPMODE = 94,
207 ENOTRECOVERABLE = 95,
208 EOWNERDEAD = 96,
209 EINTEGRITY = 97,
210
211 pub const EWOULDBLOCK: Enum = .EAGAIN;
212 pub const ENOTSUP: Enum = .EOPNOTSUPP;
213 };
214
215 comptime {
216 // assert Enum is sequential
217 var value: c_ushort = 0; // SUCCESS
218 for (std.enums.values(Enum)) |val| {
219 std.debug.assert(@backingInt(val) > value);
220 value = @backingInt(val);
221 }
222 }
223 comptime {
224 // sanity test
225 std.debug.assert(@backingInt(Enum.EPERM) == 1);
226 }
227 const list = blk: {
228 const values = std.enums.values(Enum);
229 const len = @backingInt(values[values.len - 1]) + 1;
230 var errors: [len]Error = @splat(error.Unexpected);
231 for (values) |f| errors[@backingInt(f)] = @field(Error, @tagName(f));
232 const final = errors;
233 break :blk final;
234 };
235 pub fn fromInt(code: c_int) Error {
236 @setRuntimeSafety(false);
237 if (code >= list.len) return error.Unexpected;
238 if (code <= 0) return error.Unexpected;
239 return list[@intCast(code)];
240 }
241 pub fn fromLibC() c_int {
242 return libc.__error().*;
243 }
244};
245
246pub const eai = struct {
247 pub const Error = error{
248 EAI_ADDRFAMILY,
249 EAI_AGAIN,
250 EAI_BADFLAGS,
251 EAI_FAIL,
252 EAI_FAMILY,
253 EAI_MEMORY,
254 EAI_NODATA,
255 EAI_NONAME,
256 EAI_SERVICE,
257 EAI_SOCKTYPE,
258 EAI_SYSTEM,
259 EAI_BADHINTS,
260 EAI_PROTOCOL,
261 EAI_OVERFLOW,
262 };
263
264 pub const Enum = enum(c_int) {
265 EAI_ADDRFAMILY = 1,
266 EAI_AGAIN = 2,
267 EAI_BADFLAGS = 3,
268 EAI_FAIL = 4,
269 EAI_FAMILY = 5,
270 EAI_MEMORY = 6,
271 EAI_NODATA = 7,
272 EAI_NONAME = 8,
273 EAI_SERVICE = 9,
274 EAI_SOCKTYPE = 10,
275 EAI_SYSTEM = 11,
276 EAI_BADHINTS = 12,
277 EAI_PROTOCOL = 13,
278 EAI_OVERFLOW = 14,
279 };
280
281 pub fn fromInt(code: c_int) Error {
282 return switch (@as(Enum, @fromBackingInt(@intCast(code)))) {
283 .EAI_ADDRFAMILY => error.EAI_ADDRFAMILY,
284 .EAI_AGAIN => error.EAI_AGAIN,
285 .EAI_BADFLAGS => error.EAI_BADFLAGS,
286 .EAI_FAIL => error.EAI_FAIL,
287 .EAI_FAMILY => error.EAI_FAMILY,
288 .EAI_MEMORY => error.EAI_MEMORY,
289 .EAI_NODATA => error.EAI_NODATA,
290 .EAI_NONAME => error.EAI_NONAME,
291 .EAI_SERVICE => error.EAI_SERVICE,
292 .EAI_SOCKTYPE => error.EAI_SOCKTYPE,
293 .EAI_SYSTEM => error.EAI_SYSTEM,
294 .EAI_BADHINTS => error.EAI_BADHINTS,
295 .EAI_PROTOCOL => error.EAI_PROTOCOL,
296 .EAI_OVERFLOW => error.EAI_OVERFLOW,
297 };
298 }
299};
300
301pub const libc = struct {
302 pub extern fn __error() *c_int;
303 pub extern fn pipe2(pipefd: *[2]c_int, flag: c_int) c_int;
304 pub extern fn openat(fd: c_int, file: [*:0]const u8, oflag: c_int, ...) c_int;
305 pub extern fn close(fildes: c_int) c_int;
306 pub extern fn fork() pid_t;
307 pub extern fn dup2(fildes: c_int, fildes2: c_int) c_int;
308 pub extern fn _exit(status: c_int) noreturn;
309 pub extern fn fchdir(fildes: c_int) c_int;
310 pub extern fn execvp(file: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) c_int;
311 pub extern fn kill(pid: pid_t, sig: c_int) c_int;
312 pub extern fn poll(fds: [*]struct_pollfd, nfds: nfds_t, timeout: c_int) c_int;
313 pub extern fn read(fd: c_int, buf: [*]u8, count: usize) isize;
314 pub extern fn write(fd: c_int, buf: *const anyopaque, n: usize) isize;
315 pub extern fn waitpid(pid: pid_t, stat_loc: ?*c_int, options: c_int) pid_t;
316 pub extern fn getenv(name: [*:0]const u8) ?[*:0]u8;
317 pub extern fn exit(status: c_int) noreturn;
318 pub extern fn mkdirat(fd: c_int, path: [*:0]const u8, mode: mode_t) c_int;
319 pub extern fn fstatat(fd: c_int, noalias path: [*:0]const u8, noalias buf: *struct_stat, flag: c_int) c_int;
320 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;
321 pub extern fn freeaddrinfo(ai: *const struct_addrinfo) void;
322 pub extern fn socket(domain: c_int, type: c_int, protocol: c_int) c_int;
323 pub extern fn connect(socket: c_int, address: *const struct_sockaddr, address_len: socklen_t) c_int;
324 pub extern fn getrandom(buf: [*]u8, size: usize, flags: c_uint) isize;
325 pub extern fn arc4random_buf(buf: [*]u8, n: usize) void;
326 pub extern fn pthread_mutex_init(mutex: *pthread_mutex_t, attr: ?*const pthread_mutexattr_t) c_int;
327 pub extern fn pthread_mutex_destroy(mutex: *pthread_mutex_t) c_int;
328 pub extern fn pthread_mutex_lock(mutex: *pthread_mutex_t) c_int;
329 pub extern fn pthread_mutex_trylock(mutex: *pthread_mutex_t) c_int;
330 pub extern fn pthread_mutex_unlock(mutex: *pthread_mutex_t) c_int;
331 pub extern fn pthread_cond_init(noalias cond: *pthread_cond_t, noalias attr: ?*const pthread_condattr_t) c_int;
332 pub extern fn pthread_cond_destroy(cond: *pthread_cond_t) c_int;
333 pub extern fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) c_int;
334 pub extern fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const struct_timespec) c_int;
335 pub extern fn pthread_cond_signal(cond: *pthread_cond_t) c_int;
336 pub extern fn pthread_cond_broadcast(cond: *pthread_cond_t) c_int;
337 pub extern fn pthread_rwlock_init(noalias rwlock: *pthread_rwlock_t, noalias attr: ?*const pthread_rwlockattr_t) c_int;
338 pub extern fn pthread_rwlock_destroy(rwlock: *pthread_rwlock_t) c_int;
339 pub extern fn pthread_rwlock_rdlock(rwlock: *pthread_rwlock_t) c_int;
340 pub extern fn pthread_rwlock_tryrdlock(rwlock: *pthread_rwlock_t) c_int;
341 pub extern fn pthread_rwlock_wrlock(rwlock: *pthread_rwlock_t) c_int;
342 pub extern fn pthread_rwlock_trywrlock(rwlock: *pthread_rwlock_t) c_int;
343 pub extern fn pthread_rwlock_unlock(rwlock: *pthread_rwlock_t) c_int;
344 pub extern fn clock_gettime(clock_id: clockid_t, tp: *struct_timespec) c_int;
345 pub extern fn renameat(oldfd: c_int, old: [*:0]const u8, newfd: c_int, new: [*:0]const u8) c_int;
346 pub extern fn send(fd: c_int, buffer: [*]const u8, length: usize, flags: c_int) isize;
347 pub extern fn recv(fd: c_int, buffer: [*]u8, length: usize, flags: c_int) isize;
348 pub extern fn fstat(fd: c_int, buf: *struct_stat) c_int;
349 pub extern fn mmap(addr: ?*anyopaque, len: usize, prot: c_int, flags: c_int, fd: c_int, offset: off_t) *allowzero anyopaque;
350 pub extern fn writev(fd: c_int, iovec: [*]const struct_iovec, count: c_int) isize;
351 pub extern fn faccessat(fd: c_int, path: [*:0]const u8, amode: c_int, flag: c_int) c_int;
352 pub extern fn readlinkat(fd: c_int, noalias path: [*:0]const u8, noalias buf: [*]u8, len: usize) isize;
353 pub extern fn futimens(fd: c_int, times: *const [2]struct_timespec) c_int;
354 pub extern fn setsockopt(fd: c_int, level: c_int, optname: c_int, optval: *const anyopaque, optlen: socklen_t) c_int;
355 pub extern fn bind(socket: c_int, address: *const struct_sockaddr, address_len: socklen_t) c_int;
356 pub extern fn listen(socket: c_int, backlog: c_int) c_int;
357 pub extern fn getsockname(fd: c_int, noalias addr: *struct_sockaddr, noalias len: *socklen_t) c_int;
358 pub extern fn pthread_attr_init(attr: *pthread_attr_t) c_int;
359 pub extern fn pthread_attr_destroy(attr: *pthread_attr_t) c_int;
360 pub extern fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) c_int;
361 pub extern fn pthread_attr_setstacksize(attr: *pthread_attr_t, stacksize: usize) c_int;
362 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;
363 pub extern fn pthread_detach(thread: pthread_t) c_int;
364 pub extern fn pthread_join(thread: pthread_t, retval: ?*?*anyopaque) c_int;
365 pub extern fn munmap(addr: *const anyopaque, len: usize) c_int;
366 pub extern fn getdents(dirfd: c_int, buf: [*]u8, nbytes: usize) isize;
367 pub extern fn accept4(socket: c_int, noalias address: ?*struct_sockaddr, noalias address_len: *socklen_t, flags: c_int) c_int;
368 pub extern fn shutdown(socket: c_int, how: c_int) c_int;
369 pub extern fn unlinkat(fd: c_int, name: [*:0]const u8, flag: c_int) c_int;
370 pub extern fn lseek(fd: c_int, offset: off_t, whence: c_int) off_t;
371};
372
373pub const blksize_t = i32;
374pub const blkcnt_t = i64;
375pub const clockid_t = i32;
376pub const fflags_t = u32;
377pub const fsblkcnt_t = u64;
378pub const fsfilcnt_t = u64;
379pub const gid_t = u32;
380pub const id_t = i64;
381pub const ino_t = u64;
382pub const key_t = c_long;
383pub const lwpid_t = i32;
384pub const mode_t = u16;
385pub const accmode_t = c_int;
386pub const nl_item = c_int;
387pub const nlink_t = u64;
388pub const off_t = i64;
389pub const off64_t = i64;
390pub const pid_t = i32;
391pub const sbintime_t = i64;
392pub const rlim_t = i64;
393pub const sa_family_t = u8;
394pub const socklen_t = u32;
395pub const suseconds_t = c_long;
396pub const uid_t = u32;
397pub const useconds_t = c_uint;
398pub const cpuwhich_t = c_int;
399pub const cpulevel_t = c_int;
400pub const cpusetid_t = c_int;
401pub const daddr_t = i64;
402pub const struct_pollfd = extern struct { fd: c_int, events: c_short, revents: c_short };
403pub const nfds_t = c_uint;
404pub const struct_stat = extern struct { dev: dev_t, ino: ino_t, nlink: nlink_t, mode: mode_t, bsdflags: i16, uid: uid_t, gid: gid_t, padding1: i32, 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: fflags_t, gen: u64, filerev: u64, spare: [9]u64 };
405pub const dev_t = u64;
406pub const struct_timespec = extern struct { sec: time_t, nsec: c_long };
407pub const time_t = i64;
408pub const struct_iovec = extern struct { base: [*]u8, len: usize };
409pub const in_addr_t = u32;
410pub const in_port_t = u16;
411pub const struct_in_addr = extern struct { addr: in_addr_t };
412pub const struct_in6_addr = extern struct { addr: extern union { a8: [16]u8, a16: [8]u16, a32: [4]u32 } };
413pub const struct_sockaddr = extern struct { len: u8 = 6, family: AF, data: [14]u8 };
414pub 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) };
415pub 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 };
416pub const struct_sockaddr_un = extern struct { len: u8 = 106, family: AF = .UNIX, path: [104]u8 };
417comptime {
418 std.debug.assert(@sizeOf(struct_sockaddr_in) == 16);
419 std.debug.assert(@sizeOf(struct_sockaddr_in6) == 28);
420 std.debug.assert(@sizeOf(struct_sockaddr_un) == 106);
421}
422pub 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 };
423pub const struct_dirent = extern struct { fileno: ino_t, off: off_t, reclen: u16, type: DT, pad0: u8, namlen: u16, pad1: u16, name: [NAME_MAX + 1]u8 };
424pub const struct_timeval = extern struct { sec: time_t, usec: suseconds_t };
425
426const impdef = @import("c");
427pub const pthread_t = impdef.pthread_t;
428pub const pthread_attr_t = impdef.pthread_attr_t;
429pub const pthread_mutexattr_t = impdef.pthread_mutexattr_t;
430pub const pthread_mutex_t = impdef.pthread_mutex_t;
431pub const pthread_condattr_t = impdef.pthread_condattr_t;
432pub const pthread_cond_t = impdef.pthread_cond_t;
433pub const pthread_rwlockattr_t = impdef.pthread_rwlockattr_t;
434pub const pthread_rwlock_t = impdef.pthread_rwlock_t;
435
436pub const ARG_MAX = (256 * 1024);
437pub const CHILD_MAX = 40;
438pub const MAX_CANON = 255;
439pub const MAX_INPUT = 255;
440pub const NAME_MAX = 255;
441pub const NGROUPS_MAX = 1023;
442pub const OPEN_MAX = 64;
443pub const PATH_MAX = 1024;
444pub const PIPE_BUF = 512;
445pub const IOV_MAX = 1024;
446
447pub const O = struct {
448 pub const RDONLY = 0x0000;
449 pub const WRONLY = 0x0001;
450 pub const RDWR = 0x0002;
451 pub const ACCMODE = 0x0003;
452 pub const NONBLOCK = 0x0004;
453 pub const APPEND = 0x0008;
454 pub const SHLOCK = 0x0010;
455 pub const EXLOCK = 0x0020;
456 pub const ASYNC = 0x0040;
457 pub const FSYNC = 0x0080;
458 pub const SYNC = 0x0080;
459 pub const NOFOLLOW = 0x0100;
460 pub const CREAT = 0x0200;
461 pub const TRUNC = 0x0400;
462 pub const EXCL = 0x0800;
463 pub const NOCTTY = 0x8000;
464 pub const DIRECT = 0x00010000;
465 pub const DIRECTORY = 0x00020000;
466 pub const EXEC = 0x00040000;
467 pub const SEARCH = EXEC;
468 pub const TTY_INIT = 0x00080000;
469 pub const CLOEXEC = 0x00100000;
470 pub const VERIFY = 0x00200000;
471 pub const PATH = 0x00400000;
472 pub const RESOLVE_BENEATH = 0x00800000;
473 pub const DSYNC = 0x01000000;
474 pub const EMPTY_PATH = 0x02000000;
475 pub const NAMEDATTR = 0x04000000;
476 pub const XATTR = NAMEDATTR;
477 pub const SYMLINK = (PATH | NOFOLLOW);
478 pub const CLOFORK = 0x08000000;
479};
480
481pub const AT = struct {
482 pub const FDCWD = -100;
483 pub const EACCESS = 0x0100;
484 pub const SYMLINK_NOFOLLOW = 0x0200;
485 pub const SYMLINK_FOLLOW = 0x0400;
486 pub const REMOVEDIR = 0x0800;
487 pub const BENEATH = 0x1000;
488 pub const RESOLVE_BENEATH = 0x2000;
489 pub const EMPTY_PATH = 0x4000;
490 pub const RENAME_NOREPLACE = 0x0001;
491 pub const RENAME_EXCHANGE = 0x0002;
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 THR = 32;
528 pub const LWP = THR;
529 pub const LIBRT = 33;
530};
531
532pub const POLL = struct {
533 pub const IN = 0x0001;
534 pub const PRI = 0x0002;
535 pub const OUT = 0x0004;
536 pub const RDNORM = 0x0040;
537 pub const WRNORM = OUT;
538 pub const RDBAND = 0x0080;
539 pub const WRBAND = 0x0100;
540 pub const INIGNEOF = 0x2000;
541 pub const RDHUP = 0x4000;
542 pub const ERR = 0x0008;
543 pub const HUP = 0x0010;
544 pub const NVAL = 0x0020;
545};
546
547pub const W = struct {
548 pub const COREFLAG = 0o200;
549 pub const _STOPPED = 0o177;
550 pub const NOHANG = 1;
551 pub const UNTRACED = 2;
552 pub const STOPPED = UNTRACED;
553 pub const CONTINUED = 4;
554 pub const NOWAIT = 8;
555 pub const EXITED = 16;
556 pub const TRAPPED = 32;
557 pub const LINUXCLONE = 0x80000000;
558
559 pub fn _INT(s: c_int) c_int {
560 return s;
561 }
562 pub fn _STATUS(s: c_int) u8 {
563 return @intCast(_INT(s) & 0o177);
564 }
565 pub fn IFSTOPPED(s: c_int) bool {
566 return _STATUS(s) == _STOPPED;
567 }
568 pub fn STOPSIG(s: c_int) u8 {
569 return @intCast(_INT(s) >> 8);
570 }
571 pub fn IFSIGNALED(s: c_int) bool {
572 return _STATUS(s) != _STOPPED and _STATUS(s) != 0 and s != 0x13;
573 }
574 pub fn TERMSIG(s: c_int) u8 {
575 return _STATUS(s);
576 }
577 pub fn IFEXITED(s: c_int) bool {
578 return _STATUS(s) == 0;
579 }
580 pub fn EXITSTATUS(s: c_int) u8 {
581 return @intCast(_INT(s) >> 8);
582 }
583 pub fn IFCONTINUED(s: c_int) bool {
584 return s == SIG.CONT;
585 }
586 pub fn COREDUMP(s: c_int) bool {
587 return s == SIG.CONT;
588 }
589 pub fn _EXITCODE(r: c_int, s: c_int) c_int {
590 return r << 8 | s;
591 }
592 pub fn _STOPCODE(s: c_int) c_int {
593 return s << 8 | _STOPPED;
594 }
595};
596
597pub const S = struct {
598 pub const ISUID = 0o004000;
599 pub const ISGID = 0o002000;
600 pub const ISTXT = 0o001000;
601 pub const IRWXU = 0o000700;
602 pub const IRUSR = 0o000400;
603 pub const IWUSR = 0o000200;
604 pub const IXUSR = 0o000100;
605 pub const IREAD = IRUSR;
606 pub const IWRITE = IWUSR;
607 pub const IEXEC = IXUSR;
608 pub const IRWXG = 0o000070;
609 pub const IRGRP = 0o000040;
610 pub const IWGRP = 0o000020;
611 pub const IXGRP = 0o000010;
612 pub const IRWXO = 0o000007;
613 pub const IROTH = 0o000004;
614 pub const IWOTH = 0o000002;
615 pub const IXOTH = 0o000001;
616 pub const IFMT = 0o170000;
617 pub const IFIFO = 0o010000;
618 pub const IFCHR = 0o020000;
619 pub const IFDIR = 0o040000;
620 pub const IFBLK = 0o060000;
621 pub const IFREG = 0o100000;
622 pub const IFLNK = 0o120000;
623 pub const IFSOCK = 0o140000;
624 pub const ISVTX = 0o001000;
625 pub const IFWHT = 0o160000;
626};
627
628pub const AF = enum(sa_family_t) {
629 UNSPEC = 0,
630 UNIX = 1,
631 INET = 2,
632 IMPLINK = 3,
633 PUP = 4,
634 CHAOS = 5,
635 NETBIOS = 6,
636 ISO = 7,
637 ECMA = 8,
638 DATAKIT = 9,
639 CCITT = 10,
640 SNA = 11,
641 DECnet = 12,
642 DLI = 13,
643 LAT = 14,
644 HYLINK = 15,
645 APPLETALK = 16,
646 ROUTE = 17,
647 LINK = 18,
648 XTP = 19,
649 COIP = 20,
650 CNT = 21,
651 RTIP = 22,
652 IPX = 23,
653 SIP = 24,
654 PIP = 25,
655 ISDN = 26,
656 KEY = 27,
657 INET6 = 28,
658 NATM = 29,
659 ATM = 30,
660 HDRCMPLT = 31,
661 NETGRAPH = 32,
662 SLOW = 33,
663 SCLUSTER = 34,
664 ARP = 35,
665 BLUETOOTH = 36,
666 IEEE80211 = 37,
667 NETLINK = 38,
668 INET_SDP = 40,
669 INET6_SDP = 42,
670 HYPERV = 43,
671 DIVERT = 44,
672 IPFWLOG = 46,
673
674 pub const LOCAL: AF = .UNIX;
675 pub const OSI: AF = .ISO;
676 pub const E164: AF = .ISDN;
677};
678
679pub const SOCK = struct {
680 pub const STREAM = 1;
681 pub const DGRAM = 2;
682 pub const RAW = 3;
683 pub const RDM = 4;
684 pub const SEQPACKET = 5;
685 pub const CLOEXEC = 0x10000000;
686 pub const NONBLOCK = 0x20000000;
687 pub const CLOFORK = 0x40000000;
688};
689
690pub const IPPROTO = struct {
691 pub const IP = 0;
692 pub const ICMP = 1;
693 pub const TCP = 6;
694 pub const UDP = 17;
695 pub const IPV6 = 41;
696 pub const RAW = 255;
697 pub const HOPOPTS = 0;
698 pub const IGMP = 2;
699 pub const GGP = 3;
700 pub const IPV4 = 4;
701 pub const IPIP = IPV4;
702 pub const ST = 7;
703 pub const EGP = 8;
704 pub const PIGP = 9;
705 pub const RCCMON = 10;
706 pub const NVPII = 11;
707 pub const PUP = 12;
708 pub const ARGUS = 13;
709 pub const EMCON = 14;
710 pub const XNET = 15;
711 pub const CHAOS = 16;
712 pub const MUX = 18;
713 pub const MEAS = 19;
714 pub const HMP = 20;
715 pub const PRM = 21;
716 pub const IDP = 22;
717 pub const TRUNK1 = 23;
718 pub const TRUNK2 = 24;
719 pub const LEAF1 = 25;
720 pub const LEAF2 = 26;
721 pub const RDP = 27;
722 pub const IRTP = 28;
723 pub const TP = 29;
724 pub const BLT = 30;
725 pub const NSP = 31;
726 pub const INP = 32;
727 pub const DCCP = 33;
728 pub const @"3PC" = 34;
729 pub const IDPR = 35;
730 pub const XTP = 36;
731 pub const DDP = 37;
732 pub const CMTP = 38;
733 pub const TPXX = 39;
734 pub const IL = 40;
735 pub const SDRP = 42;
736 pub const ROUTING = 43;
737 pub const FRAGMENT = 44;
738 pub const IDRP = 45;
739 pub const RSVP = 46;
740 pub const GRE = 47;
741 pub const MHRP = 48;
742 pub const BHA = 49;
743 pub const ESP = 50;
744 pub const AH = 51;
745 pub const INLSP = 52;
746 pub const SWIPE = 53;
747 pub const NHRP = 54;
748 pub const MOBILE = 55;
749 pub const TLSP = 56;
750 pub const SKIP = 57;
751 pub const ICMPV6 = 58;
752 pub const NONE = 59;
753 pub const DSTOPTS = 60;
754 pub const AHIP = 61;
755 pub const CFTP = 62;
756 pub const HELLO = 63;
757 pub const SATEXPAK = 64;
758 pub const KRYPTOLAN = 65;
759 pub const RVD = 66;
760 pub const IPPC = 67;
761 pub const ADFS = 68;
762 pub const SATMON = 69;
763 pub const VISA = 70;
764 pub const IPCV = 71;
765 pub const CPNX = 72;
766 pub const CPHB = 73;
767 pub const WSN = 74;
768 pub const PVP = 75;
769 pub const BRSATMON = 76;
770 pub const ND = 77;
771 pub const WBMON = 78;
772 pub const WBEXPAK = 79;
773 pub const EON = 80;
774 pub const VMTP = 81;
775 pub const SVMTP = 82;
776 pub const VINES = 83;
777 pub const TTP = 84;
778 pub const IGP = 85;
779 pub const DGP = 86;
780 pub const TCF = 87;
781 pub const IGRP = 88;
782 pub const OSPFIGP = 89;
783 pub const SRPC = 90;
784 pub const LARP = 91;
785 pub const MTP = 92;
786 pub const AX25 = 93;
787 pub const IPEIP = 94;
788 pub const MICP = 95;
789 pub const SCCSP = 96;
790 pub const ETHERIP = 97;
791 pub const ENCAP = 98;
792 pub const APES = 99;
793 pub const GMTP = 100;
794 pub const IPCOMP = 108;
795 pub const SCTP = 132;
796 pub const MH = 135;
797 pub const UDPLITE = 136;
798 pub const HIP = 139;
799 pub const SHIM6 = 140;
800 pub const PIM = 103;
801 pub const CARP = 112;
802 pub const PGM = 113;
803 pub const MPLS = 137;
804 pub const PFSYNC = 240;
805};
806
807pub const CLOCK = enum(clockid_t) {
808 REALTIME = 0,
809 VIRTUAL = 1,
810 PROF = 2,
811 MONOTONIC = 4,
812 UPTIME_FAST = 8,
813 UPTIME = 5,
814 UPTIME_PRECISE = 7,
815 REALTIME_PRECISE = 9,
816 REALTIME_FAST = 10,
817 MONOTONIC_PRECISE = 11,
818 MONOTONIC_FAST = 12,
819 SECOND = 13,
820 THREAD_CPUTIME_ID = 14,
821 PROCESS_CPUTIME_ID = 15,
822 TAI = 16,
823 _,
824
825 pub const BOOTTIME: CLOCK = .MONOTONIC;
826 pub const REALTIME_COARSE: CLOCK = .REALTIME_FAST;
827 pub const MONOTONIC_COARSE: CLOCK = .MONOTONIC_FAST;
828};
829
830pub const SOL = struct {
831 pub const SOCKET = 0xffff;
832};
833
834pub const SO = struct {
835 pub const DEBUG = 0x00000001;
836 pub const ACCEPTCONN = 0x00000002;
837 pub const REUSEADDR = 0x00000004;
838 pub const KEEPALIVE = 0x00000008;
839 pub const DONTROUTE = 0x00000010;
840 pub const BROADCAST = 0x00000020;
841 pub const USELOOPBACK = 0x00000040;
842 pub const LINGER = 0x00000080;
843 pub const OOBINLINE = 0x00000100;
844 pub const REUSEPORT = 0x00000200;
845 pub const TIMESTAMP = 0x00000400;
846 pub const NOSIGPIPE = 0x00000800;
847 pub const ACCEPTFILTER = 0x00001000;
848 pub const BINTIME = 0x00002000;
849 pub const NO_OFFLOAD = 0x00004000;
850 pub const NO_DDP = 0x00008000;
851 pub const REUSEPORT_LB = 0x00010000;
852 pub const RERROR = 0x00020000;
853 pub const PASSRIGHTS = 0x00040000;
854 pub const SNDBUF = 0x1001;
855 pub const RCVBUF = 0x1002;
856 pub const SNDLOWAT = 0x1003;
857 pub const RCVLOWAT = 0x1004;
858 pub const SNDTIMEO = 0x1005;
859 pub const RCVTIMEO = 0x1006;
860 pub const ERROR = 0x1007;
861 pub const TYPE = 0x1008;
862 pub const LABEL = 0x1009;
863 pub const PEERLABEL = 0x1010;
864 pub const LISTENQLIMIT = 0x1011;
865 pub const LISTENQLEN = 0x1012;
866 pub const LISTENINCQLEN = 0x1013;
867 pub const FIB = 0x1014;
868 pub const SETFIB = FIB;
869 pub const USER_COOKIE = 0x1015;
870 pub const PROTOCOL = 0x1016;
871 pub const PROTOTYPE = PROTOCOL;
872 pub const TS_CLOCK = 0x1017;
873 pub const MAX_PACING_RATE = 0x1018;
874 pub const DOMAIN = 0x1019;
875 pub const SPLICE = 0x1023;
876 pub const TS_REALTIME_MICRO = 0;
877 pub const TS_BINTIME = 1;
878 pub const TS_REALTIME = 2;
879 pub const TS_MONOTONIC = 3;
880 pub const TS_DEFAULT = TS_REALTIME_MICRO;
881 pub const TS_CLOCK_MAX = TS_MONOTONIC;
882};
883
884pub const DT = enum(u8) {
885 UNKNOWN = 0,
886 FIFO = 1,
887 CHR = 2,
888 DIR = 4,
889 BLK = 6,
890 REG = 8,
891 LNK = 10,
892 SOCK = 12,
893 WHT = 14,
894};
895
896pub const SHUT = enum(c_int) {
897 RD = 0,
898 WR = 1,
899 RDWR = 2,
900};
901
902pub const MAP = struct {
903 pub const SHARED = 0x0001;
904 pub const PRIVATE = 0x0002;
905 pub const FIXED = 0x0010;
906 pub const FILE = 0x0000;
907 pub const ANON = 0x1000;
908 pub const ANONYMOUS = ANON;
909 pub const GUARD = 0x00002000;
910 pub const EXCL = 0x00004000;
911 pub const NOCORE = 0x00020000;
912 pub const PREFAULT_READ = 0x00040000;
913 pub const _32BIT = 0x00080000;
914 pub const FAILED = -1;
915};
916
917pub const PROT = struct {
918 pub const NONE = 0x00;
919 pub const READ = 0x01;
920 pub const WRITE = 0x02;
921 pub const EXEC = 0x04;
922 pub const CHERI0 = 0x08;
923 pub const CHERI1 = 0x10;
924};
925
926pub const IPV6 = struct {
927 pub const UNICAST_HOPS = 4;
928 pub const MULTICAST_IF = 9;
929 pub const MULTICAST_HOPS = 10;
930 pub const MULTICAST_LOOP = 11;
931 pub const JOIN_GROUP = 12;
932 pub const LEAVE_GROUP = 13;
933 pub const PORTRANGE = 14;
934 pub const CHECKSUM = 26;
935 pub const V6ONLY = 27;
936 pub const IPSEC_POLICY = 28;
937 pub const FW_ADD = 30;
938 pub const FW_DEL = 31;
939 pub const FW_FLUSH = 32;
940 pub const FW_ZERO = 33;
941 pub const FW_GET = 34;
942 pub const RTHDRDSTOPTS = 35;
943 pub const RECVPKTINFO = 36;
944 pub const RECVHOPLIMIT = 37;
945 pub const RECVRTHDR = 38;
946 pub const RECVHOPOPTS = 39;
947 pub const RECVDSTOPTS = 40;
948 pub const USE_MIN_MTU = 42;
949 pub const RECVPATHMTU = 43;
950 pub const PATHMTU = 44;
951 pub const PKTINFO = 46;
952 pub const HOPLIMIT = 47;
953 pub const NEXTHOP = 48;
954 pub const HOPOPTS = 49;
955 pub const DSTOPTS = 50;
956 pub const RTHDR = 51;
957 pub const RECVTCLASS = 57;
958 pub const AUTOFLOWLABEL = 59;
959 pub const TCLASS = 61;
960 pub const DONTFRAG = 62;
961 pub const PREFER_TEMPADDR = 63;
962 pub const BINDANY = 64;
963 pub const FLOWID = 67;
964 pub const FLOWTYPE = 68;
965 pub const RSSBUCKETID = 69;
966 pub const RECVFLOWID = 70;
967 pub const RECVRSSBUCKETID = 71;
968 pub const ORIGDSTADDR = 72;
969 pub const RECVORIGDSTADDR = ORIGDSTADDR;
970 pub const MSFILTER = 74;
971 pub const VLAN_PCP = 75;
972};
973
974pub const SEEK = struct {
975 pub const SET = 0;
976 pub const CUR = 1;
977 pub const END = 2;
978 pub const DATA = 3;
979 pub const HOLE = 4;
980};
981
982pub fn pipe2(flag: c_int) ![2]c_int {
983 var fildes: [2]c_int = @splat(-1);
984 const rc = libc.pipe2(&fildes, flag);
985 if (rc == -1) return errno.fromInt(errno.fromLibC());
986 std.debug.assert(rc == 0);
987 return fildes;
988}
989pub fn openat(fd: c_int, file: [*:0]const u8, oflag: c_int) errno.Error!c_int {
990 const rc = libc.openat(fd, file, oflag);
991 if (rc == -1) return errno.fromInt(errno.fromLibC());
992 std.debug.assert(rc >= 0);
993 return rc;
994}
995pub fn openat4(fd: c_int, file: [*:0]const u8, oflag: c_int, mode: mode_t) errno.Error!c_int {
996 const rc = libc.openat(fd, file, oflag, mode);
997 if (rc == -1) return errno.fromInt(errno.fromLibC());
998 return rc;
999}
1000pub fn close(fd: c_int) errno.Error!void {
1001 const rc = libc.close(fd);
1002 if (rc == -1) return errno.fromInt(errno.fromLibC());
1003 std.debug.assert(rc == 0);
1004}
1005pub fn fork() !pid_t {
1006 const rc = libc.fork();
1007 if (rc == -1) return errno.fromInt(errno.fromLibC());
1008 std.debug.assert(rc >= 0);
1009 return rc;
1010}
1011pub fn dup2(fildes: c_int, fildes2: c_int) !void {
1012 const rc = libc.dup2(fildes, fildes2);
1013 if (rc == -1) return errno.fromInt(errno.fromLibC());
1014 std.debug.assert(rc >= 0);
1015}
1016pub fn fchdir(fildes: c_int) !void {
1017 const rc = libc.fchdir(fildes);
1018 if (rc == -1) return errno.fromInt(errno.fromLibC());
1019 std.debug.assert(rc == 0);
1020}
1021pub fn execvp(file: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) !noreturn {
1022 const rc = libc.execvp(file, argv);
1023 std.debug.assert(rc == -1);
1024 return errno.fromInt(errno.fromLibC());
1025}
1026pub fn kill(pid: pid_t, sig: c_int) !void {
1027 const rc = libc.kill(pid, sig);
1028 if (rc == -1) return errno.fromInt(errno.fromLibC());
1029 std.debug.assert(rc == 0);
1030}
1031pub fn poll(fds: []struct_pollfd, timeout_ms: c_int) !c_int {
1032 const rc = libc.poll(fds.ptr, @intCast(fds.len), timeout_ms);
1033 if (rc == -1) return errno.fromInt(errno.fromLibC());
1034 std.debug.assert(rc >= 0);
1035 return rc;
1036}
1037pub fn read(fd: c_int, buf: []u8) errno.Error!usize {
1038 const rc = libc.read(fd, buf.ptr, buf.len);
1039 if (rc == -1) return errno.fromInt(errno.fromLibC());
1040 std.debug.assert(rc >= 0);
1041 return @intCast(rc);
1042}
1043pub fn write(fd: c_int, buf: []const u8) !usize {
1044 const rc = libc.write(fd, buf.ptr, buf.len);
1045 if (rc == -1) return errno.fromInt(errno.fromLibC());
1046 std.debug.assert(rc >= 0);
1047 return @intCast(rc);
1048}
1049pub fn waitpid(pid: pid_t, options: c_int) !struct { pid_t, c_int } {
1050 var status: c_int = 0;
1051 const rc = libc.waitpid(pid, &status, options);
1052 if (rc == -1) return errno.fromInt(errno.fromLibC());
1053 std.debug.assert(rc >= 0);
1054 return .{ rc, status };
1055}
1056pub fn getenv(name: [:0]const u8) ?[:0]u8 {
1057 return std.mem.sliceTo(libc.getenv(name.ptr) orelse return null, 0);
1058}
1059pub fn exit(status: c_int) noreturn {
1060 return libc.exit(status);
1061}
1062pub fn mkdirat(fd: c_int, path: [*:0]const u8, mode: mode_t) errno.Error!void {
1063 const rc = libc.mkdirat(fd, path, mode);
1064 if (rc == -1) return errno.fromInt(errno.fromLibC());
1065 std.debug.assert(rc == 0);
1066}
1067pub fn fstatat(fd: c_int, path: [*:0]const u8, flag: c_int) errno.Error!struct_stat {
1068 var buf: struct_stat = undefined;
1069 const rc = libc.fstatat(fd, path, &buf, flag);
1070 if (rc == -1) return errno.fromInt(errno.fromLibC());
1071 std.debug.assert(rc == 0);
1072 return buf;
1073}
1074pub fn getaddrinfo(noalias nodename: ?[*:0]const u8, noalias servname: ?[*:0]const u8, noalias req: ?*const struct_addrinfo) eai.Error!*const struct_addrinfo {
1075 var pai: *const struct_addrinfo = undefined;
1076 var hints = std.mem.zeroes(struct_addrinfo);
1077 const rc = libc.getaddrinfo(nodename, servname, req orelse &hints, &pai);
1078 if (rc > 0) return eai.fromInt(rc);
1079 std.debug.assert(rc == 0);
1080 return pai;
1081}
1082pub fn freeaddrinfo(ai: *const struct_addrinfo) void {
1083 return libc.freeaddrinfo(ai);
1084}
1085pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint {
1086 const rc = libc.socket(@backingInt(domain), ty, protocol);
1087 if (rc == -1) return errno.fromInt(errno.fromLibC());
1088 std.debug.assert(rc > 0);
1089 return @intCast(rc);
1090}
1091pub fn connect(socketfd: c_uint, address: *const struct_sockaddr, address_len: socklen_t) errno.Error!void {
1092 const rc = libc.connect(@intCast(socketfd), address, address_len);
1093 if (rc == -1) return errno.fromInt(errno.fromLibC());
1094 std.debug.assert(rc == 0);
1095}
1096pub fn getrandom(buf: []u8, flags: c_uint) ![]u8 {
1097 const rc = libc.getrandom(buf.ptr, buf.len, flags);
1098 if (rc == -1) return errno.fromInt(errno.fromLibC());
1099 std.debug.assert(rc >= 0);
1100 return buf[0..@intCast(rc)];
1101}
1102pub fn clock_gettime(clock_id: CLOCK) !struct_timespec {
1103 var tp: struct_timespec = undefined;
1104 const rc = libc.clock_gettime(@backingInt(clock_id), &tp);
1105 if (rc == -1) return errno.fromInt(errno.fromLibC());
1106 std.debug.assert(rc == 0);
1107 return tp;
1108}
1109pub fn renameat(oldfd: c_int, old: [*:0]const u8, newfd: c_int, new: [*:0]const u8) !void {
1110 const rc = libc.renameat(oldfd, old, newfd, new);
1111 if (rc == -1) return errno.fromInt(errno.fromLibC());
1112 std.debug.assert(rc == 0);
1113}
1114pub fn send(socketfd: c_uint, buffer: []const u8, flags: c_int) errno.Error!usize {
1115 const rc = libc.send(@intCast(socketfd), buffer.ptr, buffer.len, flags);
1116 if (rc == -1) return errno.fromInt(errno.fromLibC());
1117 std.debug.assert(rc >= 0);
1118 return @intCast(rc);
1119}
1120
1121pub fn recv(socketfd: c_uint, buffer: []u8, flags: c_int) errno.Error!usize {
1122 const rc = libc.recv(@intCast(socketfd), buffer.ptr, buffer.len, flags);
1123 if (rc == -1) return errno.fromInt(errno.fromLibC());
1124 std.debug.assert(rc >= 0);
1125 return @intCast(rc);
1126}
1127pub fn fstat(fd: c_int) errno.Error!struct_stat {
1128 var buf: struct_stat = undefined;
1129 const rc = libc.fstat(fd, &buf);
1130 if (rc == -1) return errno.fromInt(errno.fromLibC());
1131 std.debug.assert(rc == 0);
1132 return buf;
1133}
1134pub fn mmap(addr: ?*anyopaque, len: usize, prot: c_int, flags: c_int, fd: c_int, offset: off_t) errno.Error![]u8 {
1135 const rc = libc.mmap(addr, len, prot, flags, fd, offset);
1136 if (@intFromPtr(rc) == MAP.FAILED) return errno.fromInt(errno.fromLibC());
1137 const ptr: [*]u8 = @ptrCast(rc);
1138 return ptr[0..len];
1139}
1140pub fn writev(fd: c_int, iovec: []const struct_iovec) !usize {
1141 const rc = libc.writev(fd, iovec.ptr, @intCast(iovec.len));
1142 if (rc == -1) return errno.fromInt(errno.fromLibC());
1143 std.debug.assert(rc >= 0);
1144 return @intCast(rc);
1145}
1146pub fn faccessat(fd: c_int, path: [*:0]const u8, amode: c_int, flag: c_int) !void {
1147 const rc = libc.faccessat(fd, path, amode, flag);
1148 if (rc == -1) return errno.fromInt(errno.fromLibC());
1149 std.debug.assert(rc == 0);
1150}
1151pub fn readlinkat(dirfd: c_int, noalias path: [*:0]const u8, noalias buf: []u8) ![:0]u8 {
1152 const rc = libc.readlinkat(dirfd, path, buf.ptr, buf.len);
1153 if (rc == -1) return errno.fromInt(errno.fromLibC());
1154 std.debug.assert(rc >= 0);
1155 buf[@intCast(rc)] = 0;
1156 return buf[0..@intCast(rc) :0];
1157}
1158pub fn futimens(fd: c_int, times: [2]struct_timespec) !void {
1159 const rc = libc.futimens(fd, &times);
1160 if (rc == -1) return errno.fromInt(errno.fromLibC());
1161 std.debug.assert(rc == 0);
1162}
1163pub fn setsockopt(socketfd: c_uint, level: c_int, optname: c_int, opaque_opt: []const u8) errno.Error!void {
1164 const rc = libc.setsockopt(@intCast(socketfd), level, optname, opaque_opt.ptr, @intCast(opaque_opt.len));
1165 if (rc == -1) return errno.fromInt(errno.fromLibC());
1166 std.debug.assert(rc == 0);
1167}
1168pub fn bind(socketfd: c_uint, address: *const struct_sockaddr, address_len: socklen_t) errno.Error!void {
1169 const rc = libc.bind(@intCast(socketfd), address, address_len);
1170 if (rc == -1) return errno.fromInt(errno.fromLibC());
1171 std.debug.assert(rc == 0);
1172}
1173pub fn listen(socketfd: c_uint, backlog: c_int) errno.Error!void {
1174 const rc = libc.listen(@intCast(socketfd), backlog);
1175 if (rc == -1) return errno.fromInt(errno.fromLibC());
1176 std.debug.assert(rc == 0);
1177}
1178pub fn getsockname(socketfd: c_uint, noalias address: *struct_sockaddr, noalias address_len: *socklen_t) errno.Error!void {
1179 const rc = libc.getsockname(@intCast(socketfd), address, address_len);
1180 if (rc == -1) return errno.fromInt(errno.fromLibC());
1181 std.debug.assert(rc == 0);
1182}
1183pub fn munmap(addr: *const anyopaque, len: usize) errno.Error!void {
1184 const rc = libc.munmap(addr, len);
1185 if (rc == -1) return errno.fromInt(errno.fromLibC());
1186 std.debug.assert(rc == 0);
1187}
1188pub fn getdents(dirfd: c_int, buf: []u8) errno.Error!usize {
1189 const rc = libc.getdents(dirfd, buf.ptr, buf.len);
1190 if (rc == -1) return errno.fromInt(errno.fromLibC());
1191 std.debug.assert(rc >= 0);
1192 return @intCast(rc);
1193}
1194pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias address_len: *socklen_t, flags: c_int) errno.Error!c_uint {
1195 const rc = libc.accept4(@intCast(socketfd), address, address_len, flags);
1196 if (rc == -1) return errno.fromInt(errno.fromLibC());
1197 std.debug.assert(rc > 0);
1198 return @intCast(rc);
1199}
1200pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void {
1201 const rc = libc.shutdown(@intCast(socketfd), @backingInt(how));
1202 if (rc == -1) return errno.fromInt(errno.fromLibC());
1203 std.debug.assert(rc == 0);
1204}
1205pub fn unlinkat(fd: c_int, name: [*:0]const u8, flag: c_int) !void {
1206 const rc = libc.unlinkat(fd, name, flag);
1207 if (rc == -1) return errno.fromInt(errno.fromLibC());
1208 std.debug.assert(rc == 0);
1209}
1210pub fn lseek(fd: c_int, offset: off_t, whence: c_int) !void {
1211 const rc = libc.lseek(fd, offset, whence);
1212 if (rc == -1) return errno.fromInt(errno.fromLibC());
1213 std.debug.assert(rc >= 0);
1214}