1const builtin = @import("builtin");
2const native_abi = builtin.abi;
3const native_arch = builtin.cpu.arch;
4const native_os = builtin.os.tag;
5const native_endian = builtin.cpu.arch.endian();
6
7const std = @import("std");
8const c = @This();
9const maxInt = std.math.maxInt;
10const assert = std.debug.assert;
11const page_size = std.heap.page_size_min;
12const linux = std.os.linux;
13const emscripten = std.os.emscripten;
14const wasi = std.os.wasi;
15const windows = std.os.windows;
16const ws2_32 = std.os.windows.ws2_32;
17const darwin = @import("c/darwin.zig");
18const freebsd = @import("c/freebsd.zig");
19const illumos = @import("c/illumos.zig");
20const netbsd = @import("c/netbsd.zig");
21const dragonfly = @import("c/dragonfly.zig");
22const haiku = @import("c/haiku.zig");
23const openbsd = @import("c/openbsd.zig");
24const serenity = @import("c/serenity.zig");
25
26// These constants are shared among all operating systems even when not linking
27// libc.
28
29pub const iovec = std.posix.iovec;
30pub const iovec_const = std.posix.iovec_const;
31pub const LOCK = std.posix.LOCK;
32pub const winsize = std.posix.winsize;
33
34/// The value of the link editor defined symbol _MH_EXECUTE_SYM is the address
35/// of the mach header in a Mach-O executable file type. It does not appear in
36/// any file type other than a MH_EXECUTE file type. The type of the symbol is
37/// absolute as the header is not part of any section.
38/// This symbol is populated when linking the system's libc, which is guaranteed
39/// on this operating system. However when building object files or libraries,
40/// the system libc won't be linked until the final executable. So we
41/// export a weak symbol here, to be overridden by the real one.
42pub extern var _mh_execute_header: mach_hdr;
43var dummy_execute_header: mach_hdr = undefined;
44comptime {
45 if (native_os.isDarwin()) {
46 @export(&dummy_execute_header, .{ .name = "_mh_execute_header", .linkage = .weak });
47 }
48}
49
50/// * If not linking libc, returns `false`.
51/// * If linking musl libc, returns `true`.
52/// * If linking GNU libc (glibc), returns `true` if the target version is greater than or equal to
53/// `version`.
54/// * If linking Android libc (bionic), returns `true` if the target API level is greater than or
55/// equal to `version.major`, ignoring other components.
56/// * If linking a libc other than these, returns `false`.
57pub inline fn versionCheck(comptime version: std.SemanticVersion) bool {
58 return comptime blk: {
59 if (!builtin.link_libc) break :blk false;
60 if (native_abi.isMusl()) break :blk true;
61 if (builtin.target.isGnuLibC()) {
62 const ver = builtin.os.versionRange().gnuLibCVersion().?;
63 break :blk switch (ver.order(version)) {
64 .gt, .eq => true,
65 .lt => false,
66 };
67 } else if (builtin.abi.isAndroid()) {
68 break :blk builtin.os.version_range.linux.android >= version.major;
69 } else {
70 break :blk false;
71 }
72 };
73}
74
75/// Get the errno if rc is -1 and SUCCESS if rc is not -1.
76pub fn errno(rc: anytype) E {
77 return if (rc == -1) @fromBackingInt(@intCast(_errno().*)) else .SUCCESS;
78}
79
80pub const ino_t = switch (native_os) {
81 .linux => linux.ino_t,
82 .emscripten => emscripten.ino_t,
83 .wasi => wasi.inode_t,
84 .windows => windows.LARGE_INTEGER,
85 .haiku => i64,
86 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L38
87 else => u64,
88};
89
90pub const off_t = switch (native_os) {
91 .linux => linux.off_t,
92 .emscripten => emscripten.off_t,
93 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L39
94 else => i64,
95};
96
97/// For use with `utimensat` and `futimens`.
98pub const UTIME = switch (native_os) {
99 .dragonfly, .freebsd, .illumos, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .wasi => struct {
100 pub const NOW: timespec = .{ .sec = 0, .nsec = -1 };
101 pub const OMIT: timespec = .{ .sec = 0, .nsec = -2 };
102 },
103 .emscripten => emscripten.UTIME,
104 .haiku => struct {
105 pub const NOW: timespec = .{ .sec = 0, .nsec = 1000000000 };
106 pub const OMIT: timespec = .{ .sec = 0, .nsec = 1000000001 };
107 },
108 .linux => linux.UTIME,
109 .netbsd => struct {
110 pub const NOW: timespec = .{ .sec = 0, .nsec = 0x3fffffff };
111 pub const OMIT: timespec = .{ .sec = 0, .nsec = 0x3ffffffe };
112 },
113 .openbsd, .serenity => struct {
114 pub const NOW: timespec = .{ .sec = 0, .nsec = -2 };
115 pub const OMIT: timespec = .{ .sec = 0, .nsec = -1 };
116 },
117 else => void,
118};
119
120pub const timespec = switch (native_os) {
121 .linux => linux.timespec,
122 .emscripten => emscripten.timespec,
123 // lib/libc/include/wasm-wasi-musl/__struct_timespec.h
124 .wasi => extern struct {
125 sec: time_t,
126 nsec: c_long,
127
128 pub fn fromTimestamp(tm: wasi.timestamp_t) timespec {
129 const sec: wasi.timestamp_t = tm / 1_000_000_000;
130 const nsec = tm - sec * 1_000_000_000;
131 return .{
132 .sec = @as(time_t, @intCast(sec)),
133 .nsec = @as(isize, @intCast(nsec)),
134 };
135 }
136
137 pub fn toTimestamp(ts: timespec) wasi.timestamp_t {
138 return @as(wasi.timestamp_t, @intCast(ts.sec * 1_000_000_000)) +
139 @as(wasi.timestamp_t, @intCast(ts.nsec));
140 }
141 },
142 // https://github.com/SerenityOS/serenity/blob/0a78056453578c18e0a04a0b45ebfb1c96d59005/Kernel/API/POSIX/time.h#L17-L20
143 .dragonfly, .freebsd, .netbsd, .openbsd, .illumos, .haiku, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows => extern struct {
144 sec: time_t,
145 nsec: c_long,
146 },
147 else => void,
148};
149
150pub const dev_t = switch (native_os) {
151 .emscripten => emscripten.dev_t,
152 .wasi => wasi.device_t,
153 .openbsd, .haiku, .illumos, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => i32,
154 // glibc and musl define dev_t as u64, while in Linux kernel it is u32.
155 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L43
156 .linux, .netbsd, .freebsd, .serenity => u64,
157 else => void,
158};
159
160pub const mode_t = switch (native_os) {
161 .linux => linux.mode_t,
162 .emscripten => emscripten.mode_t,
163 .openbsd, .haiku, .netbsd, .illumos, .windows => u32,
164 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L44
165 .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .dragonfly, .serenity => u16,
166 .wasi => if (builtin.link_libc) u32 else u0, // WASI libc emulates mode.
167 else => u0,
168};
169
170pub const nlink_t = switch (native_os) {
171 .linux => linux.nlink_t,
172 .emscripten => emscripten.nlink_t,
173 .wasi => c_ulonglong,
174 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L45
175 .freebsd, .serenity => u64,
176 .openbsd, .netbsd, .dragonfly, .illumos, .windows => u32,
177 .haiku => i32,
178 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => u16,
179 else => u0,
180};
181
182pub const uid_t = switch (native_os) {
183 .linux => linux.uid_t,
184 .emscripten => emscripten.uid_t,
185 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L28
186 else => u32,
187};
188
189pub const gid_t = switch (native_os) {
190 .linux => linux.gid_t,
191 .emscripten => emscripten.gid_t,
192 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L29
193 else => u32,
194};
195
196pub const blksize_t = switch (native_os) {
197 .linux => linux.blksize_t,
198 .emscripten => emscripten.blksize_t,
199 .wasi => c_long,
200 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L42
201 .serenity => u64,
202 else => i32,
203};
204
205pub const passwd = switch (native_os) {
206 // https://github.com/SerenityOS/serenity/blob/7442cfb5072b74a62c0e061e6e9ff44fda08780d/Userland/Libraries/LibC/pwd.h#L15-L23
207 .linux, .serenity => extern struct {
208 name: ?[*:0]const u8, // username
209 passwd: ?[*:0]const u8, // user password
210 uid: uid_t, // user ID
211 gid: gid_t, // group ID
212 gecos: ?[*:0]const u8, // user information
213 dir: ?[*:0]const u8, // home directory
214 shell: ?[*:0]const u8, // shell program
215 },
216 .netbsd, .openbsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
217 name: ?[*:0]const u8, // user name
218 passwd: ?[*:0]const u8, // encrypted password
219 uid: uid_t, // user uid
220 gid: gid_t, // user gid
221 change: time_t, // password change time
222 class: ?[*:0]const u8, // user access class
223 gecos: ?[*:0]const u8, // Honeywell login info
224 dir: ?[*:0]const u8, // home directory
225 shell: ?[*:0]const u8, // default shell
226 expire: time_t, // account expiration
227 },
228 .dragonfly, .freebsd => extern struct {
229 name: ?[*:0]const u8, // user name
230 passwd: ?[*:0]const u8, // encrypted password
231 uid: uid_t, // user uid
232 gid: gid_t, // user gid
233 change: time_t, // password change time
234 class: ?[*:0]const u8, // user access class
235 gecos: ?[*:0]const u8, // Honeywell login info
236 dir: ?[*:0]const u8, // home directory
237 shell: ?[*:0]const u8, // default shell
238 expire: time_t, // account expiration
239 fields: c_int, // internal
240 },
241 else => void,
242};
243
244pub const group = switch (native_os) {
245 .linux, .freebsd, .openbsd, .dragonfly, .netbsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
246 name: ?[*:0]const u8,
247 passwd: ?[*:0]const u8,
248 gid: gid_t,
249 mem: [*:null]?[*:0]const u8,
250 },
251 else => void,
252};
253
254pub const blkcnt_t = switch (native_os) {
255 .linux => linux.blkcnt_t,
256 .emscripten => emscripten.blkcnt_t,
257 .wasi => c_longlong,
258 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L41
259 .serenity => u64,
260 else => i64,
261};
262
263pub const fd_t = switch (native_os) {
264 .linux => linux.fd_t,
265 .wasi => wasi.fd_t,
266 .windows => windows.HANDLE,
267 .serenity => c_int,
268 else => i32,
269};
270
271pub const ARCH = switch (native_os) {
272 .linux => linux.ARCH,
273 else => void,
274};
275
276// For use with posix.timerfd_create()
277// Actually, the parameter for the timerfd_create() function is an integer,
278// which means that the developer has to figure out which value is appropriate.
279// To make this easier and, above all, safer, because an incorrect value leads
280// to a panic, an enum is introduced which only allows the values
281// that actually work.
282pub const TIMERFD_CLOCK = timerfd_clockid_t;
283pub const timerfd_clockid_t = switch (native_os) {
284 .freebsd => enum(u32) {
285 REALTIME = 0,
286 MONOTONIC = 4,
287 _,
288 },
289 .linux => linux.timerfd_clockid_t,
290 else => clockid_t,
291};
292
293pub const CLOCK = clockid_t;
294pub const clockid_t = switch (native_os) {
295 .linux, .emscripten => linux.clockid_t,
296 .wasi => wasi.clockid_t,
297 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => enum(u32) {
298 REALTIME = 0,
299 MONOTONIC = 6,
300 MONOTONIC_RAW = 4,
301 MONOTONIC_RAW_APPROX = 5,
302 UPTIME_RAW = 8,
303 UPTIME_RAW_APPROX = 9,
304 PROCESS_CPUTIME_ID = 12,
305 THREAD_CPUTIME_ID = 16,
306 _,
307 },
308 .haiku => enum(i32) {
309 /// system-wide monotonic clock (aka system time)
310 MONOTONIC = 0,
311 /// system-wide real time clock
312 REALTIME = -1,
313 /// clock measuring the used CPU time of the current process
314 PROCESS_CPUTIME_ID = -2,
315 /// clock measuring the used CPU time of the current thread
316 THREAD_CPUTIME_ID = -3,
317 },
318 .freebsd => enum(u32) {
319 REALTIME = 0,
320 VIRTUAL = 1,
321 PROF = 2,
322 MONOTONIC = 4,
323 UPTIME = 5,
324 UPTIME_PRECISE = 7,
325 UPTIME_FAST = 8,
326 REALTIME_PRECISE = 9,
327 REALTIME_FAST = 10,
328 MONOTONIC_PRECISE = 11,
329 MONOTONIC_FAST = 12,
330 SECOND = 13,
331 THREAD_CPUTIME_ID = 14,
332 PROCESS_CPUTIME_ID = 15,
333 },
334 .illumos => enum(u32) {
335 VIRTUAL = 1,
336 THREAD_CPUTIME_ID = 2,
337 REALTIME = 3,
338 MONOTONIC = 4,
339 PROCESS_CPUTIME_ID = 5,
340 },
341 .netbsd => enum(u32) {
342 REALTIME = 0,
343 VIRTUAL = 1,
344 PROF = 2,
345 MONOTONIC = 3,
346 THREAD_CPUTIME_ID = 0x20000000,
347 PROCESS_CPUTIME_ID = 0x40000000,
348 },
349 .dragonfly => enum(u32) {
350 REALTIME = 0,
351 VIRTUAL = 1,
352 PROF = 2,
353 MONOTONIC = 4,
354 UPTIME = 5,
355 UPTIME_PRECISE = 7,
356 UPTIME_FAST = 8,
357 REALTIME_PRECISE = 9,
358 REALTIME_FAST = 10,
359 MONOTONIC_PRECISE = 11,
360 MONOTONIC_FAST = 12,
361 SECOND = 13,
362 THREAD_CPUTIME_ID = 14,
363 PROCESS_CPUTIME_ID = 15,
364 },
365 .openbsd => enum(u32) {
366 REALTIME = 0,
367 PROCESS_CPUTIME_ID = 2,
368 MONOTONIC = 3,
369 THREAD_CPUTIME_ID = 4,
370 },
371 // https://github.com/SerenityOS/serenity/blob/0a78056453578c18e0a04a0b45ebfb1c96d59005/Kernel/API/POSIX/time.h#L24-L36
372 .serenity => enum(c_int) {
373 REALTIME = 0,
374 MONOTONIC = 1,
375 MONOTONIC_RAW = 2,
376 REALTIME_COARSE = 3,
377 MONOTONIC_COARSE = 4,
378 },
379 else => void,
380};
381pub const CPU_COUNT = switch (native_os) {
382 .linux => linux.CPU_COUNT,
383 .emscripten => emscripten.CPU_COUNT,
384 else => void,
385};
386pub const E = switch (native_os) {
387 .linux => linux.E,
388 .emscripten => emscripten.E,
389 .wasi => wasi.errno_t,
390 .windows => enum(u16) {
391 /// No error occurred.
392 SUCCESS = 0,
393 PERM = 1,
394 NOENT = 2,
395 SRCH = 3,
396 INTR = 4,
397 IO = 5,
398 NXIO = 6,
399 @"2BIG" = 7,
400 NOEXEC = 8,
401 BADF = 9,
402 CHILD = 10,
403 AGAIN = 11,
404 NOMEM = 12,
405 ACCES = 13,
406 FAULT = 14,
407 BUSY = 16,
408 EXIST = 17,
409 XDEV = 18,
410 NODEV = 19,
411 NOTDIR = 20,
412 ISDIR = 21,
413 NFILE = 23,
414 MFILE = 24,
415 NOTTY = 25,
416 FBIG = 27,
417 NOSPC = 28,
418 SPIPE = 29,
419 ROFS = 30,
420 MLINK = 31,
421 PIPE = 32,
422 DOM = 33,
423 /// Also means `DEADLOCK`.
424 DEADLK = 36,
425 NAMETOOLONG = 38,
426 NOLCK = 39,
427 NOSYS = 40,
428 NOTEMPTY = 41,
429
430 INVAL = 22,
431 RANGE = 34,
432 ILSEQ = 42,
433
434 // POSIX Supplement
435 ADDRINUSE = 100,
436 ADDRNOTAVAIL = 101,
437 AFNOSUPPORT = 102,
438 ALREADY = 103,
439 BADMSG = 104,
440 CANCELED = 105,
441 CONNABORTED = 106,
442 CONNREFUSED = 107,
443 CONNRESET = 108,
444 DESTADDRREQ = 109,
445 HOSTUNREACH = 110,
446 IDRM = 111,
447 INPROGRESS = 112,
448 ISCONN = 113,
449 LOOP = 114,
450 MSGSIZE = 115,
451 NETDOWN = 116,
452 NETRESET = 117,
453 NETUNREACH = 118,
454 NOBUFS = 119,
455 NODATA = 120,
456 NOLINK = 121,
457 NOMSG = 122,
458 NOPROTOOPT = 123,
459 NOSR = 124,
460 NOSTR = 125,
461 NOTCONN = 126,
462 NOTRECOVERABLE = 127,
463 NOTSOCK = 128,
464 NOTSUP = 129,
465 OPNOTSUPP = 130,
466 OTHER = 131,
467 OVERFLOW = 132,
468 OWNERDEAD = 133,
469 PROTO = 134,
470 PROTONOSUPPORT = 135,
471 PROTOTYPE = 136,
472 TIME = 137,
473 TIMEDOUT = 138,
474 TXTBSY = 139,
475 WOULDBLOCK = 140,
476 DQUOT = 10069,
477 _,
478 },
479 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => darwin.E,
480 .freebsd => freebsd.E,
481 .illumos => enum(u16) {
482 /// No error occurred.
483 SUCCESS = 0,
484 /// Not super-user
485 PERM = 1,
486 /// No such file or directory
487 NOENT = 2,
488 /// No such process
489 SRCH = 3,
490 /// interrupted system call
491 INTR = 4,
492 /// I/O error
493 IO = 5,
494 /// No such device or address
495 NXIO = 6,
496 /// Arg list too long
497 @"2BIG" = 7,
498 /// Exec format error
499 NOEXEC = 8,
500 /// Bad file number
501 BADF = 9,
502 /// No children
503 CHILD = 10,
504 /// Resource temporarily unavailable.
505 /// also: WOULDBLOCK: Operation would block.
506 AGAIN = 11,
507 /// Not enough core
508 NOMEM = 12,
509 /// Permission denied
510 ACCES = 13,
511 /// Bad address
512 FAULT = 14,
513 /// Block device required
514 NOTBLK = 15,
515 /// Mount device busy
516 BUSY = 16,
517 /// File exists
518 EXIST = 17,
519 /// Cross-device link
520 XDEV = 18,
521 /// No such device
522 NODEV = 19,
523 /// Not a directory
524 NOTDIR = 20,
525 /// Is a directory
526 ISDIR = 21,
527 /// Invalid argument
528 INVAL = 22,
529 /// File table overflow
530 NFILE = 23,
531 /// Too many open files
532 MFILE = 24,
533 /// Inappropriate ioctl for device
534 NOTTY = 25,
535 /// Text file busy
536 TXTBSY = 26,
537 /// File too large
538 FBIG = 27,
539 /// No space left on device
540 NOSPC = 28,
541 /// Illegal seek
542 SPIPE = 29,
543 /// Read only file system
544 ROFS = 30,
545 /// Too many links
546 MLINK = 31,
547 /// Broken pipe
548 PIPE = 32,
549 /// Math arg out of domain of func
550 DOM = 33,
551 /// Math result not representable
552 RANGE = 34,
553 /// No message of desired type
554 NOMSG = 35,
555 /// Identifier removed
556 IDRM = 36,
557 /// Channel number out of range
558 CHRNG = 37,
559 /// Level 2 not synchronized
560 L2NSYNC = 38,
561 /// Level 3 halted
562 L3HLT = 39,
563 /// Level 3 reset
564 L3RST = 40,
565 /// Link number out of range
566 LNRNG = 41,
567 /// Protocol driver not attached
568 UNATCH = 42,
569 /// No CSI structure available
570 NOCSI = 43,
571 /// Level 2 halted
572 L2HLT = 44,
573 /// Deadlock condition.
574 DEADLK = 45,
575 /// No record locks available.
576 NOLCK = 46,
577 /// Operation canceled
578 CANCELED = 47,
579 /// Operation not supported
580 NOTSUP = 48,
581
582 // Filesystem Quotas
583 /// Disc quota exceeded
584 DQUOT = 49,
585
586 // Convergent Error Returns
587 /// invalid exchange
588 BADE = 50,
589 /// invalid request descriptor
590 BADR = 51,
591 /// exchange full
592 XFULL = 52,
593 /// no anode
594 NOANO = 53,
595 /// invalid request code
596 BADRQC = 54,
597 /// invalid slot
598 BADSLT = 55,
599 /// file locking deadlock error
600 DEADLOCK = 56,
601 /// bad font file fmt
602 BFONT = 57,
603
604 // Interprocess Robust Locks
605 /// process died with the lock
606 OWNERDEAD = 58,
607 /// lock is not recoverable
608 NOTRECOVERABLE = 59,
609 /// locked lock was unmapped
610 LOCKUNMAPPED = 72,
611 /// Facility is not active
612 NOTACTIVE = 73,
613 /// multihop attempted
614 MULTIHOP = 74,
615 /// trying to read unreadable message
616 BADMSG = 77,
617 /// path name is too long
618 NAMETOOLONG = 78,
619 /// value too large to be stored in data type
620 OVERFLOW = 79,
621 /// given log. name not unique
622 NOTUNIQ = 80,
623 /// f.d. invalid for this operation
624 BADFD = 81,
625 /// Remote address changed
626 REMCHG = 82,
627
628 // Stream Problems
629 /// Device not a stream
630 NOSTR = 60,
631 /// no data (for no delay io)
632 NODATA = 61,
633 /// timer expired
634 TIME = 62,
635 /// out of streams resources
636 NOSR = 63,
637 /// Machine is not on the network
638 NONET = 64,
639 /// Package not installed
640 NOPKG = 65,
641 /// The object is remote
642 REMOTE = 66,
643 /// the link has been severed
644 NOLINK = 67,
645 /// advertise error
646 ADV = 68,
647 /// srmount error
648 SRMNT = 69,
649 /// Communication error on send
650 COMM = 70,
651 /// Protocol error
652 PROTO = 71,
653
654 // Shared Library Problems
655 /// Can't access a needed shared lib.
656 LIBACC = 83,
657 /// Accessing a corrupted shared lib.
658 LIBBAD = 84,
659 /// .lib section in a.out corrupted.
660 LIBSCN = 85,
661 /// Attempting to link in too many libs.
662 LIBMAX = 86,
663 /// Attempting to exec a shared library.
664 LIBEXEC = 87,
665 /// Illegal byte sequence.
666 ILSEQ = 88,
667 /// Unsupported file system operation
668 NOSYS = 89,
669 /// Symbolic link loop
670 LOOP = 90,
671 /// Restartable system call
672 RESTART = 91,
673 /// if pipe/FIFO, don't sleep in stream head
674 STRPIPE = 92,
675 /// directory not empty
676 NOTEMPTY = 93,
677 /// Too many users (for UFS)
678 USERS = 94,
679
680 // BSD Networking Software
681 // Argument Errors
682 /// Socket operation on non-socket
683 NOTSOCK = 95,
684 /// Destination address required
685 DESTADDRREQ = 96,
686 /// Message too long
687 MSGSIZE = 97,
688 /// Protocol wrong type for socket
689 PROTOTYPE = 98,
690 /// Protocol not available
691 NOPROTOOPT = 99,
692 /// Protocol not supported
693 PROTONOSUPPORT = 120,
694 /// Socket type not supported
695 SOCKTNOSUPPORT = 121,
696 /// Operation not supported on socket
697 OPNOTSUPP = 122,
698 /// Protocol family not supported
699 PFNOSUPPORT = 123,
700 /// Address family not supported by
701 AFNOSUPPORT = 124,
702 /// Address already in use
703 ADDRINUSE = 125,
704 /// Can't assign requested address
705 ADDRNOTAVAIL = 126,
706
707 // Operational Errors
708 /// Network is down
709 NETDOWN = 127,
710 /// Network is unreachable
711 NETUNREACH = 128,
712 /// Network dropped connection because
713 NETRESET = 129,
714 /// Software caused connection abort
715 CONNABORTED = 130,
716 /// Connection reset by peer
717 CONNRESET = 131,
718 /// No buffer space available
719 NOBUFS = 132,
720 /// Socket is already connected
721 ISCONN = 133,
722 /// Socket is not connected
723 NOTCONN = 134,
724 /// Can't send after socket shutdown
725 SHUTDOWN = 143,
726 /// Too many references: can't splice
727 TOOMANYREFS = 144,
728 /// Connection timed out
729 TIMEDOUT = 145,
730 /// Connection refused
731 CONNREFUSED = 146,
732 /// Host is down
733 HOSTDOWN = 147,
734 /// No route to host
735 HOSTUNREACH = 148,
736 /// operation already in progress
737 ALREADY = 149,
738 /// operation now in progress
739 INPROGRESS = 150,
740
741 // SUN Network File System
742 /// Stale NFS file handle
743 STALE = 151,
744
745 _,
746 },
747 .netbsd => netbsd.E,
748 .dragonfly => dragonfly.E,
749 .haiku => haiku.E,
750 .openbsd => openbsd.E,
751 // https://github.com/SerenityOS/serenity/blob/dd59fe35c7e5bbaf6b6b3acb3f9edc56619d4b66/Kernel/API/POSIX/errno.h
752 .serenity => enum(c_int) {
753 SUCCESS = 0,
754 PERM = 1,
755 NOENT = 2,
756 SRCH = 3,
757 INTR = 4,
758 IO = 5,
759 NXIO = 6,
760 @"2BIG" = 7,
761 NOEXEC = 8,
762 BADF = 9,
763 CHILD = 10,
764 AGAIN = 11,
765 NOMEM = 12,
766 ACCES = 13,
767 FAULT = 14,
768 NOTBLK = 15,
769 BUSY = 16,
770 EXIST = 17,
771 XDEV = 18,
772 NODEV = 19,
773 NOTDIR = 20,
774 ISDIR = 21,
775 INVAL = 22,
776 NFILE = 23,
777 MFILE = 24,
778 NOTTY = 25,
779 TXTBSY = 26,
780 FBIG = 27,
781 NOSPC = 28,
782 SPIPE = 29,
783 ROFS = 30,
784 MLINK = 31,
785 PIPE = 32,
786 RANGE = 33,
787 NAMETOOLONG = 34,
788 LOOP = 35,
789 OVERFLOW = 36,
790 OPNOTSUPP = 37,
791 NOSYS = 38,
792 NOTIMPL = 39,
793 AFNOSUPPORT = 40,
794 NOTSOCK = 41,
795 ADDRINUSE = 42,
796 NOTEMPTY = 43,
797 DOM = 44,
798 CONNREFUSED = 45,
799 HOSTDOWN = 46,
800 ADDRNOTAVAIL = 47,
801 ISCONN = 48,
802 CONNABORTED = 49,
803 ALREADY = 50,
804 CONNRESET = 51,
805 DESTADDRREQ = 52,
806 HOSTUNREACH = 53,
807 ILSEQ = 54,
808 MSGSIZE = 55,
809 NETDOWN = 56,
810 NETUNREACH = 57,
811 NETRESET = 58,
812 NOBUFS = 59,
813 NOLCK = 60,
814 NOMSG = 61,
815 NOPROTOOPT = 62,
816 NOTCONN = 63,
817 SHUTDOWN = 64,
818 TOOMANYREFS = 65,
819 SOCKTNOSUPPORT = 66,
820 PROTONOSUPPORT = 67,
821 DEADLK = 68,
822 TIMEDOUT = 69,
823 PROTOTYPE = 70,
824 INPROGRESS = 71,
825 NOTHREAD = 72,
826 PROTO = 73,
827 NOTSUP = 74,
828 PFNOSUPPORT = 75,
829 DIRINTOSELF = 76,
830 DQUOT = 77,
831 NOTRECOVERABLE = 78,
832 CANCELED = 79,
833 PROMISEVIOLATION = 80,
834 STALE = 81,
835 SRCNOTFOUND = 82,
836 _,
837 },
838 else => void,
839};
840pub const Elf_Symndx = switch (native_os) {
841 .linux => linux.Elf_Symndx,
842 else => void,
843};
844/// Command flags for fcntl(2).
845pub const F = switch (native_os) {
846 .linux => linux.F,
847 .emscripten => emscripten.F,
848 .wasi => struct {
849 // Match `F_*` constants from lib/libc/include/wasm-wasi-musl/__header_fcntl.h
850 pub const GETFD = 1;
851 pub const SETFD = 2;
852 pub const GETFL = 3;
853 pub const SETFL = 4;
854 },
855 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
856 /// duplicate file descriptor
857 pub const DUPFD = 0;
858 /// get file descriptor flags
859 pub const GETFD = 1;
860 /// set file descriptor flags
861 pub const SETFD = 2;
862 /// get file status flags
863 pub const GETFL = 3;
864 /// set file status flags
865 pub const SETFL = 4;
866 /// get SIGIO/SIGURG proc/pgrp
867 pub const GETOWN = 5;
868 /// set SIGIO/SIGURG proc/pgrp
869 pub const SETOWN = 6;
870 /// get record locking information
871 pub const GETLK = 7;
872 /// set record locking information
873 pub const SETLK = 8;
874 /// F.SETLK; wait if blocked
875 pub const SETLKW = 9;
876 /// F.SETLK; wait if blocked, return on timeout
877 pub const SETLKWTIMEOUT = 10;
878 pub const FLUSH_DATA = 40;
879 /// Used for regression test
880 pub const CHKCLEAN = 41;
881 /// Preallocate storage
882 pub const PREALLOCATE = 42;
883 /// Truncate a file without zeroing space
884 pub const SETSIZE = 43;
885 /// Issue an advisory read async with no copy to user
886 pub const RDADVISE = 44;
887 /// turn read ahead off/on for this fd
888 pub const RDAHEAD = 45;
889 /// turn data caching off/on for this fd
890 pub const NOCACHE = 48;
891 /// file offset to device offset
892 pub const LOG2PHYS = 49;
893 /// return the full path of the fd
894 pub const GETPATH = 50;
895 /// fsync + ask the drive to flush to the media
896 pub const FULLFSYNC = 51;
897 /// find which component (if any) is a package
898 pub const PATHPKG_CHECK = 52;
899 /// "freeze" all fs operations
900 pub const FREEZE_FS = 53;
901 /// "thaw" all fs operations
902 pub const THAW_FS = 54;
903 /// turn data caching off/on (globally) for this file
904 pub const GLOBAL_NOCACHE = 55;
905 /// add detached signatures
906 pub const ADDSIGS = 59;
907 /// add signature from same file (used by dyld for shared libs)
908 pub const ADDFILESIGS = 61;
909 /// used in conjunction with F.NOCACHE to indicate that DIRECT, synchronous writes
910 /// should not be used (i.e. its ok to temporarily create cached pages)
911 pub const NODIRECT = 62;
912 /// Get the protection class of a file from the EA, returns int
913 pub const GETPROTECTIONCLASS = 63;
914 /// Set the protection class of a file for the EA, requires int
915 pub const SETPROTECTIONCLASS = 64;
916 /// file offset to device offset, extended
917 pub const LOG2PHYS_EXT = 65;
918 /// get record locking information, per-process
919 pub const GETLKPID = 66;
920 /// Mark the file as being the backing store for another filesystem
921 pub const SETBACKINGSTORE = 70;
922 /// return the full path of the FD, but error in specific mtmd circumstances
923 pub const GETPATH_MTMINFO = 71;
924 /// Returns the code directory, with associated hashes, to the caller
925 pub const GETCODEDIR = 72;
926 /// No SIGPIPE generated on EPIPE
927 pub const SETNOSIGPIPE = 73;
928 /// Status of SIGPIPE for this fd
929 pub const GETNOSIGPIPE = 74;
930 /// For some cases, we need to rewrap the key for AKS/MKB
931 pub const TRANSCODEKEY = 75;
932 /// file being written to a by single writer... if throttling enabled, writes
933 /// may be broken into smaller chunks with throttling in between
934 pub const SINGLE_WRITER = 76;
935 /// Get the protection version number for this filesystem
936 pub const GETPROTECTIONLEVEL = 77;
937 /// Add detached code signatures (used by dyld for shared libs)
938 pub const FINDSIGS = 78;
939 /// Add signature from same file, only if it is signed by Apple (used by dyld for simulator)
940 pub const ADDFILESIGS_FOR_DYLD_SIM = 83;
941 /// fsync + issue barrier to drive
942 pub const BARRIERFSYNC = 85;
943 /// Add signature from same file, return end offset in structure on success
944 pub const ADDFILESIGS_RETURN = 97;
945 /// Check if Library Validation allows this Mach-O file to be mapped into the calling process
946 pub const CHECK_LV = 98;
947 /// Deallocate a range of the file
948 pub const PUNCHHOLE = 99;
949 /// Trim an active file
950 pub const TRIM_ACTIVE_FILE = 100;
951 /// mark the dup with FD_CLOEXEC
952 pub const DUPFD_CLOEXEC = 67;
953 /// shared or read lock
954 pub const RDLCK = 1;
955 /// unlock
956 pub const UNLCK = 2;
957 /// exclusive or write lock
958 pub const WRLCK = 3;
959 },
960 .freebsd => struct {
961 /// Duplicate file descriptor.
962 pub const DUPFD = 0;
963 /// Get file descriptor flags.
964 pub const GETFD = 1;
965 /// Set file descriptor flags.
966 pub const SETFD = 2;
967 /// Get file status flags.
968 pub const GETFL = 3;
969 /// Set file status flags.
970 pub const SETFL = 4;
971
972 /// Get SIGIO/SIGURG proc/pgrrp.
973 pub const GETOWN = 5;
974 /// Set SIGIO/SIGURG proc/pgrrp.
975 pub const SETOWN = 6;
976
977 /// Get record locking information.
978 pub const GETLK = 11;
979 /// Set record locking information.
980 pub const SETLK = 12;
981 /// Set record locking information and wait if blocked.
982 pub const SETLKW = 13;
983
984 /// Debugging support for remote locks.
985 pub const SETLK_REMOTE = 14;
986 /// Read ahead.
987 pub const READAHEAD = 15;
988
989 /// DUPFD with FD_CLOEXEC set.
990 pub const DUPFD_CLOEXEC = 17;
991 /// DUP2FD with FD_CLOEXEC set.
992 pub const DUP2FD_CLOEXEC = 18;
993
994 pub const ADD_SEALS = 19;
995 pub const GET_SEALS = 20;
996 /// Return `kinfo_file` for a file descriptor.
997 pub const KINFO = 22;
998
999 // Seals (ADD_SEALS, GET_SEALS)
1000 /// Prevent adding sealings.
1001 pub const SEAL_SEAL = 0x0001;
1002 /// May not shrink
1003 pub const SEAL_SHRINK = 0x0002;
1004 /// May not grow.
1005 pub const SEAL_GROW = 0x0004;
1006 /// May not write.
1007 pub const SEAL_WRITE = 0x0008;
1008
1009 // Record locking flags (GETLK, SETLK, SETLKW).
1010 /// Shared or read lock.
1011 pub const RDLCK = 1;
1012 /// Unlock.
1013 pub const UNLCK = 2;
1014 /// Exclusive or write lock.
1015 pub const WRLCK = 3;
1016 /// Purge locks for a given system ID.
1017 pub const UNLCKSYS = 4;
1018 /// Cancel an async lock request.
1019 pub const CANCEL = 5;
1020
1021 pub const SETOWN_EX = 15;
1022 pub const GETOWN_EX = 16;
1023
1024 pub const GETOWNER_UIDS = 17;
1025 },
1026 .illumos => struct {
1027 /// Unlock a previously locked region
1028 pub const ULOCK = 0;
1029 /// Lock a region for exclusive use
1030 pub const LOCK = 1;
1031 /// Test and lock a region for exclusive use
1032 pub const TLOCK = 2;
1033 /// Test a region for other processes locks
1034 pub const TEST = 3;
1035
1036 /// Duplicate fildes
1037 pub const DUPFD = 0;
1038 /// Get fildes flags
1039 pub const GETFD = 1;
1040 /// Set fildes flags
1041 pub const SETFD = 2;
1042 /// Get file flags
1043 pub const GETFL = 3;
1044 /// Get file flags including open-only flags
1045 pub const GETXFL = 45;
1046 /// Set file flags
1047 pub const SETFL = 4;
1048
1049 /// Unused
1050 pub const CHKFL = 8;
1051 /// Duplicate fildes at third arg
1052 pub const DUP2FD = 9;
1053 /// Like DUP2FD with O_CLOEXEC set EINVAL is fildes matches arg1
1054 pub const DUP2FD_CLOEXEC = 36;
1055 /// Like DUPFD with O_CLOEXEC set
1056 pub const DUPFD_CLOEXEC = 37;
1057
1058 /// Is the file desc. a stream ?
1059 pub const ISSTREAM = 13;
1060 /// Turn on private access to file
1061 pub const PRIV = 15;
1062 /// Turn off private access to file
1063 pub const NPRIV = 16;
1064 /// UFS quota call
1065 pub const QUOTACTL = 17;
1066 /// Get number of BLKSIZE blocks allocated
1067 pub const BLOCKS = 18;
1068 /// Get optimal I/O block size
1069 pub const BLKSIZE = 19;
1070 /// Get owner (socket emulation)
1071 pub const GETOWN = 23;
1072 /// Set owner (socket emulation)
1073 pub const SETOWN = 24;
1074 /// Object reuse revoke access to file desc.
1075 pub const REVOKE = 25;
1076 /// Does vp have NFS locks private to lock manager
1077 pub const HASREMOTELOCKS = 26;
1078
1079 /// Set file lock
1080 pub const SETLK = 6;
1081 /// Set file lock and wait
1082 pub const SETLKW = 7;
1083 /// Allocate file space
1084 pub const ALLOCSP = 10;
1085 /// Free file space
1086 pub const FREESP = 11;
1087 /// Get file lock
1088 pub const GETLK = 14;
1089 /// Get file lock owned by file
1090 pub const OFD_GETLK = 47;
1091 /// Set file lock owned by file
1092 pub const OFD_SETLK = 48;
1093 /// Set file lock owned by file and wait
1094 pub const OFD_SETLKW = 49;
1095 /// Set a file share reservation
1096 pub const SHARE = 40;
1097 /// Remove a file share reservation
1098 pub const UNSHARE = 41;
1099 /// Create Poison FD
1100 pub const BADFD = 46;
1101
1102 /// Read lock
1103 pub const RDLCK = 1;
1104 /// Write lock
1105 pub const WRLCK = 2;
1106 /// Remove lock(s)
1107 pub const UNLCK = 3;
1108 /// remove remote locks for a given system
1109 pub const UNLKSYS = 4;
1110
1111 // f_access values
1112 /// Read-only share access
1113 pub const RDACC = 0x1;
1114 /// Write-only share access
1115 pub const WRACC = 0x2;
1116 /// Read-Write share access
1117 pub const RWACC = 0x3;
1118
1119 // f_deny values
1120 /// Don't deny others access
1121 pub const NODNY = 0x0;
1122 /// Deny others read share access
1123 pub const RDDNY = 0x1;
1124 /// Deny others write share access
1125 pub const WRDNY = 0x2;
1126 /// Deny others read or write share access
1127 pub const RWDNY = 0x3;
1128 /// private flag: Deny delete share access
1129 pub const RMDNY = 0x4;
1130 },
1131 .netbsd => struct {
1132 pub const DUPFD = 0;
1133 pub const GETFD = 1;
1134 pub const SETFD = 2;
1135 pub const GETFL = 3;
1136 pub const SETFL = 4;
1137 pub const GETOWN = 5;
1138 pub const SETOWN = 6;
1139 pub const GETLK = 7;
1140 pub const SETLK = 8;
1141 pub const SETLKW = 9;
1142 pub const CLOSEM = 10;
1143 pub const MAXFD = 11;
1144 pub const DUPFD_CLOEXEC = 12;
1145 pub const GETNOSIGPIPE = 13;
1146 pub const SETNOSIGPIPE = 14;
1147 pub const GETPATH = 15;
1148
1149 pub const RDLCK = 1;
1150 pub const WRLCK = 3;
1151 pub const UNLCK = 2;
1152 },
1153 .dragonfly => struct {
1154 pub const ULOCK = 0;
1155 pub const LOCK = 1;
1156 pub const TLOCK = 2;
1157 pub const TEST = 3;
1158
1159 pub const DUPFD = 0;
1160 pub const GETFD = 1;
1161 pub const RDLCK = 1;
1162 pub const SETFD = 2;
1163 pub const UNLCK = 2;
1164 pub const WRLCK = 3;
1165 pub const GETFL = 3;
1166 pub const SETFL = 4;
1167 pub const GETOWN = 5;
1168 pub const SETOWN = 6;
1169 pub const GETLK = 7;
1170 pub const SETLK = 8;
1171 pub const SETLKW = 9;
1172 pub const DUP2FD = 10;
1173 pub const DUPFD_CLOEXEC = 17;
1174 pub const DUP2FD_CLOEXEC = 18;
1175 pub const GETPATH = 19;
1176 },
1177 .haiku => struct {
1178 pub const DUPFD = 0x0001;
1179 pub const GETFD = 0x0002;
1180 pub const SETFD = 0x0004;
1181 pub const GETFL = 0x0008;
1182 pub const SETFL = 0x0010;
1183
1184 pub const GETLK = 0x0020;
1185 pub const SETLK = 0x0080;
1186 pub const SETLKW = 0x0100;
1187 pub const DUPFD_CLOEXEC = 0x0200;
1188
1189 pub const RDLCK = 0x0040;
1190 pub const UNLCK = 0x0200;
1191 pub const WRLCK = 0x0400;
1192 },
1193 .openbsd => struct {
1194 pub const DUPFD = 0;
1195 pub const GETFD = 1;
1196 pub const SETFD = 2;
1197 pub const GETFL = 3;
1198 pub const SETFL = 4;
1199
1200 pub const GETOWN = 5;
1201 pub const SETOWN = 6;
1202
1203 pub const GETLK = 7;
1204 pub const SETLK = 8;
1205 pub const SETLKW = 9;
1206
1207 pub const RDLCK = 1;
1208 pub const UNLCK = 2;
1209 pub const WRLCK = 3;
1210 },
1211 .serenity => struct {
1212 // https://github.com/SerenityOS/serenity/blob/2808b0376406a40e31293bb3bcb9170374e90506/Kernel/API/POSIX/fcntl.h#L15-L24
1213 pub const DUPFD = 0;
1214 pub const GETFD = 1;
1215 pub const SETFD = 2;
1216 pub const GETFL = 3;
1217 pub const SETFL = 4;
1218 pub const ISTTY = 5;
1219 pub const GETLK = 6;
1220 pub const SETLK = 7;
1221 pub const SETLKW = 8;
1222 pub const DUPFD_CLOEXEC = 9;
1223
1224 // https://github.com/SerenityOS/serenity/blob/2808b0376406a40e31293bb3bcb9170374e90506/Kernel/API/POSIX/fcntl.h#L45-L47
1225 pub const RDLCK = 0;
1226 pub const WRLCK = 1;
1227 pub const UNLCK = 2;
1228 },
1229 else => void,
1230};
1231pub const FD_CLOEXEC = switch (native_os) {
1232 .linux => linux.FD_CLOEXEC,
1233 .emscripten => emscripten.FD_CLOEXEC,
1234 else => 1,
1235};
1236
1237/// Test for existence of file.
1238pub const F_OK = switch (native_os) {
1239 .linux => linux.F_OK,
1240 .emscripten => emscripten.F_OK,
1241 else => 0,
1242};
1243/// Test for execute or search permission.
1244pub const X_OK = switch (native_os) {
1245 .linux => linux.X_OK,
1246 .emscripten => emscripten.X_OK,
1247 else => 1,
1248};
1249/// Test for write permission.
1250pub const W_OK = switch (native_os) {
1251 .linux => linux.W_OK,
1252 .emscripten => emscripten.W_OK,
1253 else => 2,
1254};
1255/// Test for read permission.
1256pub const R_OK = switch (native_os) {
1257 .linux => linux.R_OK,
1258 .emscripten => emscripten.R_OK,
1259 else => 4,
1260};
1261
1262pub const Flock = switch (native_os) {
1263 .linux => linux.Flock,
1264 .emscripten => emscripten.Flock,
1265 .openbsd, .dragonfly, .netbsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
1266 start: off_t,
1267 len: off_t,
1268 pid: pid_t,
1269 type: i16,
1270 whence: i16,
1271 },
1272 .freebsd => extern struct {
1273 /// Starting offset.
1274 start: off_t,
1275 /// Number of consecutive bytes to be locked.
1276 /// A value of 0 means to the end of the file.
1277 len: off_t,
1278 /// Lock owner.
1279 pid: pid_t,
1280 /// Lock type.
1281 type: i16,
1282 /// Type of the start member.
1283 whence: i16,
1284 /// Remote system id or zero for local.
1285 sysid: i32,
1286 },
1287 .illumos => extern struct {
1288 type: c_short,
1289 whence: c_short,
1290 start: off_t,
1291 // len == 0 means until end of file.
1292 len: off_t,
1293 sysid: c_int,
1294 pid: pid_t,
1295 __pad: [4]c_long,
1296 },
1297 .haiku => extern struct {
1298 type: i16,
1299 whence: i16,
1300 start: off_t,
1301 len: off_t,
1302 pid: pid_t,
1303 },
1304 // https://github.com/SerenityOS/serenity/blob/2808b0376406a40e31293bb3bcb9170374e90506/Kernel/API/POSIX/fcntl.h#L54-L60
1305 .serenity => extern struct {
1306 type: c_short,
1307 whence: c_short,
1308 start: off_t,
1309 len: off_t,
1310 pid: pid_t,
1311 },
1312 else => void,
1313};
1314pub const HOST_NAME_MAX = switch (native_os) {
1315 .linux => linux.HOST_NAME_MAX,
1316 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => 72,
1317 .openbsd, .haiku, .dragonfly, .netbsd, .illumos, .freebsd => 255,
1318 // https://github.com/SerenityOS/serenity/blob/c87557e9c1865fa1a6440de34ff6ce6fc858a2b7/Kernel/API/POSIX/sys/limits.h#L22
1319 .serenity => 64,
1320 else => {},
1321};
1322pub const IOV_MAX = switch (native_os) {
1323 .linux => linux.IOV_MAX,
1324 .emscripten => emscripten.IOV_MAX,
1325 // https://github.com/SerenityOS/serenity/blob/098af0f846a87b651731780ff48420205fd33754/Kernel/API/POSIX/sys/uio.h#L16
1326 .openbsd, .haiku, .illumos, .wasi, .serenity => 1024,
1327 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => 16,
1328 .dragonfly, .netbsd, .freebsd => KERN.IOV_MAX,
1329 else => {},
1330};
1331pub const CTL = switch (native_os) {
1332 .freebsd => struct {
1333 pub const KERN = 1;
1334 pub const DEBUG = 5;
1335 },
1336 .netbsd => struct {
1337 pub const KERN = 1;
1338 pub const DEBUG = 5;
1339 },
1340 .dragonfly => struct {
1341 pub const UNSPEC = 0;
1342 pub const KERN = 1;
1343 pub const VM = 2;
1344 pub const VFS = 3;
1345 pub const NET = 4;
1346 pub const DEBUG = 5;
1347 pub const HW = 6;
1348 pub const MACHDEP = 7;
1349 pub const USER = 8;
1350 pub const LWKT = 10;
1351 pub const MAXID = 11;
1352 pub const MAXNAME = 12;
1353 },
1354 .openbsd => struct {
1355 pub const UNSPEC = 0;
1356 pub const KERN = 1;
1357 pub const VM = 2;
1358 pub const FS = 3;
1359 pub const NET = 4;
1360 pub const DEBUG = 5;
1361 pub const HW = 6;
1362 pub const MACHDEP = 7;
1363
1364 pub const DDB = 9;
1365 pub const VFS = 10;
1366 },
1367 else => void,
1368};
1369pub const KERN = switch (native_os) {
1370 .freebsd => struct {
1371 /// struct: process entries
1372 pub const PROC = 14;
1373 /// path to executable
1374 pub const PROC_PATHNAME = 12;
1375 /// file descriptors for process
1376 pub const PROC_FILEDESC = 33;
1377 pub const IOV_MAX = 35;
1378 },
1379 .netbsd => struct {
1380 /// struct: process argv/env
1381 pub const PROC_ARGS = 48;
1382 /// path to executable
1383 pub const PROC_PATHNAME = 5;
1384 pub const IOV_MAX = 38;
1385 },
1386 .dragonfly => struct {
1387 pub const PROC_ALL = 0;
1388 pub const OSTYPE = 1;
1389 pub const PROC_PID = 1;
1390 pub const OSRELEASE = 2;
1391 pub const PROC_PGRP = 2;
1392 pub const OSREV = 3;
1393 pub const PROC_SESSION = 3;
1394 pub const VERSION = 4;
1395 pub const PROC_TTY = 4;
1396 pub const MAXVNODES = 5;
1397 pub const PROC_UID = 5;
1398 pub const MAXPROC = 6;
1399 pub const PROC_RUID = 6;
1400 pub const MAXFILES = 7;
1401 pub const PROC_ARGS = 7;
1402 pub const ARGMAX = 8;
1403 pub const PROC_CWD = 8;
1404 pub const PROC_PATHNAME = 9;
1405 pub const SECURELVL = 9;
1406 pub const PROC_SIGTRAMP = 10;
1407 pub const HOSTNAME = 10;
1408 pub const HOSTID = 11;
1409 pub const CLOCKRATE = 12;
1410 pub const VNODE = 13;
1411 pub const PROC = 14;
1412 pub const FILE = 15;
1413 pub const PROC_FLAGMASK = 16;
1414 pub const PROF = 16;
1415 pub const PROC_FLAG_LWP = 16;
1416 pub const POSIX1 = 17;
1417 pub const NGROUPS = 18;
1418 pub const JOB_CONTROL = 19;
1419 pub const SAVED_IDS = 20;
1420 pub const BOOTTIME = 21;
1421 pub const NISDOMAINNAME = 22;
1422 pub const UPDATEINTERVAL = 23;
1423 pub const OSRELDATE = 24;
1424 pub const NTP_PLL = 25;
1425 pub const BOOTFILE = 26;
1426 pub const MAXFILESPERPROC = 27;
1427 pub const MAXPROCPERUID = 28;
1428 pub const DUMPDEV = 29;
1429 pub const IPC = 30;
1430 pub const DUMMY = 31;
1431 pub const PS_STRINGS = 32;
1432 pub const USRSTACK = 33;
1433 pub const LOGSIGEXIT = 34;
1434 pub const IOV_MAX = 35;
1435 pub const MAXPOSIXLOCKSPERUID = 36;
1436 pub const MAXID = 37;
1437 },
1438 .openbsd => struct {
1439 pub const OSTYPE = 1;
1440 pub const OSRELEASE = 2;
1441 pub const OSREV = 3;
1442 pub const VERSION = 4;
1443 pub const MAXVNODES = 5;
1444 pub const MAXPROC = 6;
1445 pub const MAXFILES = 7;
1446 pub const ARGMAX = 8;
1447 pub const SECURELVL = 9;
1448 pub const HOSTNAME = 10;
1449 pub const HOSTID = 11;
1450 pub const CLOCKRATE = 12;
1451
1452 pub const PROF = 16;
1453 pub const POSIX1 = 17;
1454 pub const NGROUPS = 18;
1455 pub const JOB_CONTROL = 19;
1456 pub const SAVED_IDS = 20;
1457 pub const BOOTTIME = 21;
1458 pub const DOMAINNAME = 22;
1459 pub const MAXPARTITIONS = 23;
1460 pub const RAWPARTITION = 24;
1461 pub const MAXTHREAD = 25;
1462 pub const NTHREADS = 26;
1463 pub const OSVERSION = 27;
1464 pub const SOMAXCONN = 28;
1465 pub const SOMINCONN = 29;
1466
1467 pub const NOSUIDCOREDUMP = 32;
1468 pub const FSYNC = 33;
1469 pub const SYSVMSG = 34;
1470 pub const SYSVSEM = 35;
1471 pub const SYSVSHM = 36;
1472
1473 pub const MSGBUFSIZE = 38;
1474 pub const MALLOCSTATS = 39;
1475 pub const CPTIME = 40;
1476 pub const NCHSTATS = 41;
1477 pub const FORKSTAT = 42;
1478 pub const NSELCOLL = 43;
1479 pub const TTY = 44;
1480 pub const CCPU = 45;
1481 pub const FSCALE = 46;
1482 pub const NPROCS = 47;
1483 pub const MSGBUF = 48;
1484 pub const POOL = 49;
1485 pub const STACKGAPRANDOM = 50;
1486 pub const SYSVIPC_INFO = 51;
1487 pub const ALLOWKMEM = 52;
1488 pub const WITNESSWATCH = 53;
1489 pub const SPLASSERT = 54;
1490 pub const PROC_ARGS = 55;
1491 pub const NFILES = 56;
1492 pub const TTYCOUNT = 57;
1493 pub const NUMVNODES = 58;
1494 pub const MBSTAT = 59;
1495 pub const WITNESS = 60;
1496 pub const SEMINFO = 61;
1497 pub const SHMINFO = 62;
1498 pub const INTRCNT = 63;
1499 pub const WATCHDOG = 64;
1500 pub const ALLOWDT = 65;
1501 pub const PROC = 66;
1502 pub const MAXCLUSTERS = 67;
1503 pub const EVCOUNT = 68;
1504 pub const TIMECOUNTER = 69;
1505 pub const MAXLOCKSPERUID = 70;
1506 pub const CPTIME2 = 71;
1507 pub const CACHEPCT = 72;
1508 pub const FILE = 73;
1509 pub const WXABORT = 74;
1510 pub const CONSDEV = 75;
1511 pub const NETLIVELOCKS = 76;
1512 pub const POOL_DEBUG = 77;
1513 pub const PROC_CWD = 78;
1514 pub const PROC_NOBROADCASTKILL = 79;
1515 pub const PROC_VMMAP = 80;
1516 pub const GLOBAL_PTRACE = 81;
1517 pub const CONSBUFSIZE = 82;
1518 pub const CONSBUF = 83;
1519 pub const AUDIO = 84;
1520 pub const CPUSTATS = 85;
1521 pub const PFSTATUS = 86;
1522 pub const TIMEOUT_STATS = 87;
1523 pub const UTC_OFFSET = 88;
1524 pub const VIDEO = 89;
1525
1526 pub const PROC_ALL = 0;
1527 pub const PROC_PID = 1;
1528 pub const PROC_PGRP = 2;
1529 pub const PROC_SESSION = 3;
1530 pub const PROC_TTY = 4;
1531 pub const PROC_UID = 5;
1532 pub const PROC_RUID = 6;
1533 pub const PROC_KTHREAD = 7;
1534 pub const PROC_SHOW_THREADS = 0x40000000;
1535
1536 pub const PROC_ARGV = 1;
1537 pub const PROC_NARGV = 2;
1538 pub const PROC_ENV = 3;
1539 pub const PROC_NENV = 4;
1540 },
1541 else => void,
1542};
1543pub const MADV = switch (native_os) {
1544 .linux => linux.MADV,
1545 .emscripten => emscripten.MADV,
1546 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
1547 pub const NORMAL = 0;
1548 pub const RANDOM = 1;
1549 pub const SEQUENTIAL = 2;
1550 pub const WILLNEED = 3;
1551 pub const DONTNEED = 4;
1552 pub const FREE = 5;
1553 pub const ZERO_WIRED_PAGES = 6;
1554 pub const FREE_REUSABLE = 7;
1555 pub const FREE_REUSE = 8;
1556 pub const CAN_REUSE = 9;
1557 pub const PAGEOUT = 10;
1558 pub const ZERO = 11;
1559 },
1560 .freebsd => struct {
1561 pub const NORMAL = 0;
1562 pub const RANDOM = 1;
1563 pub const SEQUENTIAL = 2;
1564 pub const WILLNEED = 3;
1565 pub const DONTNEED = 4;
1566 pub const FREE = 5;
1567 pub const NOSYNC = 6;
1568 pub const AUTOSYNC = 7;
1569 pub const NOCORE = 8;
1570 pub const CORE = 9;
1571 pub const PROTECT = 10;
1572 },
1573 .illumos => struct {
1574 /// no further special treatment
1575 pub const NORMAL = 0;
1576 /// expect random page references
1577 pub const RANDOM = 1;
1578 /// expect sequential page references
1579 pub const SEQUENTIAL = 2;
1580 /// will need these pages
1581 pub const WILLNEED = 3;
1582 /// don't need these pages
1583 pub const DONTNEED = 4;
1584 /// contents can be freed
1585 pub const FREE = 5;
1586 /// default access
1587 pub const ACCESS_DEFAULT = 6;
1588 /// next LWP to access heavily
1589 pub const ACCESS_LWP = 7;
1590 /// many processes to access heavily
1591 pub const ACCESS_MANY = 8;
1592 /// contents will be purged
1593 pub const PURGE = 9;
1594 },
1595 .dragonfly => struct {
1596 pub const SEQUENTIAL = 2;
1597 pub const CONTROL_END = SETMAP;
1598 pub const DONTNEED = 4;
1599 pub const RANDOM = 1;
1600 pub const WILLNEED = 3;
1601 pub const NORMAL = 0;
1602 pub const CONTROL_START = INVAL;
1603 pub const FREE = 5;
1604 pub const NOSYNC = 6;
1605 pub const AUTOSYNC = 7;
1606 pub const NOCORE = 8;
1607 pub const CORE = 9;
1608 pub const INVAL = 10;
1609 pub const SETMAP = 11;
1610 },
1611 // https://github.com/SerenityOS/serenity/blob/6d59d4d3d9e76e39112842ec487840828f1c9bfe/Kernel/API/POSIX/sys/mman.h#L35-L41
1612 .serenity => struct {
1613 pub const NORMAL = 0x0;
1614 pub const SET_VOLATILE = 0x1;
1615 pub const SET_NONVOLATILE = 0x2;
1616 pub const DONTNEED = 0x3;
1617 pub const WILLNEED = 0x4;
1618 pub const SEQUENTIAL = 0x5;
1619 pub const RANDOM = 0x6;
1620 },
1621 .netbsd, .openbsd => struct {
1622 pub const NORMAL = 0;
1623 pub const RANDOM = 1;
1624 pub const SEQUENTIAL = 2;
1625 pub const WILLNEED = 3;
1626 pub const DONTNEED = 4;
1627 pub const SPACEAVAIL = 5;
1628 pub const FREE = 6;
1629 },
1630 else => void,
1631};
1632pub const MCL = switch (native_os) {
1633 .linux => linux.MCL,
1634 // https://github.com/freebsd/freebsd-src/blob/39fea5c8dc598021e900c4feaf0e18111fda57b2/sys/sys/mman.h#L133
1635 // https://github.com/DragonFlyBSD/DragonFlyBSD/blob/088552723935447397400336f5ddb7aa5f5de660/sys/sys/mman.h#L118
1636 // https://github.com/NetBSD/src/blob/fd2741deca927c18e3ba15acdf78b8b14b2abe36/sys/sys/mman.h#L179
1637 // https://github.com/openbsd/src/blob/39404228f6d36c0ca4be5f04ab5385568ebd6aa3/sys/sys/mman.h#L129
1638 // https://github.com/illumos/illumos-gate/blob/5280477614f83fea20fc938729df6adb3e44340d/usr/src/uts/common/sys/mman.h#L343
1639 .freebsd, .dragonfly, .netbsd, .openbsd, .illumos => packed struct(u32) {
1640 CURRENT: bool = false,
1641 FUTURE: bool = false,
1642 _: u30 = 0,
1643 },
1644 else => void,
1645};
1646pub const MLOCK = switch (native_os) {
1647 .linux => linux.MLOCK,
1648 else => void,
1649};
1650pub const MSF = switch (native_os) {
1651 .linux => linux.MSF,
1652 .emscripten => emscripten.MSF,
1653 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
1654 pub const ASYNC = 0x1;
1655 pub const INVALIDATE = 0x2;
1656 /// invalidate, leave mapped
1657 pub const KILLPAGES = 0x4;
1658 /// deactivate, leave mapped
1659 pub const DEACTIVATE = 0x8;
1660 pub const SYNC = 0x10;
1661 },
1662 .freebsd, .dragonfly => struct {
1663 pub const SYNC = 0;
1664 pub const ASYNC = 1;
1665 pub const INVALIDATE = 2;
1666 },
1667 .openbsd, .haiku => struct {
1668 pub const ASYNC = 1;
1669 pub const SYNC = 2;
1670 pub const INVALIDATE = 4;
1671 },
1672 .netbsd, .illumos => struct {
1673 pub const ASYNC = 1;
1674 pub const INVALIDATE = 2;
1675 pub const SYNC = 4;
1676 },
1677 // https://github.com/SerenityOS/serenity/blob/6d59d4d3d9e76e39112842ec487840828f1c9bfe/Kernel/API/POSIX/sys/mman.h#L50-L52
1678 .serenity => struct {
1679 pub const SYNC = 1;
1680 pub const ASYNC = 2;
1681 pub const INVALIDATE = 4;
1682 },
1683 else => void,
1684};
1685pub const NAME_MAX = switch (native_os) {
1686 .linux => linux.NAME_MAX,
1687 .emscripten => emscripten.NAME_MAX,
1688 // Haiku's headers make this 256, to contain room for the terminating null
1689 // character, but POSIX definition says that NAME_MAX does not include the
1690 // terminating null.
1691 // https://github.com/SerenityOS/serenity/blob/c87557e9c1865fa1a6440de34ff6ce6fc858a2b7/Kernel/API/POSIX/sys/limits.h#L20
1692 .haiku, .openbsd, .dragonfly, .netbsd, .illumos, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .serenity => 255,
1693 else => {},
1694};
1695pub const PATH_MAX = switch (native_os) {
1696 .linux => linux.PATH_MAX,
1697 .emscripten => emscripten.PATH_MAX,
1698 .wasi => 4096,
1699 .windows => 260,
1700 .openbsd, .haiku, .dragonfly, .netbsd, .illumos, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .serenity => 1024,
1701 else => {},
1702};
1703
1704pub const POLL = switch (native_os) {
1705 .linux => linux.POLL,
1706 .emscripten => emscripten.POLL,
1707 .wasi => struct {
1708 pub const RDNORM = 0x1;
1709 pub const WRNORM = 0x2;
1710 pub const IN = RDNORM;
1711 pub const OUT = WRNORM;
1712 pub const ERR = 0x1000;
1713 pub const HUP = 0x2000;
1714 pub const NVAL = 0x4000;
1715 },
1716 .windows => ws2_32.POLL,
1717 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
1718 pub const IN = 0x001;
1719 pub const PRI = 0x002;
1720 pub const OUT = 0x004;
1721 pub const RDNORM = 0x040;
1722 pub const WRNORM = OUT;
1723 pub const RDBAND = 0x080;
1724 pub const WRBAND = 0x100;
1725
1726 pub const EXTEND = 0x0200;
1727 pub const ATTRIB = 0x0400;
1728 pub const NLINK = 0x0800;
1729 pub const WRITE = 0x1000;
1730
1731 pub const ERR = 0x008;
1732 pub const HUP = 0x010;
1733 pub const NVAL = 0x020;
1734
1735 pub const STANDARD = IN | PRI | OUT | RDNORM | RDBAND | WRBAND | ERR | HUP | NVAL;
1736 },
1737 .freebsd => struct {
1738 /// any readable data available.
1739 pub const IN = 0x0001;
1740 /// OOB/Urgent readable data.
1741 pub const PRI = 0x0002;
1742 /// file descriptor is writeable.
1743 pub const OUT = 0x0004;
1744 /// non-OOB/URG data available.
1745 pub const RDNORM = 0x0040;
1746 /// no write type differentiation.
1747 pub const WRNORM = OUT;
1748 /// OOB/Urgent readable data.
1749 pub const RDBAND = 0x0080;
1750 /// OOB/Urgent data can be written.
1751 pub const WRBAND = 0x0100;
1752 /// like IN, except ignore EOF.
1753 pub const INIGNEOF = 0x2000;
1754 /// some poll error occurred.
1755 pub const ERR = 0x0008;
1756 /// file descriptor was "hung up".
1757 pub const HUP = 0x0010;
1758 /// requested events "invalid".
1759 pub const NVAL = 0x0020;
1760
1761 pub const STANDARD = IN | PRI | OUT | RDNORM | RDBAND | WRBAND | ERR | HUP | NVAL;
1762 },
1763 .illumos => struct {
1764 pub const IN = 0x0001;
1765 pub const PRI = 0x0002;
1766 pub const OUT = 0x0004;
1767 pub const RDNORM = 0x0040;
1768 pub const WRNORM = .OUT;
1769 pub const RDBAND = 0x0080;
1770 pub const WRBAND = 0x0100;
1771 /// Read-side hangup.
1772 pub const RDHUP = 0x4000;
1773
1774 /// Non-testable events (may not be specified in events).
1775 pub const ERR = 0x0008;
1776 pub const HUP = 0x0010;
1777 pub const NVAL = 0x0020;
1778
1779 /// Events to control `/dev/poll` (not specified in revents)
1780 pub const REMOVE = 0x0800;
1781 pub const ONESHOT = 0x1000;
1782 pub const ET = 0x2000;
1783 },
1784 .dragonfly, .netbsd => struct {
1785 /// Testable events (may be specified in events field).
1786 pub const IN = 0x0001;
1787 pub const PRI = 0x0002;
1788 pub const OUT = 0x0004;
1789 pub const RDNORM = 0x0040;
1790 pub const WRNORM = OUT;
1791 pub const RDBAND = 0x0080;
1792 pub const WRBAND = 0x0100;
1793
1794 /// Non-testable events (may not be specified in events field).
1795 pub const ERR = 0x0008;
1796 pub const HUP = 0x0010;
1797 pub const NVAL = 0x0020;
1798 },
1799 .haiku => struct {
1800 /// any readable data available
1801 pub const IN = 0x0001;
1802 /// file descriptor is writeable
1803 pub const OUT = 0x0002;
1804 pub const RDNORM = IN;
1805 pub const WRNORM = OUT;
1806 /// priority readable data
1807 pub const RDBAND = 0x0008;
1808 /// priority data can be written
1809 pub const WRBAND = 0x0010;
1810 /// high priority readable data
1811 pub const PRI = 0x0020;
1812
1813 /// errors pending
1814 pub const ERR = 0x0004;
1815 /// disconnected
1816 pub const HUP = 0x0080;
1817 /// invalid file descriptor
1818 pub const NVAL = 0x1000;
1819 },
1820 .openbsd => struct {
1821 pub const IN = 0x0001;
1822 pub const PRI = 0x0002;
1823 pub const OUT = 0x0004;
1824 pub const ERR = 0x0008;
1825 pub const HUP = 0x0010;
1826 pub const NVAL = 0x0020;
1827 pub const RDNORM = 0x0040;
1828 pub const NORM = RDNORM;
1829 pub const WRNORM = OUT;
1830 pub const RDBAND = 0x0080;
1831 pub const WRBAND = 0x0100;
1832 },
1833 // https://github.com/SerenityOS/serenity/blob/265764ff2fec038855193296588a887fc322d76a/Kernel/API/POSIX/poll.h#L15-L24
1834 .serenity => struct {
1835 pub const IN = 0x0001;
1836 pub const PRI = 0x0002;
1837 pub const OUT = 0x0004;
1838 pub const ERR = 0x0008;
1839 pub const HUP = 0x0010;
1840 pub const NVAL = 0x0020;
1841 pub const RDNORM = IN;
1842 pub const WRNORM = OUT;
1843 pub const WRBAND = 0x1000;
1844 pub const RDHUP = 0x2000;
1845 },
1846 else => void,
1847};
1848
1849/// Basic memory protection flags
1850pub const PROT = switch (native_os) {
1851 .linux => linux.PROT,
1852 .emscripten => emscripten.PROT,
1853 // https://github.com/SerenityOS/serenity/blob/6d59d4d3d9e76e39112842ec487840828f1c9bfe/Kernel/API/POSIX/sys/mman.h#L28-L31
1854 .openbsd, .haiku, .dragonfly, .netbsd, .illumos, .freebsd, .windows, .serenity => packed struct(u32) {
1855 READ: bool = false,
1856 WRITE: bool = false,
1857 EXEC: bool = false,
1858 _: u29 = 0,
1859 },
1860 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => vm_prot_t,
1861 else => void,
1862};
1863
1864pub const RLIM = switch (native_os) {
1865 .linux => linux.RLIM,
1866 .emscripten => emscripten.RLIM,
1867 // https://github.com/SerenityOS/serenity/blob/aae106e37b48f2158e68902293df1e4bf7b80c0f/Userland/Libraries/LibC/sys/resource.h#L52
1868 .openbsd, .haiku, .dragonfly, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .serenity => struct {
1869 /// No limit
1870 pub const INFINITY: rlim_t = (1 << 63) - 1;
1871
1872 pub const SAVED_MAX = INFINITY;
1873 pub const SAVED_CUR = INFINITY;
1874 },
1875 .illumos => struct {
1876 /// No limit
1877 pub const INFINITY: rlim_t = (1 << 63) - 3;
1878 pub const SAVED_MAX: rlim_t = (1 << 63) - 2;
1879 pub const SAVED_CUR: rlim_t = (1 << 63) - 1;
1880 },
1881 else => void,
1882};
1883pub const S = switch (native_os) {
1884 .linux => linux.S,
1885 .emscripten => emscripten.S,
1886 .wasi => struct {
1887 // Match `S_*` constants from lib/libc/include/wasm-wasi-musl/__mode_t.h
1888 pub const IFBLK = 0x6000;
1889 pub const IFCHR = 0x2000;
1890 pub const IFDIR = 0x4000;
1891 pub const IFIFO = 0x1000;
1892 pub const IFLNK = 0xa000;
1893 pub const IFMT = IFBLK | IFCHR | IFDIR | IFIFO | IFLNK | IFREG | IFSOCK;
1894 pub const IFREG = 0x8000;
1895 pub const IFSOCK = 0xc000;
1896
1897 pub fn ISBLK(m: u32) bool {
1898 return m & IFMT == IFBLK;
1899 }
1900
1901 pub fn ISCHR(m: u32) bool {
1902 return m & IFMT == IFCHR;
1903 }
1904
1905 pub fn ISDIR(m: u32) bool {
1906 return m & IFMT == IFDIR;
1907 }
1908
1909 pub fn ISFIFO(m: u32) bool {
1910 return m & IFMT == IFIFO;
1911 }
1912
1913 pub fn ISLNK(m: u32) bool {
1914 return m & IFMT == IFLNK;
1915 }
1916
1917 pub fn ISREG(m: u32) bool {
1918 return m & IFMT == IFREG;
1919 }
1920
1921 pub fn ISSOCK(m: u32) bool {
1922 return m & IFMT == IFSOCK;
1923 }
1924 },
1925 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
1926 pub const IFMT = 0o170000;
1927
1928 pub const IFIFO = 0o010000;
1929 pub const IFCHR = 0o020000;
1930 pub const IFDIR = 0o040000;
1931 pub const IFBLK = 0o060000;
1932 pub const IFREG = 0o100000;
1933 pub const IFLNK = 0o120000;
1934 pub const IFSOCK = 0o140000;
1935 pub const IFWHT = 0o160000;
1936
1937 pub const ISUID = 0o4000;
1938 pub const ISGID = 0o2000;
1939 pub const ISVTX = 0o1000;
1940 pub const IRWXU = 0o700;
1941 pub const IRUSR = 0o400;
1942 pub const IWUSR = 0o200;
1943 pub const IXUSR = 0o100;
1944 pub const IRWXG = 0o070;
1945 pub const IRGRP = 0o040;
1946 pub const IWGRP = 0o020;
1947 pub const IXGRP = 0o010;
1948 pub const IRWXO = 0o007;
1949 pub const IROTH = 0o004;
1950 pub const IWOTH = 0o002;
1951 pub const IXOTH = 0o001;
1952
1953 pub fn ISFIFO(m: u32) bool {
1954 return m & IFMT == IFIFO;
1955 }
1956
1957 pub fn ISCHR(m: u32) bool {
1958 return m & IFMT == IFCHR;
1959 }
1960
1961 pub fn ISDIR(m: u32) bool {
1962 return m & IFMT == IFDIR;
1963 }
1964
1965 pub fn ISBLK(m: u32) bool {
1966 return m & IFMT == IFBLK;
1967 }
1968
1969 pub fn ISREG(m: u32) bool {
1970 return m & IFMT == IFREG;
1971 }
1972
1973 pub fn ISLNK(m: u32) bool {
1974 return m & IFMT == IFLNK;
1975 }
1976
1977 pub fn ISSOCK(m: u32) bool {
1978 return m & IFMT == IFSOCK;
1979 }
1980
1981 pub fn IWHT(m: u32) bool {
1982 return m & IFMT == IFWHT;
1983 }
1984 },
1985 .freebsd => struct {
1986 pub const IFMT = 0o170000;
1987
1988 pub const IFIFO = 0o010000;
1989 pub const IFCHR = 0o020000;
1990 pub const IFDIR = 0o040000;
1991 pub const IFBLK = 0o060000;
1992 pub const IFREG = 0o100000;
1993 pub const IFLNK = 0o120000;
1994 pub const IFSOCK = 0o140000;
1995 pub const IFWHT = 0o160000;
1996
1997 pub const ISUID = 0o4000;
1998 pub const ISGID = 0o2000;
1999 pub const ISVTX = 0o1000;
2000 pub const IRWXU = 0o700;
2001 pub const IRUSR = 0o400;
2002 pub const IWUSR = 0o200;
2003 pub const IXUSR = 0o100;
2004 pub const IRWXG = 0o070;
2005 pub const IRGRP = 0o040;
2006 pub const IWGRP = 0o020;
2007 pub const IXGRP = 0o010;
2008 pub const IRWXO = 0o007;
2009 pub const IROTH = 0o004;
2010 pub const IWOTH = 0o002;
2011 pub const IXOTH = 0o001;
2012
2013 pub fn ISFIFO(m: u32) bool {
2014 return m & IFMT == IFIFO;
2015 }
2016
2017 pub fn ISCHR(m: u32) bool {
2018 return m & IFMT == IFCHR;
2019 }
2020
2021 pub fn ISDIR(m: u32) bool {
2022 return m & IFMT == IFDIR;
2023 }
2024
2025 pub fn ISBLK(m: u32) bool {
2026 return m & IFMT == IFBLK;
2027 }
2028
2029 pub fn ISREG(m: u32) bool {
2030 return m & IFMT == IFREG;
2031 }
2032
2033 pub fn ISLNK(m: u32) bool {
2034 return m & IFMT == IFLNK;
2035 }
2036
2037 pub fn ISSOCK(m: u32) bool {
2038 return m & IFMT == IFSOCK;
2039 }
2040
2041 pub fn IWHT(m: u32) bool {
2042 return m & IFMT == IFWHT;
2043 }
2044 },
2045 .illumos => struct {
2046 pub const IFMT = 0o170000;
2047
2048 pub const IFIFO = 0o010000;
2049 pub const IFCHR = 0o020000;
2050 pub const IFDIR = 0o040000;
2051 pub const IFBLK = 0o060000;
2052 pub const IFREG = 0o100000;
2053 pub const IFLNK = 0o120000;
2054 pub const IFSOCK = 0o140000;
2055 /// SunOS 2.6 Door
2056 pub const IFDOOR = 0o150000;
2057 /// Solaris 10 Event Port
2058 pub const IFPORT = 0o160000;
2059
2060 pub const ISUID = 0o4000;
2061 pub const ISGID = 0o2000;
2062 pub const ISVTX = 0o1000;
2063 pub const IRWXU = 0o700;
2064 pub const IRUSR = 0o400;
2065 pub const IWUSR = 0o200;
2066 pub const IXUSR = 0o100;
2067 pub const IRWXG = 0o070;
2068 pub const IRGRP = 0o040;
2069 pub const IWGRP = 0o020;
2070 pub const IXGRP = 0o010;
2071 pub const IRWXO = 0o007;
2072 pub const IROTH = 0o004;
2073 pub const IWOTH = 0o002;
2074 pub const IXOTH = 0o001;
2075
2076 pub fn ISFIFO(m: u32) bool {
2077 return m & IFMT == IFIFO;
2078 }
2079
2080 pub fn ISCHR(m: u32) bool {
2081 return m & IFMT == IFCHR;
2082 }
2083
2084 pub fn ISDIR(m: u32) bool {
2085 return m & IFMT == IFDIR;
2086 }
2087
2088 pub fn ISBLK(m: u32) bool {
2089 return m & IFMT == IFBLK;
2090 }
2091
2092 pub fn ISREG(m: u32) bool {
2093 return m & IFMT == IFREG;
2094 }
2095
2096 pub fn ISLNK(m: u32) bool {
2097 return m & IFMT == IFLNK;
2098 }
2099
2100 pub fn ISSOCK(m: u32) bool {
2101 return m & IFMT == IFSOCK;
2102 }
2103
2104 pub fn ISDOOR(m: u32) bool {
2105 return m & IFMT == IFDOOR;
2106 }
2107
2108 pub fn ISPORT(m: u32) bool {
2109 return m & IFMT == IFPORT;
2110 }
2111 },
2112 .netbsd => struct {
2113 pub const IFMT = 0o170000;
2114
2115 pub const IFIFO = 0o010000;
2116 pub const IFCHR = 0o020000;
2117 pub const IFDIR = 0o040000;
2118 pub const IFBLK = 0o060000;
2119 pub const IFREG = 0o100000;
2120 pub const IFLNK = 0o120000;
2121 pub const IFSOCK = 0o140000;
2122 pub const IFWHT = 0o160000;
2123
2124 pub const ISUID = 0o4000;
2125 pub const ISGID = 0o2000;
2126 pub const ISVTX = 0o1000;
2127 pub const IRWXU = 0o700;
2128 pub const IRUSR = 0o400;
2129 pub const IWUSR = 0o200;
2130 pub const IXUSR = 0o100;
2131 pub const IRWXG = 0o070;
2132 pub const IRGRP = 0o040;
2133 pub const IWGRP = 0o020;
2134 pub const IXGRP = 0o010;
2135 pub const IRWXO = 0o007;
2136 pub const IROTH = 0o004;
2137 pub const IWOTH = 0o002;
2138 pub const IXOTH = 0o001;
2139
2140 pub fn ISFIFO(m: u32) bool {
2141 return m & IFMT == IFIFO;
2142 }
2143
2144 pub fn ISCHR(m: u32) bool {
2145 return m & IFMT == IFCHR;
2146 }
2147
2148 pub fn ISDIR(m: u32) bool {
2149 return m & IFMT == IFDIR;
2150 }
2151
2152 pub fn ISBLK(m: u32) bool {
2153 return m & IFMT == IFBLK;
2154 }
2155
2156 pub fn ISREG(m: u32) bool {
2157 return m & IFMT == IFREG;
2158 }
2159
2160 pub fn ISLNK(m: u32) bool {
2161 return m & IFMT == IFLNK;
2162 }
2163
2164 pub fn ISSOCK(m: u32) bool {
2165 return m & IFMT == IFSOCK;
2166 }
2167
2168 pub fn IWHT(m: u32) bool {
2169 return m & IFMT == IFWHT;
2170 }
2171 },
2172 .dragonfly => struct {
2173 pub const IFMT = 0o170000;
2174
2175 pub const IFIFO = 0o010000;
2176 pub const IFCHR = 0o020000;
2177 pub const IFDIR = 0o040000;
2178 pub const IFBLK = 0o060000;
2179 pub const IFREG = 0o100000;
2180 pub const IFLNK = 0o120000;
2181 pub const IFSOCK = 0o140000;
2182 pub const IFWHT = 0o160000;
2183
2184 pub const ISUID = 0o4000;
2185 pub const ISGID = 0o2000;
2186 pub const ISVTX = 0o1000;
2187 pub const IRWXU = 0o700;
2188 pub const IRUSR = 0o400;
2189 pub const IWUSR = 0o200;
2190 pub const IXUSR = 0o100;
2191 pub const IRWXG = 0o070;
2192 pub const IRGRP = 0o040;
2193 pub const IWGRP = 0o020;
2194 pub const IXGRP = 0o010;
2195 pub const IRWXO = 0o007;
2196 pub const IROTH = 0o004;
2197 pub const IWOTH = 0o002;
2198 pub const IXOTH = 0o001;
2199
2200 pub const IREAD = IRUSR;
2201 pub const IEXEC = IXUSR;
2202 pub const IWRITE = IWUSR;
2203 pub const ISTXT = 512;
2204 pub const BLKSIZE = 512;
2205
2206 pub fn ISFIFO(m: u32) bool {
2207 return m & IFMT == IFIFO;
2208 }
2209
2210 pub fn ISCHR(m: u32) bool {
2211 return m & IFMT == IFCHR;
2212 }
2213
2214 pub fn ISDIR(m: u32) bool {
2215 return m & IFMT == IFDIR;
2216 }
2217
2218 pub fn ISBLK(m: u32) bool {
2219 return m & IFMT == IFBLK;
2220 }
2221
2222 pub fn ISREG(m: u32) bool {
2223 return m & IFMT == IFREG;
2224 }
2225
2226 pub fn ISLNK(m: u32) bool {
2227 return m & IFMT == IFLNK;
2228 }
2229
2230 pub fn ISSOCK(m: u32) bool {
2231 return m & IFMT == IFSOCK;
2232 }
2233
2234 pub fn IWHT(m: u32) bool {
2235 return m & IFMT == IFWHT;
2236 }
2237 },
2238 .haiku => struct {
2239 pub const IFMT = 0o170000;
2240 pub const IFSOCK = 0o140000;
2241 pub const IFLNK = 0o120000;
2242 pub const IFREG = 0o100000;
2243 pub const IFBLK = 0o060000;
2244 pub const IFDIR = 0o040000;
2245 pub const IFCHR = 0o020000;
2246 pub const IFIFO = 0o010000;
2247 pub const INDEX_DIR = 0o4000000000;
2248
2249 pub const IUMSK = 0o7777;
2250 pub const ISUID = 0o4000;
2251 pub const ISGID = 0o2000;
2252 pub const ISVTX = 0o1000;
2253 pub const IRWXU = 0o700;
2254 pub const IRUSR = 0o400;
2255 pub const IWUSR = 0o200;
2256 pub const IXUSR = 0o100;
2257 pub const IRWXG = 0o070;
2258 pub const IRGRP = 0o040;
2259 pub const IWGRP = 0o020;
2260 pub const IXGRP = 0o010;
2261 pub const IRWXO = 0o007;
2262 pub const IROTH = 0o004;
2263 pub const IWOTH = 0o002;
2264 pub const IXOTH = 0o001;
2265
2266 pub fn ISREG(m: u32) bool {
2267 return m & IFMT == IFREG;
2268 }
2269
2270 pub fn ISLNK(m: u32) bool {
2271 return m & IFMT == IFLNK;
2272 }
2273
2274 pub fn ISBLK(m: u32) bool {
2275 return m & IFMT == IFBLK;
2276 }
2277
2278 pub fn ISDIR(m: u32) bool {
2279 return m & IFMT == IFDIR;
2280 }
2281
2282 pub fn ISCHR(m: u32) bool {
2283 return m & IFMT == IFCHR;
2284 }
2285
2286 pub fn ISFIFO(m: u32) bool {
2287 return m & IFMT == IFIFO;
2288 }
2289
2290 pub fn ISSOCK(m: u32) bool {
2291 return m & IFMT == IFSOCK;
2292 }
2293
2294 pub fn ISINDEX(m: u32) bool {
2295 return m & INDEX_DIR == INDEX_DIR;
2296 }
2297 },
2298 .openbsd => struct {
2299 pub const IFMT = 0o170000;
2300
2301 pub const IFIFO = 0o010000;
2302 pub const IFCHR = 0o020000;
2303 pub const IFDIR = 0o040000;
2304 pub const IFBLK = 0o060000;
2305 pub const IFREG = 0o100000;
2306 pub const IFLNK = 0o120000;
2307 pub const IFSOCK = 0o140000;
2308
2309 pub const ISUID = 0o4000;
2310 pub const ISGID = 0o2000;
2311 pub const ISVTX = 0o1000;
2312 pub const IRWXU = 0o700;
2313 pub const IRUSR = 0o400;
2314 pub const IWUSR = 0o200;
2315 pub const IXUSR = 0o100;
2316 pub const IRWXG = 0o070;
2317 pub const IRGRP = 0o040;
2318 pub const IWGRP = 0o020;
2319 pub const IXGRP = 0o010;
2320 pub const IRWXO = 0o007;
2321 pub const IROTH = 0o004;
2322 pub const IWOTH = 0o002;
2323 pub const IXOTH = 0o001;
2324
2325 pub const BLKSIZE = 512;
2326
2327 pub fn ISFIFO(m: u32) bool {
2328 return m & IFMT == IFIFO;
2329 }
2330
2331 pub fn ISCHR(m: u32) bool {
2332 return m & IFMT == IFCHR;
2333 }
2334
2335 pub fn ISDIR(m: u32) bool {
2336 return m & IFMT == IFDIR;
2337 }
2338
2339 pub fn ISBLK(m: u32) bool {
2340 return m & IFMT == IFBLK;
2341 }
2342
2343 pub fn ISREG(m: u32) bool {
2344 return m & IFMT == IFREG;
2345 }
2346
2347 pub fn ISLNK(m: u32) bool {
2348 return m & IFMT == IFLNK;
2349 }
2350
2351 pub fn ISSOCK(m: u32) bool {
2352 return m & IFMT == IFSOCK;
2353 }
2354 },
2355 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/sys/stat.h#L16-L51
2356 .serenity => struct {
2357 pub const IFMT = 0o170000;
2358 pub const IFDIR = 0o040000;
2359 pub const IFCHR = 0o020000;
2360 pub const IFBLK = 0o060000;
2361 pub const IFREG = 0o100000;
2362 pub const IFIFO = 0o010000;
2363 pub const IFLNK = 0o120000;
2364 pub const IFSOCK = 0o140000;
2365
2366 pub const ISUID = 0o4000;
2367 pub const ISGID = 0o2000;
2368 pub const ISVTX = 0o1000;
2369 pub const IRUSR = 0o400;
2370 pub const IWUSR = 0o200;
2371 pub const IXUSR = 0o100;
2372 pub const IREAD = IRUSR;
2373 pub const IWRITE = IWUSR;
2374 pub const IEXEC = IXUSR;
2375 pub const IRGRP = 0o040;
2376 pub const IWGRP = 0o020;
2377 pub const IXGRP = 0o010;
2378 pub const IROTH = 0o004;
2379 pub const IWOTH = 0o002;
2380 pub const IXOTH = 0o001;
2381
2382 pub const IRWXU = IRUSR | IWUSR | IXUSR;
2383
2384 pub const IRWXG = IRWXU >> 3;
2385 pub const IRWXO = IRWXG >> 3;
2386
2387 pub fn ISDIR(m: u32) bool {
2388 return m & IFMT == IFDIR;
2389 }
2390
2391 pub fn ISCHR(m: u32) bool {
2392 return m & IFMT == IFCHR;
2393 }
2394
2395 pub fn ISBLK(m: u32) bool {
2396 return m & IFMT == IFBLK;
2397 }
2398
2399 pub fn ISREG(m: u32) bool {
2400 return m & IFMT == IFREG;
2401 }
2402
2403 pub fn ISFIFO(m: u32) bool {
2404 return m & IFMT == IFIFO;
2405 }
2406
2407 pub fn ISLNK(m: u32) bool {
2408 return m & IFMT == IFLNK;
2409 }
2410
2411 pub fn ISSOCK(m: u32) bool {
2412 return m & IFMT == IFSOCK;
2413 }
2414 },
2415 else => void,
2416};
2417pub const SA = switch (native_os) {
2418 .linux => linux.SA,
2419 .emscripten => emscripten.SA,
2420 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
2421 /// take signal on signal stack
2422 pub const ONSTACK = 0x0001;
2423 /// restart system on signal return
2424 pub const RESTART = 0x0002;
2425 /// reset to SIG.DFL when taking signal
2426 pub const RESETHAND = 0x0004;
2427 /// do not generate SIG.CHLD on child stop
2428 pub const NOCLDSTOP = 0x0008;
2429 /// don't mask the signal we're delivering
2430 pub const NODEFER = 0x0010;
2431 /// don't keep zombies around
2432 pub const NOCLDWAIT = 0x0020;
2433 /// signal handler with SIGINFO args
2434 pub const SIGINFO = 0x0040;
2435 /// do not bounce off kernel's sigtramp
2436 pub const USERTRAMP = 0x0100;
2437 /// signal handler with SIGINFO args with 64bit regs information
2438 pub const @"64REGSET" = 0x0200;
2439 },
2440 .freebsd => struct {
2441 pub const ONSTACK = 0x0001;
2442 pub const RESTART = 0x0002;
2443 pub const RESETHAND = 0x0004;
2444 pub const NOCLDSTOP = 0x0008;
2445 pub const NODEFER = 0x0010;
2446 pub const NOCLDWAIT = 0x0020;
2447 pub const SIGINFO = 0x0040;
2448 },
2449 .illumos => struct {
2450 pub const ONSTACK = 0x00000001;
2451 pub const RESETHAND = 0x00000002;
2452 pub const RESTART = 0x00000004;
2453 pub const SIGINFO = 0x00000008;
2454 pub const NODEFER = 0x00000010;
2455 pub const NOCLDWAIT = 0x00010000;
2456 },
2457 .netbsd => struct {
2458 pub const ONSTACK = 0x0001;
2459 pub const RESTART = 0x0002;
2460 pub const RESETHAND = 0x0004;
2461 pub const NOCLDSTOP = 0x0008;
2462 pub const NODEFER = 0x0010;
2463 pub const NOCLDWAIT = 0x0020;
2464 pub const SIGINFO = 0x0040;
2465 },
2466 .dragonfly => struct {
2467 pub const ONSTACK = 0x0001;
2468 pub const RESTART = 0x0002;
2469 pub const RESETHAND = 0x0004;
2470 pub const NODEFER = 0x0010;
2471 pub const NOCLDWAIT = 0x0020;
2472 pub const SIGINFO = 0x0040;
2473 },
2474 .haiku => struct {
2475 pub const NOCLDSTOP = 0x01;
2476 pub const NOCLDWAIT = 0x02;
2477 pub const RESETHAND = 0x04;
2478 pub const NODEFER = 0x08;
2479 pub const RESTART = 0x10;
2480 pub const ONSTACK = 0x20;
2481 pub const SIGINFO = 0x40;
2482 pub const NOMASK = NODEFER;
2483 pub const STACK = ONSTACK;
2484 pub const ONESHOT = RESETHAND;
2485 },
2486 .openbsd => struct {
2487 pub const ONSTACK = 0x0001;
2488 pub const RESTART = 0x0002;
2489 pub const RESETHAND = 0x0004;
2490 pub const NOCLDSTOP = 0x0008;
2491 pub const NODEFER = 0x0010;
2492 pub const NOCLDWAIT = 0x0020;
2493 pub const SIGINFO = 0x0040;
2494 },
2495 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L65-L71
2496 .serenity => struct {
2497 pub const NOCLDSTOP = 1;
2498 pub const NOCLDWAIT = 2;
2499 pub const SIGINFO = 4;
2500 pub const ONSTACK = 0x08000000;
2501 pub const RESTART = 0x10000000;
2502 pub const NODEFER = 0x40000000;
2503 pub const RESETHAND = 0x80000000;
2504 pub const NOMASK = NODEFER;
2505 pub const ONESHOT = RESETHAND;
2506 },
2507 else => void,
2508};
2509pub const sigval_t = switch (native_os) {
2510 .netbsd, .illumos => extern union {
2511 int: i32,
2512 ptr: ?*anyopaque,
2513 },
2514 else => void,
2515};
2516
2517pub const SC = switch (native_os) {
2518 .linux => linux.SC,
2519 else => void,
2520};
2521
2522pub const _SC = if (builtin.abi.isAndroid()) enum(c_int) {
2523 PAGESIZE = 39,
2524 NPROCESSORS_ONLN = 97,
2525} else switch (native_os) {
2526 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => enum(c_int) {
2527 PAGESIZE = 29,
2528 },
2529 .dragonfly => enum(c_int) {
2530 PAGESIZE = 47,
2531 },
2532 .freebsd => enum(c_int) {
2533 PAGESIZE = 47,
2534 },
2535 .fuchsia => enum(c_int) {
2536 PAGESIZE = 30,
2537 },
2538 .haiku => enum(c_int) {
2539 PAGESIZE = 27,
2540 },
2541 .linux => enum(c_int) {
2542 PAGESIZE = 30,
2543 },
2544 .netbsd => enum(c_int) {
2545 PAGESIZE = 28,
2546 },
2547 .openbsd => enum(c_int) {
2548 PAGESIZE = 28,
2549 },
2550 .illumos => enum(c_int) {
2551 PAGESIZE = 11,
2552 NPROCESSORS_ONLN = 15,
2553 SIGRT_MIN = 40,
2554 SIGRT_MAX = 41,
2555 },
2556 // https://github.com/SerenityOS/serenity/blob/1dfc9e2df39dd23f1de92530677c845aae4345f2/Kernel/API/POSIX/unistd.h#L36-L52
2557 .serenity => enum(c_int) {
2558 MONOTONIC_CLOCK = 0,
2559 NPROCESSORS_CONF = 1,
2560 NPROCESSORS_ONLN = 2,
2561 OPEN_MAX = 3,
2562 HOST_NAME_MAX = 4,
2563 TTY_NAME_MAX = 5,
2564 PAGESIZE = 6,
2565 GETPW_R_SIZE_MAX = 7,
2566 GETGR_R_SIZE_MAX = 8,
2567 CLK_TCK = 9,
2568 SYMLOOP_MAX = 10,
2569 MAPPED_FILES = 11,
2570 ARG_MAX = 12,
2571 IOV_MAX = 13,
2572 PHYS_PAGES = 14,
2573 },
2574 else => void,
2575};
2576
2577pub const SEEK = switch (native_os) {
2578 .linux => linux.SEEK,
2579 .emscripten => emscripten.SEEK,
2580 .wasi => struct {
2581 pub const SET: wasi.whence_t = .SET;
2582 pub const CUR: wasi.whence_t = .CUR;
2583 pub const END: wasi.whence_t = .END;
2584 },
2585 // https://github.com/SerenityOS/serenity/blob/808ce594db1f2190e5212a250e900bde2ffe710b/Kernel/API/POSIX/stdio.h#L15-L17
2586 .openbsd, .haiku, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows, .serenity => struct {
2587 pub const SET = 0;
2588 pub const CUR = 1;
2589 pub const END = 2;
2590 },
2591 .dragonfly, .illumos => struct {
2592 pub const SET = 0;
2593 pub const CUR = 1;
2594 pub const END = 2;
2595 pub const DATA = 3;
2596 pub const HOLE = 4;
2597 },
2598 else => void,
2599};
2600pub const SHUT = switch (native_os) {
2601 .linux => linux.SHUT,
2602 .emscripten => emscripten.SHUT,
2603 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L40-L42
2604 else => struct {
2605 pub const RD = 0;
2606 pub const WR = 1;
2607 pub const RDWR = 2;
2608 },
2609};
2610
2611/// Signal types
2612pub const SIG = switch (native_os) {
2613 .linux => linux.SIG,
2614 .emscripten => emscripten.SIG,
2615 .windows => enum(u32) {
2616 /// interrupt
2617 INT = 2,
2618 /// illegal instruction - invalid function image
2619 ILL = 4,
2620 /// floating point exception
2621 FPE = 8,
2622 /// segment violation
2623 SEGV = 11,
2624 /// Software termination signal from kill
2625 TERM = 15,
2626 /// Ctrl-Break sequence
2627 BREAK = 21,
2628 /// abnormal termination triggered by abort call
2629 ABRT = 22,
2630 /// SIGABRT compatible with other platforms, same as SIGABRT
2631 ABRT_COMPAT = 6,
2632 _,
2633
2634 // Signal action codes
2635 /// default signal action
2636 pub const DFL = 0;
2637 /// ignore signal
2638 pub const IGN = 1;
2639 /// return current value
2640 pub const GET = 2;
2641 /// signal gets error
2642 pub const SGE = 3;
2643 /// acknowledge
2644 pub const ACK = 4;
2645 /// Signal error value (returned by signal call on error)
2646 pub const ERR = -1;
2647 },
2648 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => enum(u32) {
2649 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2650 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2651 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2652 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(5);
2653
2654 /// block specified signal set
2655 pub const BLOCK = 1;
2656 /// unblock specified signal set
2657 pub const UNBLOCK = 2;
2658 /// set specified signal set
2659 pub const SETMASK = 3;
2660
2661 pub const IOT: SIG = .ABRT;
2662 pub const POLL: SIG = .EMT;
2663
2664 /// hangup
2665 HUP = 1,
2666 /// interrupt
2667 INT = 2,
2668 /// quit
2669 QUIT = 3,
2670 /// illegal instruction (not reset when caught)
2671 ILL = 4,
2672 /// trace trap (not reset when caught)
2673 TRAP = 5,
2674 /// abort()
2675 ABRT = 6,
2676 /// EMT instruction
2677 EMT = 7,
2678 /// floating point exception
2679 FPE = 8,
2680 /// kill (cannot be caught or ignored)
2681 KILL = 9,
2682 /// bus error
2683 BUS = 10,
2684 /// segmentation violation
2685 SEGV = 11,
2686 /// bad argument to system call
2687 SYS = 12,
2688 /// write on a pipe with no one to read it
2689 PIPE = 13,
2690 /// alarm clock
2691 ALRM = 14,
2692 /// software termination signal from kill
2693 TERM = 15,
2694 /// urgent condition on IO channel
2695 URG = 16,
2696 /// sendable stop signal not from tty
2697 STOP = 17,
2698 /// stop signal from tty
2699 TSTP = 18,
2700 /// continue a stopped process
2701 CONT = 19,
2702 /// to parent on child stop or exit
2703 CHLD = 20,
2704 /// to readers pgrp upon background tty read
2705 TTIN = 21,
2706 /// like TTIN for output if (tp->t_local&LTOSTOP)
2707 TTOU = 22,
2708 /// input/output possible signal
2709 IO = 23,
2710 /// exceeded CPU time limit
2711 XCPU = 24,
2712 /// exceeded file size limit
2713 XFSZ = 25,
2714 /// virtual time alarm
2715 VTALRM = 26,
2716 /// profiling time alarm
2717 PROF = 27,
2718 /// window size changes
2719 WINCH = 28,
2720 /// information request
2721 INFO = 29,
2722 /// user defined signal 1
2723 USR1 = 30,
2724 /// user defined signal 2
2725 USR2 = 31,
2726 _,
2727 },
2728 .freebsd => enum(u32) {
2729 pub const BLOCK = 1;
2730 pub const UNBLOCK = 2;
2731 pub const SETMASK = 3;
2732
2733 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2734 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2735 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2736
2737 pub const WORDS = 4;
2738 pub const MAXSIG = 128;
2739
2740 pub inline fn IDX(sig: usize) usize {
2741 return sig - 1;
2742 }
2743 pub inline fn WORD(sig: usize) usize {
2744 return IDX(sig) >> 5;
2745 }
2746 pub inline fn BIT(sig: usize) usize {
2747 return 1 << (IDX(sig) & 31);
2748 }
2749 pub inline fn VALID(sig: usize) usize {
2750 return sig <= MAXSIG and sig > 0;
2751 }
2752
2753 pub const IOT: SIG = .ABRT;
2754 pub const LWP: SIG = .THR;
2755
2756 pub const RTMIN = 65;
2757 pub const RTMAX = 126;
2758
2759 HUP = 1,
2760 INT = 2,
2761 QUIT = 3,
2762 ILL = 4,
2763 TRAP = 5,
2764 ABRT = 6,
2765 EMT = 7,
2766 FPE = 8,
2767 KILL = 9,
2768 BUS = 10,
2769 SEGV = 11,
2770 SYS = 12,
2771 PIPE = 13,
2772 ALRM = 14,
2773 TERM = 15,
2774 URG = 16,
2775 STOP = 17,
2776 TSTP = 18,
2777 CONT = 19,
2778 CHLD = 20,
2779 TTIN = 21,
2780 TTOU = 22,
2781 IO = 23,
2782 XCPU = 24,
2783 XFSZ = 25,
2784 VTALRM = 26,
2785 PROF = 27,
2786 WINCH = 28,
2787 INFO = 29,
2788 USR1 = 30,
2789 USR2 = 31,
2790 THR = 32,
2791 LIBRT = 33,
2792 _,
2793 },
2794 .illumos => enum(u32) {
2795 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2796 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2797 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2798 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(2);
2799
2800 pub const WORDS = 4;
2801 pub const MAXSIG = 75;
2802
2803 pub const BLOCK = 1;
2804 pub const UNBLOCK = 2;
2805 pub const SETMASK = 3;
2806
2807 pub const RTMIN = 42;
2808 pub const RTMAX = 74;
2809
2810 pub inline fn IDX(sig: usize) usize {
2811 return sig - 1;
2812 }
2813 pub inline fn WORD(sig: usize) usize {
2814 return IDX(sig) >> 5;
2815 }
2816 pub inline fn BIT(sig: usize) usize {
2817 return 1 << (IDX(sig) & 31);
2818 }
2819 pub inline fn VALID(sig: usize) usize {
2820 return sig <= MAXSIG and sig > 0;
2821 }
2822
2823 pub const POLL: SIG = .IO;
2824 pub const IOT: SIG = .ABRT;
2825 pub const CLD: SIG = .CHLD;
2826
2827 HUP = 1,
2828 INT = 2,
2829 QUIT = 3,
2830 ILL = 4,
2831 TRAP = 5,
2832 ABRT = 6,
2833 EMT = 7,
2834 FPE = 8,
2835 KILL = 9,
2836 BUS = 10,
2837 SEGV = 11,
2838 SYS = 12,
2839 PIPE = 13,
2840 ALRM = 14,
2841 TERM = 15,
2842 USR1 = 16,
2843 USR2 = 17,
2844 CHLD = 18,
2845 PWR = 19,
2846 WINCH = 20,
2847 URG = 21,
2848 IO = 22,
2849 STOP = 23,
2850 TSTP = 24,
2851 CONT = 25,
2852 TTIN = 26,
2853 TTOU = 27,
2854 VTALRM = 28,
2855 PROF = 29,
2856 XCPU = 30,
2857 XFSZ = 31,
2858 WAITING = 32,
2859 LWP = 33,
2860 FREEZE = 34,
2861 THAW = 35,
2862 CANCEL = 36,
2863 LOST = 37,
2864 XRES = 38,
2865 JVM1 = 39,
2866 JVM2 = 40,
2867 INFO = 41,
2868 _,
2869 },
2870 .netbsd => enum(u32) {
2871 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2872 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2873 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2874
2875 pub const WORDS = 4;
2876 pub const MAXSIG = 128;
2877
2878 pub const BLOCK = 1;
2879 pub const UNBLOCK = 2;
2880 pub const SETMASK = 3;
2881
2882 pub const RTMIN = 33;
2883 pub const RTMAX = 63;
2884
2885 pub inline fn IDX(sig: usize) usize {
2886 return sig - 1;
2887 }
2888 pub inline fn WORD(sig: usize) usize {
2889 return IDX(sig) >> 5;
2890 }
2891 pub inline fn BIT(sig: usize) usize {
2892 return 1 << (IDX(sig) & 31);
2893 }
2894 pub inline fn VALID(sig: usize) usize {
2895 return sig <= MAXSIG and sig > 0;
2896 }
2897
2898 pub const IOT: SIG = .ABRT;
2899
2900 HUP = 1,
2901 INT = 2,
2902 QUIT = 3,
2903 ILL = 4,
2904 TRAP = 5,
2905 ABRT = 6,
2906 EMT = 7,
2907 FPE = 8,
2908 KILL = 9,
2909 BUS = 10,
2910 SEGV = 11,
2911 SYS = 12,
2912 PIPE = 13,
2913 ALRM = 14,
2914 TERM = 15,
2915 URG = 16,
2916 STOP = 17,
2917 TSTP = 18,
2918 CONT = 19,
2919 CHLD = 20,
2920 TTIN = 21,
2921 TTOU = 22,
2922 IO = 23,
2923 XCPU = 24,
2924 XFSZ = 25,
2925 VTALRM = 26,
2926 PROF = 27,
2927 WINCH = 28,
2928 INFO = 29,
2929 USR1 = 30,
2930 USR2 = 31,
2931 PWR = 32,
2932 _,
2933 },
2934 .dragonfly => enum(u32) {
2935 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2936 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2937 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2938
2939 pub const BLOCK = 1;
2940 pub const UNBLOCK = 2;
2941 pub const SETMASK = 3;
2942
2943 pub const WORDS = 4;
2944
2945 pub const IOT: SIG = .ABRT;
2946
2947 HUP = 1,
2948 INT = 2,
2949 QUIT = 3,
2950 ILL = 4,
2951 TRAP = 5,
2952 ABRT = 6,
2953 EMT = 7,
2954 FPE = 8,
2955 KILL = 9,
2956 BUS = 10,
2957 SEGV = 11,
2958 SYS = 12,
2959 PIPE = 13,
2960 ALRM = 14,
2961 TERM = 15,
2962 URG = 16,
2963 STOP = 17,
2964 TSTP = 18,
2965 CONT = 19,
2966 CHLD = 20,
2967 TTIN = 21,
2968 TTOU = 22,
2969 IO = 23,
2970 XCPU = 24,
2971 XFSZ = 25,
2972 VTALRM = 26,
2973 PROF = 27,
2974 WINCH = 28,
2975 INFO = 29,
2976 USR1 = 30,
2977 USR2 = 31,
2978 THR = 32,
2979 CKPT = 33,
2980 CKPTEXIT = 34,
2981 _,
2982 },
2983 .haiku => enum(u32) {
2984 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2985 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2986 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2987
2988 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);
2989
2990 pub const BLOCK = 1;
2991 pub const UNBLOCK = 2;
2992 pub const SETMASK = 3;
2993
2994 pub const IO: SIG = .POLL;
2995 pub const IOT: SIG = .ABRT;
2996
2997 HUP = 1,
2998 INT = 2,
2999 QUIT = 3,
3000 ILL = 4,
3001 CHLD = 5,
3002 ABRT = 6,
3003 PIPE = 7,
3004 FPE = 8,
3005 KILL = 9,
3006 STOP = 10,
3007 SEGV = 11,
3008 CONT = 12,
3009 TSTP = 13,
3010 ALRM = 14,
3011 TERM = 15,
3012 TTIN = 16,
3013 TTOU = 17,
3014 USR1 = 18,
3015 USR2 = 19,
3016 WINCH = 20,
3017 KILLTHR = 21,
3018 TRAP = 22,
3019 POLL = 23,
3020 PROF = 24,
3021 SYS = 25,
3022 URG = 26,
3023 VTALRM = 27,
3024 XCPU = 28,
3025 XFSZ = 29,
3026 BUS = 30,
3027 RESERVED1 = 31,
3028 RESERVED2 = 32,
3029 _,
3030 },
3031 .openbsd => enum(u32) {
3032 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
3033 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
3034 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
3035 pub const CATCH: ?Sigaction.handler_fn = @ptrFromInt(2);
3036 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);
3037
3038 pub const BLOCK = 1;
3039 pub const UNBLOCK = 2;
3040 pub const SETMASK = 3;
3041
3042 pub const IOT: SIG = .ABRT;
3043
3044 HUP = 1,
3045 INT = 2,
3046 QUIT = 3,
3047 ILL = 4,
3048 TRAP = 5,
3049 ABRT = 6,
3050 EMT = 7,
3051 FPE = 8,
3052 KILL = 9,
3053 BUS = 10,
3054 SEGV = 11,
3055 SYS = 12,
3056 PIPE = 13,
3057 ALRM = 14,
3058 TERM = 15,
3059 URG = 16,
3060 STOP = 17,
3061 TSTP = 18,
3062 CONT = 19,
3063 CHLD = 20,
3064 TTIN = 21,
3065 TTOU = 22,
3066 IO = 23,
3067 XCPU = 24,
3068 XFSZ = 25,
3069 VTALRM = 26,
3070 PROF = 27,
3071 WINCH = 28,
3072 INFO = 29,
3073 USR1 = 30,
3074 USR2 = 31,
3075 PWR = 32,
3076 _,
3077 },
3078 // https://github.com/SerenityOS/serenity/blob/046c23f567a17758d762a33bdf04bacbfd088f9f/Kernel/API/POSIX/signal.h
3079 // https://github.com/SerenityOS/serenity/blob/046c23f567a17758d762a33bdf04bacbfd088f9f/Kernel/API/POSIX/signal_numbers.h
3080 .serenity => enum(u32) {
3081 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
3082 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
3083 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
3084
3085 pub const BLOCK = 1;
3086 pub const UNBLOCK = 2;
3087 pub const SETMASK = 3;
3088
3089 INVAL = 0,
3090 HUP = 1,
3091 INT = 2,
3092 QUIT = 3,
3093 ILL = 4,
3094 TRAP = 5,
3095 ABRT = 6,
3096 BUS = 7,
3097 FPE = 8,
3098 KILL = 9,
3099 USR1 = 10,
3100 SEGV = 11,
3101 USR2 = 12,
3102 PIPE = 13,
3103 ALRM = 14,
3104 TERM = 15,
3105 STKFLT = 16,
3106 CHLD = 17,
3107 CONT = 18,
3108 STOP = 19,
3109 TSTP = 20,
3110 TTIN = 21,
3111 TTOU = 22,
3112 URG = 23,
3113 XCPU = 24,
3114 XFSZ = 25,
3115 VTALRM = 26,
3116 PROF = 27,
3117 WINCH = 28,
3118 IO = 29,
3119 INFO = 30,
3120 SYS = 31,
3121 CANCEL = 32,
3122 _,
3123 },
3124 else => void,
3125};
3126
3127pub const SIOCGIFINDEX = switch (native_os) {
3128 .linux => linux.SIOCGIFINDEX,
3129 .emscripten => emscripten.SIOCGIFINDEX,
3130 .illumos => illumos.SIOCGLIFINDEX,
3131 // https://github.com/SerenityOS/serenity/blob/cb10f70394fb7e9cfc77f827adb2e46d199bc3a5/Kernel/API/Ioctl.h#L118
3132 .serenity => 34,
3133 else => void,
3134};
3135
3136pub const STDIN_FILENO = switch (native_os) {
3137 .linux => linux.STDIN_FILENO,
3138 .emscripten => emscripten.STDIN_FILENO,
3139 else => 0,
3140};
3141pub const STDOUT_FILENO = switch (native_os) {
3142 .linux => linux.STDOUT_FILENO,
3143 .emscripten => emscripten.STDOUT_FILENO,
3144 else => 1,
3145};
3146pub const STDERR_FILENO = switch (native_os) {
3147 .linux => linux.STDERR_FILENO,
3148 .emscripten => emscripten.STDERR_FILENO,
3149 else => 2,
3150};
3151
3152pub const SYS = switch (native_os) {
3153 .linux => linux.SYS,
3154 else => void,
3155};
3156
3157/// A common format for the Sigaction struct across a variety of Linux flavors.
3158const common_linux_Sigaction = extern struct {
3159 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3160 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
3161
3162 handler: extern union {
3163 handler: ?handler_fn,
3164 sigaction: ?sigaction_fn,
3165 },
3166 mask: sigset_t,
3167 flags: c_uint,
3168 restorer: ?*const fn () callconv(.c) void = null, // C library will fill this in
3169};
3170
3171/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
3172pub const Sigaction = switch (native_os) {
3173 .linux => switch (native_arch) {
3174 .mips,
3175 .mipsel,
3176 .mips64,
3177 .mips64el,
3178 => if (builtin.target.abi.isMusl())
3179 common_linux_Sigaction
3180 else if (builtin.target.ptrBitWidth() == 64) extern struct {
3181 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3182 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
3183
3184 flags: c_uint,
3185 handler: extern union {
3186 handler: ?handler_fn,
3187 sigaction: ?sigaction_fn,
3188 },
3189 mask: sigset_t,
3190 restorer: ?*const fn () callconv(.c) void = null,
3191 } else extern struct {
3192 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3193 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
3194
3195 flags: c_uint,
3196 handler: extern union {
3197 handler: ?handler_fn,
3198 sigaction: ?sigaction_fn,
3199 },
3200 mask: sigset_t,
3201 restorer: ?*const fn () callconv(.c) void = null,
3202 __resv: [1]c_int = .{0},
3203 },
3204 .s390x => if (builtin.abi == .gnu) extern struct {
3205 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3206 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
3207
3208 handler: extern union {
3209 handler: ?handler_fn,
3210 sigaction: ?sigaction_fn,
3211 },
3212 __glibc_reserved0: c_int = 0,
3213 flags: c_uint,
3214 restorer: ?*const fn () callconv(.c) void = null,
3215 mask: sigset_t,
3216 } else common_linux_Sigaction,
3217 else => common_linux_Sigaction,
3218 },
3219 .emscripten => emscripten.Sigaction,
3220 .netbsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
3221 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3222 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
3223
3224 handler: extern union {
3225 handler: ?handler_fn,
3226 sigaction: ?sigaction_fn,
3227 },
3228 mask: sigset_t,
3229 flags: c_uint,
3230 },
3231 .dragonfly, .freebsd => extern struct {
3232 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3233 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
3234
3235 /// signal handler
3236 handler: extern union {
3237 handler: ?handler_fn,
3238 sigaction: ?sigaction_fn,
3239 },
3240 /// see signal options
3241 flags: c_uint,
3242 /// signal mask to apply
3243 mask: sigset_t,
3244 },
3245 .illumos => extern struct {
3246 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3247 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
3248
3249 /// signal options
3250 flags: c_uint,
3251 /// signal handler
3252 handler: extern union {
3253 handler: ?handler_fn,
3254 sigaction: ?sigaction_fn,
3255 },
3256 /// signal mask to apply
3257 mask: sigset_t,
3258 },
3259 .haiku => extern struct {
3260 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3261 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
3262
3263 /// signal handler
3264 handler: extern union {
3265 handler: ?handler_fn,
3266 sigaction: ?sigaction_fn,
3267 },
3268
3269 /// signal mask to apply
3270 mask: sigset_t,
3271
3272 /// see signal options
3273 flags: i32,
3274
3275 /// will be passed to the signal handler, BeOS extension
3276 userdata: *allowzero anyopaque = undefined,
3277 },
3278 .openbsd => extern struct {
3279 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3280 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
3281
3282 /// signal handler
3283 handler: extern union {
3284 handler: ?handler_fn,
3285 sigaction: ?sigaction_fn,
3286 },
3287 /// signal mask to apply
3288 mask: sigset_t,
3289 /// signal options
3290 flags: c_uint,
3291 },
3292 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L39-L46
3293 .serenity => extern struct {
3294 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
3295 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
3296
3297 handler: extern union {
3298 handler: ?handler_fn,
3299 sigaction: ?sigaction_fn,
3300 },
3301 mask: sigset_t,
3302 flags: c_uint,
3303 },
3304 else => void,
3305};
3306pub const T = switch (native_os) {
3307 .linux => linux.T,
3308 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
3309 pub const IOCGWINSZ = ior(0x40000000, 't', 104, @sizeOf(winsize));
3310
3311 fn ior(inout: u32, group_arg: usize, num: usize, len: usize) usize {
3312 return (inout | ((len & IOCPARM_MASK) << 16) | ((group_arg) << 8) | (num));
3313 }
3314 },
3315 .freebsd => struct {
3316 pub const IOCEXCL = 0x2000740d;
3317 pub const IOCNXCL = 0x2000740e;
3318 pub const IOCSCTTY = 0x20007461;
3319 pub const IOCGPGRP = 0x40047477;
3320 pub const IOCSPGRP = 0x80047476;
3321 pub const IOCOUTQ = 0x40047473;
3322 pub const IOCSTI = 0x80017472;
3323 pub const IOCGWINSZ = 0x40087468;
3324 pub const IOCSWINSZ = 0x80087467;
3325 pub const IOCMGET = 0x4004746a;
3326 pub const IOCMBIS = 0x8004746c;
3327 pub const IOCMBIC = 0x8004746b;
3328 pub const IOCMSET = 0x8004746d;
3329 pub const FIONREAD = 0x4004667f;
3330 pub const IOCCONS = 0x80047462;
3331 pub const IOCPKT = 0x80047470;
3332 pub const FIONBIO = 0x8004667e;
3333 pub const IOCNOTTY = 0x20007471;
3334 pub const IOCSETD = 0x8004741b;
3335 pub const IOCGETD = 0x4004741a;
3336 pub const IOCSBRK = 0x2000747b;
3337 pub const IOCCBRK = 0x2000747a;
3338 pub const IOCGSID = 0x40047463;
3339 pub const IOCGPTN = 0x4004740f;
3340 pub const IOCSIG = 0x2004745f;
3341 },
3342 .illumos => struct {
3343 pub const CGETA = tioc('T', 1);
3344 pub const CSETA = tioc('T', 2);
3345 pub const CSETAW = tioc('T', 3);
3346 pub const CSETAF = tioc('T', 4);
3347 pub const CSBRK = tioc('T', 5);
3348 pub const CXONC = tioc('T', 6);
3349 pub const CFLSH = tioc('T', 7);
3350 pub const IOCGWINSZ = tioc('T', 104);
3351 pub const IOCSWINSZ = tioc('T', 103);
3352 // Softcarrier ioctls
3353 pub const IOCGSOFTCAR = tioc('T', 105);
3354 pub const IOCSSOFTCAR = tioc('T', 106);
3355 // termios ioctls
3356 pub const CGETS = tioc('T', 13);
3357 pub const CSETS = tioc('T', 14);
3358 pub const CSANOW = tioc('T', 14);
3359 pub const CSETSW = tioc('T', 15);
3360 pub const CSADRAIN = tioc('T', 15);
3361 pub const CSETSF = tioc('T', 16);
3362 pub const IOCSETLD = tioc('T', 123);
3363 pub const IOCGETLD = tioc('T', 124);
3364 // NTP PPS ioctls
3365 pub const IOCGPPS = tioc('T', 125);
3366 pub const IOCSPPS = tioc('T', 126);
3367 pub const IOCGPPSEV = tioc('T', 127);
3368
3369 pub const IOCGETD = tioc('t', 0);
3370 pub const IOCSETD = tioc('t', 1);
3371 pub const IOCHPCL = tioc('t', 2);
3372 pub const IOCGETP = tioc('t', 8);
3373 pub const IOCSETP = tioc('t', 9);
3374 pub const IOCSETN = tioc('t', 10);
3375 pub const IOCEXCL = tioc('t', 13);
3376 pub const IOCNXCL = tioc('t', 14);
3377 pub const IOCFLUSH = tioc('t', 16);
3378 pub const IOCSETC = tioc('t', 17);
3379 pub const IOCGETC = tioc('t', 18);
3380 /// bis local mode bits
3381 pub const IOCLBIS = tioc('t', 127);
3382 /// bic local mode bits
3383 pub const IOCLBIC = tioc('t', 126);
3384 /// set entire local mode word
3385 pub const IOCLSET = tioc('t', 125);
3386 /// get local modes
3387 pub const IOCLGET = tioc('t', 124);
3388 /// set break bit
3389 pub const IOCSBRK = tioc('t', 123);
3390 /// clear break bit
3391 pub const IOCCBRK = tioc('t', 122);
3392 /// set data terminal ready
3393 pub const IOCSDTR = tioc('t', 121);
3394 /// clear data terminal ready
3395 pub const IOCCDTR = tioc('t', 120);
3396 /// set local special chars
3397 pub const IOCSLTC = tioc('t', 117);
3398 /// get local special chars
3399 pub const IOCGLTC = tioc('t', 116);
3400 /// driver output queue size
3401 pub const IOCOUTQ = tioc('t', 115);
3402 /// void tty association
3403 pub const IOCNOTTY = tioc('t', 113);
3404 /// get a ctty
3405 pub const IOCSCTTY = tioc('t', 132);
3406 /// stop output, like ^S
3407 pub const IOCSTOP = tioc('t', 111);
3408 /// start output, like ^Q
3409 pub const IOCSTART = tioc('t', 110);
3410 /// get pgrp of tty
3411 pub const IOCGPGRP = tioc('t', 20);
3412 /// set pgrp of tty
3413 pub const IOCSPGRP = tioc('t', 21);
3414 /// get session id on ctty
3415 pub const IOCGSID = tioc('t', 22);
3416 /// simulate terminal input
3417 pub const IOCSTI = tioc('t', 23);
3418 /// set all modem bits
3419 pub const IOCMSET = tioc('t', 26);
3420 /// bis modem bits
3421 pub const IOCMBIS = tioc('t', 27);
3422 /// bic modem bits
3423 pub const IOCMBIC = tioc('t', 28);
3424 /// get all modem bits
3425 pub const IOCMGET = tioc('t', 29);
3426
3427 fn tioc(t: u16, num: u8) u16 {
3428 return (t << 8) | num;
3429 }
3430 },
3431 .netbsd => struct {
3432 pub const IOCCBRK = 0x2000747a;
3433 pub const IOCCDTR = 0x20007478;
3434 pub const IOCCONS = 0x80047462;
3435 pub const IOCDCDTIMESTAMP = 0x40107458;
3436 pub const IOCDRAIN = 0x2000745e;
3437 pub const IOCEXCL = 0x2000740d;
3438 pub const IOCEXT = 0x80047460;
3439 pub const IOCFLAG_CDTRCTS = 0x10;
3440 pub const IOCFLAG_CLOCAL = 0x2;
3441 pub const IOCFLAG_CRTSCTS = 0x4;
3442 pub const IOCFLAG_MDMBUF = 0x8;
3443 pub const IOCFLAG_SOFTCAR = 0x1;
3444 pub const IOCFLUSH = 0x80047410;
3445 pub const IOCGETA = 0x402c7413;
3446 pub const IOCGETD = 0x4004741a;
3447 pub const IOCGFLAGS = 0x4004745d;
3448 pub const IOCGLINED = 0x40207442;
3449 pub const IOCGPGRP = 0x40047477;
3450 pub const IOCGQSIZE = 0x40047481;
3451 pub const IOCGRANTPT = 0x20007447;
3452 pub const IOCGSID = 0x40047463;
3453 pub const IOCGSIZE = 0x40087468;
3454 pub const IOCGWINSZ = 0x40087468;
3455 pub const IOCMBIC = 0x8004746b;
3456 pub const IOCMBIS = 0x8004746c;
3457 pub const IOCMGET = 0x4004746a;
3458 pub const IOCMSET = 0x8004746d;
3459 pub const IOCM_CAR = 0x40;
3460 pub const IOCM_CD = 0x40;
3461 pub const IOCM_CTS = 0x20;
3462 pub const IOCM_DSR = 0x100;
3463 pub const IOCM_DTR = 0x2;
3464 pub const IOCM_LE = 0x1;
3465 pub const IOCM_RI = 0x80;
3466 pub const IOCM_RNG = 0x80;
3467 pub const IOCM_RTS = 0x4;
3468 pub const IOCM_SR = 0x10;
3469 pub const IOCM_ST = 0x8;
3470 pub const IOCNOTTY = 0x20007471;
3471 pub const IOCNXCL = 0x2000740e;
3472 pub const IOCOUTQ = 0x40047473;
3473 pub const IOCPKT = 0x80047470;
3474 pub const IOCPKT_DATA = 0x0;
3475 pub const IOCPKT_DOSTOP = 0x20;
3476 pub const IOCPKT_FLUSHREAD = 0x1;
3477 pub const IOCPKT_FLUSHWRITE = 0x2;
3478 pub const IOCPKT_IOCTL = 0x40;
3479 pub const IOCPKT_NOSTOP = 0x10;
3480 pub const IOCPKT_START = 0x8;
3481 pub const IOCPKT_STOP = 0x4;
3482 pub const IOCPTMGET = 0x40287446;
3483 pub const IOCPTSNAME = 0x40287448;
3484 pub const IOCRCVFRAME = 0x80087445;
3485 pub const IOCREMOTE = 0x80047469;
3486 pub const IOCSBRK = 0x2000747b;
3487 pub const IOCSCTTY = 0x20007461;
3488 pub const IOCSDTR = 0x20007479;
3489 pub const IOCSETA = 0x802c7414;
3490 pub const IOCSETAF = 0x802c7416;
3491 pub const IOCSETAW = 0x802c7415;
3492 pub const IOCSETD = 0x8004741b;
3493 pub const IOCSFLAGS = 0x8004745c;
3494 pub const IOCSIG = 0x2000745f;
3495 pub const IOCSLINED = 0x80207443;
3496 pub const IOCSPGRP = 0x80047476;
3497 pub const IOCSQSIZE = 0x80047480;
3498 pub const IOCSSIZE = 0x80087467;
3499 pub const IOCSTART = 0x2000746e;
3500 pub const IOCSTAT = 0x80047465;
3501 pub const IOCSTI = 0x80017472;
3502 pub const IOCSTOP = 0x2000746f;
3503 pub const IOCSWINSZ = 0x80087467;
3504 pub const IOCUCNTL = 0x80047466;
3505 pub const IOCXMTFRAME = 0x80087444;
3506 },
3507 .haiku => struct {
3508 pub const CGETA = 0x8000;
3509 pub const CSETA = 0x8001;
3510 pub const CSETAF = 0x8002;
3511 pub const CSETAW = 0x8003;
3512 pub const CWAITEVENT = 0x8004;
3513 pub const CSBRK = 0x8005;
3514 pub const CFLSH = 0x8006;
3515 pub const CXONC = 0x8007;
3516 pub const CQUERYCONNECTED = 0x8008;
3517 pub const CGETBITS = 0x8009;
3518 pub const CSETDTR = 0x8010;
3519 pub const CSETRTS = 0x8011;
3520 pub const IOCGWINSZ = 0x8012;
3521 pub const IOCSWINSZ = 0x8013;
3522 pub const CVTIME = 0x8014;
3523 pub const IOCGPGRP = 0x8015;
3524 pub const IOCSPGRP = 0x8016;
3525 pub const IOCSCTTY = 0x8017;
3526 pub const IOCMGET = 0x8018;
3527 pub const IOCMSET = 0x8019;
3528 pub const IOCSBRK = 0x8020;
3529 pub const IOCCBRK = 0x8021;
3530 pub const IOCMBIS = 0x8022;
3531 pub const IOCMBIC = 0x8023;
3532 pub const IOCGSID = 0x8024;
3533
3534 pub const FIONREAD = 0xbe000001;
3535 pub const FIONBIO = 0xbe000000;
3536 },
3537 .openbsd => struct {
3538 pub const IOCCBRK = 0x2000747a;
3539 pub const IOCCDTR = 0x20007478;
3540 pub const IOCCONS = 0x80047462;
3541 pub const IOCDCDTIMESTAMP = 0x40107458;
3542 pub const IOCDRAIN = 0x2000745e;
3543 pub const IOCEXCL = 0x2000740d;
3544 pub const IOCEXT = 0x80047460;
3545 pub const IOCFLAG_CDTRCTS = 0x10;
3546 pub const IOCFLAG_CLOCAL = 0x2;
3547 pub const IOCFLAG_CRTSCTS = 0x4;
3548 pub const IOCFLAG_MDMBUF = 0x8;
3549 pub const IOCFLAG_SOFTCAR = 0x1;
3550 pub const IOCFLUSH = 0x80047410;
3551 pub const IOCGETA = 0x402c7413;
3552 pub const IOCGETD = 0x4004741a;
3553 pub const IOCGFLAGS = 0x4004745d;
3554 pub const IOCGLINED = 0x40207442;
3555 pub const IOCGPGRP = 0x40047477;
3556 pub const IOCGQSIZE = 0x40047481;
3557 pub const IOCGRANTPT = 0x20007447;
3558 pub const IOCGSID = 0x40047463;
3559 pub const IOCGSIZE = 0x40087468;
3560 pub const IOCGWINSZ = 0x40087468;
3561 pub const IOCMBIC = 0x8004746b;
3562 pub const IOCMBIS = 0x8004746c;
3563 pub const IOCMGET = 0x4004746a;
3564 pub const IOCMSET = 0x8004746d;
3565 pub const IOCM_CAR = 0x40;
3566 pub const IOCM_CD = 0x40;
3567 pub const IOCM_CTS = 0x20;
3568 pub const IOCM_DSR = 0x100;
3569 pub const IOCM_DTR = 0x2;
3570 pub const IOCM_LE = 0x1;
3571 pub const IOCM_RI = 0x80;
3572 pub const IOCM_RNG = 0x80;
3573 pub const IOCM_RTS = 0x4;
3574 pub const IOCM_SR = 0x10;
3575 pub const IOCM_ST = 0x8;
3576 pub const IOCNOTTY = 0x20007471;
3577 pub const IOCNXCL = 0x2000740e;
3578 pub const IOCOUTQ = 0x40047473;
3579 pub const IOCPKT = 0x80047470;
3580 pub const IOCPKT_DATA = 0x0;
3581 pub const IOCPKT_DOSTOP = 0x20;
3582 pub const IOCPKT_FLUSHREAD = 0x1;
3583 pub const IOCPKT_FLUSHWRITE = 0x2;
3584 pub const IOCPKT_IOCTL = 0x40;
3585 pub const IOCPKT_NOSTOP = 0x10;
3586 pub const IOCPKT_START = 0x8;
3587 pub const IOCPKT_STOP = 0x4;
3588 pub const IOCPTMGET = 0x40287446;
3589 pub const IOCPTSNAME = 0x40287448;
3590 pub const IOCRCVFRAME = 0x80087445;
3591 pub const IOCREMOTE = 0x80047469;
3592 pub const IOCSBRK = 0x2000747b;
3593 pub const IOCSCTTY = 0x20007461;
3594 pub const IOCSDTR = 0x20007479;
3595 pub const IOCSETA = 0x802c7414;
3596 pub const IOCSETAF = 0x802c7416;
3597 pub const IOCSETAW = 0x802c7415;
3598 pub const IOCSETD = 0x8004741b;
3599 pub const IOCSFLAGS = 0x8004745c;
3600 pub const IOCSIG = 0x2000745f;
3601 pub const IOCSLINED = 0x80207443;
3602 pub const IOCSPGRP = 0x80047476;
3603 pub const IOCSQSIZE = 0x80047480;
3604 pub const IOCSSIZE = 0x80087467;
3605 pub const IOCSTART = 0x2000746e;
3606 pub const IOCSTAT = 0x80047465;
3607 pub const IOCSTI = 0x80017472;
3608 pub const IOCSTOP = 0x2000746f;
3609 pub const IOCSWINSZ = 0x80087467;
3610 pub const IOCUCNTL = 0x80047466;
3611 pub const IOCXMTFRAME = 0x80087444;
3612 },
3613 .dragonfly => struct {
3614 pub const IOCMODG = 0x40047403;
3615 pub const IOCMODS = 0x80047404;
3616 pub const IOCM_LE = 0x00000001;
3617 pub const IOCM_DTR = 0x00000002;
3618 pub const IOCM_RTS = 0x00000004;
3619 pub const IOCM_ST = 0x00000008;
3620 pub const IOCM_SR = 0x00000010;
3621 pub const IOCM_CTS = 0x00000020;
3622 pub const IOCM_CAR = 0x00000040;
3623 pub const IOCM_CD = 0x00000040;
3624 pub const IOCM_RNG = 0x00000080;
3625 pub const IOCM_RI = 0x00000080;
3626 pub const IOCM_DSR = 0x00000100;
3627 pub const IOCEXCL = 0x2000740d;
3628 pub const IOCNXCL = 0x2000740e;
3629 pub const IOCFLUSH = 0x80047410;
3630 pub const IOCGETA = 0x402c7413;
3631 pub const IOCSETA = 0x802c7414;
3632 pub const IOCSETAW = 0x802c7415;
3633 pub const IOCSETAF = 0x802c7416;
3634 pub const IOCGETD = 0x4004741a;
3635 pub const IOCSETD = 0x8004741b;
3636 pub const IOCSBRK = 0x2000747b;
3637 pub const IOCCBRK = 0x2000747a;
3638 pub const IOCSDTR = 0x20007479;
3639 pub const IOCCDTR = 0x20007478;
3640 pub const IOCGPGRP = 0x40047477;
3641 pub const IOCSPGRP = 0x80047476;
3642 pub const IOCOUTQ = 0x40047473;
3643 pub const IOCSTI = 0x80017472;
3644 pub const IOCNOTTY = 0x20007471;
3645 pub const IOCPKT = 0x80047470;
3646 pub const IOCPKT_DATA = 0x00000000;
3647 pub const IOCPKT_FLUSHREAD = 0x00000001;
3648 pub const IOCPKT_FLUSHWRITE = 0x00000002;
3649 pub const IOCPKT_STOP = 0x00000004;
3650 pub const IOCPKT_START = 0x00000008;
3651 pub const IOCPKT_NOSTOP = 0x00000010;
3652 pub const IOCPKT_DOSTOP = 0x00000020;
3653 pub const IOCPKT_IOCTL = 0x00000040;
3654 pub const IOCSTOP = 0x2000746f;
3655 pub const IOCSTART = 0x2000746e;
3656 pub const IOCMSET = 0x8004746d;
3657 pub const IOCMBIS = 0x8004746c;
3658 pub const IOCMBIC = 0x8004746b;
3659 pub const IOCMGET = 0x4004746a;
3660 pub const IOCREMOTE = 0x80047469;
3661 pub const IOCGWINSZ = 0x40087468;
3662 pub const IOCSWINSZ = 0x80087467;
3663 pub const IOCUCNTL = 0x80047466;
3664 pub const IOCSTAT = 0x20007465;
3665 pub const IOCGSID = 0x40047463;
3666 pub const IOCCONS = 0x80047462;
3667 pub const IOCSCTTY = 0x20007461;
3668 pub const IOCEXT = 0x80047460;
3669 pub const IOCSIG = 0x2000745f;
3670 pub const IOCDRAIN = 0x2000745e;
3671 pub const IOCMSDTRWAIT = 0x8004745b;
3672 pub const IOCMGDTRWAIT = 0x4004745a;
3673 pub const IOCTIMESTAMP = 0x40107459;
3674 pub const IOCDCDTIMESTAMP = 0x40107458;
3675 pub const IOCSDRAINWAIT = 0x80047457;
3676 pub const IOCGDRAINWAIT = 0x40047456;
3677 pub const IOCISPTMASTER = 0x20007455;
3678 },
3679 // https://github.com/SerenityOS/serenity/blob/cb10f70394fb7e9cfc77f827adb2e46d199bc3a5/Kernel/API/Ioctl.h#L84-L96
3680 .serenity => struct {
3681 pub const IOCGPGRP = 0;
3682 pub const IOCSPGRP = 1;
3683 pub const CGETS = 2;
3684 pub const CSETS = 3;
3685 pub const CSETSW = 4;
3686 pub const CSETSF = 5;
3687 pub const CFLSH = 6;
3688 pub const IOCGWINSZ = 7;
3689 pub const IOCSCTTY = 8;
3690 pub const IOCSTI = 9;
3691 pub const IOCNOTTY = 10;
3692 pub const IOCSWINSZ = 11;
3693 pub const IOCGPTN = 12;
3694 },
3695 else => void,
3696};
3697pub const IOCPARM_MASK = switch (native_os) {
3698 .windows => ws2_32.IOCPARM_MASK,
3699 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => 0x1fff,
3700 else => void,
3701};
3702pub const TCSA = std.posix.TCSA;
3703pub const TFD = switch (native_os) {
3704 .linux => linux.TFD,
3705 else => void,
3706};
3707pub const VDSO = switch (native_os) {
3708 .linux => linux.VDSO,
3709 else => void,
3710};
3711pub const W = switch (native_os) {
3712 .linux => linux.W,
3713 .emscripten => emscripten.W,
3714 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
3715 /// [XSI] no hang in wait/no child to reap
3716 pub const NOHANG = 0x00000001;
3717 /// [XSI] notify on stop, untraced child
3718 pub const UNTRACED = 0x00000002;
3719
3720 pub fn EXITSTATUS(x: u32) u8 {
3721 return @as(u8, @intCast(x >> 8));
3722 }
3723 pub fn TERMSIG(x: u32) SIG {
3724 return @fromBackingInt(@intCast(status(x)));
3725 }
3726 pub fn STOPSIG(x: u32) SIG {
3727 return @fromBackingInt(@intCast(x >> 8));
3728 }
3729 pub fn IFEXITED(x: u32) bool {
3730 return status(x) == 0;
3731 }
3732 pub fn IFSTOPPED(x: u32) bool {
3733 return status(x) == stopped and @as(u32, @backingInt(STOPSIG(x))) != 0x13;
3734 }
3735 pub fn IFSIGNALED(x: u32) bool {
3736 return status(x) != stopped and status(x) != 0;
3737 }
3738
3739 fn status(x: u32) u32 {
3740 return x & 0o177;
3741 }
3742 const stopped = 0o177;
3743 },
3744 .freebsd => struct {
3745 pub const NOHANG = 1;
3746 pub const UNTRACED = 2;
3747 pub const STOPPED = UNTRACED;
3748 pub const CONTINUED = 4;
3749 pub const NOWAIT = 8;
3750 pub const EXITED = 16;
3751 pub const TRAPPED = 32;
3752
3753 pub fn EXITSTATUS(s: u32) u8 {
3754 return @as(u8, @intCast((s & 0xff00) >> 8));
3755 }
3756 pub fn TERMSIG(s: u32) SIG {
3757 return @fromBackingInt(@intCast(s & 0x7f));
3758 }
3759 pub fn STOPSIG(s: u32) SIG {
3760 return @fromBackingInt(@intCast(EXITSTATUS(s)));
3761 }
3762 pub fn IFEXITED(s: u32) bool {
3763 return (s & 0x7f) == 0;
3764 }
3765 pub fn IFSTOPPED(s: u32) bool {
3766 return @as(u16, @truncate((((s & 0xffff) *% 0x10001) >> 8))) > 0x7f00;
3767 }
3768 pub fn IFSIGNALED(s: u32) bool {
3769 return (s & 0xffff) -% 1 < 0xff;
3770 }
3771 },
3772 .illumos => struct {
3773 pub const EXITED = 0o001;
3774 pub const TRAPPED = 0o002;
3775 pub const UNTRACED = 0o004;
3776 pub const STOPPED = UNTRACED;
3777 pub const CONTINUED = 0o010;
3778 pub const NOHANG = 0o100;
3779 pub const NOWAIT = 0o200;
3780
3781 pub fn EXITSTATUS(s: u32) u8 {
3782 return @as(u8, @intCast((s >> 8) & 0xff));
3783 }
3784 pub fn TERMSIG(s: u32) SIG {
3785 return @fromBackingInt(@intCast(s & 0x7f));
3786 }
3787 pub fn STOPSIG(s: u32) SIG {
3788 return @fromBackingInt(@intCast(EXITSTATUS(s)));
3789 }
3790 pub fn IFEXITED(s: u32) bool {
3791 return (s & 0x7f) == 0;
3792 }
3793
3794 pub fn IFCONTINUED(s: u32) bool {
3795 return ((s & 0o177777) == 0o177777);
3796 }
3797
3798 pub fn IFSTOPPED(s: u32) bool {
3799 return (s & 0x00ff != 0o177) and !(s & 0xff00 != 0);
3800 }
3801
3802 pub fn IFSIGNALED(s: u32) bool {
3803 return s & 0x00ff > 0 and s & 0xff00 == 0;
3804 }
3805 },
3806 .netbsd => struct {
3807 pub const NOHANG = 0x00000001;
3808 pub const UNTRACED = 0x00000002;
3809 pub const STOPPED = UNTRACED;
3810 pub const CONTINUED = 0x00000010;
3811 pub const NOWAIT = 0x00010000;
3812 pub const EXITED = 0x00000020;
3813 pub const TRAPPED = 0x00000040;
3814
3815 pub fn EXITSTATUS(s: u32) u8 {
3816 return @as(u8, @intCast((s >> 8) & 0xff));
3817 }
3818 pub fn TERMSIG(s: u32) SIG {
3819 return @fromBackingInt(@intCast(s & 0x7f));
3820 }
3821 pub fn STOPSIG(s: u32) SIG {
3822 return @fromBackingInt(@intCast(EXITSTATUS(s)));
3823 }
3824 pub fn IFEXITED(s: u32) bool {
3825 return (s & 0x7f) == 0;
3826 }
3827
3828 pub fn IFCONTINUED(s: u32) bool {
3829 return (s == CONTINUED);
3830 }
3831
3832 pub fn IFSTOPPED(s: u32) bool {
3833 return (((s & 0x7f) == STOPPED) and !IFCONTINUED(s));
3834 }
3835
3836 pub fn IFSIGNALED(s: u32) bool {
3837 return !IFSTOPPED(s) and !IFCONTINUED(s) and !IFEXITED(s);
3838 }
3839 },
3840 .dragonfly => struct {
3841 pub const NOHANG = 0x0001;
3842 pub const UNTRACED = 0x0002;
3843 pub const CONTINUED = 0x0004;
3844 pub const STOPPED = UNTRACED;
3845 pub const NOWAIT = 0x0008;
3846 pub const EXITED = 0x0010;
3847 pub const TRAPPED = 0x0020;
3848
3849 pub fn EXITSTATUS(s: u32) u8 {
3850 return @as(u8, @intCast((s & 0xff00) >> 8));
3851 }
3852 pub fn TERMSIG(s: u32) SIG {
3853 return @fromBackingInt(@intCast(s & 0x7f));
3854 }
3855 pub fn STOPSIG(s: u32) SIG {
3856 return @fromBackingInt(@intCast(EXITSTATUS(s)));
3857 }
3858 pub fn IFEXITED(s: u32) bool {
3859 return (s & 0x7f) == 0;
3860 }
3861 pub fn IFSTOPPED(s: u32) bool {
3862 return @as(u16, @truncate((((s & 0xffff) *% 0x10001) >> 8))) > 0x7f00;
3863 }
3864 pub fn IFSIGNALED(s: u32) bool {
3865 return (s & 0xffff) -% 1 < 0xff;
3866 }
3867 },
3868 .haiku => struct {
3869 pub const NOHANG = 0x1;
3870 pub const UNTRACED = 0x2;
3871 pub const CONTINUED = 0x4;
3872 pub const EXITED = 0x08;
3873 pub const STOPPED = 0x10;
3874 pub const NOWAIT = 0x20;
3875
3876 pub fn EXITSTATUS(s: u32) u8 {
3877 return @as(u8, @intCast(s & 0xff));
3878 }
3879
3880 pub fn TERMSIG(s: u32) SIG {
3881 return @fromBackingInt(@intCast((s >> 8) & 0xff));
3882 }
3883
3884 pub fn STOPSIG(s: u32) SIG {
3885 return @fromBackingInt(@intCast((s >> 16) & 0xff));
3886 }
3887
3888 pub fn IFEXITED(s: u32) bool {
3889 return (s & ~@as(u32, 0xff)) == 0;
3890 }
3891
3892 pub fn IFSTOPPED(s: u32) bool {
3893 return ((s >> 16) & 0xff) != 0;
3894 }
3895
3896 pub fn IFSIGNALED(s: u32) bool {
3897 return ((s >> 8) & 0xff) != 0;
3898 }
3899 },
3900 .openbsd => struct {
3901 pub const NOHANG = 1;
3902 pub const UNTRACED = 2;
3903 pub const CONTINUED = 8;
3904
3905 pub fn EXITSTATUS(s: u32) u8 {
3906 return @as(u8, @intCast((s >> 8) & 0xff));
3907 }
3908 pub fn TERMSIG(s: u32) SIG {
3909 return @fromBackingInt(@intCast(s & 0x7f));
3910 }
3911 pub fn STOPSIG(s: u32) SIG {
3912 return @fromBackingInt(@intCast(EXITSTATUS(s)));
3913 }
3914 pub fn IFEXITED(s: u32) bool {
3915 return (s & 0x7f) == 0;
3916 }
3917
3918 pub fn IFCONTINUED(s: u32) bool {
3919 return ((s & 0o177777) == 0o177777);
3920 }
3921
3922 pub fn IFSTOPPED(s: u32) bool {
3923 return (s & 0xff == 0o177);
3924 }
3925
3926 pub fn IFSIGNALED(s: u32) bool {
3927 return (((s) & 0o177) != 0o177) and (((s) & 0o177) != 0);
3928 }
3929 },
3930 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/sys/wait.h
3931 .serenity => struct {
3932 pub const NOHANG = 1;
3933 pub const UNTRACED = 2;
3934 pub const STOPPED = UNTRACED;
3935 pub const EXITED = 4;
3936 pub const CONTINUED = 8;
3937 pub const NOWAIT = 0x1000000;
3938
3939 pub fn EXITSTATUS(s: u32) u8 {
3940 return @intCast((s & 0xff00) >> 8);
3941 }
3942
3943 pub fn STOPSIG(s: u32) SIG {
3944 return @fromBackingInt(@intCast(EXITSTATUS(s)));
3945 }
3946
3947 pub fn TERMSIG(s: u32) SIG {
3948 return @fromBackingInt(@intCast(s & 0x7f));
3949 }
3950
3951 pub fn IFEXITED(s: u32) bool {
3952 return (s & 0x7f) == 0;
3953 }
3954
3955 pub fn IFSTOPPED(s: u32) bool {
3956 return (s & 0xff) == 0x7f;
3957 }
3958
3959 pub fn IFSIGNALED(s: u32) bool {
3960 return (((s & 0x7f) + 1) >> 1) > 0;
3961 }
3962
3963 pub fn IFCONTINUED(s: u32) bool {
3964 return s == 0xffff;
3965 }
3966 },
3967 else => void,
3968};
3969pub const accept_filter_arg = switch (native_os) {
3970 // https://github.com/freebsd/freebsd-src/blob/2024887abc7d1b931e00fbb0697658e98adf048d/sys/sys/socket.h#L205
3971 // https://github.com/DragonFlyBSD/DragonFlyBSD/blob/6098912863ed4c7b3f70d7483910ce2956cf4ed3/sys/sys/socket.h#L164
3972 // https://github.com/NetBSD/src/blob/cad5c68a8524927f65e22ad651de3905382be6e0/sys/sys/socket.h#L188
3973 // https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/socket.h#L504
3974 .freebsd, .dragonfly, .netbsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
3975 name: [16]u8,
3976 arg: [240]u8,
3977 },
3978 else => void,
3979};
3980pub const clock_t = switch (native_os) {
3981 .linux => linux.clock_t,
3982 .emscripten => emscripten.clock_t,
3983 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => c_ulong,
3984 .freebsd => isize,
3985 .openbsd, .illumos => i64,
3986 .netbsd => u32,
3987 .haiku => i32,
3988 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L50
3989 .serenity => u64,
3990 else => void,
3991};
3992pub const cpu_set_t = switch (native_os) {
3993 .linux => linux.cpu_set_t,
3994 .emscripten => emscripten.cpu_set_t,
3995 else => void,
3996};
3997pub const dl_phdr_info = switch (native_os) {
3998 .linux => linux.dl_phdr_info,
3999 .emscripten => emscripten.dl_phdr_info,
4000 .freebsd => extern struct {
4001 /// Module relocation base.
4002 addr: std.elf.Addr,
4003 /// Module name.
4004 name: ?[*:0]const u8,
4005 /// Pointer to module's phdr.
4006 phdr: [*]std.elf.ElfN.Phdr,
4007 /// Number of entries in phdr.
4008 phnum: u16,
4009 /// Total number of loads.
4010 adds: u64,
4011 /// Total number of unloads.
4012 subs: u64,
4013 tls_modid: usize,
4014 tls_data: ?*anyopaque,
4015 },
4016 .illumos => extern struct {
4017 addr: std.elf.Addr,
4018 name: ?[*:0]const u8,
4019 phdr: [*]std.elf.ElfN.Phdr,
4020 phnum: std.elf.Half,
4021 /// Incremented when a new object is mapped into the process.
4022 adds: u64,
4023 /// Incremented when an object is unmapped from the process.
4024 subs: u64,
4025 },
4026 // https://github.com/SerenityOS/serenity/blob/45d81dceed81df0c8ef75b440b20cc0938195faa/Userland/Libraries/LibC/link.h#L15-L20
4027 .openbsd, .haiku, .dragonfly, .netbsd, .serenity => extern struct {
4028 addr: usize,
4029 name: ?[*:0]const u8,
4030 phdr: [*]std.elf.ElfN.Phdr,
4031 phnum: std.elf.Half,
4032 },
4033 else => void,
4034};
4035pub const epoll_event = switch (native_os) {
4036 .linux => linux.epoll_event,
4037 else => void,
4038};
4039pub const ifreq = switch (native_os) {
4040 .linux => linux.ifreq,
4041 .emscripten => emscripten.ifreq,
4042 .illumos => lifreq,
4043 // https://github.com/SerenityOS/serenity/blob/9882848e0bf783dfc8e8a6d887a848d70d9c58f4/Kernel/API/POSIX/net/if.h#L49-L82
4044 .serenity => extern struct {
4045 // Not actually in a union, but the stdlib expects one for ifreq
4046 ifrn: extern union {
4047 name: [IFNAMESIZE]u8,
4048 },
4049 ifru: extern union {
4050 addr: sockaddr,
4051 dstaddr: sockaddr,
4052 broadaddr: sockaddr,
4053 netmask: sockaddr,
4054 hwaddr: sockaddr,
4055 flags: c_short,
4056 metric: c_int,
4057 vnetid: i64,
4058 media: u64,
4059 data: ?*anyopaque,
4060 index: c_uint,
4061 },
4062 },
4063 else => void,
4064};
4065pub const in_pktinfo = switch (native_os) {
4066 .linux => linux.in_pktinfo,
4067 // https://github.com/illumos/illumos-gate/blob/608eb926e14f4ba4736b2d59e891335f1cba9e1e/usr/src/uts/common/netinet/in.h#L1132
4068 // https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/netinet/in.h#L696
4069 .illumos, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
4070 ifindex: u32,
4071 spec_dst: u32,
4072 addr: u32,
4073 },
4074 else => void,
4075};
4076pub const in6_pktinfo = switch (native_os) {
4077 .linux => linux.in6_pktinfo,
4078 // https://github.com/freebsd/freebsd-src/blob/9bfbc6826f72eb385bf52f4cde8080bccf7e3ebd/sys/netinet6/in6.h#L547
4079 // https://github.com/DragonFlyBSD/DragonFlyBSD/blob/6098912863ed4c7b3f70d7483910ce2956cf4ed3/sys/netinet6/in6.h#L575
4080 // https://github.com/NetBSD/src/blob/80bf25a5691072d4755e84567ccbdf0729370dea/sys/netinet6/in6.h#L468
4081 // https://github.com/openbsd/src/blob/718a31b40d39fc6064de6355eb144e74633133fc/sys/netinet6/in6.h#L365
4082 // https://github.com/illumos/illumos-gate/blob/608eb926e14f4ba4736b2d59e891335f1cba9e1e/usr/src/uts/common/netinet/in.h#L114IP1
4083 // https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/netinet6/in6.h#L737
4084 // https://github.com/haiku/haiku/blob/2aab5f5f14aeb3f34c3a3d9a9064cc3c0d914bea/headers/posix/netinet6/in6.h#L63
4085 // https://github.com/SerenityOS/serenity/blob/5bd8af99be0bc4b2e14f361fd7d7590e6bcfa4d6/Kernel/API/POSIX/sys/socket.h#L122
4086 .freebsd, .dragonfly, .netbsd, .openbsd, .illumos, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .haiku, .serenity => extern struct {
4087 addr: [16]u8,
4088 ifindex: u32,
4089 },
4090 else => void,
4091};
4092pub const itimerspec = switch (native_os) {
4093 .linux => linux.itimerspec,
4094 .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .windows, .wasi => extern struct {
4095 interval: timespec,
4096 value: timespec,
4097 },
4098 else => void,
4099};
4100pub const linger = switch (native_os) {
4101 .linux => linux.linger,
4102 // https://github.com/freebsd/freebsd-src/blob/46347b3619757e3d683a87ca03efaf2ae242335f/sys/sys/socket.h#L200
4103 .freebsd,
4104 // https://github.com/DragonFlyBSD/DragonFlyBSD/blob/6098912863ed4c7b3f70d7483910ce2956cf4ed3/sys/sys/socket.h#L158
4105 .dragonfly,
4106 // https://github.com/NetBSD/src/blob/80bf25a5691072d4755e84567ccbdf0729370dea/sys/sys/socket.h#L183
4107 .netbsd,
4108 // https://github.com/openbsd/src/blob/718a31b40d39fc6064de6355eb144e74633133fc/sys/sys/socket.h#L126
4109 .openbsd,
4110 // https://github.com/illumos/illumos-gate/blob/608eb926e14f4ba4736b2d59e891335f1cba9e1e/usr/src/uts/common/sys/socket.h#L250
4111 .illumos,
4112 // https://github.com/haiku/haiku/blob/2aab5f5f14aeb3f34c3a3d9a9064cc3c0d914bea/headers/posix/sys/socket.h#L87
4113 .haiku,
4114 // https://github.com/SerenityOS/serenity/blob/5bd8af99be0bc4b2e14f361fd7d7590e6bcfa4d6/Kernel/API/POSIX/sys/socket.h#L122
4115 .serenity,
4116 // https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/socket.h#L498
4117 .driverkit,
4118 .ios,
4119 .maccatalyst,
4120 .macos,
4121 .tvos,
4122 .visionos,
4123 .watchos,
4124 => extern struct {
4125 onoff: i32, // non-zero to linger on close
4126 linger: i32, // time to linger in seconds
4127 },
4128 else => void,
4129};
4130
4131pub const msghdr = switch (native_os) {
4132 .linux => if (@bitSizeOf(usize) > @bitSizeOf(i32) and builtin.abi.isMusl()) posix_msghdr else linux.msghdr,
4133 .openbsd,
4134 .emscripten,
4135 .dragonfly,
4136 .freebsd,
4137 .netbsd,
4138 .haiku,
4139 .illumos,
4140 .driverkit,
4141 .ios,
4142 .maccatalyst,
4143 .macos,
4144 .tvos,
4145 .visionos,
4146 .watchos,
4147 .serenity, // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L74-L82
4148 => posix_msghdr,
4149 else => void,
4150};
4151
4152/// There are several instances of struct fields that POSIX defines as either int or socklen_t, but
4153/// on Linux are size_t. glibc ignores POSIX, and uses the Linux kernel's definitions. musl on the
4154/// other hand aims to be POSIX-ly correct, and defines those fields in a manner aligning with
4155/// POSIX.
4156///
4157/// musl works around this incompatibility between the 64-bit Linux ABI and the POSIX specification
4158/// by adding padding fields on either side depending on host endianness:
4159///
4160/// #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN
4161/// int __pad2;
4162/// #endif
4163/// socklen_t msg_controllen;
4164/// #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN
4165/// int __pad2;
4166/// #endif
4167///
4168/// To emulate this quirk of musl, the MuslOnlyPadding field is used in these structs
4169///
4170/// pad0: MuslOnlyPadding(.big) = 0,
4171/// msg_controllen: socklen_t,
4172/// pad1: MuslOnlyPadding(.little) = 0,
4173///
4174/// On 32-bit and non-musl systems, these fields will be zero sized, and ignored.
4175fn MuslOnlyPadding(endian: std.builtin.Endian) type {
4176 return if (builtin.abi.isMusl() and @sizeOf(usize) == 8 and native_endian == endian) u32 else u0;
4177}
4178
4179/// https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_socket.h.html
4180const posix_msghdr = extern struct {
4181 name: ?*sockaddr,
4182 namelen: socklen_t,
4183 iov: [*]iovec,
4184 pad0: MuslOnlyPadding(.big) = 0,
4185 iovlen: u32,
4186 pad1: MuslOnlyPadding(.little) = 0,
4187 control: ?*anyopaque,
4188 pad2: MuslOnlyPadding(.big) = 0,
4189 controllen: socklen_t,
4190 pad3: MuslOnlyPadding(.little) = 0,
4191 flags: u32,
4192};
4193
4194pub const msghdr_const = switch (native_os) {
4195 .linux => if (@bitSizeOf(usize) > @bitSizeOf(i32) and builtin.abi.isMusl()) posix_msghdr_const else linux.msghdr_const,
4196 .openbsd,
4197 .emscripten,
4198 .dragonfly,
4199 .freebsd,
4200 .netbsd,
4201 .haiku,
4202 .illumos,
4203 .driverkit,
4204 .ios,
4205 .maccatalyst,
4206 .macos,
4207 .tvos,
4208 .visionos,
4209 .watchos,
4210 .serenity,
4211 => posix_msghdr_const,
4212 else => void,
4213};
4214
4215const posix_msghdr_const = extern struct {
4216 name: ?*const sockaddr,
4217 namelen: socklen_t,
4218 iov: [*]const iovec_const,
4219 pad0: MuslOnlyPadding(.big) = 0,
4220 iovlen: u32,
4221 pad1: MuslOnlyPadding(.little) = 0,
4222 control: ?*const anyopaque,
4223 pad2: MuslOnlyPadding(.big) = 0,
4224 controllen: socklen_t,
4225 pad3: MuslOnlyPadding(.little) = 0,
4226 flags: u32,
4227};
4228
4229pub const mmsghdr = switch (native_os) {
4230 .linux => linux.mmsghdr,
4231 else => extern struct {
4232 hdr: msghdr,
4233 len: u32,
4234 },
4235};
4236
4237pub const cmsghdr = switch (native_os) {
4238 .linux => if (@bitSizeOf(usize) > @bitSizeOf(i32) and builtin.abi.isMusl()) posix_cmsghdr else linux.cmsghdr,
4239 // https://github.com/emscripten-core/emscripten/blob/96371ed7888fc78c040179f4d4faa82a6a07a116/system/lib/libc/musl/include/sys/socket.h#L44
4240 .emscripten => linux.cmsghdr,
4241 // https://github.com/freebsd/freebsd-src/blob/b197d2abcb6895d78bc9df8404e374397aa44748/sys/sys/socket.h#L492
4242 .freebsd,
4243 // https://github.com/DragonFlyBSD/DragonFlyBSD/blob/107c0518337ba90e7fa49e74845d8d44320c9a6d/sys/sys/socket.h#L452
4244 .dragonfly,
4245 // https://github.com/NetBSD/src/blob/ba8e1774fd9c0c26ecca461c07bc95d9ebb69579/sys/sys/socket.h#L528
4246 .netbsd,
4247 // https://github.com/openbsd/src/blob/master/sys/sys/socket.h#L527
4248 .openbsd,
4249 // https://github.com/illumos/illumos-gate/blob/afdf2e523873cb523df379676067bf9785a0f456/usr/src/uts/common/sys/socket.h#L460
4250 .illumos,
4251 // https://github.com/SerenityOS/serenity/blob/4ee360a348a5e2490eeaeeabb3eb19e70dd450eb/Kernel/API/POSIX/sys/socket.h#L68
4252 .serenity,
4253 // https://github.com/haiku/haiku/blob/b54f586058fd6623645512e4631468cede9933b9/headers/posix/sys/socket.h#L132
4254 .haiku,
4255 // https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/socket.h#L1041
4256 .driverkit,
4257 .ios,
4258 .maccatalyst,
4259 .macos,
4260 .tvos,
4261 .visionos,
4262 .watchos,
4263 => posix_cmsghdr,
4264
4265 else => void,
4266};
4267
4268const posix_cmsghdr = extern struct {
4269 pad0: MuslOnlyPadding(.big) = 0,
4270 len: socklen_t,
4271 pad1: MuslOnlyPadding(.little) = 0,
4272 level: c_int,
4273 type: c_int,
4274};
4275
4276pub const nfds_t = switch (native_os) {
4277 .linux => linux.nfds_t,
4278 .emscripten => emscripten.nfds_t,
4279 .haiku, .illumos, .wasi => usize,
4280 .windows => c_ulong,
4281 .openbsd, .dragonfly, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => u32,
4282 // https://github.com/SerenityOS/serenity/blob/265764ff2fec038855193296588a887fc322d76a/Kernel/API/POSIX/poll.h#L32
4283 .serenity => c_uint,
4284 else => void,
4285};
4286pub const perf_event_attr = switch (native_os) {
4287 .linux => linux.perf_event_attr,
4288 else => void,
4289};
4290pub const pid_t = switch (native_os) {
4291 .linux => linux.pid_t,
4292 .emscripten => emscripten.pid_t,
4293 .windows => windows.HANDLE,
4294 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L31-L32
4295 .serenity => c_int,
4296 else => i32,
4297};
4298pub const pollfd = switch (native_os) {
4299 .linux => linux.pollfd,
4300 .emscripten => emscripten.pollfd,
4301 .windows => ws2_32.pollfd,
4302 // https://github.com/SerenityOS/serenity/blob/265764ff2fec038855193296588a887fc322d76a/Kernel/API/POSIX/poll.h#L26-L30
4303 .serenity => extern struct {
4304 fd: fd_t,
4305 events: c_short,
4306 revents: c_short = undefined,
4307 },
4308 else => extern struct {
4309 fd: fd_t,
4310 events: i16,
4311 revents: i16 = undefined,
4312 },
4313};
4314pub const rlim_t = switch (native_os) {
4315 .linux => linux.rlim_t,
4316 .emscripten => emscripten.rlim_t,
4317 .openbsd, .netbsd, .illumos, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => u64,
4318 .haiku, .dragonfly, .freebsd => i64,
4319 // https://github.com/SerenityOS/serenity/blob/aae106e37b48f2158e68902293df1e4bf7b80c0f/Userland/Libraries/LibC/sys/resource.h#L54
4320 .serenity => usize,
4321 else => void,
4322};
4323pub const rlimit = switch (native_os) {
4324 .linux, .emscripten => linux.rlimit,
4325 .windows => void,
4326 // https://github.com/SerenityOS/serenity/blob/aae106e37b48f2158e68902293df1e4bf7b80c0f/Userland/Libraries/LibC/sys/resource.h#L56-L59
4327 else => extern struct {
4328 /// Soft limit
4329 cur: rlim_t,
4330 /// Hard limit
4331 max: rlim_t,
4332 },
4333};
4334pub const rlimit_resource = switch (native_os) {
4335 .linux => linux.rlimit_resource,
4336 .emscripten => emscripten.rlimit_resource,
4337 .openbsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => enum(c_int) {
4338 CPU = 0,
4339 FSIZE = 1,
4340 DATA = 2,
4341 STACK = 3,
4342 CORE = 4,
4343 RSS = 5,
4344 MEMLOCK = 6,
4345 NPROC = 7,
4346 NOFILE = 8,
4347 _,
4348
4349 pub const AS: rlimit_resource = .RSS;
4350 },
4351 .freebsd => enum(c_int) {
4352 CPU = 0,
4353 FSIZE = 1,
4354 DATA = 2,
4355 STACK = 3,
4356 CORE = 4,
4357 RSS = 5,
4358 MEMLOCK = 6,
4359 NPROC = 7,
4360 NOFILE = 8,
4361 SBSIZE = 9,
4362 VMEM = 10,
4363 NPTS = 11,
4364 SWAP = 12,
4365 KQUEUES = 13,
4366 UMTXP = 14,
4367 _,
4368
4369 pub const AS: rlimit_resource = .VMEM;
4370 },
4371 .illumos => enum(c_int) {
4372 CPU = 0,
4373 FSIZE = 1,
4374 DATA = 2,
4375 STACK = 3,
4376 CORE = 4,
4377 NOFILE = 5,
4378 VMEM = 6,
4379 _,
4380
4381 pub const AS: rlimit_resource = .VMEM;
4382 },
4383 .netbsd => enum(c_int) {
4384 CPU = 0,
4385 FSIZE = 1,
4386 DATA = 2,
4387 STACK = 3,
4388 CORE = 4,
4389 RSS = 5,
4390 MEMLOCK = 6,
4391 NPROC = 7,
4392 NOFILE = 8,
4393 SBSIZE = 9,
4394 VMEM = 10,
4395 NTHR = 11,
4396 _,
4397
4398 pub const AS: rlimit_resource = .VMEM;
4399 },
4400 .dragonfly => enum(c_int) {
4401 CPU = 0,
4402 FSIZE = 1,
4403 DATA = 2,
4404 STACK = 3,
4405 CORE = 4,
4406 RSS = 5,
4407 MEMLOCK = 6,
4408 NPROC = 7,
4409 NOFILE = 8,
4410 SBSIZE = 9,
4411 VMEM = 10,
4412 POSIXLOCKS = 11,
4413 _,
4414
4415 pub const AS: rlimit_resource = .VMEM;
4416 },
4417 .haiku => enum(i32) {
4418 CORE = 0,
4419 CPU = 1,
4420 DATA = 2,
4421 FSIZE = 3,
4422 NOFILE = 4,
4423 STACK = 5,
4424 AS = 6,
4425 NOVMON = 7,
4426 _,
4427 },
4428 // https://github.com/SerenityOS/serenity/blob/aae106e37b48f2158e68902293df1e4bf7b80c0f/Userland/Libraries/LibC/sys/resource.h#L42-L48
4429 .serenity => enum(c_int) {
4430 CORE = 1,
4431 CPU = 2,
4432 DATA = 3,
4433 FSIZE = 4,
4434 NOFILE = 5,
4435 STACK = 6,
4436 AS = 7,
4437 _,
4438 },
4439 else => void,
4440};
4441pub const rusage = switch (native_os) {
4442 .linux => linux.rusage,
4443 .emscripten => emscripten.rusage,
4444 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
4445 utime: timeval,
4446 stime: timeval,
4447 maxrss: isize,
4448 ixrss: isize,
4449 idrss: isize,
4450 isrss: isize,
4451 minflt: isize,
4452 majflt: isize,
4453 nswap: isize,
4454 inblock: isize,
4455 oublock: isize,
4456 msgsnd: isize,
4457 msgrcv: isize,
4458 nsignals: isize,
4459 nvcsw: isize,
4460 nivcsw: isize,
4461
4462 pub const SELF = 0;
4463 pub const CHILDREN = -1;
4464 },
4465 .illumos => extern struct {
4466 utime: timeval,
4467 stime: timeval,
4468 maxrss: isize,
4469 ixrss: isize,
4470 idrss: isize,
4471 isrss: isize,
4472 minflt: isize,
4473 majflt: isize,
4474 nswap: isize,
4475 inblock: isize,
4476 oublock: isize,
4477 msgsnd: isize,
4478 msgrcv: isize,
4479 nsignals: isize,
4480 nvcsw: isize,
4481 nivcsw: isize,
4482
4483 pub const SELF = 0;
4484 pub const CHILDREN = -1;
4485 pub const THREAD = 1;
4486 },
4487 // https://github.com/SerenityOS/serenity/blob/aae106e37b48f2158e68902293df1e4bf7b80c0f/Userland/Libraries/LibC/sys/resource.h#L18-L38
4488 .serenity => extern struct {
4489 utime: timeval,
4490 stime: timeval,
4491 maxrss: c_long,
4492 ixrss: c_long,
4493 idrss: c_long,
4494 isrss: c_long,
4495 minflt: c_long,
4496 majflt: c_long,
4497 nswap: c_long,
4498 inblock: c_long,
4499 oublock: c_long,
4500 msgsnd: c_long,
4501 msgrcv: c_long,
4502 nsignals: c_long,
4503 nvcsw: c_long,
4504 nivcsw: c_long,
4505
4506 pub const SELF = 1;
4507 pub const CHILDREN = 2;
4508 },
4509 .freebsd, .openbsd => extern struct {
4510 utime: timeval,
4511 stime: timeval,
4512 maxrss: c_long,
4513 ixrss: c_long,
4514 idrss: c_long,
4515 isrss: c_long,
4516 minflt: c_long,
4517 majflt: c_long,
4518 nswap: c_long,
4519 inblock: c_long,
4520 oublock: c_long,
4521 msgsnd: c_long,
4522 msgrcv: c_long,
4523 nsignals: c_long,
4524 nvcsw: c_long,
4525 nivcsw: c_long,
4526
4527 pub const SELF = 0;
4528 pub const CHILDREN = -1;
4529 pub const THREAD = 1;
4530 },
4531 .dragonfly, .netbsd => extern struct {
4532 utime: timeval,
4533 stime: timeval,
4534 maxrss: c_long,
4535 ixrss: c_long,
4536 idrss: c_long,
4537 isrss: c_long,
4538 minflt: c_long,
4539 majflt: c_long,
4540 nswap: c_long,
4541 inblock: c_long,
4542 oublock: c_long,
4543 msgsnd: c_long,
4544 msgrcv: c_long,
4545 nsignals: c_long,
4546 nvcsw: c_long,
4547 nivcsw: c_long,
4548
4549 pub const SELF = 0;
4550 pub const CHILDREN = -1;
4551 },
4552 else => void,
4553};
4554
4555pub const siginfo_t = switch (native_os) {
4556 .linux => linux.siginfo_t,
4557 .emscripten => emscripten.siginfo_t,
4558 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
4559 signo: SIG,
4560 errno: c_int,
4561 code: c_int,
4562 pid: pid_t,
4563 uid: uid_t,
4564 status: c_int,
4565 addr: *allowzero anyopaque,
4566 value: extern union {
4567 int: c_int,
4568 ptr: *anyopaque,
4569 },
4570 si_band: c_long,
4571 _pad: [7]c_ulong,
4572 },
4573 .freebsd => extern struct {
4574 // Signal number.
4575 signo: SIG,
4576 // Errno association.
4577 errno: c_int,
4578 /// Signal code.
4579 ///
4580 /// Cause of signal, one of the SI_ macros or signal-specific values, i.e.
4581 /// one of the FPE_... values for SIGFPE.
4582 /// This value is equivalent to the second argument to an old-style FreeBSD
4583 /// signal handler.
4584 code: c_int,
4585 /// Sending process.
4586 pid: pid_t,
4587 /// Sender's ruid.
4588 uid: uid_t,
4589 /// Exit value.
4590 status: c_int,
4591 /// Faulting instruction.
4592 addr: *allowzero anyopaque,
4593 /// Signal value.
4594 value: sigval,
4595 reason: extern union {
4596 fault: extern struct {
4597 /// Machine specific trap code.
4598 trapno: c_int,
4599 },
4600 timer: extern struct {
4601 timerid: c_int,
4602 overrun: c_int,
4603 },
4604 mesgq: extern struct {
4605 mqd: c_int,
4606 },
4607 poll: extern struct {
4608 /// Band event for SIGPOLL. UNUSED.
4609 band: c_long,
4610 },
4611 spare: extern struct {
4612 spare1: c_long,
4613 spare2: [7]c_int,
4614 },
4615 },
4616 },
4617 .illumos => extern struct {
4618 signo: SIG,
4619 code: c_int,
4620 errno: c_int,
4621 // 64bit architectures insert 4bytes of padding here, this is done by
4622 // correctly aligning the reason field
4623 reason: extern union {
4624 proc: extern struct {
4625 pid: pid_t,
4626 pdata: extern union {
4627 kill: extern struct {
4628 uid: uid_t,
4629 value: sigval_t,
4630 },
4631 cld: extern struct {
4632 utime: clock_t,
4633 status: c_int,
4634 stime: clock_t,
4635 },
4636 },
4637 contract: illumos.ctid_t,
4638 zone: illumos.zoneid_t,
4639 },
4640 fault: extern struct {
4641 addr: *allowzero anyopaque,
4642 trapno: c_int,
4643 pc: ?*anyopaque,
4644 },
4645 file: extern struct {
4646 // fd not currently available for SIGPOLL.
4647 fd: c_int,
4648 band: c_long,
4649 },
4650 prof: extern struct {
4651 addr: ?*anyopaque,
4652 timestamp: timespec,
4653 syscall: c_short,
4654 sysarg: u8,
4655 fault: u8,
4656 args: [8]c_long,
4657 state: [10]c_int,
4658 },
4659 rctl: extern struct {
4660 entity: i32,
4661 },
4662 __pad: [256 - 4 * @sizeOf(c_int)]u8,
4663 } align(@sizeOf(usize)),
4664
4665 comptime {
4666 assert(@sizeOf(@This()) == 256);
4667 assert(@alignOf(@This()) == @sizeOf(usize));
4668 }
4669 },
4670 .netbsd => extern union {
4671 pad: [128]u8,
4672 info: netbsd._ksiginfo,
4673 },
4674 .dragonfly => extern struct {
4675 signo: SIG,
4676 errno: c_int,
4677 code: c_int,
4678 pid: c_int,
4679 uid: uid_t,
4680 status: c_int,
4681 addr: *allowzero anyopaque,
4682 value: sigval,
4683 band: c_long,
4684 __spare__: [7]c_int,
4685 },
4686 .haiku => extern struct {
4687 signo: SIG,
4688 code: i32,
4689 errno: i32,
4690
4691 pid: pid_t,
4692 uid: uid_t,
4693 addr: *allowzero anyopaque,
4694 },
4695 .openbsd => extern struct {
4696 signo: SIG,
4697 code: c_int,
4698 errno: c_int,
4699 data: extern union {
4700 proc: extern struct {
4701 pid: pid_t,
4702 pdata: extern union {
4703 kill: extern struct {
4704 uid: uid_t,
4705 value: sigval,
4706 },
4707 cld: extern struct {
4708 utime: clock_t,
4709 stime: clock_t,
4710 status: c_int,
4711 },
4712 },
4713 },
4714 fault: extern struct {
4715 addr: *allowzero anyopaque,
4716 trapno: c_int,
4717 },
4718 __pad: [128 - 3 * @sizeOf(c_int)]u8,
4719 },
4720 },
4721 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L27-L37
4722 .serenity => extern struct {
4723 signo: SIG,
4724 code: c_int,
4725 errno: c_int,
4726 pid: pid_t,
4727 uid: uid_t,
4728 addr: ?*anyopaque,
4729 status: c_int,
4730 band: c_int,
4731 value: sigval,
4732 },
4733 else => void,
4734};
4735pub const sigset_t = switch (native_os) {
4736 .linux => [1024 / @bitSizeOf(c_ulong)]c_ulong, // glibc and musl present a 1024-bit sigset_t, while kernel's is 128-bit or less.
4737 .emscripten => emscripten.sigset_t,
4738 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L19
4739 .openbsd, .serenity => u32,
4740 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => darwin.sigset_t,
4741 .dragonfly, .netbsd, .illumos, .freebsd => extern struct {
4742 __bits: [SIG.WORDS]u32,
4743 },
4744 .haiku => u64,
4745 else => u0,
4746};
4747
4748pub const sigval = switch (native_os) {
4749 .linux => linux.sigval,
4750 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L22-L25
4751 .openbsd, .dragonfly, .freebsd, .serenity => extern union {
4752 int: c_int,
4753 ptr: ?*anyopaque,
4754 },
4755 else => void,
4756};
4757
4758pub const addrinfo = if (builtin.abi.isAndroid()) extern struct {
4759 flags: AI,
4760 family: i32,
4761 socktype: i32,
4762 protocol: i32,
4763 addrlen: socklen_t,
4764 canonname: ?[*:0]u8,
4765 addr: ?*sockaddr,
4766 next: ?*addrinfo,
4767} else switch (native_os) {
4768 .linux, .emscripten => linux.addrinfo,
4769 .windows => ws2_32.addrinfo,
4770 .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
4771 flags: AI,
4772 family: i32,
4773 socktype: i32,
4774 protocol: i32,
4775 addrlen: socklen_t,
4776 canonname: ?[*:0]u8,
4777 addr: ?*sockaddr,
4778 next: ?*addrinfo,
4779 },
4780 .illumos => extern struct {
4781 flags: AI,
4782 family: i32,
4783 socktype: i32,
4784 protocol: i32,
4785 addrlen: socklen_t,
4786 canonname: ?[*:0]u8,
4787 addr: ?*sockaddr,
4788 next: ?*addrinfo,
4789 },
4790 .netbsd => extern struct {
4791 flags: AI,
4792 family: i32,
4793 socktype: i32,
4794 protocol: i32,
4795 addrlen: socklen_t,
4796 canonname: ?[*:0]u8,
4797 addr: ?*sockaddr,
4798 next: ?*addrinfo,
4799 },
4800 .dragonfly => extern struct {
4801 flags: AI,
4802 family: i32,
4803 socktype: i32,
4804 protocol: i32,
4805 addrlen: socklen_t,
4806 canonname: ?[*:0]u8,
4807 addr: ?*sockaddr,
4808 next: ?*addrinfo,
4809 },
4810 .haiku => extern struct {
4811 flags: AI,
4812 family: i32,
4813 socktype: i32,
4814 protocol: i32,
4815 addrlen: socklen_t,
4816 canonname: ?[*:0]u8,
4817 addr: ?*sockaddr,
4818 next: ?*addrinfo,
4819 },
4820 // https://github.com/SerenityOS/serenity/blob/d510d2aeb2facbd8f6c383d70fd1b033e1fee5dd/Userland/Libraries/LibC/netdb.h#L66-L75
4821 .openbsd, .serenity => extern struct {
4822 flags: AI,
4823 family: c_int,
4824 socktype: c_int,
4825 protocol: c_int,
4826 addrlen: socklen_t,
4827 addr: ?*sockaddr,
4828 canonname: ?[*:0]u8,
4829 next: ?*addrinfo,
4830 },
4831 else => void,
4832};
4833pub const sockaddr = switch (native_os) {
4834 .linux, .emscripten => linux.sockaddr,
4835 .windows => ws2_32.sockaddr,
4836 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
4837 len: u8,
4838 family: sa_family_t,
4839 data: [14]u8,
4840
4841 pub const SS_MAXSIZE = 128;
4842 pub const storage = extern struct {
4843 len: u8 align(8),
4844 family: sa_family_t,
4845 padding: [126]u8 = undefined,
4846
4847 comptime {
4848 assert(@sizeOf(storage) == SS_MAXSIZE);
4849 assert(@alignOf(storage) == 8);
4850 }
4851 };
4852 pub const in = extern struct {
4853 len: u8 = @sizeOf(in),
4854 family: sa_family_t = AF.INET,
4855 port: in_port_t,
4856 addr: u32,
4857 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
4858 };
4859 pub const in6 = extern struct {
4860 len: u8 = @sizeOf(in6),
4861 family: sa_family_t = AF.INET6,
4862 port: in_port_t,
4863 flowinfo: u32,
4864 addr: [16]u8,
4865 scope_id: u32,
4866 };
4867
4868 /// UNIX domain socket
4869 pub const un = extern struct {
4870 len: u8 = @sizeOf(un),
4871 family: sa_family_t = AF.UNIX,
4872 path: [104]u8,
4873 };
4874 },
4875 .freebsd => extern struct {
4876 /// total length
4877 len: u8,
4878 /// address family
4879 family: sa_family_t,
4880 /// actually longer; address value
4881 data: [14]u8,
4882
4883 pub const SS_MAXSIZE = 128;
4884 pub const storage = extern struct {
4885 len: u8 align(8),
4886 family: sa_family_t,
4887 padding: [126]u8 = undefined,
4888
4889 comptime {
4890 assert(@sizeOf(storage) == SS_MAXSIZE);
4891 assert(@alignOf(storage) == 8);
4892 }
4893 };
4894
4895 pub const in = extern struct {
4896 len: u8 = @sizeOf(in),
4897 family: sa_family_t = AF.INET,
4898 port: in_port_t,
4899 addr: u32,
4900 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
4901 };
4902
4903 pub const in6 = extern struct {
4904 len: u8 = @sizeOf(in6),
4905 family: sa_family_t = AF.INET6,
4906 port: in_port_t,
4907 flowinfo: u32,
4908 addr: [16]u8,
4909 scope_id: u32,
4910 };
4911
4912 pub const un = extern struct {
4913 len: u8 = @sizeOf(un),
4914 family: sa_family_t = AF.UNIX,
4915 path: [104]u8,
4916 };
4917 },
4918 .illumos => extern struct {
4919 /// address family
4920 family: sa_family_t,
4921
4922 /// actually longer; address value
4923 data: [14]u8,
4924
4925 pub const SS_MAXSIZE = 256;
4926 pub const storage = extern struct {
4927 family: sa_family_t align(8),
4928 padding: [254]u8 = undefined,
4929
4930 comptime {
4931 assert(@sizeOf(storage) == SS_MAXSIZE);
4932 assert(@alignOf(storage) == 8);
4933 }
4934 };
4935
4936 pub const in = extern struct {
4937 family: sa_family_t = AF.INET,
4938 port: in_port_t,
4939 addr: u32,
4940 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
4941 };
4942
4943 pub const in6 = extern struct {
4944 family: sa_family_t = AF.INET6,
4945 port: in_port_t,
4946 flowinfo: u32,
4947 addr: [16]u8,
4948 scope_id: u32,
4949 __src_id: u32 = 0,
4950 };
4951
4952 /// Definitions for UNIX IPC domain.
4953 pub const un = extern struct {
4954 family: sa_family_t = AF.UNIX,
4955 path: [108]u8,
4956 };
4957 },
4958 .netbsd => extern struct {
4959 /// total length
4960 len: u8,
4961 /// address family
4962 family: sa_family_t,
4963 /// actually longer; address value
4964 data: [14]u8,
4965
4966 pub const SS_MAXSIZE = 128;
4967 pub const storage = extern struct {
4968 len: u8 align(8),
4969 family: sa_family_t,
4970 padding: [126]u8 = undefined,
4971
4972 comptime {
4973 assert(@sizeOf(storage) == SS_MAXSIZE);
4974 assert(@alignOf(storage) == 8);
4975 }
4976 };
4977
4978 pub const in = extern struct {
4979 len: u8 = @sizeOf(in),
4980 family: sa_family_t = AF.INET,
4981 port: in_port_t,
4982 addr: u32,
4983 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
4984 };
4985
4986 pub const in6 = extern struct {
4987 len: u8 = @sizeOf(in6),
4988 family: sa_family_t = AF.INET6,
4989 port: in_port_t,
4990 flowinfo: u32,
4991 addr: [16]u8,
4992 scope_id: u32,
4993 };
4994
4995 /// Definitions for UNIX IPC domain.
4996 pub const un = extern struct {
4997 /// total sockaddr length
4998 len: u8 = @sizeOf(un),
4999
5000 family: sa_family_t = AF.LOCAL,
5001
5002 /// path name
5003 path: [104]u8,
5004 };
5005 },
5006 .dragonfly => extern struct {
5007 len: u8,
5008 family: sa_family_t,
5009 data: [14]u8,
5010
5011 pub const SS_MAXSIZE = 128;
5012 pub const storage = extern struct {
5013 len: u8 align(8),
5014 family: sa_family_t,
5015 padding: [126]u8 = undefined,
5016
5017 comptime {
5018 assert(@sizeOf(storage) == SS_MAXSIZE);
5019 assert(@alignOf(storage) == 8);
5020 }
5021 };
5022
5023 pub const in = extern struct {
5024 len: u8 = @sizeOf(in),
5025 family: sa_family_t = AF.INET,
5026 port: in_port_t,
5027 addr: u32,
5028 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
5029 };
5030
5031 pub const in6 = extern struct {
5032 len: u8 = @sizeOf(in6),
5033 family: sa_family_t = AF.INET6,
5034 port: in_port_t,
5035 flowinfo: u32,
5036 addr: [16]u8,
5037 scope_id: u32,
5038 };
5039
5040 pub const un = extern struct {
5041 len: u8 = @sizeOf(un),
5042 family: sa_family_t = AF.UNIX,
5043 path: [104]u8,
5044 };
5045 },
5046 .haiku => extern struct {
5047 /// total length
5048 len: u8,
5049 /// address family
5050 family: sa_family_t,
5051 /// actually longer; address value
5052 data: [14]u8,
5053
5054 pub const SS_MAXSIZE = 128;
5055 pub const storage = extern struct {
5056 len: u8 align(8),
5057 family: sa_family_t,
5058 padding: [126]u8 = undefined,
5059
5060 comptime {
5061 assert(@sizeOf(storage) == SS_MAXSIZE);
5062 assert(@alignOf(storage) == 8);
5063 }
5064 };
5065
5066 pub const in = extern struct {
5067 len: u8 = @sizeOf(in),
5068 family: sa_family_t = AF.INET,
5069 port: in_port_t,
5070 addr: u32,
5071 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
5072 };
5073
5074 pub const in6 = extern struct {
5075 len: u8 = @sizeOf(in6),
5076 family: sa_family_t = AF.INET6,
5077 port: in_port_t,
5078 flowinfo: u32,
5079 addr: [16]u8,
5080 scope_id: u32,
5081 };
5082
5083 pub const un = extern struct {
5084 len: u8 = @sizeOf(un),
5085 family: sa_family_t = AF.UNIX,
5086 path: [104]u8,
5087 };
5088 },
5089 .openbsd => extern struct {
5090 /// total length
5091 len: u8,
5092 /// address family
5093 family: sa_family_t,
5094 /// actually longer; address value
5095 data: [14]u8,
5096
5097 pub const SS_MAXSIZE = 256;
5098 pub const storage = extern struct {
5099 len: u8 align(8),
5100 family: sa_family_t,
5101 padding: [254]u8 = undefined,
5102
5103 comptime {
5104 assert(@sizeOf(storage) == SS_MAXSIZE);
5105 assert(@alignOf(storage) == 8);
5106 }
5107 };
5108
5109 pub const in = extern struct {
5110 len: u8 = @sizeOf(in),
5111 family: sa_family_t = AF.INET,
5112 port: in_port_t,
5113 addr: u32,
5114 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
5115 };
5116
5117 pub const in6 = extern struct {
5118 len: u8 = @sizeOf(in6),
5119 family: sa_family_t = AF.INET6,
5120 port: in_port_t,
5121 flowinfo: u32,
5122 addr: [16]u8,
5123 scope_id: u32,
5124 };
5125
5126 /// Definitions for UNIX IPC domain.
5127 pub const un = extern struct {
5128 /// total sockaddr length
5129 len: u8 = @sizeOf(un),
5130
5131 family: sa_family_t = AF.LOCAL,
5132
5133 /// path name
5134 path: [104]u8,
5135 };
5136 },
5137 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L110-L114
5138 .serenity => extern struct {
5139 family: sa_family_t,
5140 data: [26]u8,
5141
5142 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/netinet/in.h
5143 const in_addr = u32;
5144 const in6_addr = [16]u8;
5145 pub const in = extern struct {
5146 family: sa_family_t = AF.INET,
5147 port: in_port_t,
5148 addr: in_addr,
5149 zero: [8]u8 = @splat(0),
5150 };
5151 pub const in6 = extern struct {
5152 family: sa_family_t = AF.INET6,
5153 port: in_port_t,
5154 flowinfo: u32,
5155 addr: in6_addr,
5156 scope_id: u32,
5157 };
5158
5159 // https://github.com/SerenityOS/serenity/blob/b92e6b02e53b2927732f31b1442cad420b62d1ef/Kernel/API/POSIX/sys/un.h
5160 const UNIX_PATH_MAX = 108;
5161 pub const un = extern struct {
5162 family: sa_family_t = AF.LOCAL,
5163 path: [UNIX_PATH_MAX]u8,
5164 };
5165 },
5166 else => void,
5167};
5168pub const socklen_t = switch (native_os) {
5169 .linux, .emscripten => linux.socklen_t,
5170 .windows => ws2_32.socklen_t,
5171 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L57
5172 else => u32,
5173};
5174pub const in_port_t = u16;
5175pub const sa_family_t = switch (native_os) {
5176 .linux, .emscripten => linux.sa_family_t,
5177 .windows => ws2_32.ADDRESS_FAMILY,
5178 .openbsd, .haiku, .dragonfly, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => u8,
5179 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L66
5180 .illumos, .serenity => u16,
5181 else => void,
5182};
5183pub const AF = if (builtin.abi.isAndroid()) struct {
5184 pub const UNSPEC = 0;
5185 pub const UNIX = 1;
5186 pub const LOCAL = 1;
5187 pub const INET = 2;
5188 pub const AX25 = 3;
5189 pub const IPX = 4;
5190 pub const APPLETALK = 5;
5191 pub const NETROM = 6;
5192 pub const BRIDGE = 7;
5193 pub const ATMPVC = 8;
5194 pub const X25 = 9;
5195 pub const INET6 = 10;
5196 pub const ROSE = 11;
5197 pub const DECnet = 12;
5198 pub const NETBEUI = 13;
5199 pub const SECURITY = 14;
5200 pub const KEY = 15;
5201 pub const NETLINK = 16;
5202 pub const ROUTE = NETLINK;
5203 pub const PACKET = 17;
5204 pub const ASH = 18;
5205 pub const ECONET = 19;
5206 pub const ATMSVC = 20;
5207 pub const RDS = 21;
5208 pub const SNA = 22;
5209 pub const IRDA = 23;
5210 pub const PPPOX = 24;
5211 pub const WANPIPE = 25;
5212 pub const LLC = 26;
5213 pub const CAN = 29;
5214 pub const TIPC = 30;
5215 pub const BLUETOOTH = 31;
5216 pub const IUCV = 32;
5217 pub const RXRPC = 33;
5218 pub const ISDN = 34;
5219 pub const PHONET = 35;
5220 pub const IEEE802154 = 36;
5221 pub const CAIF = 37;
5222 pub const ALG = 38;
5223 pub const NFC = 39;
5224 pub const VSOCK = 40;
5225 pub const KCM = 41;
5226 pub const QIPCRTR = 42;
5227 pub const MAX = 43;
5228} else switch (native_os) {
5229 .linux, .emscripten => linux.AF,
5230 .windows => ws2_32.AF,
5231 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
5232 pub const UNSPEC = 0;
5233 pub const LOCAL = 1;
5234 pub const UNIX = LOCAL;
5235 pub const INET = 2;
5236 pub const SYS_CONTROL = 2;
5237 pub const IMPLINK = 3;
5238 pub const PUP = 4;
5239 pub const CHAOS = 5;
5240 pub const NS = 6;
5241 pub const ISO = 7;
5242 pub const OSI = ISO;
5243 pub const ECMA = 8;
5244 pub const DATAKIT = 9;
5245 pub const CCITT = 10;
5246 pub const SNA = 11;
5247 pub const DECnet = 12;
5248 pub const DLI = 13;
5249 pub const LAT = 14;
5250 pub const HYLINK = 15;
5251 pub const APPLETALK = 16;
5252 pub const ROUTE = 17;
5253 pub const LINK = 18;
5254 pub const XTP = 19;
5255 pub const COIP = 20;
5256 pub const CNT = 21;
5257 pub const RTIP = 22;
5258 pub const IPX = 23;
5259 pub const SIP = 24;
5260 pub const PIP = 25;
5261 pub const ISDN = 28;
5262 pub const E164 = ISDN;
5263 pub const KEY = 29;
5264 pub const INET6 = 30;
5265 pub const NATM = 31;
5266 pub const SYSTEM = 32;
5267 pub const NETBIOS = 33;
5268 pub const PPP = 34;
5269 pub const MAX = 40;
5270 },
5271 .freebsd => struct {
5272 pub const UNSPEC = 0;
5273 pub const UNIX = 1;
5274 pub const LOCAL = UNIX;
5275 pub const FILE = LOCAL;
5276 pub const INET = 2;
5277 pub const IMPLINK = 3;
5278 pub const PUP = 4;
5279 pub const CHAOS = 5;
5280 pub const NETBIOS = 6;
5281 pub const ISO = 7;
5282 pub const OSI = ISO;
5283 pub const ECMA = 8;
5284 pub const DATAKIT = 9;
5285 pub const CCITT = 10;
5286 pub const SNA = 11;
5287 pub const DECnet = 12;
5288 pub const DLI = 13;
5289 pub const LAT = 14;
5290 pub const HYLINK = 15;
5291 pub const APPLETALK = 16;
5292 pub const ROUTE = 17;
5293 pub const LINK = 18;
5294 pub const pseudo_XTP = 19;
5295 pub const COIP = 20;
5296 pub const CNT = 21;
5297 pub const pseudo_RTIP = 22;
5298 pub const IPX = 23;
5299 pub const SIP = 24;
5300 pub const pseudo_PIP = 25;
5301 pub const ISDN = 26;
5302 pub const E164 = ISDN;
5303 pub const pseudo_KEY = 27;
5304 pub const INET6 = 28;
5305 pub const NATM = 29;
5306 pub const ATM = 30;
5307 pub const pseudo_HDRCMPLT = 31;
5308 pub const NETGRAPH = 32;
5309 pub const SLOW = 33;
5310 pub const SCLUSTER = 34;
5311 pub const ARP = 35;
5312 pub const BLUETOOTH = 36;
5313 pub const IEEE80211 = 37;
5314 pub const INET_SDP = 40;
5315 pub const INET6_SDP = 42;
5316 pub const MAX = 42;
5317 },
5318 .illumos => struct {
5319 pub const UNSPEC = 0;
5320 pub const UNIX = 1;
5321 pub const LOCAL = UNIX;
5322 pub const FILE = UNIX;
5323 pub const INET = 2;
5324 pub const IMPLINK = 3;
5325 pub const PUP = 4;
5326 pub const CHAOS = 5;
5327 pub const NS = 6;
5328 pub const NBS = 7;
5329 pub const ECMA = 8;
5330 pub const DATAKIT = 9;
5331 pub const CCITT = 10;
5332 pub const SNA = 11;
5333 pub const DECnet = 12;
5334 pub const DLI = 13;
5335 pub const LAT = 14;
5336 pub const HYLINK = 15;
5337 pub const APPLETALK = 16;
5338 pub const NIT = 17;
5339 pub const @"802" = 18;
5340 pub const OSI = 19;
5341 pub const X25 = 20;
5342 pub const OSINET = 21;
5343 pub const GOSIP = 22;
5344 pub const IPX = 23;
5345 pub const ROUTE = 24;
5346 pub const LINK = 25;
5347 pub const INET6 = 26;
5348 pub const KEY = 27;
5349 pub const NCA = 28;
5350 pub const POLICY = 29;
5351 pub const INET_OFFLOAD = 30;
5352 pub const TRILL = 31;
5353 pub const PACKET = 32;
5354 pub const LX_NETLINK = 33;
5355 pub const MAX = 33;
5356 },
5357 .netbsd => struct {
5358 pub const UNSPEC = 0;
5359 pub const LOCAL = 1;
5360 pub const UNIX = LOCAL;
5361 pub const INET = 2;
5362 pub const IMPLINK = 3;
5363 pub const PUP = 4;
5364 pub const CHAOS = 5;
5365 pub const NS = 6;
5366 pub const ISO = 7;
5367 pub const OSI = ISO;
5368 pub const ECMA = 8;
5369 pub const DATAKIT = 9;
5370 pub const CCITT = 10;
5371 pub const SNA = 11;
5372 pub const DECnet = 12;
5373 pub const DLI = 13;
5374 pub const LAT = 14;
5375 pub const HYLINK = 15;
5376 pub const APPLETALK = 16;
5377 pub const OROUTE = 17;
5378 pub const LINK = 18;
5379 pub const COIP = 20;
5380 pub const CNT = 21;
5381 pub const IPX = 23;
5382 pub const INET6 = 24;
5383 pub const ISDN = 26;
5384 pub const E164 = ISDN;
5385 pub const NATM = 27;
5386 pub const ARP = 28;
5387 pub const BLUETOOTH = 31;
5388 pub const IEEE80211 = 32;
5389 pub const MPLS = 33;
5390 pub const ROUTE = 34;
5391 pub const CAN = 35;
5392 pub const ETHER = 36;
5393 pub const MAX = 37;
5394 },
5395 .dragonfly => struct {
5396 pub const UNSPEC = 0;
5397 pub const OSI = ISO;
5398 pub const UNIX = LOCAL;
5399 pub const LOCAL = 1;
5400 pub const INET = 2;
5401 pub const IMPLINK = 3;
5402 pub const PUP = 4;
5403 pub const CHAOS = 5;
5404 pub const NETBIOS = 6;
5405 pub const ISO = 7;
5406 pub const ECMA = 8;
5407 pub const DATAKIT = 9;
5408 pub const CCITT = 10;
5409 pub const SNA = 11;
5410 pub const DLI = 13;
5411 pub const LAT = 14;
5412 pub const HYLINK = 15;
5413 pub const APPLETALK = 16;
5414 pub const ROUTE = 17;
5415 pub const LINK = 18;
5416 pub const COIP = 20;
5417 pub const CNT = 21;
5418 pub const IPX = 23;
5419 pub const SIP = 24;
5420 pub const ISDN = 26;
5421 pub const INET6 = 28;
5422 pub const NATM = 29;
5423 pub const ATM = 30;
5424 pub const NETGRAPH = 32;
5425 pub const BLUETOOTH = 33;
5426 pub const MPLS = 34;
5427 pub const MAX = 36;
5428 },
5429 .haiku => struct {
5430 pub const UNSPEC = 0;
5431 pub const INET = 1;
5432 pub const APPLETALK = 2;
5433 pub const ROUTE = 3;
5434 pub const LINK = 4;
5435 pub const INET6 = 5;
5436 pub const DLI = 6;
5437 pub const IPX = 7;
5438 pub const NOTIFY = 8;
5439 pub const LOCAL = 9;
5440 pub const UNIX = LOCAL;
5441 pub const BLUETOOTH = 10;
5442 pub const MAX = 11;
5443 },
5444 .openbsd => struct {
5445 pub const UNSPEC = 0;
5446 pub const UNIX = 1;
5447 pub const LOCAL = UNIX;
5448 pub const INET = 2;
5449 pub const APPLETALK = 16;
5450 pub const INET6 = 24;
5451 pub const KEY = 30;
5452 pub const ROUTE = 17;
5453 pub const SNA = 11;
5454 pub const MPLS = 33;
5455 pub const BLUETOOTH = 32;
5456 pub const ISDN = 26;
5457 pub const MAX = 36;
5458 },
5459 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L17-L22
5460 .serenity => struct {
5461 pub const UNSPEC = 0;
5462 pub const LOCAL = 1;
5463 pub const UNIX = LOCAL;
5464 pub const INET = 2;
5465 pub const INET6 = 3;
5466 pub const MAX = 4;
5467 },
5468 else => void,
5469};
5470pub const PF = if (builtin.abi.isAndroid()) struct {
5471 pub const UNSPEC = AF.UNSPEC;
5472 pub const UNIX = AF.UNIX;
5473 pub const LOCAL = AF.LOCAL;
5474 pub const INET = AF.INET;
5475 pub const AX25 = AF.AX25;
5476 pub const IPX = AF.IPX;
5477 pub const APPLETALK = AF.APPLETALK;
5478 pub const NETROM = AF.NETROM;
5479 pub const BRIDGE = AF.BRIDGE;
5480 pub const ATMPVC = AF.ATMPVC;
5481 pub const X25 = AF.X25;
5482 pub const PF_INET6 = AF.INET6;
5483 pub const PF_ROSE = AF.ROSE;
5484 pub const PF_DECnet = AF.DECnet;
5485 pub const PF_NETBEUI = AF.NETBEUI;
5486 pub const PF_SECURITY = AF.SECURITY;
5487 pub const PF_KEY = AF.KEY;
5488 pub const PF_NETLINK = AF.NETLINK;
5489 pub const PF_ROUTE = AF.ROUTE;
5490 pub const PF_PACKET = AF.PACKET;
5491 pub const PF_ASH = AF.ASH;
5492 pub const PF_ECONET = AF.ECONET;
5493 pub const PF_ATMSVC = AF.ATMSVC;
5494 pub const PF_RDS = AF.RDS;
5495 pub const PF_SNA = AF.SNA;
5496 pub const PF_IRDA = AF.IRDA;
5497 pub const PF_PPPOX = AF.PPPOX;
5498 pub const PF_WANPIPE = AF.WANPIPE;
5499 pub const PF_LLC = AF.LLC;
5500 pub const PF_CAN = AF.CAN;
5501 pub const PF_TIPC = AF.TIPC;
5502 pub const PF_BLUETOOTH = AF.BLUETOOTH;
5503 pub const PF_IUCV = AF.IUCV;
5504 pub const PF_RXRPC = AF.RXRPC;
5505 pub const PF_ISDN = AF.ISDN;
5506 pub const PF_PHONET = AF.PHONET;
5507 pub const PF_IEEE802154 = AF.IEEE802154;
5508 pub const PF_CAIF = AF.CAIF;
5509 pub const PF_ALG = AF.ALG;
5510 pub const PF_NFC = AF.NFC;
5511 pub const PF_VSOCK = AF.VSOCK;
5512 pub const PF_KCM = AF.KCM;
5513 pub const PF_QIPCRTR = AF.QIPCRTR;
5514 pub const PF_MAX = AF.MAX;
5515} else switch (native_os) {
5516 .linux, .emscripten => linux.PF,
5517 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
5518 pub const UNSPEC = AF.UNSPEC;
5519 pub const LOCAL = AF.LOCAL;
5520 pub const UNIX = PF.LOCAL;
5521 pub const INET = AF.INET;
5522 pub const IMPLINK = AF.IMPLINK;
5523 pub const PUP = AF.PUP;
5524 pub const CHAOS = AF.CHAOS;
5525 pub const NS = AF.NS;
5526 pub const ISO = AF.ISO;
5527 pub const OSI = AF.ISO;
5528 pub const ECMA = AF.ECMA;
5529 pub const DATAKIT = AF.DATAKIT;
5530 pub const CCITT = AF.CCITT;
5531 pub const SNA = AF.SNA;
5532 pub const DECnet = AF.DECnet;
5533 pub const DLI = AF.DLI;
5534 pub const LAT = AF.LAT;
5535 pub const HYLINK = AF.HYLINK;
5536 pub const APPLETALK = AF.APPLETALK;
5537 pub const ROUTE = AF.ROUTE;
5538 pub const LINK = AF.LINK;
5539 pub const XTP = AF.XTP;
5540 pub const COIP = AF.COIP;
5541 pub const CNT = AF.CNT;
5542 pub const SIP = AF.SIP;
5543 pub const IPX = AF.IPX;
5544 pub const RTIP = AF.RTIP;
5545 pub const PIP = AF.PIP;
5546 pub const ISDN = AF.ISDN;
5547 pub const KEY = AF.KEY;
5548 pub const INET6 = AF.INET6;
5549 pub const NATM = AF.NATM;
5550 pub const SYSTEM = AF.SYSTEM;
5551 pub const NETBIOS = AF.NETBIOS;
5552 pub const PPP = AF.PPP;
5553 pub const MAX = AF.MAX;
5554 },
5555 .freebsd => struct {
5556 pub const UNSPEC = AF.UNSPEC;
5557 pub const LOCAL = AF.LOCAL;
5558 pub const UNIX = PF.LOCAL;
5559 pub const INET = AF.INET;
5560 pub const IMPLINK = AF.IMPLINK;
5561 pub const PUP = AF.PUP;
5562 pub const CHAOS = AF.CHAOS;
5563 pub const NETBIOS = AF.NETBIOS;
5564 pub const ISO = AF.ISO;
5565 pub const OSI = AF.ISO;
5566 pub const ECMA = AF.ECMA;
5567 pub const DATAKIT = AF.DATAKIT;
5568 pub const CCITT = AF.CCITT;
5569 pub const DECnet = AF.DECnet;
5570 pub const DLI = AF.DLI;
5571 pub const LAT = AF.LAT;
5572 pub const HYLINK = AF.HYLINK;
5573 pub const APPLETALK = AF.APPLETALK;
5574 pub const ROUTE = AF.ROUTE;
5575 pub const LINK = AF.LINK;
5576 pub const XTP = AF.pseudo_XTP;
5577 pub const COIP = AF.COIP;
5578 pub const CNT = AF.CNT;
5579 pub const SIP = AF.SIP;
5580 pub const IPX = AF.IPX;
5581 pub const RTIP = AF.pseudo_RTIP;
5582 pub const PIP = AF.pseudo_PIP;
5583 pub const ISDN = AF.ISDN;
5584 pub const KEY = AF.pseudo_KEY;
5585 pub const INET6 = AF.pseudo_INET6;
5586 pub const NATM = AF.NATM;
5587 pub const ATM = AF.ATM;
5588 pub const NETGRAPH = AF.NETGRAPH;
5589 pub const SLOW = AF.SLOW;
5590 pub const SCLUSTER = AF.SCLUSTER;
5591 pub const ARP = AF.ARP;
5592 pub const BLUETOOTH = AF.BLUETOOTH;
5593 pub const IEEE80211 = AF.IEEE80211;
5594 pub const INET_SDP = AF.INET_SDP;
5595 pub const INET6_SDP = AF.INET6_SDP;
5596 pub const MAX = AF.MAX;
5597 },
5598 .illumos => struct {
5599 pub const UNSPEC = AF.UNSPEC;
5600 pub const UNIX = AF.UNIX;
5601 pub const LOCAL = UNIX;
5602 pub const FILE = UNIX;
5603 pub const INET = AF.INET;
5604 pub const IMPLINK = AF.IMPLINK;
5605 pub const PUP = AF.PUP;
5606 pub const CHAOS = AF.CHAOS;
5607 pub const NS = AF.NS;
5608 pub const NBS = AF.NBS;
5609 pub const ECMA = AF.ECMA;
5610 pub const DATAKIT = AF.DATAKIT;
5611 pub const CCITT = AF.CCITT;
5612 pub const SNA = AF.SNA;
5613 pub const DECnet = AF.DECnet;
5614 pub const DLI = AF.DLI;
5615 pub const LAT = AF.LAT;
5616 pub const HYLINK = AF.HYLINK;
5617 pub const APPLETALK = AF.APPLETALK;
5618 pub const NIT = AF.NIT;
5619 pub const @"802" = AF.@"802";
5620 pub const OSI = AF.OSI;
5621 pub const X25 = AF.X25;
5622 pub const OSINET = AF.OSINET;
5623 pub const GOSIP = AF.GOSIP;
5624 pub const IPX = AF.IPX;
5625 pub const ROUTE = AF.ROUTE;
5626 pub const LINK = AF.LINK;
5627 pub const INET6 = AF.INET6;
5628 pub const KEY = AF.KEY;
5629 pub const NCA = AF.NCA;
5630 pub const POLICY = AF.POLICY;
5631 pub const TRILL = AF.TRILL;
5632 pub const PACKET = AF.PACKET;
5633 pub const LX_NETLINK = AF.LX_NETLINK;
5634 pub const MAX = AF.MAX;
5635 },
5636 .netbsd => struct {
5637 pub const UNSPEC = AF.UNSPEC;
5638 pub const LOCAL = AF.LOCAL;
5639 pub const UNIX = PF.LOCAL;
5640 pub const INET = AF.INET;
5641 pub const IMPLINK = AF.IMPLINK;
5642 pub const PUP = AF.PUP;
5643 pub const CHAOS = AF.CHAOS;
5644 pub const NS = AF.NS;
5645 pub const ISO = AF.ISO;
5646 pub const OSI = AF.ISO;
5647 pub const ECMA = AF.ECMA;
5648 pub const DATAKIT = AF.DATAKIT;
5649 pub const CCITT = AF.CCITT;
5650 pub const SNA = AF.SNA;
5651 pub const DECnet = AF.DECnet;
5652 pub const DLI = AF.DLI;
5653 pub const LAT = AF.LAT;
5654 pub const HYLINK = AF.HYLINK;
5655 pub const APPLETALK = AF.APPLETALK;
5656 pub const OROUTE = AF.OROUTE;
5657 pub const LINK = AF.LINK;
5658 pub const COIP = AF.COIP;
5659 pub const CNT = AF.CNT;
5660 pub const INET6 = AF.INET6;
5661 pub const IPX = AF.IPX;
5662 pub const ISDN = AF.ISDN;
5663 pub const E164 = AF.E164;
5664 pub const NATM = AF.NATM;
5665 pub const ARP = AF.ARP;
5666 pub const BLUETOOTH = AF.BLUETOOTH;
5667 pub const MPLS = AF.MPLS;
5668 pub const ROUTE = AF.ROUTE;
5669 pub const CAN = AF.CAN;
5670 pub const ETHER = AF.ETHER;
5671 pub const MAX = AF.MAX;
5672 },
5673 .dragonfly => struct {
5674 pub const INET6 = AF.INET6;
5675 pub const IMPLINK = AF.IMPLINK;
5676 pub const ROUTE = AF.ROUTE;
5677 pub const ISO = AF.ISO;
5678 pub const PIP = AF.pseudo_PIP;
5679 pub const CHAOS = AF.CHAOS;
5680 pub const DATAKIT = AF.DATAKIT;
5681 pub const INET = AF.INET;
5682 pub const APPLETALK = AF.APPLETALK;
5683 pub const SIP = AF.SIP;
5684 pub const OSI = AF.ISO;
5685 pub const CNT = AF.CNT;
5686 pub const LINK = AF.LINK;
5687 pub const HYLINK = AF.HYLINK;
5688 pub const MAX = AF.MAX;
5689 pub const KEY = AF.pseudo_KEY;
5690 pub const PUP = AF.PUP;
5691 pub const COIP = AF.COIP;
5692 pub const SNA = AF.SNA;
5693 pub const LOCAL = AF.LOCAL;
5694 pub const NETBIOS = AF.NETBIOS;
5695 pub const NATM = AF.NATM;
5696 pub const BLUETOOTH = AF.BLUETOOTH;
5697 pub const UNSPEC = AF.UNSPEC;
5698 pub const NETGRAPH = AF.NETGRAPH;
5699 pub const ECMA = AF.ECMA;
5700 pub const IPX = AF.IPX;
5701 pub const DLI = AF.DLI;
5702 pub const ATM = AF.ATM;
5703 pub const CCITT = AF.CCITT;
5704 pub const ISDN = AF.ISDN;
5705 pub const RTIP = AF.pseudo_RTIP;
5706 pub const LAT = AF.LAT;
5707 pub const UNIX = PF.LOCAL;
5708 pub const XTP = AF.pseudo_XTP;
5709 pub const DECnet = AF.DECnet;
5710 },
5711 .haiku => struct {
5712 pub const UNSPEC = AF.UNSPEC;
5713 pub const INET = AF.INET;
5714 pub const ROUTE = AF.ROUTE;
5715 pub const LINK = AF.LINK;
5716 pub const INET6 = AF.INET6;
5717 pub const LOCAL = AF.LOCAL;
5718 pub const UNIX = AF.UNIX;
5719 pub const BLUETOOTH = AF.BLUETOOTH;
5720 },
5721 .openbsd => struct {
5722 pub const UNSPEC = AF.UNSPEC;
5723 pub const LOCAL = AF.LOCAL;
5724 pub const UNIX = AF.UNIX;
5725 pub const INET = AF.INET;
5726 pub const APPLETALK = AF.APPLETALK;
5727 pub const INET6 = AF.INET6;
5728 pub const DECnet = AF.DECnet;
5729 pub const KEY = AF.KEY;
5730 pub const ROUTE = AF.ROUTE;
5731 pub const SNA = AF.SNA;
5732 pub const MPLS = AF.MPLS;
5733 pub const BLUETOOTH = AF.BLUETOOTH;
5734 pub const ISDN = AF.ISDN;
5735 pub const MAX = AF.MAX;
5736 },
5737 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L24-L29
5738 .serenity => struct {
5739 pub const LOCAL = AF.LOCAL;
5740 pub const UNIX = AF.LOCAL;
5741 pub const INET = AF.INET;
5742 pub const INET6 = AF.INET6;
5743 pub const UNSPEC = AF.UNSPEC;
5744 pub const MAX = AF.MAX;
5745 },
5746 else => void,
5747};
5748pub const DT = switch (native_os) {
5749 .linux => linux.DT,
5750 // https://github.com/SerenityOS/serenity/blob/1262a7d1424d0d2e89d80644409721cbf056ab17/Kernel/API/POSIX/dirent.h#L16-L35
5751 .netbsd, .freebsd, .openbsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .serenity => struct {
5752 pub const UNKNOWN = 0;
5753 pub const FIFO = 1;
5754 pub const CHR = 2;
5755 pub const DIR = 4;
5756 pub const BLK = 6;
5757 pub const REG = 8;
5758 pub const LNK = 10;
5759 pub const SOCK = 12;
5760 pub const WHT = 14;
5761 },
5762 .dragonfly => struct {
5763 pub const UNKNOWN = 0;
5764 pub const FIFO = 1;
5765 pub const CHR = 2;
5766 pub const DIR = 4;
5767 pub const BLK = 6;
5768 pub const REG = 8;
5769 pub const LNK = 10;
5770 pub const SOCK = 12;
5771 pub const WHT = 14;
5772 pub const DBF = 15;
5773 },
5774 else => void,
5775};
5776pub const MSG = switch (native_os) {
5777 .linux => linux.MSG,
5778 .emscripten => emscripten.MSG,
5779 .windows => ws2_32.MSG,
5780 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => darwin.MSG,
5781 .haiku => struct {
5782 pub const OOB = 0x0001;
5783 pub const PEEK = 0x0002;
5784 pub const DONTROUTE = 0x0004;
5785 pub const EOR = 0x0008;
5786 pub const TRUNC = 0x0010;
5787 pub const CTRUNC = 0x0020;
5788 pub const WAITALL = 0x0040;
5789 pub const DONTWAIT = 0x0080;
5790 pub const BCAST = 0x0100;
5791 pub const MCAST = 0x0200;
5792 pub const EOF = 0x0400;
5793 pub const NOSIGNAL = 0x0800;
5794 },
5795 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L56-L64
5796 .serenity => struct {
5797 pub const TRUNC = 0x1;
5798 pub const CTRUNC = 0x2;
5799 pub const PEEK = 0x4;
5800 pub const OOB = 0x8;
5801 pub const DONTROUTE = 0x10;
5802 pub const WAITALL = 0x20;
5803 pub const DONTWAIT = 0x40;
5804 pub const NOSIGNAL = 0x80;
5805 pub const EOR = 0x100;
5806 },
5807 .freebsd => struct {
5808 pub const OOB = 0x00000001;
5809 pub const PEEK = 0x00000002;
5810 pub const DONTROUTE = 0x00000004;
5811 pub const EOR = 0x00000008;
5812 pub const TRUNC = 0x00000010;
5813 pub const CTRUNC = 0x00000020;
5814 pub const WAITALL = 0x00000040;
5815 pub const DONTWAIT = 0x00000080;
5816 pub const EOF = 0x00000100;
5817 pub const NOTIFICATION = 0x00002000;
5818 pub const NBIO = 0x00004000;
5819 pub const COMPAT = 0x00008000;
5820 pub const SOCALLBCK = 0x00010000;
5821 pub const NOSIGNAL = 0x00020000;
5822 pub const CMSG_CLOEXEC = 0x00040000;
5823 pub const WAITFORONE = 0x00080000;
5824 pub const MORETOCOME = 0x00100000;
5825 pub const TLSAPPDATA = 0x00200000;
5826 },
5827 .netbsd => struct {
5828 pub const OOB = 0x0001;
5829 pub const PEEK = 0x0002;
5830 pub const DONTROUTE = 0x0004;
5831 pub const EOR = 0x0008;
5832 pub const TRUNC = 0x0010;
5833 pub const CTRUNC = 0x0020;
5834 pub const WAITALL = 0x0040;
5835 pub const DONTWAIT = 0x0080;
5836 pub const BCAST = 0x0100;
5837 pub const MCAST = 0x0200;
5838 pub const NOSIGNAL = 0x0400;
5839 pub const CMSG_CLOEXEC = 0x0800;
5840 pub const NBIO = 0x1000;
5841 pub const WAITFORONE = 0x2000;
5842 pub const NOTIFICATION = 0x4000;
5843 },
5844 // https://github.com/openbsd/src/blob/42a7be81bef70c04732f45ec573622effe56b563/sys/sys/socket.h#L506
5845 .openbsd => struct {
5846 pub const OOB = 0x1;
5847 pub const PEEK = 0x2;
5848 pub const DONTROUTE = 0x4;
5849 pub const EOR = 0x8;
5850 pub const TRUNC = 0x10;
5851 pub const CTRUNC = 0x20;
5852 pub const WAITALL = 0x40;
5853 pub const DONTWAIT = 0x80;
5854 pub const BCAST = 0x100;
5855 pub const MCAST = 0x200;
5856 pub const NOSIGNAL = 0x400;
5857 pub const CMSG_CLOEXEC = 0x800;
5858 pub const WAITFORONE = 0x1000;
5859 pub const CMSG_CLOFORK = 0x2000;
5860 },
5861 .dragonfly => struct {
5862 pub const OOB = 0x0001;
5863 pub const PEEK = 0x0002;
5864 pub const DONTROUTE = 0x0004;
5865 pub const EOR = 0x0008;
5866 pub const TRUNC = 0x0010;
5867 pub const CTRUNC = 0x0020;
5868 pub const WAITALL = 0x0040;
5869 pub const DONTWAIT = 0x0080;
5870 pub const NOSIGNAL = 0x0400;
5871 pub const SYNC = 0x0800;
5872 pub const CMSG_CLOEXEC = 0x1000;
5873 pub const CMSG_CLOFORK = 0x2000;
5874 pub const FBLOCKING = 0x10000;
5875 pub const FNONBLOCKING = 0x20000;
5876 },
5877 .illumos => struct {
5878 pub const OOB = 0x0001;
5879 pub const PEEK = 0x0002;
5880 pub const DONTROUTE = 0x0004;
5881 pub const EOR = 0x0008;
5882 pub const CTRUNC = 0x0010;
5883 pub const TRUNC = 0x0020;
5884 pub const WAITALL = 0x0040;
5885 pub const DONTWAIT = 0x0080;
5886 pub const NOTIFICATION = 0x0100;
5887 pub const NOSIGNAL = 0x0200;
5888 pub const CMSG_CLOEXEC = 0x1000;
5889 pub const CMSG_CLOFORK = 0x2000;
5890 },
5891 else => void,
5892};
5893pub const SOCK = switch (native_os) {
5894 .linux => linux.SOCK,
5895 .emscripten => emscripten.SOCK,
5896 .windows => ws2_32.SOCK,
5897 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
5898 pub const STREAM = 1;
5899 pub const DGRAM = 2;
5900 pub const RAW = 3;
5901 pub const RDM = 4;
5902 pub const SEQPACKET = 5;
5903 pub const MAXADDRLEN = 255;
5904
5905 /// Not actually supported by Darwin, but Zig supplies a shim.
5906 /// This numerical value is not ABI-stable. It need only not conflict
5907 /// with any other `SOCK` bits.
5908 pub const CLOEXEC = 1 << 15;
5909 /// Not actually supported by Darwin, but Zig supplies a shim.
5910 /// This numerical value is not ABI-stable. It need only not conflict
5911 /// with any other `SOCK` bits.
5912 pub const NONBLOCK = 1 << 16;
5913 },
5914 .freebsd => struct {
5915 pub const STREAM = 1;
5916 pub const DGRAM = 2;
5917 pub const RAW = 3;
5918 pub const RDM = 4;
5919 pub const SEQPACKET = 5;
5920
5921 pub const CLOEXEC = 0x10000000;
5922 pub const NONBLOCK = 0x20000000;
5923 },
5924 .illumos => struct {
5925 /// Datagram.
5926 pub const DGRAM = 1;
5927 /// STREAM.
5928 pub const STREAM = 2;
5929 /// Raw-protocol interface.
5930 pub const RAW = 4;
5931 /// Reliably-delivered message.
5932 pub const RDM = 5;
5933 /// Sequenced packed stream.
5934 pub const SEQPACKET = 6;
5935
5936 pub const NONBLOCK = 0x100000;
5937 pub const NDELAY = 0x200000;
5938 pub const CLOEXEC = 0x080000;
5939 },
5940 .netbsd => struct {
5941 pub const STREAM = 1;
5942 pub const DGRAM = 2;
5943 pub const RAW = 3;
5944 pub const RDM = 4;
5945 pub const SEQPACKET = 5;
5946 pub const CONN_DGRAM = 6;
5947 pub const DCCP = CONN_DGRAM;
5948
5949 pub const CLOEXEC = 0x10000000;
5950 pub const NONBLOCK = 0x20000000;
5951 pub const NOSIGPIPE = 0x40000000;
5952 pub const FLAGS_MASK = 0xf0000000;
5953 },
5954 .dragonfly => struct {
5955 pub const STREAM = 1;
5956 pub const DGRAM = 2;
5957 pub const RAW = 3;
5958 pub const RDM = 4;
5959 pub const SEQPACKET = 5;
5960 pub const MAXADDRLEN = 255;
5961 pub const CLOEXEC = 0x10000000;
5962 pub const NONBLOCK = 0x20000000;
5963 },
5964 .haiku => struct {
5965 pub const STREAM = 1;
5966 pub const DGRAM = 2;
5967 pub const RAW = 3;
5968 pub const SEQPACKET = 5;
5969 pub const MISC = 255;
5970
5971 pub const NONBLOCK = 0x40000;
5972 pub const CLOEXEC = 0x80000;
5973 },
5974 .openbsd => struct {
5975 pub const STREAM = 1;
5976 pub const DGRAM = 2;
5977 pub const RAW = 3;
5978 pub const RDM = 4;
5979 pub const SEQPACKET = 5;
5980
5981 pub const CLOEXEC = 0x8000;
5982 pub const NONBLOCK = 0x4000;
5983 },
5984 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L31-L38
5985 .serenity => struct {
5986 pub const STREAM = 1;
5987 pub const DGRAM = 2;
5988 pub const RAW = 3;
5989 pub const RDM = 4;
5990 pub const SEQPACKET = 5;
5991
5992 pub const NONBLOCK = 0o4000;
5993 pub const CLOEXEC = 0o2000000;
5994 },
5995 else => void,
5996};
5997pub const TCP = switch (native_os) {
5998 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => darwin.TCP,
5999 .linux => linux.TCP,
6000 .emscripten => emscripten.TCP,
6001 .windows => ws2_32.TCP,
6002 // https://github.com/SerenityOS/serenity/blob/61ac554a3403838f79ca746bd1c65ded6f97d124/Kernel/API/POSIX/netinet/tcp.h#L13-L14
6003 .serenity => struct {
6004 pub const NODELAY = 10;
6005 pub const MAXSEG = 11;
6006 },
6007 else => void,
6008};
6009pub const IPPROTO = switch (native_os) {
6010 .linux, .emscripten => linux.IPPROTO,
6011 .windows => ws2_32.IPPROTO,
6012 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
6013 pub const ICMP = 1;
6014 pub const ICMPV6 = 58;
6015 pub const TCP = 6;
6016 pub const UDP = 17;
6017 pub const IP = 0;
6018 pub const IPV6 = 41;
6019 pub const RAW = 255;
6020 },
6021 .freebsd => struct {
6022 /// dummy for IP
6023 pub const IP = 0;
6024 /// control message protocol
6025 pub const ICMP = 1;
6026 /// tcp
6027 pub const TCP = 6;
6028 /// user datagram protocol
6029 pub const UDP = 17;
6030 /// IP6 header
6031 pub const IPV6 = 41;
6032 /// raw IP packet
6033 pub const RAW = 255;
6034 /// IP6 hop-by-hop options
6035 pub const HOPOPTS = 0;
6036 /// group mgmt protocol
6037 pub const IGMP = 2;
6038 /// gateway^2 (deprecated)
6039 pub const GGP = 3;
6040 /// IPv4 encapsulation
6041 pub const IPV4 = 4;
6042 /// for compatibility
6043 pub const IPIP = IPV4;
6044 /// Stream protocol II
6045 pub const ST = 7;
6046 /// exterior gateway protocol
6047 pub const EGP = 8;
6048 /// private interior gateway
6049 pub const PIGP = 9;
6050 /// BBN RCC Monitoring
6051 pub const RCCMON = 10;
6052 /// network voice protocol
6053 pub const NVPII = 11;
6054 /// pup
6055 pub const PUP = 12;
6056 /// Argus
6057 pub const ARGUS = 13;
6058 /// EMCON
6059 pub const EMCON = 14;
6060 /// Cross Net Debugger
6061 pub const XNET = 15;
6062 /// Chaos
6063 pub const CHAOS = 16;
6064 /// Multiplexing
6065 pub const MUX = 18;
6066 /// DCN Measurement Subsystems
6067 pub const MEAS = 19;
6068 /// Host Monitoring
6069 pub const HMP = 20;
6070 /// Packet Radio Measurement
6071 pub const PRM = 21;
6072 /// xns idp
6073 pub const IDP = 22;
6074 /// Trunk-1
6075 pub const TRUNK1 = 23;
6076 /// Trunk-2
6077 pub const TRUNK2 = 24;
6078 /// Leaf-1
6079 pub const LEAF1 = 25;
6080 /// Leaf-2
6081 pub const LEAF2 = 26;
6082 /// Reliable Data
6083 pub const RDP = 27;
6084 /// Reliable Transaction
6085 pub const IRTP = 28;
6086 /// tp-4 w/ class negotiation
6087 pub const TP = 29;
6088 /// Bulk Data Transfer
6089 pub const BLT = 30;
6090 /// Network Services
6091 pub const NSP = 31;
6092 /// Merit Internodal
6093 pub const INP = 32;
6094 /// Datagram Congestion Control Protocol
6095 pub const DCCP = 33;
6096 /// Third Party Connect
6097 pub const @"3PC" = 34;
6098 /// InterDomain Policy Routing
6099 pub const IDPR = 35;
6100 /// XTP
6101 pub const XTP = 36;
6102 /// Datagram Delivery
6103 pub const DDP = 37;
6104 /// Control Message Transport
6105 pub const CMTP = 38;
6106 /// TP++ Transport
6107 pub const TPXX = 39;
6108 /// IL transport protocol
6109 pub const IL = 40;
6110 /// Source Demand Routing
6111 pub const SDRP = 42;
6112 /// IP6 routing header
6113 pub const ROUTING = 43;
6114 /// IP6 fragmentation header
6115 pub const FRAGMENT = 44;
6116 /// InterDomain Routing
6117 pub const IDRP = 45;
6118 /// resource reservation
6119 pub const RSVP = 46;
6120 /// General Routing Encap.
6121 pub const GRE = 47;
6122 /// Mobile Host Routing
6123 pub const MHRP = 48;
6124 /// BHA
6125 pub const BHA = 49;
6126 /// IP6 Encap Sec. Payload
6127 pub const ESP = 50;
6128 /// IP6 Auth Header
6129 pub const AH = 51;
6130 /// Integ. Net Layer Security
6131 pub const INLSP = 52;
6132 /// IP with encryption
6133 pub const SWIPE = 53;
6134 /// Next Hop Resolution
6135 pub const NHRP = 54;
6136 /// IP Mobility
6137 pub const MOBILE = 55;
6138 /// Transport Layer Security
6139 pub const TLSP = 56;
6140 /// SKIP
6141 pub const SKIP = 57;
6142 /// ICMP6
6143 pub const ICMPV6 = 58;
6144 /// IP6 no next header
6145 pub const NONE = 59;
6146 /// IP6 destination option
6147 pub const DSTOPTS = 60;
6148 /// any host internal protocol
6149 pub const AHIP = 61;
6150 /// CFTP
6151 pub const CFTP = 62;
6152 /// "hello" routing protocol
6153 pub const HELLO = 63;
6154 /// SATNET/Backroom EXPAK
6155 pub const SATEXPAK = 64;
6156 /// Kryptolan
6157 pub const KRYPTOLAN = 65;
6158 /// Remote Virtual Disk
6159 pub const RVD = 66;
6160 /// Pluribus Packet Core
6161 pub const IPPC = 67;
6162 /// Any distributed FS
6163 pub const ADFS = 68;
6164 /// Satnet Monitoring
6165 pub const SATMON = 69;
6166 /// VISA Protocol
6167 pub const VISA = 70;
6168 /// Packet Core Utility
6169 pub const IPCV = 71;
6170 /// Comp. Prot. Net. Executive
6171 pub const CPNX = 72;
6172 /// Comp. Prot. HeartBeat
6173 pub const CPHB = 73;
6174 /// Wang Span Network
6175 pub const WSN = 74;
6176 /// Packet Video Protocol
6177 pub const PVP = 75;
6178 /// BackRoom SATNET Monitoring
6179 pub const BRSATMON = 76;
6180 /// Sun net disk proto (temp.)
6181 pub const ND = 77;
6182 /// WIDEBAND Monitoring
6183 pub const WBMON = 78;
6184 /// WIDEBAND EXPAK
6185 pub const WBEXPAK = 79;
6186 /// ISO cnlp
6187 pub const EON = 80;
6188 /// VMTP
6189 pub const VMTP = 81;
6190 /// Secure VMTP
6191 pub const SVMTP = 82;
6192 /// Banyon VINES
6193 pub const VINES = 83;
6194 /// TTP
6195 pub const TTP = 84;
6196 /// NSFNET-IGP
6197 pub const IGP = 85;
6198 /// dissimilar gateway prot.
6199 pub const DGP = 86;
6200 /// TCF
6201 pub const TCF = 87;
6202 /// Cisco/GXS IGRP
6203 pub const IGRP = 88;
6204 /// OSPFIGP
6205 pub const OSPFIGP = 89;
6206 /// Strite RPC protocol
6207 pub const SRPC = 90;
6208 /// Locus Address Resoloution
6209 pub const LARP = 91;
6210 /// Multicast Transport
6211 pub const MTP = 92;
6212 /// AX.25 Frames
6213 pub const AX25 = 93;
6214 /// IP encapsulated in IP
6215 pub const IPEIP = 94;
6216 /// Mobile Int.ing control
6217 pub const MICP = 95;
6218 /// Semaphore Comm. security
6219 pub const SCCSP = 96;
6220 /// Ethernet IP encapsulation
6221 pub const ETHERIP = 97;
6222 /// encapsulation header
6223 pub const ENCAP = 98;
6224 /// any private encr. scheme
6225 pub const APES = 99;
6226 /// GMTP
6227 pub const GMTP = 100;
6228 /// payload compression (IPComp)
6229 pub const IPCOMP = 108;
6230 /// SCTP
6231 pub const SCTP = 132;
6232 /// IPv6 Mobility Header
6233 pub const MH = 135;
6234 /// UDP-Lite
6235 pub const UDPLITE = 136;
6236 /// IP6 Host Identity Protocol
6237 pub const HIP = 139;
6238 /// IP6 Shim6 Protocol
6239 pub const SHIM6 = 140;
6240 /// Protocol Independent Mcast
6241 pub const PIM = 103;
6242 /// CARP
6243 pub const CARP = 112;
6244 /// PGM
6245 pub const PGM = 113;
6246 /// MPLS-in-IP
6247 pub const MPLS = 137;
6248 /// PFSYNC
6249 pub const PFSYNC = 240;
6250 /// Reserved
6251 pub const RESERVED_253 = 253;
6252 /// Reserved
6253 pub const RESERVED_254 = 254;
6254 },
6255 .illumos => struct {
6256 /// dummy for IP
6257 pub const IP = 0;
6258 /// Hop by hop header for IPv6
6259 pub const HOPOPTS = 0;
6260 /// control message protocol
6261 pub const ICMP = 1;
6262 /// group control protocol
6263 pub const IGMP = 2;
6264 /// gateway^2 (deprecated)
6265 pub const GGP = 3;
6266 /// IP in IP encapsulation
6267 pub const ENCAP = 4;
6268 /// tcp
6269 pub const TCP = 6;
6270 /// exterior gateway protocol
6271 pub const EGP = 8;
6272 /// pup
6273 pub const PUP = 12;
6274 /// user datagram protocol
6275 pub const UDP = 17;
6276 /// xns idp
6277 pub const IDP = 22;
6278 /// IPv6 encapsulated in IP
6279 pub const IPV6 = 41;
6280 /// Routing header for IPv6
6281 pub const ROUTING = 43;
6282 /// Fragment header for IPv6
6283 pub const FRAGMENT = 44;
6284 /// rsvp
6285 pub const RSVP = 46;
6286 /// IPsec Encap. Sec. Payload
6287 pub const ESP = 50;
6288 /// IPsec Authentication Hdr.
6289 pub const AH = 51;
6290 /// ICMP for IPv6
6291 pub const ICMPV6 = 58;
6292 /// No next header for IPv6
6293 pub const NONE = 59;
6294 /// Destination options
6295 pub const DSTOPTS = 60;
6296 /// "hello" routing protocol
6297 pub const HELLO = 63;
6298 /// UNOFFICIAL net disk proto
6299 pub const ND = 77;
6300 /// ISO clnp
6301 pub const EON = 80;
6302 /// OSPF
6303 pub const OSPF = 89;
6304 /// PIM routing protocol
6305 pub const PIM = 103;
6306 /// Stream Control
6307 pub const SCTP = 132;
6308 /// raw IP packet
6309 pub const RAW = 255;
6310 /// Sockets Direct Protocol
6311 pub const PROTO_SDP = 257;
6312 },
6313 .netbsd => struct {
6314 /// dummy for IP
6315 pub const IP = 0;
6316 /// IP6 hop-by-hop options
6317 pub const HOPOPTS = 0;
6318 /// control message protocol
6319 pub const ICMP = 1;
6320 /// group mgmt protocol
6321 pub const IGMP = 2;
6322 /// gateway^2 (deprecated)
6323 pub const GGP = 3;
6324 /// IP header
6325 pub const IPV4 = 4;
6326 /// IP inside IP
6327 pub const IPIP = 4;
6328 /// tcp
6329 pub const TCP = 6;
6330 /// exterior gateway protocol
6331 pub const EGP = 8;
6332 /// pup
6333 pub const PUP = 12;
6334 /// user datagram protocol
6335 pub const UDP = 17;
6336 /// xns idp
6337 pub const IDP = 22;
6338 /// tp-4 w/ class negotiation
6339 pub const TP = 29;
6340 /// DCCP
6341 pub const DCCP = 33;
6342 /// IP6 header
6343 pub const IPV6 = 41;
6344 /// IP6 routing header
6345 pub const ROUTING = 43;
6346 /// IP6 fragmentation header
6347 pub const FRAGMENT = 44;
6348 /// resource reservation
6349 pub const RSVP = 46;
6350 /// GRE encaps RFC 1701
6351 pub const GRE = 47;
6352 /// encap. security payload
6353 pub const ESP = 50;
6354 /// authentication header
6355 pub const AH = 51;
6356 /// IP Mobility RFC 2004
6357 pub const MOBILE = 55;
6358 /// IPv6 ICMP
6359 pub const IPV6_ICMP = 58;
6360 /// ICMP6
6361 pub const ICMPV6 = 58;
6362 /// IP6 no next header
6363 pub const NONE = 59;
6364 /// IP6 destination option
6365 pub const DSTOPTS = 60;
6366 /// ISO cnlp
6367 pub const EON = 80;
6368 /// Ethernet-in-IP
6369 pub const ETHERIP = 97;
6370 /// encapsulation header
6371 pub const ENCAP = 98;
6372 /// Protocol indep. multicast
6373 pub const PIM = 103;
6374 /// IP Payload Comp. Protocol
6375 pub const IPCOMP = 108;
6376 /// VRRP RFC 2338
6377 pub const VRRP = 112;
6378 /// Common Address Resolution Protocol
6379 pub const CARP = 112;
6380 /// L2TPv3
6381 pub const L2TP = 115;
6382 /// SCTP
6383 pub const SCTP = 132;
6384 /// PFSYNC
6385 pub const PFSYNC = 240;
6386 /// raw IP packet
6387 pub const RAW = 255;
6388 },
6389 .dragonfly => struct {
6390 pub const IP = 0;
6391 pub const ICMP = 1;
6392 pub const TCP = 6;
6393 pub const UDP = 17;
6394 pub const IPV6 = 41;
6395 pub const RAW = 255;
6396 pub const HOPOPTS = 0;
6397 pub const IGMP = 2;
6398 pub const GGP = 3;
6399 pub const IPV4 = 4;
6400 pub const IPIP = IPV4;
6401 pub const ST = 7;
6402 pub const EGP = 8;
6403 pub const PIGP = 9;
6404 pub const RCCMON = 10;
6405 pub const NVPII = 11;
6406 pub const PUP = 12;
6407 pub const ARGUS = 13;
6408 pub const EMCON = 14;
6409 pub const XNET = 15;
6410 pub const CHAOS = 16;
6411 pub const MUX = 18;
6412 pub const MEAS = 19;
6413 pub const HMP = 20;
6414 pub const PRM = 21;
6415 pub const IDP = 22;
6416 pub const TRUNK1 = 23;
6417 pub const TRUNK2 = 24;
6418 pub const LEAF1 = 25;
6419 pub const LEAF2 = 26;
6420 pub const RDP = 27;
6421 pub const IRTP = 28;
6422 pub const TP = 29;
6423 pub const BLT = 30;
6424 pub const NSP = 31;
6425 pub const INP = 32;
6426 pub const SEP = 33;
6427 pub const @"3PC" = 34;
6428 pub const IDPR = 35;
6429 pub const XTP = 36;
6430 pub const DDP = 37;
6431 pub const CMTP = 38;
6432 pub const TPXX = 39;
6433 pub const IL = 40;
6434 pub const SDRP = 42;
6435 pub const ROUTING = 43;
6436 pub const FRAGMENT = 44;
6437 pub const IDRP = 45;
6438 pub const RSVP = 46;
6439 pub const GRE = 47;
6440 pub const MHRP = 48;
6441 pub const BHA = 49;
6442 pub const ESP = 50;
6443 pub const AH = 51;
6444 pub const INLSP = 52;
6445 pub const SWIPE = 53;
6446 pub const NHRP = 54;
6447 pub const MOBILE = 55;
6448 pub const TLSP = 56;
6449 pub const SKIP = 57;
6450 pub const ICMPV6 = 58;
6451 pub const NONE = 59;
6452 pub const DSTOPTS = 60;
6453 pub const AHIP = 61;
6454 pub const CFTP = 62;
6455 pub const HELLO = 63;
6456 pub const SATEXPAK = 64;
6457 pub const KRYPTOLAN = 65;
6458 pub const RVD = 66;
6459 pub const IPPC = 67;
6460 pub const ADFS = 68;
6461 pub const SATMON = 69;
6462 pub const VISA = 70;
6463 pub const IPCV = 71;
6464 pub const CPNX = 72;
6465 pub const CPHB = 73;
6466 pub const WSN = 74;
6467 pub const PVP = 75;
6468 pub const BRSATMON = 76;
6469 pub const ND = 77;
6470 pub const WBMON = 78;
6471 pub const WBEXPAK = 79;
6472 pub const EON = 80;
6473 pub const VMTP = 81;
6474 pub const SVMTP = 82;
6475 pub const VINES = 83;
6476 pub const TTP = 84;
6477 pub const IGP = 85;
6478 pub const DGP = 86;
6479 pub const TCF = 87;
6480 pub const IGRP = 88;
6481 pub const OSPFIGP = 89;
6482 pub const SRPC = 90;
6483 pub const LARP = 91;
6484 pub const MTP = 92;
6485 pub const AX25 = 93;
6486 pub const IPEIP = 94;
6487 pub const MICP = 95;
6488 pub const SCCSP = 96;
6489 pub const ETHERIP = 97;
6490 pub const ENCAP = 98;
6491 pub const APES = 99;
6492 pub const GMTP = 100;
6493 pub const IPCOMP = 108;
6494 pub const PIM = 103;
6495 pub const CARP = 112;
6496 pub const PGM = 113;
6497 pub const PFSYNC = 240;
6498 pub const DIVERT = 254;
6499 pub const MAX = 256;
6500 pub const DONE = 257;
6501 pub const UNKNOWN = 258;
6502 },
6503 .haiku => struct {
6504 pub const IP = 0;
6505 pub const HOPOPTS = 0;
6506 pub const ICMP = 1;
6507 pub const IGMP = 2;
6508 pub const TCP = 6;
6509 pub const UDP = 17;
6510 pub const IPV6 = 41;
6511 pub const ROUTING = 43;
6512 pub const FRAGMENT = 44;
6513 pub const ESP = 50;
6514 pub const AH = 51;
6515 pub const ICMPV6 = 58;
6516 pub const NONE = 59;
6517 pub const DSTOPTS = 60;
6518 pub const ETHERIP = 97;
6519 pub const RAW = 255;
6520 pub const MAX = 256;
6521 },
6522 .openbsd => struct {
6523 /// dummy for IP
6524 pub const IP = 0;
6525 /// IP6 hop-by-hop options
6526 pub const HOPOPTS = IPPROTO.IP;
6527 /// control message protocol
6528 pub const ICMP = 1;
6529 /// group mgmt protocol
6530 pub const IGMP = 2;
6531 /// gateway^2 (deprecated)
6532 pub const GGP = 3;
6533 /// IP header
6534 pub const IPV4 = IPIP;
6535 /// IP inside IP
6536 pub const IPIP = 4;
6537 /// tcp
6538 pub const TCP = 6;
6539 /// exterior gateway protocol
6540 pub const EGP = 8;
6541 /// pup
6542 pub const PUP = 12;
6543 /// user datagram protocol
6544 pub const UDP = 17;
6545 /// xns idp
6546 pub const IDP = 22;
6547 /// tp-4 w/ class negotiation
6548 pub const TP = 29;
6549 /// IP6 header
6550 pub const IPV6 = 41;
6551 /// IP6 routing header
6552 pub const ROUTING = 43;
6553 /// IP6 fragmentation header
6554 pub const FRAGMENT = 44;
6555 /// resource reservation
6556 pub const RSVP = 46;
6557 /// GRE encaps RFC 1701
6558 pub const GRE = 47;
6559 /// encap. security payload
6560 pub const ESP = 50;
6561 /// authentication header
6562 pub const AH = 51;
6563 /// IP Mobility RFC 2004
6564 pub const MOBILE = 55;
6565 /// IPv6 ICMP
6566 pub const IPV6_ICMP = 58;
6567 /// ICMP6
6568 pub const ICMPV6 = 58;
6569 /// IP6 no next header
6570 pub const NONE = 59;
6571 /// IP6 destination option
6572 pub const DSTOPTS = 60;
6573 /// ISO cnlp
6574 pub const EON = 80;
6575 /// Ethernet-in-IP
6576 pub const ETHERIP = 97;
6577 /// encapsulation header
6578 pub const ENCAP = 98;
6579 /// Protocol indep. multicast
6580 pub const PIM = 103;
6581 /// IP Payload Comp. Protocol
6582 pub const IPCOMP = 108;
6583 /// VRRP RFC 2338
6584 pub const VRRP = 112;
6585 /// Common Address Resolution Protocol
6586 pub const CARP = 112;
6587 /// PFSYNC
6588 pub const PFSYNC = 240;
6589 /// raw IP packet
6590 pub const RAW = 255;
6591 },
6592 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L44-L54
6593 .serenity => struct {
6594 pub const IP = 0;
6595 pub const ICMP = 1;
6596 pub const IGMP = 2;
6597 pub const IPIP = 4;
6598 pub const TCP = 6;
6599 pub const UDP = 17;
6600 pub const IPV6 = 41;
6601 pub const ESP = 50;
6602 pub const AH = 51;
6603 pub const ICMPV6 = 58;
6604 pub const RAW = 255;
6605 },
6606 else => void,
6607};
6608pub const IP = switch (native_os) {
6609 .linux => linux.IP,
6610 .freebsd => freebsd.IP,
6611 .dragonfly => dragonfly.IP,
6612 .netbsd => netbsd.IP,
6613 .openbsd => openbsd.IP,
6614 .illumos => illumos.IP,
6615 .haiku => haiku.IP,
6616 .serenity => serenity.IP,
6617 else => void,
6618};
6619pub const IPV6 = switch (native_os) {
6620 .linux => linux.IPV6,
6621 .freebsd => freebsd.IPV6,
6622 .dragonfly => dragonfly.IPV6,
6623 .netbsd => netbsd.IPV6,
6624 .openbsd => openbsd.IPV6,
6625 .illumos => illumos.IPV6,
6626 .haiku => haiku.IPV6,
6627 .serenity => serenity.IPV6,
6628 else => void,
6629};
6630pub const IPTOS = switch (native_os) {
6631 .linux => linux.IPTOS,
6632 .freebsd => freebsd.IPTOS,
6633 .dragonfly => dragonfly.IPTOS,
6634 .netbsd => netbsd.IPTOS,
6635 .openbsd => openbsd.IPTOS,
6636 .illumos => illumos.IPTOS,
6637 .haiku => haiku.IPTOS,
6638 .serenity => serenity.IPTOS,
6639 else => void,
6640};
6641pub const SOL = switch (native_os) {
6642 .linux => linux.SOL,
6643 .emscripten => emscripten.SOL,
6644 .windows => ws2_32.SOL,
6645 .openbsd, .haiku, .dragonfly, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
6646 pub const SOCKET = 0xffff;
6647 },
6648 .illumos => struct {
6649 pub const SOCKET = 0xffff;
6650 pub const ROUTE = 0xfffe;
6651 pub const PACKET = 0xfffd;
6652 pub const FILTER = 0xfffc;
6653 },
6654 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L127
6655 .serenity => struct {
6656 pub const SOCKET = 1;
6657 },
6658 else => void,
6659};
6660pub const SO = switch (native_os) {
6661 .linux => linux.SO,
6662 .emscripten => emscripten.SO,
6663 .windows => ws2_32.SO,
6664 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
6665 pub const DEBUG = 0x0001;
6666 pub const ACCEPTCONN = 0x0002;
6667 pub const REUSEADDR = 0x0004;
6668 pub const KEEPALIVE = 0x0008;
6669 pub const DONTROUTE = 0x0010;
6670 pub const BROADCAST = 0x0020;
6671 pub const USELOOPBACK = 0x0040;
6672 pub const LINGER = 0x0080;
6673 pub const OOBINLINE = 0x0100;
6674 pub const REUSEPORT = 0x0200;
6675 pub const ACCEPTFILTER = 0x1000;
6676 pub const SNDBUF = 0x1001;
6677 pub const RCVBUF = 0x1002;
6678 pub const SNDLOWAT = 0x1003;
6679 pub const RCVLOWAT = 0x1004;
6680 pub const SNDTIMEO = 0x1005;
6681 pub const RCVTIMEO = 0x1006;
6682 pub const ERROR = 0x1007;
6683 pub const TYPE = 0x1008;
6684
6685 pub const NREAD = 0x1020;
6686 pub const NKE = 0x1021;
6687 pub const NOSIGPIPE = 0x1022;
6688 pub const NOADDRERR = 0x1023;
6689 pub const NWRITE = 0x1024;
6690 pub const REUSESHAREUID = 0x1025;
6691 pub const LINGER_SEC = 0x1080;
6692 },
6693 .freebsd => struct {
6694 pub const DEBUG = 0x00000001;
6695 pub const ACCEPTCONN = 0x00000002;
6696 pub const REUSEADDR = 0x00000004;
6697 pub const KEEPALIVE = 0x00000008;
6698 pub const DONTROUTE = 0x00000010;
6699 pub const BROADCAST = 0x00000020;
6700 pub const USELOOPBACK = 0x00000040;
6701 pub const LINGER = 0x00000080;
6702 pub const OOBINLINE = 0x00000100;
6703 pub const REUSEPORT = 0x00000200;
6704 pub const TIMESTAMP = 0x00000400;
6705 pub const NOSIGPIPE = 0x00000800;
6706 pub const ACCEPTFILTER = 0x00001000;
6707 pub const BINTIME = 0x00002000;
6708 pub const NO_OFFLOAD = 0x00004000;
6709 pub const NO_DDP = 0x00008000;
6710 pub const REUSEPORT_LB = 0x00010000;
6711
6712 pub const SNDBUF = 0x1001;
6713 pub const RCVBUF = 0x1002;
6714 pub const SNDLOWAT = 0x1003;
6715 pub const RCVLOWAT = 0x1004;
6716 pub const SNDTIMEO = 0x1005;
6717 pub const RCVTIMEO = 0x1006;
6718 pub const ERROR = 0x1007;
6719 pub const TYPE = 0x1008;
6720 pub const LABEL = 0x1009;
6721 pub const PEERLABEL = 0x1010;
6722 pub const LISTENQLIMIT = 0x1011;
6723 pub const LISTENQLEN = 0x1012;
6724 pub const LISTENINCQLEN = 0x1013;
6725 pub const SETFIB = 0x1014;
6726 pub const USER_COOKIE = 0x1015;
6727 pub const PROTOCOL = 0x1016;
6728 pub const PROTOTYPE = PROTOCOL;
6729 pub const TS_CLOCK = 0x1017;
6730 pub const MAX_PACING_RATE = 0x1018;
6731 pub const DOMAIN = 0x1019;
6732 },
6733 .illumos => struct {
6734 pub const DEBUG = 0x0001;
6735 pub const ACCEPTCONN = 0x0002;
6736 pub const REUSEADDR = 0x0004;
6737 pub const KEEPALIVE = 0x0008;
6738 pub const DONTROUTE = 0x0010;
6739 pub const BROADCAST = 0x0020;
6740 pub const USELOOPBACK = 0x0040;
6741 pub const LINGER = 0x0080;
6742 pub const OOBINLINE = 0x0100;
6743 pub const DGRAM_ERRIND = 0x0200;
6744 pub const RECVUCRED = 0x0400;
6745
6746 pub const SNDBUF = 0x1001;
6747 pub const RCVBUF = 0x1002;
6748 pub const SNDLOWAT = 0x1003;
6749 pub const RCVLOWAT = 0x1004;
6750 pub const SNDTIMEO = 0x1005;
6751 pub const RCVTIMEO = 0x1006;
6752 pub const ERROR = 0x1007;
6753 pub const TYPE = 0x1008;
6754 pub const PROTOTYPE = 0x1009;
6755 pub const ANON_MLP = 0x100a;
6756 pub const MAC_EXEMPT = 0x100b;
6757 pub const DOMAIN = 0x100c;
6758 pub const RCVPSH = 0x100d;
6759
6760 pub const SECATTR = 0x1011;
6761 pub const TIMESTAMP = 0x1013;
6762 pub const ALLZONES = 0x1014;
6763 pub const EXCLBIND = 0x1015;
6764 pub const MAC_IMPLICIT = 0x1016;
6765 pub const VRRP = 0x1017;
6766 },
6767 .netbsd => struct {
6768 pub const DEBUG = 0x0001;
6769 pub const ACCEPTCONN = 0x0002;
6770 pub const REUSEADDR = 0x0004;
6771 pub const KEEPALIVE = 0x0008;
6772 pub const DONTROUTE = 0x0010;
6773 pub const BROADCAST = 0x0020;
6774 pub const USELOOPBACK = 0x0040;
6775 pub const LINGER = 0x0080;
6776 pub const OOBINLINE = 0x0100;
6777 pub const REUSEPORT = 0x0200;
6778 pub const NOSIGPIPE = 0x0800;
6779 pub const ACCEPTFILTER = 0x1000;
6780 pub const TIMESTAMP = 0x2000;
6781 pub const RERROR = 0x4000;
6782
6783 pub const SNDBUF = 0x1001;
6784 pub const RCVBUF = 0x1002;
6785 pub const SNDLOWAT = 0x1003;
6786 pub const RCVLOWAT = 0x1004;
6787 pub const ERROR = 0x1007;
6788 pub const TYPE = 0x1008;
6789 pub const OVERFLOWED = 0x1009;
6790
6791 pub const NOHEADER = 0x100a;
6792 pub const SNDTIMEO = 0x100b;
6793 pub const RCVTIMEO = 0x100c;
6794 },
6795 .dragonfly => struct {
6796 pub const DEBUG = 0x0001;
6797 pub const ACCEPTCONN = 0x0002;
6798 pub const REUSEADDR = 0x0004;
6799 pub const KEEPALIVE = 0x0008;
6800 pub const DONTROUTE = 0x0010;
6801 pub const BROADCAST = 0x0020;
6802 pub const USELOOPBACK = 0x0040;
6803 pub const LINGER = 0x0080;
6804 pub const OOBINLINE = 0x0100;
6805 pub const REUSEPORT = 0x0200;
6806 pub const TIMESTAMP = 0x0400;
6807 pub const NOSIGPIPE = 0x0800;
6808 pub const ACCEPTFILTER = 0x1000;
6809 pub const RERROR = 0x2000;
6810 pub const PASSCRED = 0x4000;
6811
6812 pub const SNDBUF = 0x1001;
6813 pub const RCVBUF = 0x1002;
6814 pub const SNDLOWAT = 0x1003;
6815 pub const RCVLOWAT = 0x1004;
6816 pub const SNDTIMEO = 0x1005;
6817 pub const RCVTIMEO = 0x1006;
6818 pub const ERROR = 0x1007;
6819 pub const TYPE = 0x1008;
6820 pub const SNDSPACE = 0x100a;
6821 pub const CPUHINT = 0x1030;
6822 },
6823 .haiku => struct {
6824 pub const ACCEPTCONN = 0x00000001;
6825 pub const BROADCAST = 0x00000002;
6826 pub const DEBUG = 0x00000004;
6827 pub const DONTROUTE = 0x00000008;
6828 pub const KEEPALIVE = 0x00000010;
6829 pub const OOBINLINE = 0x00000020;
6830 pub const REUSEADDR = 0x00000040;
6831 pub const REUSEPORT = 0x00000080;
6832 pub const USELOOPBACK = 0x00000100;
6833 pub const LINGER = 0x00000200;
6834
6835 pub const SNDBUF = 0x40000001;
6836 pub const SNDLOWAT = 0x40000002;
6837 pub const SNDTIMEO = 0x40000003;
6838 pub const RCVBUF = 0x40000004;
6839 pub const RCVLOWAT = 0x40000005;
6840 pub const RCVTIMEO = 0x40000006;
6841 pub const ERROR = 0x40000007;
6842 pub const TYPE = 0x40000008;
6843 pub const NONBLOCK = 0x40000009;
6844 pub const BINDTODEVICE = 0x4000000a;
6845 pub const PEERCRED = 0x4000000b;
6846 },
6847 .openbsd => struct {
6848 pub const DEBUG = 0x0001;
6849 pub const ACCEPTCONN = 0x0002;
6850 pub const REUSEADDR = 0x0004;
6851 pub const KEEPALIVE = 0x0008;
6852 pub const DONTROUTE = 0x0010;
6853 pub const BROADCAST = 0x0020;
6854 pub const USELOOPBACK = 0x0040;
6855 pub const LINGER = 0x0080;
6856 pub const OOBINLINE = 0x0100;
6857 pub const REUSEPORT = 0x0200;
6858 pub const TIMESTAMP = 0x0800;
6859 pub const BINDANY = 0x1000;
6860 pub const ZEROIZE = 0x2000;
6861 pub const SNDBUF = 0x1001;
6862 pub const RCVBUF = 0x1002;
6863 pub const SNDLOWAT = 0x1003;
6864 pub const RCVLOWAT = 0x1004;
6865 pub const SNDTIMEO = 0x1005;
6866 pub const RCVTIMEO = 0x1006;
6867 pub const ERROR = 0x1007;
6868 pub const TYPE = 0x1008;
6869 pub const NETPROC = 0x1020;
6870 pub const RTABLE = 0x1021;
6871 pub const PEERCRED = 0x1022;
6872 pub const SPLICE = 0x1023;
6873 pub const DOMAIN = 0x1024;
6874 pub const PROTOCOL = 0x1025;
6875 },
6876 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L130-L150
6877 .serenity => struct {
6878 pub const RCVTIMEO = 0;
6879 pub const SNDTIMEO = 1;
6880 pub const TYPE = 2;
6881 pub const ERROR = 3;
6882 pub const PEERCRED = 4;
6883 pub const RCVBUF = 5;
6884 pub const SNDBUF = 6;
6885 pub const DEBUG = 7;
6886 pub const REUSEADDR = 8;
6887 pub const BINDTODEVICE = 9;
6888 pub const KEEPALIVE = 10;
6889 pub const TIMESTAMP = 11;
6890 pub const BROADCAST = 12;
6891 pub const LINGER = 13;
6892 pub const ACCEPTCONN = 14;
6893 pub const DONTROUTE = 15;
6894 pub const OOBINLINE = 16;
6895 pub const SNDLOWAT = 17;
6896 pub const RCVLOWAT = 18;
6897 },
6898 else => void,
6899};
6900pub const SOMAXCONN = switch (native_os) {
6901 .linux => linux.SOMAXCONN,
6902 .windows => ws2_32.SOMAXCONN,
6903 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L128
6904 .illumos, .serenity => 128,
6905 // https://github.com/freebsd/freebsd-src/blob/9ab31f821ad1c6bad474510447387c50bef2c24c/sys/sys/socket.h#L434
6906 // https://github.com/DragonFlyBSD/DragonFlyBSD/blob/fd3d1949d526ffa646e57037770acd6f2f3bb617/sys/sys/socket.h#L393
6907 // https://github.com/NetBSD/src/blob/a673fb3f8487e974c669216064f7588207229fea/sys/sys/socket.h#L472
6908 // https://github.com/openbsd/src/blob/8ba9cd88f10123fef7af805b8e5ccc2463ad8fa4/sys/sys/socket.h#L483
6909 // https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/socket.h#L815
6910 .freebsd, .dragonfly, .netbsd, .openbsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => 128,
6911 else => void,
6912};
6913pub const SCM = switch (native_os) {
6914 .linux, .emscripten => linux.SCM,
6915 // https://github.com/illumos/illumos-gate/blob/489f6310fe8952e87fc1dce8af87990fcfd90f18/usr/src/uts/common/sys/socket.h#L196
6916 .illumos => struct {
6917 pub const RIGHTS = 0x1010;
6918 pub const UCRED = 0x1012;
6919 pub const TIMESTAMP = SO.TIMESTAMP;
6920 },
6921 // https://github.com/haiku/haiku/blob/e3d01e53a25446d5ba4999d0ff6dff29a2418657/headers/posix/sys/socket.h#L156
6922 .haiku => struct {
6923 pub const RIGHTS = 1;
6924 },
6925 // https://github.com/SerenityOS/serenity/blob/c6618f36bf0949bd76177f202659b1f3079e0792/Kernel/API/POSIX/sys/socket.h#L171
6926 .serenity => struct {
6927 pub const TIMESTAMP = 0;
6928 pub const RIGHTS = 1;
6929 },
6930 // https://github.com/freebsd/freebsd-src/blob/614e9b33bf5594d9d09b5d296afa4f3aa6971823/sys/sys/socket.h#L593
6931 .freebsd => struct {
6932 pub const RIGHTS = 1;
6933 pub const TIMESTAMP = 2;
6934 pub const CREDS = 3;
6935 pub const BINTIME = 4;
6936 pub const REALTIME = 5;
6937 pub const MONOTONIC = 6;
6938 pub const TIME_INFO = 7;
6939 pub const CREDS2 = 8;
6940 },
6941 // https://github.com/DragonFlyBSD/DragonFlyBSD/blob/6098912863ed4c7b3f70d7483910ce2956cf4ed3/sys/sys/socket.h#L520
6942 .dragonfly => struct {
6943 pub const RIGHTS = 1;
6944 pub const TIMESTAMP = 2;
6945 pub const CREDS = 3;
6946 },
6947 // https://github.com/NetBSD/src/blob/3311177ea898ab8322292ba0e48faa9b2e834cb6/sys/sys/socket.h#L578
6948 .netbsd => struct {
6949 pub const RIGHTS = 0x01;
6950 pub const TIMESTAMP = 0x08;
6951 pub const CREDS = 0x10;
6952 },
6953 // https://github.com/openbsd/src/blob/1b1dd04c9634112eb763374379af99a68ace4328/sys/sys/socket.h#L566
6954 .openbsd => struct {
6955 pub const RIGHTS = 0x01;
6956 pub const TIMESTAMP = 0x04;
6957 },
6958 // https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/socket.h#L1114
6959 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
6960 pub const RIGHTS = 1;
6961 pub const TIMESTAMP = 2;
6962 pub const CREDS = 3;
6963 pub const TIMESTAMP_MONOTONIC = 4;
6964 },
6965 else => void,
6966};
6967
6968pub const IFNAMESIZE = switch (native_os) {
6969 .linux => linux.IFNAMESIZE,
6970 .emscripten => emscripten.IFNAMESIZE,
6971 .windows => 30,
6972 // https://github.com/SerenityOS/serenity/blob/9882848e0bf783dfc8e8a6d887a848d70d9c58f4/Kernel/API/POSIX/net/if.h#L50
6973 .openbsd, .dragonfly, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .serenity => 16,
6974 .illumos => 32,
6975 else => {},
6976};
6977
6978pub const stack_t = switch (native_os) {
6979 .linux => linux.stack_t,
6980 .emscripten => emscripten.stack_t,
6981 .freebsd, .openbsd => extern struct {
6982 /// Signal stack base.
6983 sp: *anyopaque,
6984 /// Signal stack length.
6985 size: usize,
6986 /// SS_DISABLE and/or SS_ONSTACK.
6987 flags: i32,
6988 },
6989 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L48-L52
6990 .serenity => extern struct {
6991 sp: *anyopaque,
6992 flags: c_int,
6993 size: usize,
6994 },
6995 else => extern struct {
6996 sp: [*]u8,
6997 size: isize,
6998 flags: i32,
6999 },
7000};
7001pub const time_t = switch (native_os) {
7002 .linux => linux.time_t,
7003 .dragonfly, .illumos, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => c_long,
7004 .emscripten => emscripten.time_t,
7005 .freebsd, .haiku => if (native_arch == .x86) c_int else c_longlong,
7006 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L47
7007 // lib/libc/include/wasm-wasi-musl/__typedef_time_t.h
7008 .netbsd, .openbsd, .serenity, .wasi => c_longlong,
7009 else => void,
7010};
7011pub const suseconds_t = switch (native_os) {
7012 .dragonfly, .freebsd, .openbsd, .illumos => c_long,
7013 .netbsd, .haiku, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => c_int,
7014 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L49
7015 .serenity, .wasi => c_longlong,
7016 else => void,
7017};
7018
7019pub const timeval = switch (native_os) {
7020 .linux => linux.timeval,
7021 .emscripten => emscripten.timeval,
7022 .windows => extern struct {
7023 sec: c_long,
7024 usec: c_long,
7025 },
7026 // https://github.com/SerenityOS/serenity/blob/6b6eca0631c893c5f8cfb8274cdfe18e2d0637c0/Kernel/API/POSIX/sys/time.h#L15-L18
7027 .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .wasi => extern struct {
7028 /// seconds
7029 sec: time_t,
7030 /// microseconds
7031 usec: suseconds_t,
7032 },
7033 else => void,
7034};
7035pub const timezone = switch (native_os) {
7036 .linux => linux.timezone,
7037 .emscripten => emscripten.timezone,
7038 // https://github.com/SerenityOS/serenity/blob/ba776390b5878ec0be1a9e595a3471a6cfe0a0cf/Userland/Libraries/LibC/sys/time.h#L19-L22
7039 .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows, .wasi => extern struct {
7040 minuteswest: c_int,
7041 dsttime: c_int,
7042 },
7043 else => void,
7044};
7045
7046pub const user_desc = switch (native_os) {
7047 .linux => linux.user_desc,
7048 else => void,
7049};
7050pub const utsname = switch (native_os) {
7051 .linux => linux.utsname,
7052 .emscripten => emscripten.utsname,
7053 .wasi => extern struct {
7054 sysname: [64:0]u8,
7055 nodename: [64:0]u8,
7056 release: [64:0]u8,
7057 version: [64:0]u8,
7058 machine: [64:0]u8,
7059 domainname: [64:0]u8,
7060 },
7061 .illumos => extern struct {
7062 sysname: [256:0]u8,
7063 nodename: [256:0]u8,
7064 release: [256:0]u8,
7065 version: [256:0]u8,
7066 machine: [256:0]u8,
7067 domainname: [256:0]u8,
7068 },
7069 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
7070 sysname: [255:0]u8,
7071 nodename: [255:0]u8,
7072 release: [255:0]u8,
7073 version: [255:0]u8,
7074 machine: [255:0]u8,
7075 },
7076 // https://github.com/SerenityOS/serenity/blob/d794ed1de7a46482272683f8dc4c858806390f29/Kernel/API/POSIX/sys/utsname.h#L17-L23
7077 .serenity => extern struct {
7078 sysname: [UTSNAME_ENTRY_LEN:0]u8,
7079 nodename: [UTSNAME_ENTRY_LEN:0]u8,
7080 release: [UTSNAME_ENTRY_LEN:0]u8,
7081 version: [UTSNAME_ENTRY_LEN:0]u8,
7082 machine: [UTSNAME_ENTRY_LEN:0]u8,
7083
7084 const UTSNAME_ENTRY_LEN = 64;
7085 },
7086 else => void,
7087};
7088pub const PR = switch (native_os) {
7089 .linux => linux.PR,
7090 else => void,
7091};
7092pub const _errno = switch (native_os) {
7093 .linux => switch (native_abi) {
7094 .android, .androideabi => private.__errno,
7095 else => private.__errno_location,
7096 },
7097 .emscripten => private.__errno_location,
7098 .wasi, .dragonfly => private.errnoFromThreadLocal,
7099 .windows => private._errno,
7100 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .freebsd => private.__error,
7101 .illumos => private.___errno,
7102 .openbsd, .netbsd => private.__errno,
7103 .haiku => haiku._errnop,
7104 // https://github.com/SerenityOS/serenity/blob/a353ceecf13b6f156a078e32f1ddf1d21366934c/Userland/Libraries/LibC/errno.h#L33
7105 .serenity => private.__errno_location,
7106 else => {},
7107};
7108
7109pub const RTLD = switch (native_os) {
7110 .linux, .emscripten => packed struct(u32) {
7111 LAZY: bool = false,
7112 NOW: bool = false,
7113 NOLOAD: bool = false,
7114 DEEPBIND: bool = false,
7115 _4: u4 = 0,
7116 GLOBAL: bool = false,
7117 _9: u3 = 0,
7118 NODELETE: bool = false,
7119 _: u19 = 0,
7120 },
7121 .dragonfly, .freebsd => packed struct(u32) {
7122 LAZY: bool = false,
7123 NOW: bool = false,
7124 _2: u6 = 0,
7125 GLOBAL: bool = false,
7126 TRACE: bool = false,
7127 _10: u2 = 0,
7128 NODELETE: bool = false,
7129 NOLOAD: bool = false,
7130 _: u18 = 0,
7131 },
7132 .haiku => packed struct(u32) {
7133 NOW: bool = false,
7134 GLOBAL: bool = false,
7135 _: u30 = 0,
7136 },
7137 .netbsd => packed struct(u32) {
7138 LAZY: bool = false,
7139 NOW: bool = false,
7140 _2: u6 = 0,
7141 GLOBAL: bool = false,
7142 LOCAL: bool = false,
7143 _10: u2 = 0,
7144 NODELETE: bool = false,
7145 NOLOAD: bool = false,
7146 _: u18 = 0,
7147 },
7148 .illumos => packed struct(u32) {
7149 LAZY: bool = false,
7150 NOW: bool = false,
7151 NOLOAD: bool = false,
7152 _3: u5 = 0,
7153 GLOBAL: bool = false,
7154 PARENT: bool = false,
7155 GROUP: bool = false,
7156 WORLD: bool = false,
7157 NODELETE: bool = false,
7158 FIRST: bool = false,
7159 _14: u2 = 0,
7160 CONFGEN: bool = false,
7161 _: u15 = 0,
7162 },
7163 .openbsd => packed struct(u32) {
7164 LAZY: bool = false,
7165 NOW: bool = false,
7166 _2: u6 = 0,
7167 GLOBAL: bool = false,
7168 TRACE: bool = false,
7169 _: u22 = 0,
7170 },
7171 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => packed struct(u32) {
7172 LAZY: bool = false,
7173 NOW: bool = false,
7174 LOCAL: bool = false,
7175 GLOBAL: bool = false,
7176 NOLOAD: bool = false,
7177 _5: u2 = 0,
7178 NODELETE: bool = false,
7179 FIRST: bool = false,
7180 _: u23 = 0,
7181 },
7182 // https://github.com/SerenityOS/serenity/blob/36a26d7fa80bc9c72b19442912d8967f448368ff/Userland/Libraries/LibC/dlfcn.h#L13-L17
7183 .serenity => packed struct(c_int) {
7184 DEFAULT: bool = false,
7185 _1: u1,
7186 LAZY: bool = false,
7187 NOW: bool = false,
7188 GLOBAL: bool = false,
7189 LOCAL: bool = false,
7190 _: @Int(.unsigned, @bitSizeOf(c_int) - 6) = 0,
7191 },
7192 else => void,
7193};
7194
7195pub const dirent = switch (native_os) {
7196 .linux, .emscripten => extern struct {
7197 ino: ino_t,
7198 off: off_t,
7199 reclen: c_ushort,
7200 type: u8,
7201 name: [256]u8,
7202 },
7203 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
7204 ino: u64,
7205 seekoff: u64,
7206 reclen: u16,
7207 namlen: u16,
7208 type: u8,
7209 name: [1024]u8,
7210 },
7211 .freebsd => extern struct {
7212 /// File number of entry.
7213 fileno: ino_t,
7214 /// Directory offset of entry.
7215 off: off_t,
7216 /// Length of this record.
7217 reclen: u16,
7218 /// File type, one of DT_.
7219 type: u8,
7220 pad0: u8 = 0,
7221 /// Length of the name member.
7222 namlen: u16,
7223 pad1: u16 = 0,
7224 /// Name of entry.
7225 name: [255:0]u8,
7226 },
7227 .illumos => extern struct {
7228 /// Inode number of entry.
7229 ino: ino_t,
7230 /// Offset of this entry on disk.
7231 off: off_t,
7232 /// Length of this record.
7233 reclen: u16,
7234 /// File name.
7235 name: [MAXNAMLEN:0]u8,
7236 },
7237 .netbsd => extern struct {
7238 fileno: ino_t,
7239 reclen: u16,
7240 namlen: u16,
7241 type: u8,
7242 name: [MAXNAMLEN:0]u8,
7243 },
7244 .dragonfly => extern struct {
7245 fileno: c_ulong,
7246 namlen: u16,
7247 type: u8,
7248 unused1: u8,
7249 unused2: u32,
7250 name: [256]u8,
7251
7252 pub fn reclen(self: dirent) u16 {
7253 return (@offsetOf(dirent, "name") + self.namlen + 1 + 7) & ~@as(u16, 7);
7254 }
7255 },
7256 .openbsd => extern struct {
7257 fileno: ino_t,
7258 off: off_t,
7259 reclen: u16,
7260 type: u8,
7261 namlen: u8,
7262 _: u32 align(1) = 0,
7263 name: [MAXNAMLEN:0]u8,
7264 },
7265 // https://github.com/SerenityOS/serenity/blob/abc150085f532f123b598949218893cb272ccc4c/Userland/Libraries/LibC/dirent.h#L14-L20
7266 .serenity => extern struct {
7267 ino: ino_t,
7268 off: off_t,
7269 reclen: c_ushort,
7270 type: u8,
7271 name: [255:0]u8,
7272 },
7273 else => void,
7274};
7275pub const MAXNAMLEN = switch (native_os) {
7276 .netbsd, .illumos => 511,
7277 // https://github.com/SerenityOS/serenity/blob/1262a7d1424d0d2e89d80644409721cbf056ab17/Kernel/API/POSIX/dirent.h#L37
7278 .haiku, .serenity => NAME_MAX,
7279 .openbsd => 255,
7280 else => {},
7281};
7282pub const dirent64 = switch (native_os) {
7283 .linux => extern struct {
7284 ino: c_ulong,
7285 off: c_ulong,
7286 reclen: c_ushort,
7287 type: u8,
7288 name: [256]u8,
7289 },
7290 else => void,
7291};
7292
7293pub const AI = if (builtin.abi.isAndroid()) packed struct(u32) {
7294 PASSIVE: bool = false,
7295 CANONNAME: bool = false,
7296 NUMERICHOST: bool = false,
7297 NUMERICSERV: bool = false,
7298 _4: u4 = 0,
7299 ALL: bool = false,
7300 V4MAPPED_CFG: bool = false,
7301 ADDRCONFIG: bool = false,
7302 V4MAPPED: bool = false,
7303 _: u20 = 0,
7304} else switch (native_os) {
7305 .linux, .emscripten => linux.AI,
7306 .dragonfly, .haiku, .freebsd => packed struct(u32) {
7307 PASSIVE: bool = false,
7308 CANONNAME: bool = false,
7309 NUMERICHOST: bool = false,
7310 NUMERICSERV: bool = false,
7311 _4: u4 = 0,
7312 ALL: bool = false,
7313 V4MAPPED_CFG: bool = false,
7314 ADDRCONFIG: bool = false,
7315 V4MAPPED: bool = false,
7316 _: u20 = 0,
7317 },
7318 .netbsd => packed struct(u32) {
7319 PASSIVE: bool = false,
7320 CANONNAME: bool = false,
7321 NUMERICHOST: bool = false,
7322 NUMERICSERV: bool = false,
7323 _4: u6 = 0,
7324 ADDRCONFIG: bool = false,
7325 SRV: bool = false,
7326 _: u20 = 0,
7327 },
7328 .illumos => packed struct(u32) {
7329 V4MAPPED: bool = false,
7330 ALL: bool = false,
7331 ADDRCONFIG: bool = false,
7332 PASSIVE: bool = false,
7333 CANONNAME: bool = false,
7334 NUMERICHOST: bool = false,
7335 NUMERICSERV: bool = false,
7336 _: u25 = 0,
7337 },
7338 .openbsd => packed struct(u32) {
7339 PASSIVE: bool = false,
7340 CANONNAME: bool = false,
7341 NUMERICHOST: bool = false,
7342 EXT: bool = false,
7343 NUMERICSERV: bool = false,
7344 FQDN: bool = false,
7345 ADDRCONFIG: bool = false,
7346 _: u25 = 0,
7347 },
7348 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => packed struct(u32) {
7349 PASSIVE: bool = false,
7350 CANONNAME: bool = false,
7351 NUMERICHOST: bool = false,
7352 _3: u5 = 0,
7353 ALL: bool = false,
7354 V4MAPPED_CFG: bool = false,
7355 ADDRCONFIG: bool = false,
7356 V4MAPPED: bool = false,
7357 NUMERICSERV: bool = false,
7358 _: u19 = 0,
7359 },
7360 .windows => ws2_32.AI,
7361 // https://github.com/SerenityOS/serenity/blob/d510d2aeb2facbd8f6c383d70fd1b033e1fee5dd/Userland/Libraries/LibC/netdb.h#L90-L96
7362 .serenity => packed struct(c_int) {
7363 PASSIVE: bool = false,
7364 CANONNAME: bool = false,
7365 NUMERICHOST: bool = false,
7366 NUMERICSERV: bool = false,
7367 V4MAPPED: bool = false,
7368 ALL: bool = false,
7369 ADDRCONFIG: bool = false,
7370 _: @Int(.unsigned, @bitSizeOf(c_int) - 7) = 0,
7371 },
7372 else => void,
7373};
7374
7375pub const NI = switch (native_os) {
7376 .linux, .emscripten => packed struct(u32) {
7377 NUMERICHOST: bool = false,
7378 NUMERICSERV: bool = false,
7379 NOFQDN: bool = false,
7380 NAMEREQD: bool = false,
7381 DGRAM: bool = false,
7382 _5: u3 = 0,
7383 NUMERICSCOPE: bool = false,
7384 _: u23 = 0,
7385 },
7386 .illumos => packed struct(u32) {
7387 NOFQDN: bool = false,
7388 NUMERICHOST: bool = false,
7389 NAMEREQD: bool = false,
7390 NUMERICSERV: bool = false,
7391 DGRAM: bool = false,
7392 WITHSCOPEID: bool = false,
7393 NUMERICSCOPE: bool = false,
7394 _: u25 = 0,
7395 },
7396 // https://github.com/SerenityOS/serenity/blob/d510d2aeb2facbd8f6c383d70fd1b033e1fee5dd/Userland/Libraries/LibC/netdb.h#L101-L105
7397 .serenity => packed struct(c_int) {
7398 NUMERICHOST: bool = false,
7399 NUMERICSERV: bool = false,
7400 NAMEREQD: bool = false,
7401 NOFQDN: bool = false,
7402 DGRAM: bool = false,
7403 _: @Int(.unsigned, @bitSizeOf(c_int) - 5) = 0,
7404 },
7405 .freebsd, .haiku => packed struct(u32) {
7406 NOFQDN: bool = false,
7407 NUMERICHOST: bool = false,
7408 NAMEREQD: bool = false,
7409 NUMERICSERV: bool = false,
7410 DGRAM: bool = false,
7411 NUMERICSCOPE: bool = false,
7412 _: u26 = 0,
7413 },
7414 .dragonfly, .netbsd => packed struct(u32) {
7415 NOFQDN: bool = false,
7416 NUMERICHOST: bool = false,
7417 NAMEREQD: bool = false,
7418 NUMERICSERV: bool = false,
7419 DGRAM: bool = false,
7420 _5: u1 = 0,
7421 NUMERICSCOPE: bool = false,
7422 _: u25 = 0,
7423 },
7424 .openbsd => packed struct(u32) {
7425 NUMERICHOST: bool = false,
7426 NUMERICSERV: bool = false,
7427 NOFQDN: bool = false,
7428 NAMEREQD: bool = false,
7429 DGRAM: bool = false,
7430 _: u27 = 0,
7431 },
7432 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => packed struct(u32) {
7433 NOFQDN: bool = false,
7434 NUMERICHOST: bool = false,
7435 NAMEREQD: bool = false,
7436 NUMERICSERV: bool = false,
7437 DGRAM: bool = false,
7438 _5: u3 = 0,
7439 NUMERICSCOPE: bool = false,
7440 _: u23 = 0,
7441 },
7442 else => void,
7443};
7444
7445pub const EAI = if (builtin.abi.isAndroid()) enum(c_int) {
7446 /// address family for hostname not supported
7447 ADDRFAMILY = 1,
7448 /// temporary failure in name resolution
7449 AGAIN = 2,
7450 /// invalid value for ai_flags
7451 BADFLAGS = 3,
7452 /// non-recoverable failure in name resolution
7453 FAIL = 4,
7454 /// ai_family not supported
7455 FAMILY = 5,
7456 /// memory allocation failure
7457 MEMORY = 6,
7458 /// no address associated with hostname
7459 NODATA = 7,
7460 /// hostname nor servname provided, or not known
7461 NONAME = 8,
7462 /// servname not supported for ai_socktype
7463 SERVICE = 9,
7464 /// ai_socktype not supported
7465 SOCKTYPE = 10,
7466 /// system error returned in errno
7467 SYSTEM = 11,
7468 /// invalid value for hints
7469 BADHINTS = 12,
7470 /// resolved protocol is unknown
7471 PROTOCOL = 13,
7472 /// argument buffer overflow
7473 OVERFLOW = 14,
7474
7475 MAX = 15,
7476
7477 _,
7478} else switch (native_os) {
7479 .linux, .emscripten => enum(c_int) {
7480 BADFLAGS = -1,
7481 NONAME = -2,
7482 AGAIN = -3,
7483 FAIL = -4,
7484 FAMILY = -6,
7485 SOCKTYPE = -7,
7486 SERVICE = -8,
7487 MEMORY = -10,
7488 SYSTEM = -11,
7489 OVERFLOW = -12,
7490
7491 NODATA = -5,
7492 ADDRFAMILY = -9,
7493 INPROGRESS = -100,
7494 CANCELED = -101,
7495 NOTCANCELED = -102,
7496 ALLDONE = -103,
7497 INTR = -104,
7498 IDN_ENCODE = -105,
7499
7500 _,
7501 },
7502 .haiku, .dragonfly, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => enum(c_int) {
7503 /// address family for hostname not supported
7504 ADDRFAMILY = 1,
7505 /// temporary failure in name resolution
7506 AGAIN = 2,
7507 /// invalid value for ai_flags
7508 BADFLAGS = 3,
7509 /// non-recoverable failure in name resolution
7510 FAIL = 4,
7511 /// ai_family not supported
7512 FAMILY = 5,
7513 /// memory allocation failure
7514 MEMORY = 6,
7515 /// no address associated with hostname
7516 NODATA = 7,
7517 /// hostname nor servname provided, or not known
7518 NONAME = 8,
7519 /// servname not supported for ai_socktype
7520 SERVICE = 9,
7521 /// ai_socktype not supported
7522 SOCKTYPE = 10,
7523 /// system error returned in errno
7524 SYSTEM = 11,
7525 /// invalid value for hints
7526 BADHINTS = 12,
7527 /// resolved protocol is unknown
7528 PROTOCOL = 13,
7529 /// argument buffer overflow
7530 OVERFLOW = 14,
7531 _,
7532 },
7533 .illumos => enum(c_int) {
7534 /// address family for hostname not supported
7535 ADDRFAMILY = 1,
7536 /// name could not be resolved at this time
7537 AGAIN = 2,
7538 /// flags parameter had an invalid value
7539 BADFLAGS = 3,
7540 /// non-recoverable failure in name resolution
7541 FAIL = 4,
7542 /// address family not recognized
7543 FAMILY = 5,
7544 /// memory allocation failure
7545 MEMORY = 6,
7546 /// no address associated with hostname
7547 NODATA = 7,
7548 /// name does not resolve
7549 NONAME = 8,
7550 /// service not recognized for socket type
7551 SERVICE = 9,
7552 /// intended socket type was not recognized
7553 SOCKTYPE = 10,
7554 /// system error returned in errno
7555 SYSTEM = 11,
7556 /// argument buffer overflow
7557 OVERFLOW = 12,
7558 /// resolved protocol is unknown
7559 PROTOCOL = 13,
7560
7561 _,
7562 },
7563 .openbsd => enum(c_int) {
7564 /// address family for hostname not supported
7565 ADDRFAMILY = -9,
7566 /// name could not be resolved at this time
7567 AGAIN = -3,
7568 /// flags parameter had an invalid value
7569 BADFLAGS = -1,
7570 /// non-recoverable failure in name resolution
7571 FAIL = -4,
7572 /// address family not recognized
7573 FAMILY = -6,
7574 /// memory allocation failure
7575 MEMORY = -10,
7576 /// no address associated with hostname
7577 NODATA = -5,
7578 /// name does not resolve
7579 NONAME = -2,
7580 /// service not recognized for socket type
7581 SERVICE = -8,
7582 /// intended socket type was not recognized
7583 SOCKTYPE = -7,
7584 /// system error returned in errno
7585 SYSTEM = -11,
7586 /// invalid value for hints
7587 BADHINTS = -12,
7588 /// resolved protocol is unknown
7589 PROTOCOL = -13,
7590 /// argument buffer overflow
7591 OVERFLOW = -14,
7592 _,
7593 },
7594 // https://github.com/SerenityOS/serenity/blob/d510d2aeb2facbd8f6c383d70fd1b033e1fee5dd/Userland/Libraries/LibC/netdb.h#L77-L88
7595 .serenity => enum(c_int) {
7596 ADDRFAMILY = 1,
7597 AGAIN = 2,
7598 BADFLAGS = 3,
7599 FAIL = 4,
7600 FAMILY = 5,
7601 MEMORY = 6,
7602 NODATA = 7,
7603 NONAME = 8,
7604 SERVICE = 9,
7605 SOCKTYPE = 10,
7606 SYSTEM = 11,
7607 OVERFLOW = 12,
7608 _,
7609 },
7610 else => void,
7611};
7612
7613pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.c) c_int;
7614
7615pub const Stat = switch (native_os) {
7616 .emscripten => emscripten.Stat,
7617 .wasi => extern struct {
7618 // Match wasi-libc's `struct stat` in lib/libc/include/wasm-wasi-musl/__struct_stat.h
7619 dev: dev_t,
7620 ino: ino_t,
7621 nlink: nlink_t,
7622 mode: mode_t,
7623 uid: uid_t,
7624 gid: gid_t,
7625 __pad0: c_uint = 0,
7626 rdev: dev_t,
7627 size: off_t,
7628 blksize: blksize_t,
7629 blocks: blkcnt_t,
7630 atim: timespec,
7631 mtim: timespec,
7632 ctim: timespec,
7633 __reserved: [3]c_longlong = [3]c_longlong{ 0, 0, 0 },
7634
7635 pub fn atime(self: @This()) timespec {
7636 return self.atim;
7637 }
7638
7639 pub fn mtime(self: @This()) timespec {
7640 return self.mtim;
7641 }
7642
7643 pub fn ctime(self: @This()) timespec {
7644 return self.ctim;
7645 }
7646
7647 pub fn fromFilestat(st: wasi.filestat_t) Stat {
7648 return .{
7649 .dev = st.dev,
7650 .ino = st.ino,
7651 .mode = switch (st.filetype) {
7652 .UNKNOWN => 0,
7653 .BLOCK_DEVICE => S.IFBLK,
7654 .CHARACTER_DEVICE => S.IFCHR,
7655 .DIRECTORY => S.IFDIR,
7656 .REGULAR_FILE => S.IFREG,
7657 .SOCKET_DGRAM => S.IFSOCK,
7658 .SOCKET_STREAM => S.IFIFO,
7659 .SYMBOLIC_LINK => S.IFLNK,
7660 _ => 0,
7661 },
7662 .nlink = st.nlink,
7663 .size = @intCast(st.size),
7664 .atim = timespec.fromTimestamp(st.atim),
7665 .mtim = timespec.fromTimestamp(st.mtim),
7666 .ctim = timespec.fromTimestamp(st.ctim),
7667
7668 .uid = 0,
7669 .gid = 0,
7670 .rdev = 0,
7671 .blksize = 0,
7672 .blocks = 0,
7673 };
7674 }
7675 },
7676 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
7677 dev: i32,
7678 mode: u16,
7679 nlink: u16,
7680 ino: ino_t,
7681 uid: uid_t,
7682 gid: gid_t,
7683 rdev: i32,
7684 atimespec: timespec,
7685 mtimespec: timespec,
7686 ctimespec: timespec,
7687 birthtimespec: timespec,
7688 size: off_t,
7689 blocks: i64,
7690 blksize: i32,
7691 flags: u32,
7692 gen: u32,
7693 lspare: i32,
7694 qspare: [2]i64,
7695
7696 pub fn atime(self: @This()) timespec {
7697 return self.atimespec;
7698 }
7699
7700 pub fn mtime(self: @This()) timespec {
7701 return self.mtimespec;
7702 }
7703
7704 pub fn ctime(self: @This()) timespec {
7705 return self.ctimespec;
7706 }
7707
7708 pub fn birthtime(self: @This()) timespec {
7709 return self.birthtimespec;
7710 }
7711 },
7712 .freebsd => freebsd.Stat,
7713 .illumos => extern struct {
7714 dev: dev_t,
7715 ino: ino_t,
7716 mode: mode_t,
7717 nlink: nlink_t,
7718 uid: uid_t,
7719 gid: gid_t,
7720 rdev: dev_t,
7721 size: off_t,
7722 atim: timespec,
7723 mtim: timespec,
7724 ctim: timespec,
7725 blksize: blksize_t,
7726 blocks: blkcnt_t,
7727 fstype: [16]u8,
7728
7729 pub fn atime(self: @This()) timespec {
7730 return self.atim;
7731 }
7732
7733 pub fn mtime(self: @This()) timespec {
7734 return self.mtim;
7735 }
7736
7737 pub fn ctime(self: @This()) timespec {
7738 return self.ctim;
7739 }
7740 },
7741 .netbsd => extern struct {
7742 dev: dev_t,
7743 mode: mode_t,
7744 ino: ino_t,
7745 nlink: nlink_t,
7746 uid: uid_t,
7747 gid: gid_t,
7748 rdev: dev_t,
7749 atim: timespec,
7750 mtim: timespec,
7751 ctim: timespec,
7752 birthtim: timespec,
7753 size: off_t,
7754 blocks: blkcnt_t,
7755 blksize: blksize_t,
7756 flags: u32,
7757 gen: u32,
7758 __spare: [2]u32,
7759
7760 pub fn atime(self: @This()) timespec {
7761 return self.atim;
7762 }
7763
7764 pub fn mtime(self: @This()) timespec {
7765 return self.mtim;
7766 }
7767
7768 pub fn ctime(self: @This()) timespec {
7769 return self.ctim;
7770 }
7771
7772 pub fn birthtime(self: @This()) timespec {
7773 return self.birthtim;
7774 }
7775 },
7776 .dragonfly => extern struct {
7777 ino: ino_t,
7778 nlink: c_uint,
7779 dev: c_uint,
7780 mode: c_ushort,
7781 padding1: u16,
7782 uid: uid_t,
7783 gid: gid_t,
7784 rdev: c_uint,
7785 atim: timespec,
7786 mtim: timespec,
7787 ctim: timespec,
7788 size: c_ulong,
7789 blocks: i64,
7790 blksize: u32,
7791 flags: u32,
7792 gen: u32,
7793 lspare: i32,
7794 qspare1: i64,
7795 qspare2: i64,
7796 pub fn atime(self: @This()) timespec {
7797 return self.atim;
7798 }
7799
7800 pub fn mtime(self: @This()) timespec {
7801 return self.mtim;
7802 }
7803
7804 pub fn ctime(self: @This()) timespec {
7805 return self.ctim;
7806 }
7807 },
7808 .haiku => extern struct {
7809 dev: dev_t,
7810 ino: ino_t,
7811 mode: mode_t,
7812 nlink: nlink_t,
7813 uid: uid_t,
7814 gid: gid_t,
7815 size: off_t,
7816 rdev: dev_t,
7817 blksize: blksize_t,
7818 atim: timespec,
7819 mtim: timespec,
7820 ctim: timespec,
7821 crtim: timespec,
7822 type: u32,
7823 blocks: blkcnt_t,
7824
7825 pub fn atime(self: @This()) timespec {
7826 return self.atim;
7827 }
7828 pub fn mtime(self: @This()) timespec {
7829 return self.mtim;
7830 }
7831 pub fn ctime(self: @This()) timespec {
7832 return self.ctim;
7833 }
7834 pub fn birthtime(self: @This()) timespec {
7835 return self.crtim;
7836 }
7837 },
7838 .openbsd => extern struct {
7839 mode: mode_t,
7840 dev: dev_t,
7841 ino: ino_t,
7842 nlink: nlink_t,
7843 uid: uid_t,
7844 gid: gid_t,
7845 rdev: dev_t,
7846 atim: timespec,
7847 mtim: timespec,
7848 ctim: timespec,
7849 size: off_t,
7850 blocks: blkcnt_t,
7851 blksize: blksize_t,
7852 flags: u32,
7853 gen: u32,
7854 birthtim: timespec,
7855
7856 pub fn atime(self: @This()) timespec {
7857 return self.atim;
7858 }
7859
7860 pub fn mtime(self: @This()) timespec {
7861 return self.mtim;
7862 }
7863
7864 pub fn ctime(self: @This()) timespec {
7865 return self.ctim;
7866 }
7867
7868 pub fn birthtime(self: @This()) timespec {
7869 return self.birthtim;
7870 }
7871 },
7872 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/sys/stat.h#L53-L67
7873 .serenity => extern struct {
7874 dev: dev_t,
7875 ino: ino_t,
7876 mode: mode_t,
7877 nlink: nlink_t,
7878 uid: uid_t,
7879 gid: gid_t,
7880 rdev: dev_t,
7881 size: off_t,
7882 blksize: blksize_t,
7883 blocks: blkcnt_t,
7884 atim: timespec,
7885 mtim: timespec,
7886 ctim: timespec,
7887
7888 pub fn atime(self: @This()) timespec {
7889 return self.atim;
7890 }
7891
7892 pub fn mtime(self: @This()) timespec {
7893 return self.mtim;
7894 }
7895
7896 pub fn ctime(self: @This()) timespec {
7897 return self.ctim;
7898 }
7899 },
7900 else => void,
7901};
7902
7903pub const pthread_spinlock_t = switch (native_os) {
7904 .openbsd => openbsd.pthread_spinlock_t,
7905 .freebsd => extern struct {
7906 inner: ?*anyopaque = null,
7907 },
7908 .netbsd => extern struct {
7909 pts_magic: c_uint,
7910 spin: pthread_spin_t,
7911 pts_flags: c_int,
7912 },
7913 .windows => isize,
7914 else => c_int,
7915};
7916
7917pub const pthread_mutex_t = switch (native_os) {
7918 .linux => extern struct {
7919 data: [data_len]u8 align(@alignOf(usize)) = @splat(0),
7920
7921 const data_len = switch (native_abi) {
7922 .musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24,
7923 .gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (native_arch) {
7924 .aarch64 => 48,
7925 .x86_64 => if (native_abi == .gnux32) 32 else 40,
7926 .mips64, .powerpc64, .powerpc64le, .sparc64 => 40,
7927 else => if (@sizeOf(usize) == 8) 40 else 24,
7928 },
7929 .android, .androideabi => if (@sizeOf(usize) == 8) 40 else 4,
7930 else => @compileError("unsupported ABI"),
7931 };
7932 },
7933 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
7934 sig: c_long = 0x32AAABA7,
7935 data: [data_len]u8 = @splat(0),
7936
7937 const data_len = if (@sizeOf(usize) == 8) 56 else 40;
7938 },
7939 .freebsd, .dragonfly, .openbsd => extern struct {
7940 inner: ?*anyopaque = null,
7941 },
7942 .hermit => extern struct {
7943 ptr: usize = maxInt(usize),
7944 },
7945 .netbsd => extern struct {
7946 magic: u32 = 0x33330003,
7947 errorcheck: padded_pthread_spin_t = 0,
7948 ceiling: padded_pthread_spin_t = 0,
7949 owner: usize = 0,
7950 waiters: ?*u8 = null,
7951 recursed: u32 = 0,
7952 spare2: ?*anyopaque = null,
7953 },
7954 .haiku => extern struct {
7955 flags: u32 = 0,
7956 lock: i32 = 0,
7957 unused: i32 = -42,
7958 owner: i32 = -1,
7959 owner_count: i32 = 0,
7960 },
7961 .illumos => extern struct {
7962 flag1: u16 = 0,
7963 flag2: u8 = 0,
7964 ceiling: u8 = 0,
7965 type: u16 = 0,
7966 magic: u16 = 0x4d58,
7967 lock: u64 = 0,
7968 data: u64 = 0,
7969 },
7970 .fuchsia => extern struct {
7971 data: [40]u8 align(@alignOf(usize)) = @splat(0),
7972 },
7973 .emscripten => extern struct {
7974 data: [24]u8 align(4) = @splat(0),
7975 },
7976 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L68-L73
7977 .serenity => extern struct {
7978 lock: u32 = 0,
7979 owner: pthread_t = 0,
7980 level: c_int = 0,
7981 type: c_int = 0,
7982 },
7983 else => void,
7984};
7985
7986pub const pthread_cond_t = switch (native_os) {
7987 .linux => extern struct {
7988 data: [48]u8 align(@alignOf(usize)) = @splat(0),
7989 },
7990 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
7991 sig: c_long = 0x3CB0B1BB,
7992 data: [data_len]u8 = @splat(0),
7993 const data_len = if (@sizeOf(usize) == 8) 40 else 24;
7994 },
7995 .freebsd, .dragonfly, .openbsd => extern struct {
7996 inner: ?*anyopaque = null,
7997 },
7998 .hermit => extern struct {
7999 ptr: usize = maxInt(usize),
8000 },
8001 .netbsd => extern struct {
8002 magic: u32 = 0x55550005,
8003 lock: pthread_spin_t = 0,
8004 waiters_first: ?*u8 = null,
8005 waiters_last: ?*u8 = null,
8006 mutex: ?*pthread_mutex_t = null,
8007 private: ?*anyopaque = null,
8008 },
8009 .haiku => extern struct {
8010 flags: u32 = 0,
8011 unused: i32 = -42,
8012 mutex: ?*anyopaque = null,
8013 waiter_count: i32 = 0,
8014 lock: i32 = 0,
8015 },
8016 .illumos => extern struct {
8017 flag: [4]u8 = @splat(0),
8018 type: u16 = 0,
8019 magic: u16 = 0x4356,
8020 data: u64 = 0,
8021 },
8022 .fuchsia, .emscripten => extern struct {
8023 data: [48]u8 align(@alignOf(usize)) = @splat(0),
8024 },
8025 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L80-L84
8026 .serenity => extern struct {
8027 mutex: ?*pthread_mutex_t = null,
8028 value: u32 = 0,
8029 clockid: clockid_t = .REALTIME_COARSE,
8030 },
8031 else => void,
8032};
8033
8034pub const pthread_rwlock_t = switch (native_os) {
8035 .linux => switch (native_abi) {
8036 .android, .androideabi => switch (@sizeOf(usize)) {
8037 4 => extern struct {
8038 data: [40]u8 align(@alignOf(usize)) = @splat(0),
8039 },
8040 8 => extern struct {
8041 data: [56]u8 align(@alignOf(usize)) = @splat(0),
8042 },
8043 else => @compileError("impossible pointer size"),
8044 },
8045 else => extern struct {
8046 data: [56]u8 align(@alignOf(usize)) = @splat(0),
8047 },
8048 },
8049 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
8050 sig: c_long = 0x2DA8B3B4,
8051 data: [192]u8 = @splat(0),
8052 },
8053 .freebsd, .dragonfly, .openbsd => extern struct {
8054 ptr: ?*anyopaque = null,
8055 },
8056 .hermit => extern struct {
8057 ptr: usize = maxInt(usize),
8058 },
8059 .netbsd => extern struct {
8060 magic: c_uint = 0x99990009,
8061 interlock: switch (builtin.cpu.arch) {
8062 .aarch64, .aarch64_be, .m68k, .sparc, .sparc64, .x86, .x86_64 => u8,
8063 .arm, .armeb, .powerpc => c_int,
8064 .mips, .mipsel, .mips64, .mips64el => c_uint,
8065 else => unreachable,
8066 } = 0,
8067 rblocked_first: ?*u8 = null,
8068 rblocked_last: ?*u8 = null,
8069 wblocked_first: ?*u8 = null,
8070 wblocked_last: ?*u8 = null,
8071 nreaders: c_uint = 0,
8072 owner: ?pthread_t = null,
8073 private: ?*anyopaque = null,
8074 },
8075 .illumos => extern struct {
8076 readers: i32 = 0,
8077 type: u16 = 0,
8078 magic: u16 = 0x5257,
8079 mutex: pthread_mutex_t = .{},
8080 readercv: pthread_cond_t = .{},
8081 writercv: pthread_cond_t = .{},
8082 },
8083 .fuchsia => extern struct {
8084 size: [56]u8 align(@alignOf(usize)) = @splat(0),
8085 },
8086 .emscripten => extern struct {
8087 size: [32]u8 align(4) = @splat(0),
8088 },
8089 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L86
8090 .serenity => extern struct {
8091 inner: u64 = 0,
8092 },
8093 else => void,
8094};
8095
8096pub const pthread_attr_t = switch (native_os) {
8097 .linux, .emscripten, .dragonfly => extern struct {
8098 __size: [56]u8,
8099 __align: c_long,
8100 },
8101 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
8102 __sig: c_long,
8103 __opaque: [56]u8,
8104 },
8105 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L75
8106 .freebsd, .openbsd, .serenity => extern struct {
8107 inner: ?*anyopaque = null,
8108 },
8109 .illumos => extern struct {
8110 mutexattr: ?*anyopaque = null,
8111 },
8112 .netbsd => extern struct {
8113 magic: u32,
8114 flags: i32,
8115 private: ?*anyopaque,
8116 },
8117 .haiku => extern struct {
8118 detach_state: i32,
8119 sched_priority: i32,
8120 stack_size: i32,
8121 guard_size: i32,
8122 stack_address: ?*anyopaque,
8123 },
8124 else => void,
8125};
8126
8127pub const pthread_key_t = switch (native_os) {
8128 .linux, .emscripten => c_uint,
8129 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => c_ulong,
8130 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L65
8131 .openbsd, .illumos, .serenity => c_int,
8132 else => void,
8133};
8134
8135pub const padded_pthread_spin_t = switch (native_os) {
8136 .netbsd => switch (builtin.cpu.arch) {
8137 .x86, .x86_64 => u32,
8138 .sparc, .sparc64 => u32,
8139 else => pthread_spin_t,
8140 },
8141 else => void,
8142};
8143
8144pub const pthread_spin_t = switch (native_os) {
8145 .netbsd => switch (builtin.cpu.arch) {
8146 .aarch64, .aarch64_be => u8,
8147 .mips, .mipsel, .mips64, .mips64el => u32,
8148 .powerpc, .powerpc64, .powerpc64le => i32,
8149 .x86, .x86_64 => u8,
8150 .arm, .armeb, .thumb, .thumbeb => i32,
8151 .sparc, .sparc64 => u8,
8152 .riscv32, .riscv64 => u32,
8153 else => @compileError("undefined pthread_spin_t for this arch"),
8154 },
8155 else => void,
8156};
8157
8158pub const sem_t = switch (native_os) {
8159 .linux, .emscripten => extern struct {
8160 __size: [4 * @sizeOf(usize)]u8 align(@alignOf(usize)),
8161 },
8162 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => c_int,
8163 .freebsd => extern struct {
8164 _magic: u32,
8165 _kern: extern struct {
8166 _count: u32,
8167 _flags: u32,
8168 },
8169 _padding: u32,
8170 },
8171 .illumos => extern struct {
8172 count: u32 = 0,
8173 type: u16 = 0,
8174 magic: u16 = 0x534d,
8175 __pad1: [3]u64 = @splat(0),
8176 __pad2: [2]u64 = @splat(0),
8177 },
8178 .openbsd, .netbsd, .dragonfly => ?*opaque {},
8179 .haiku => extern struct {
8180 type: i32,
8181 u: extern union {
8182 named_sem_id: i32,
8183 unnamed_sem: i32,
8184 },
8185 padding: [2]i32,
8186 },
8187 // https://github.com/SerenityOS/serenity/blob/aae106e37b48f2158e68902293df1e4bf7b80c0f/Userland/Libraries/LibC/semaphore.h#L23-L27
8188 .serenity => extern struct {
8189 magic: u32,
8190 value: u32,
8191 flags: u8,
8192 },
8193 else => void,
8194};
8195
8196/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
8197pub const Kevent = switch (native_os) {
8198 .netbsd => extern struct {
8199 ident: usize,
8200 filter: i32,
8201 flags: u32,
8202 fflags: u32,
8203 data: i64,
8204 udata: usize,
8205 },
8206 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
8207 ident: usize,
8208 filter: i16,
8209 flags: u16,
8210 fflags: u32,
8211 data: isize,
8212 udata: usize,
8213
8214 // sys/types.h on macos uses #pragma pack(4) so these checks are
8215 // to make sure the struct is laid out the same. These values were
8216 // produced from C code using the offsetof macro.
8217 comptime {
8218 assert(@offsetOf(@This(), "ident") == 0);
8219 assert(@offsetOf(@This(), "filter") == 8);
8220 assert(@offsetOf(@This(), "flags") == 10);
8221 assert(@offsetOf(@This(), "fflags") == 12);
8222 assert(@offsetOf(@This(), "data") == 16);
8223 assert(@offsetOf(@This(), "udata") == 24);
8224 }
8225 },
8226 .freebsd => extern struct {
8227 /// Identifier for this event.
8228 ident: usize,
8229 /// Filter for event.
8230 filter: i16,
8231 /// Action flags for kqueue.
8232 flags: u16,
8233 /// Filter flag value.
8234 fflags: u32,
8235 /// Filter data value.
8236 data: i64,
8237 /// Opaque user data identifier.
8238 udata: usize,
8239 /// Future extensions.
8240 _ext: [4]u64 = @splat(0),
8241 },
8242 .dragonfly => extern struct {
8243 ident: usize,
8244 filter: c_short,
8245 flags: c_ushort,
8246 fflags: c_uint,
8247 data: isize,
8248 udata: usize,
8249 },
8250 .openbsd => extern struct {
8251 ident: usize,
8252 filter: c_short,
8253 flags: u16,
8254 fflags: c_uint,
8255 data: i64,
8256 udata: usize,
8257 },
8258 else => void,
8259};
8260
8261pub const port_t = switch (native_os) {
8262 .illumos => c_int,
8263 else => void,
8264};
8265
8266pub const port_event = switch (native_os) {
8267 .illumos => extern struct {
8268 events: u32,
8269 /// Event source.
8270 source: u16,
8271 __pad: u16,
8272 /// Source-specific object.
8273 object: ?*anyopaque,
8274 /// User cookie.
8275 cookie: ?*anyopaque,
8276 },
8277 else => void,
8278};
8279
8280pub const AT = switch (native_os) {
8281 .linux => linux.AT,
8282 .windows => struct {
8283 /// Remove directory instead of unlinking file
8284 pub const REMOVEDIR = 0x200;
8285 },
8286 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
8287 pub const FDCWD = -2;
8288 /// Use effective ids in access check
8289 pub const EACCESS = 0x0010;
8290 /// Act on the symlink itself not the target
8291 pub const SYMLINK_NOFOLLOW = 0x0020;
8292 /// Act on target of symlink
8293 pub const SYMLINK_FOLLOW = 0x0040;
8294 /// Path refers to directory
8295 pub const REMOVEDIR = 0x0080;
8296 },
8297 .freebsd => struct {
8298 /// Magic value that specify the use of the current working directory
8299 /// to determine the target of relative file paths in the openat() and
8300 /// similar syscalls.
8301 pub const FDCWD = -100;
8302 /// Check access using effective user and group ID
8303 pub const EACCESS = 0x0100;
8304 /// Do not follow symbolic links
8305 pub const SYMLINK_NOFOLLOW = 0x0200;
8306 /// Follow symbolic link
8307 pub const SYMLINK_FOLLOW = 0x0400;
8308 /// Remove directory instead of file
8309 pub const REMOVEDIR = 0x0800;
8310 /// Fail if not under dirfd
8311 pub const BENEATH = 0x1000;
8312 },
8313 .netbsd => struct {
8314 /// Magic value that specify the use of the current working directory
8315 /// to determine the target of relative file paths in the openat() and
8316 /// similar syscalls.
8317 pub const FDCWD = -100;
8318 /// Check access using effective user and group ID
8319 pub const EACCESS = 0x0100;
8320 /// Do not follow symbolic links
8321 pub const SYMLINK_NOFOLLOW = 0x0200;
8322 /// Follow symbolic link
8323 pub const SYMLINK_FOLLOW = 0x0400;
8324 /// Remove directory instead of file
8325 pub const REMOVEDIR = 0x0800;
8326 },
8327 .dragonfly => struct {
8328 pub const FDCWD = -328243;
8329 pub const SYMLINK_NOFOLLOW = 1;
8330 pub const REMOVEDIR = 2;
8331 pub const EACCESS = 4;
8332 pub const SYMLINK_FOLLOW = 8;
8333 },
8334 .openbsd => struct {
8335 /// Magic value that specify the use of the current working directory
8336 /// to determine the target of relative file paths in the openat() and
8337 /// similar syscalls.
8338 pub const FDCWD = -100;
8339 /// Check access using effective user and group ID
8340 pub const EACCESS = 0x01;
8341 /// Do not follow symbolic links
8342 pub const SYMLINK_NOFOLLOW = 0x02;
8343 /// Follow symbolic link
8344 pub const SYMLINK_FOLLOW = 0x04;
8345 /// Remove directory instead of file
8346 pub const REMOVEDIR = 0x08;
8347 },
8348 .haiku => struct {
8349 pub const FDCWD = -1;
8350 pub const SYMLINK_NOFOLLOW = 0x01;
8351 pub const SYMLINK_FOLLOW = 0x02;
8352 pub const REMOVEDIR = 0x04;
8353 pub const EACCESS = 0x08;
8354 },
8355 .illumos => struct {
8356 /// Magic value that specify the use of the current working directory
8357 /// to determine the target of relative file paths in the openat() and
8358 /// similar syscalls.
8359 pub const FDCWD: fd_t = @bitCast(@as(u32, 0xffd19553));
8360 /// Do not follow symbolic links
8361 pub const SYMLINK_NOFOLLOW = 0x1000;
8362 /// Follow symbolic link
8363 pub const SYMLINK_FOLLOW = 0x2000;
8364 /// Remove directory instead of file
8365 pub const REMOVEDIR = 0x1;
8366 pub const TRIGGER = 0x2;
8367 /// Check access using effective user and group ID
8368 pub const EACCESS = 0x4;
8369 },
8370 .emscripten => struct {
8371 pub const FDCWD = -100;
8372 pub const SYMLINK_NOFOLLOW = 0x100;
8373 pub const REMOVEDIR = 0x200;
8374 pub const SYMLINK_FOLLOW = 0x400;
8375 pub const NO_AUTOMOUNT = 0x800;
8376 pub const EMPTY_PATH = 0x1000;
8377 pub const STATX_SYNC_TYPE = 0x6000;
8378 pub const STATX_SYNC_AS_STAT = 0x0000;
8379 pub const STATX_FORCE_SYNC = 0x2000;
8380 pub const STATX_DONT_SYNC = 0x4000;
8381 pub const RECURSIVE = 0x8000;
8382 },
8383 .wasi => struct {
8384 // Match `AT_*` constants in lib/libc/include/wasm-wasi-musl/__header_fcntl.h
8385 pub const EACCESS = 0x0;
8386 pub const SYMLINK_NOFOLLOW = 0x1;
8387 pub const SYMLINK_FOLLOW = 0x2;
8388 pub const REMOVEDIR = 0x4;
8389 /// When linking libc, we follow their convention and use -2 for current working directory.
8390 /// However, without libc, Zig does a different convention: it assumes the
8391 /// current working directory is the first preopen. This behavior can be
8392 /// overridden with a public function called `wasi_cwd` in the root source
8393 /// file.
8394 pub const FDCWD: fd_t = if (builtin.link_libc) -2 else 3;
8395 },
8396 // https://github.com/SerenityOS/serenity/blob/2808b0376406a40e31293bb3bcb9170374e90506/Kernel/API/POSIX/fcntl.h#L49-L52
8397 .serenity => struct {
8398 pub const FDCWD = -100;
8399 pub const SYMLINK_NOFOLLOW = 0x100;
8400 pub const REMOVEDIR = 0x200;
8401 pub const EACCESS = 0x400;
8402 },
8403 else => void,
8404};
8405
8406pub const O = switch (native_os) {
8407 .linux => linux.O,
8408 .emscripten => packed struct(u32) {
8409 ACCMODE: std.posix.ACCMODE = .RDONLY,
8410 _2: u4 = 0,
8411 CREAT: bool = false,
8412 EXCL: bool = false,
8413 NOCTTY: bool = false,
8414 TRUNC: bool = false,
8415 APPEND: bool = false,
8416 NONBLOCK: bool = false,
8417 DSYNC: bool = false,
8418 ASYNC: bool = false,
8419 DIRECT: bool = false,
8420 LARGEFILE: bool = false,
8421 DIRECTORY: bool = false,
8422 NOFOLLOW: bool = false,
8423 NOATIME: bool = false,
8424 CLOEXEC: bool = false,
8425 SYNC: bool = false,
8426 PATH: bool = false,
8427 /// This is typically invalid without also setting `DIRECTORY`.
8428 TMPFILE: bool = false,
8429 _: u9 = 0,
8430 },
8431 .wasi => packed struct(u32) {
8432 // Match `O_*` bits from lib/libc/include/wasm-wasi-musl/__header_fcntl.h
8433 APPEND: bool = false,
8434 DSYNC: bool = false,
8435 NONBLOCK: bool = false,
8436 RSYNC: bool = false,
8437 SYNC: bool = false,
8438 _5: u7 = 0,
8439 CREAT: bool = false,
8440 DIRECTORY: bool = false,
8441 EXCL: bool = false,
8442 TRUNC: bool = false,
8443 _16: u8 = 0,
8444 NOFOLLOW: bool = false,
8445 EXEC: bool = false,
8446 read: bool = false,
8447 SEARCH: bool = false,
8448 write: bool = false,
8449 // O_CLOEXEC, O_TTY_ININT, O_NOCTTY are 0 in wasi-musl, so they're silently
8450 // ignored in C code. Thus no mapping in Zig.
8451 _: u3 = 0,
8452 },
8453 .illumos => packed struct(u32) {
8454 ACCMODE: std.posix.ACCMODE = .RDONLY,
8455 NDELAY: bool = false,
8456 APPEND: bool = false,
8457 SYNC: bool = false,
8458 _5: u1 = 0,
8459 DSYNC: bool = false,
8460 NONBLOCK: bool = false,
8461 CREAT: bool = false,
8462 TRUNC: bool = false,
8463 EXCL: bool = false,
8464 NOCTTY: bool = false,
8465 _12: u1 = 0,
8466 LARGEFILE: bool = false,
8467 XATTR: bool = false,
8468 RSYNC: bool = false,
8469 _16: u1 = 0,
8470 NOFOLLOW: bool = false,
8471 NOLINKS: bool = false,
8472 _19: u2 = 0,
8473 SEARCH: bool = false,
8474 EXEC: bool = false,
8475 CLOEXEC: bool = false,
8476 DIRECTORY: bool = false,
8477 DIRECT: bool = false,
8478 _: u6 = 0,
8479 },
8480 .netbsd => packed struct(u32) {
8481 ACCMODE: std.posix.ACCMODE = .RDONLY,
8482 NONBLOCK: bool = false,
8483 APPEND: bool = false,
8484 SHLOCK: bool = false,
8485 EXLOCK: bool = false,
8486 ASYNC: bool = false,
8487 SYNC: bool = false,
8488 NOFOLLOW: bool = false,
8489 CREAT: bool = false,
8490 TRUNC: bool = false,
8491 EXCL: bool = false,
8492 _12: u3 = 0,
8493 NOCTTY: bool = false,
8494 DSYNC: bool = false,
8495 RSYNC: bool = false,
8496 ALT_IO: bool = false,
8497 DIRECT: bool = false,
8498 _20: u1 = 0,
8499 DIRECTORY: bool = false,
8500 CLOEXEC: bool = false,
8501 SEARCH: bool = false,
8502 _: u8 = 0,
8503 },
8504 .openbsd => packed struct(u32) {
8505 ACCMODE: std.posix.ACCMODE = .RDONLY,
8506 NONBLOCK: bool = false,
8507 APPEND: bool = false,
8508 SHLOCK: bool = false,
8509 EXLOCK: bool = false,
8510 ASYNC: bool = false,
8511 SYNC: bool = false,
8512 NOFOLLOW: bool = false,
8513 CREAT: bool = false,
8514 TRUNC: bool = false,
8515 EXCL: bool = false,
8516 _12: u3 = 0,
8517 NOCTTY: bool = false,
8518 CLOEXEC: bool = false,
8519 DIRECTORY: bool = false,
8520 _: u14 = 0,
8521 },
8522 .haiku => packed struct(u32) {
8523 ACCMODE: std.posix.ACCMODE = .RDONLY,
8524 _2: u4 = 0,
8525 CLOEXEC: bool = false,
8526 NONBLOCK: bool = false,
8527 EXCL: bool = false,
8528 CREAT: bool = false,
8529 TRUNC: bool = false,
8530 APPEND: bool = false,
8531 NOCTTY: bool = false,
8532 NOTRAVERSE: bool = false,
8533 _14: u2 = 0,
8534 SYNC: bool = false,
8535 RSYNC: bool = false,
8536 DSYNC: bool = false,
8537 NOFOLLOW: bool = false,
8538 DIRECT: bool = false,
8539 DIRECTORY: bool = false,
8540 _: u10 = 0,
8541 },
8542 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => packed struct(u32) {
8543 ACCMODE: std.posix.ACCMODE = .RDONLY,
8544 NONBLOCK: bool = false,
8545 APPEND: bool = false,
8546 SHLOCK: bool = false,
8547 EXLOCK: bool = false,
8548 ASYNC: bool = false,
8549 SYNC: bool = false,
8550 NOFOLLOW: bool = false,
8551 CREAT: bool = false,
8552 TRUNC: bool = false,
8553 EXCL: bool = false,
8554 RESOLVE_BENEATH: bool = false,
8555 _13: u2 = 0,
8556 EVTONLY: bool = false,
8557 _16: u1 = 0,
8558 NOCTTY: bool = false,
8559 _18: u2 = 0,
8560 DIRECTORY: bool = false,
8561 SYMLINK: bool = false,
8562 DSYNC: bool = false,
8563 _23: u1 = 0,
8564 CLOEXEC: bool = false,
8565 _25: u4 = 0,
8566 ALERT: bool = false,
8567 _30: u1 = 0,
8568 POPUP: bool = false,
8569 },
8570 .dragonfly => packed struct(u32) {
8571 ACCMODE: std.posix.ACCMODE = .RDONLY,
8572 NONBLOCK: bool = false,
8573 APPEND: bool = false,
8574 SHLOCK: bool = false,
8575 EXLOCK: bool = false,
8576 ASYNC: bool = false,
8577 SYNC: bool = false,
8578 NOFOLLOW: bool = false,
8579 CREAT: bool = false,
8580 TRUNC: bool = false,
8581 EXCL: bool = false,
8582 _12: u3 = 0,
8583 NOCTTY: bool = false,
8584 DIRECT: bool = false,
8585 CLOEXEC: bool = false,
8586 FBLOCKING: bool = false,
8587 FNONBLOCKING: bool = false,
8588 FAPPEND: bool = false,
8589 FOFFSET: bool = false,
8590 FSYNCWRITE: bool = false,
8591 FASYNCWRITE: bool = false,
8592 _24: u3 = 0,
8593 DIRECTORY: bool = false,
8594 _: u4 = 0,
8595 },
8596 .freebsd => packed struct(u32) {
8597 ACCMODE: std.posix.ACCMODE = .RDONLY,
8598 NONBLOCK: bool = false,
8599 APPEND: bool = false,
8600 SHLOCK: bool = false,
8601 EXLOCK: bool = false,
8602 ASYNC: bool = false,
8603 SYNC: bool = false,
8604 NOFOLLOW: bool = false,
8605 CREAT: bool = false,
8606 TRUNC: bool = false,
8607 EXCL: bool = false,
8608 _12: u3 = 0,
8609 NOCTTY: bool = false,
8610 DIRECT: bool = false,
8611 DIRECTORY: bool = false,
8612 EXEC: bool = false,
8613 TTY_INIT: bool = false,
8614 CLOEXEC: bool = false,
8615 VERIFY: bool = false,
8616 PATH: bool = false,
8617 RESOLVE_BENEATH: bool = false,
8618 DSYNC: bool = false,
8619 EMPTY_PATH: bool = false,
8620 XATTR: bool = false,
8621 CLOFORK: bool = false,
8622 _28: u4 = 0,
8623 },
8624 // https://github.com/SerenityOS/serenity/blob/2808b0376406a40e31293bb3bcb9170374e90506/Kernel/API/POSIX/fcntl.h#L28-L43
8625 .serenity => packed struct(c_int) {
8626 ACCMODE: std.posix.ACCMODE = .NONE,
8627 EXEC: bool = false,
8628 CREAT: bool = false,
8629 EXCL: bool = false,
8630 NOCTTY: bool = false,
8631 TRUNC: bool = false,
8632 APPEND: bool = false,
8633 NONBLOCK: bool = false,
8634 DIRECTORY: bool = false,
8635 NOFOLLOW: bool = false,
8636 CLOEXEC: bool = false,
8637 DIRECT: bool = false,
8638 SYNC: bool = false,
8639 _: @Int(.unsigned, @bitSizeOf(c_int) - 14) = 0,
8640 },
8641 else => void,
8642};
8643
8644pub const MAP = switch (native_os) {
8645 .linux => linux.MAP,
8646 .emscripten => packed struct(u32) {
8647 TYPE: enum(u4) {
8648 SHARED = 0x01,
8649 PRIVATE = 0x02,
8650 SHARED_VALIDATE = 0x03,
8651 },
8652 FIXED: bool = false,
8653 ANONYMOUS: bool = false,
8654 _6: u2 = 0,
8655 GROWSDOWN: bool = false,
8656 _9: u2 = 0,
8657 DENYWRITE: bool = false,
8658 EXECUTABLE: bool = false,
8659 LOCKED: bool = false,
8660 NORESERVE: bool = false,
8661 POPULATE: bool = false,
8662 NONBLOCK: bool = false,
8663 STACK: bool = false,
8664 HUGETLB: bool = false,
8665 SYNC: bool = false,
8666 FIXED_NOREPLACE: bool = false,
8667 _: u11 = 0,
8668 },
8669 .illumos => packed struct(u32) {
8670 TYPE: enum(u4) {
8671 SHARED = 0x01,
8672 PRIVATE = 0x02,
8673 },
8674 FIXED: bool = false,
8675 RENAME: bool = false,
8676 NORESERVE: bool = false,
8677 @"32BIT": bool = false,
8678 ANONYMOUS: bool = false,
8679 ALIGN: bool = false,
8680 TEXT: bool = false,
8681 INITDATA: bool = false,
8682 _: u20 = 0,
8683 },
8684 .netbsd => packed struct(u32) {
8685 TYPE: enum(u2) {
8686 SHARED = 0x01,
8687 PRIVATE = 0x02,
8688 },
8689 REMAPDUP: bool = false,
8690 _3: u1 = 0,
8691 FIXED: bool = false,
8692 RENAME: bool = false,
8693 NORESERVE: bool = false,
8694 INHERIT: bool = false,
8695 _8: u1 = 0,
8696 HASSEMAPHORE: bool = false,
8697 TRYFIXED: bool = false,
8698 WIRED: bool = false,
8699 ANONYMOUS: bool = false,
8700 STACK: bool = false,
8701 _: u18 = 0,
8702 },
8703 .openbsd => packed struct(u32) {
8704 TYPE: enum(u4) {
8705 SHARED = 0x01,
8706 PRIVATE = 0x02,
8707 },
8708 FIXED: bool = false,
8709 _5: u7 = 0,
8710 ANONYMOUS: bool = false,
8711 _13: u1 = 0,
8712 STACK: bool = false,
8713 CONCEAL: bool = false,
8714 _: u16 = 0,
8715 },
8716 .haiku => packed struct(u32) {
8717 TYPE: enum(u2) {
8718 SHARED = 0x01,
8719 PRIVATE = 0x02,
8720 },
8721 FIXED: bool = false,
8722 ANONYMOUS: bool = false,
8723 NORESERVE: bool = false,
8724 _: u27 = 0,
8725 },
8726 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => packed struct(u32) {
8727 TYPE: enum(u4) {
8728 SHARED = 0x01,
8729 PRIVATE = 0x02,
8730 },
8731 FIXED: bool = false,
8732 _5: u1 = 0,
8733 NORESERVE: bool = false,
8734 _7: u2 = 0,
8735 HASSEMAPHORE: bool = false,
8736 NOCACHE: bool = false,
8737 JIT: bool = false,
8738 ANONYMOUS: bool = false,
8739 _: u19 = 0,
8740 },
8741 .dragonfly => packed struct(u32) {
8742 TYPE: enum(u4) {
8743 SHARED = 0x01,
8744 PRIVATE = 0x02,
8745 },
8746 FIXED: bool = false,
8747 RENAME: bool = false,
8748 NORESERVE: bool = false,
8749 INHERIT: bool = false,
8750 NOEXTEND: bool = false,
8751 HASSEMAPHORE: bool = false,
8752 STACK: bool = false,
8753 NOSYNC: bool = false,
8754 ANONYMOUS: bool = false,
8755 VPAGETABLE: bool = false,
8756 _14: u2 = 0,
8757 TRYFIXED: bool = false,
8758 NOCORE: bool = false,
8759 SIZEALIGN: bool = false,
8760 _: u13 = 0,
8761 },
8762 .freebsd => packed struct(u32) {
8763 TYPE: enum(u4) {
8764 SHARED = 0x01,
8765 PRIVATE = 0x02,
8766 },
8767 FIXED: bool = false,
8768 _5: u5 = 0,
8769 STACK: bool = false,
8770 NOSYNC: bool = false,
8771 ANONYMOUS: bool = false,
8772 GUARD: bool = false,
8773 EXCL: bool = false,
8774 _15: u2 = 0,
8775 NOCORE: bool = false,
8776 PREFAULT_READ: bool = false,
8777 @"32BIT": bool = false,
8778 _: u12 = 0,
8779 },
8780 // https://github.com/SerenityOS/serenity/blob/6d59d4d3d9e76e39112842ec487840828f1c9bfe/Kernel/API/POSIX/sys/mman.h#L16-L26
8781 .serenity => packed struct(c_int) {
8782 TYPE: enum(u4) {
8783 SHARED = 0x01,
8784 PRIVATE = 0x02,
8785 },
8786 FIXED: bool = false,
8787 ANONYMOUS: bool = false,
8788 STACK: bool = false,
8789 NORESERVE: bool = false,
8790 RANDOMIZED: bool = false,
8791 PURGEABLE: bool = false,
8792 FIXED_NOREPLACE: bool = false,
8793 _: @Int(.unsigned, @bitSizeOf(c_int) - 11) = 0,
8794 },
8795 else => void,
8796};
8797
8798pub const MREMAP = switch (native_os) {
8799 .linux => linux.MREMAP,
8800 else => void,
8801};
8802
8803/// Used by libc to communicate failure. Not actually part of the underlying syscall.
8804pub const MAP_FAILED: *anyopaque = @ptrFromInt(maxInt(usize));
8805
8806pub const cc_t = u8;
8807
8808/// Indices into the `cc` array in the `termios` struct.
8809pub const V = switch (native_os) {
8810 .linux => linux.V,
8811 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .netbsd, .openbsd => enum {
8812 EOF,
8813 EOL,
8814 EOL2,
8815 ERASE,
8816 WERASE,
8817 KILL,
8818 REPRINT,
8819 reserved,
8820 INTR,
8821 QUIT,
8822 SUSP,
8823 DSUSP,
8824 START,
8825 STOP,
8826 LNEXT,
8827 DISCARD,
8828 MIN,
8829 TIME,
8830 STATUS,
8831 },
8832 .freebsd => enum {
8833 EOF,
8834 EOL,
8835 EOL2,
8836 ERASE,
8837 WERASE,
8838 KILL,
8839 REPRINT,
8840 ERASE2,
8841 INTR,
8842 QUIT,
8843 SUSP,
8844 DSUSP,
8845 START,
8846 STOP,
8847 LNEXT,
8848 DISCARD,
8849 MIN,
8850 TIME,
8851 STATUS,
8852 },
8853 .haiku => enum {
8854 INTR,
8855 QUIT,
8856 ERASE,
8857 KILL,
8858 EOF,
8859 EOL,
8860 EOL2,
8861 SWTCH,
8862 START,
8863 STOP,
8864 SUSP,
8865 },
8866 .illumos => enum {
8867 INTR,
8868 QUIT,
8869 ERASE,
8870 KILL,
8871 EOF,
8872 EOL,
8873 EOL2,
8874 SWTCH,
8875 START,
8876 STOP,
8877 SUSP,
8878 DSUSP,
8879 REPRINT,
8880 DISCARD,
8881 WERASE,
8882 LNEXT,
8883 STATUS,
8884 ERASE2,
8885 },
8886 .emscripten, .wasi => enum {
8887 INTR,
8888 QUIT,
8889 ERASE,
8890 KILL,
8891 EOF,
8892 TIME,
8893 MIN,
8894 SWTC,
8895 START,
8896 STOP,
8897 SUSP,
8898 EOL,
8899 REPRINT,
8900 DISCARD,
8901 WERASE,
8902 LNEXT,
8903 EOL2,
8904 },
8905 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L32-L49
8906 .serenity => enum {
8907 INTR,
8908 QUIT,
8909 ERASE,
8910 KILL,
8911 EOF,
8912 TIME,
8913 MIN,
8914 SWTC,
8915 START,
8916 STOP,
8917 SUSP,
8918 EOL,
8919 REPRINT,
8920 DISCARD,
8921 WERASE,
8922 LNEXT,
8923 EOL2,
8924 INFO,
8925 },
8926 else => void,
8927};
8928
8929pub const NCCS = switch (native_os) {
8930 .linux => linux.NCCS,
8931 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .freebsd, .netbsd, .openbsd, .dragonfly => 20,
8932 .haiku => 11,
8933 .illumos => 19,
8934 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L15
8935 .emscripten, .wasi, .serenity => 32,
8936 else => void,
8937};
8938
8939pub const termios = switch (native_os) {
8940 .linux => linux.termios,
8941 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
8942 iflag: tc_iflag_t,
8943 oflag: tc_oflag_t,
8944 cflag: tc_cflag_t,
8945 lflag: tc_lflag_t,
8946 cc: [NCCS]cc_t,
8947 ispeed: speed_t align(8),
8948 ospeed: speed_t,
8949 },
8950 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L21-L29
8951 .freebsd, .netbsd, .dragonfly, .openbsd, .serenity => extern struct {
8952 iflag: tc_iflag_t,
8953 oflag: tc_oflag_t,
8954 cflag: tc_cflag_t,
8955 lflag: tc_lflag_t,
8956 cc: [NCCS]cc_t,
8957 ispeed: speed_t,
8958 ospeed: speed_t,
8959 },
8960 .haiku => extern struct {
8961 iflag: tc_iflag_t,
8962 oflag: tc_oflag_t,
8963 cflag: tc_cflag_t,
8964 lflag: tc_lflag_t,
8965 line: cc_t,
8966 ispeed: speed_t,
8967 ospeed: speed_t,
8968 cc: [NCCS]cc_t,
8969 },
8970 .illumos => extern struct {
8971 iflag: tc_iflag_t,
8972 oflag: tc_oflag_t,
8973 cflag: tc_cflag_t,
8974 lflag: tc_lflag_t,
8975 cc: [NCCS]cc_t,
8976 },
8977 .emscripten, .wasi => extern struct {
8978 iflag: tc_iflag_t,
8979 oflag: tc_oflag_t,
8980 cflag: tc_cflag_t,
8981 lflag: tc_lflag_t,
8982 line: cc_t,
8983 cc: [NCCS]cc_t,
8984 ispeed: speed_t,
8985 ospeed: speed_t,
8986 },
8987 else => void,
8988};
8989
8990pub const tc_iflag_t = switch (native_os) {
8991 .linux => linux.tc_iflag_t,
8992 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => packed struct(u64) {
8993 IGNBRK: bool = false,
8994 BRKINT: bool = false,
8995 IGNPAR: bool = false,
8996 PARMRK: bool = false,
8997 INPCK: bool = false,
8998 ISTRIP: bool = false,
8999 INLCR: bool = false,
9000 IGNCR: bool = false,
9001 ICRNL: bool = false,
9002 IXON: bool = false,
9003 IXOFF: bool = false,
9004 IXANY: bool = false,
9005 _12: u1 = 0,
9006 IMAXBEL: bool = false,
9007 IUTF8: bool = false,
9008 _: u49 = 0,
9009 },
9010 .netbsd, .freebsd, .dragonfly => packed struct(u32) {
9011 IGNBRK: bool = false,
9012 BRKINT: bool = false,
9013 IGNPAR: bool = false,
9014 PARMRK: bool = false,
9015 INPCK: bool = false,
9016 ISTRIP: bool = false,
9017 INLCR: bool = false,
9018 IGNCR: bool = false,
9019 ICRNL: bool = false,
9020 IXON: bool = false,
9021 IXOFF: bool = false,
9022 IXANY: bool = false,
9023 _12: u1 = 0,
9024 IMAXBEL: bool = false,
9025 _: u18 = 0,
9026 },
9027 .openbsd => packed struct(u32) {
9028 IGNBRK: bool = false,
9029 BRKINT: bool = false,
9030 IGNPAR: bool = false,
9031 PARMRK: bool = false,
9032 INPCK: bool = false,
9033 ISTRIP: bool = false,
9034 INLCR: bool = false,
9035 IGNCR: bool = false,
9036 ICRNL: bool = false,
9037 IXON: bool = false,
9038 IXOFF: bool = false,
9039 IXANY: bool = false,
9040 IUCLC: bool = false,
9041 IMAXBEL: bool = false,
9042 _: u18 = 0,
9043 },
9044 .haiku => packed struct(u32) {
9045 IGNBRK: bool = false,
9046 BRKINT: bool = false,
9047 IGNPAR: bool = false,
9048 PARMRK: bool = false,
9049 INPCK: bool = false,
9050 ISTRIP: bool = false,
9051 INLCR: bool = false,
9052 IGNCR: bool = false,
9053 ICRNL: bool = false,
9054 IUCLC: bool = false,
9055 IXON: bool = false,
9056 IXANY: bool = false,
9057 IXOFF: bool = false,
9058 _: u19 = 0,
9059 },
9060 .illumos => packed struct(u32) {
9061 IGNBRK: bool = false,
9062 BRKINT: bool = false,
9063 IGNPAR: bool = false,
9064 PARMRK: bool = false,
9065 INPCK: bool = false,
9066 ISTRIP: bool = false,
9067 INLCR: bool = false,
9068 IGNCR: bool = false,
9069 ICRNL: bool = false,
9070 IUCLC: bool = false,
9071 IXON: bool = false,
9072 IXANY: bool = false,
9073 _12: u1 = 0,
9074 IMAXBEL: bool = false,
9075 _14: u1 = 0,
9076 DOSMODE: bool = false,
9077 _: u16 = 0,
9078 },
9079 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L52-L66
9080 .emscripten, .wasi, .serenity => packed struct(u32) {
9081 IGNBRK: bool = false,
9082 BRKINT: bool = false,
9083 IGNPAR: bool = false,
9084 PARMRK: bool = false,
9085 INPCK: bool = false,
9086 ISTRIP: bool = false,
9087 INLCR: bool = false,
9088 IGNCR: bool = false,
9089 ICRNL: bool = false,
9090 IUCLC: bool = false,
9091 IXON: bool = false,
9092 IXANY: bool = false,
9093 IXOFF: bool = false,
9094 IMAXBEL: bool = false,
9095 IUTF8: bool = false,
9096 _: u17 = 0,
9097 },
9098 else => void,
9099};
9100
9101pub const tc_oflag_t = switch (native_os) {
9102 .linux => linux.tc_oflag_t,
9103 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => packed struct(u64) {
9104 OPOST: bool = false,
9105 ONLCR: bool = false,
9106 OXTABS: bool = false,
9107 ONOEOT: bool = false,
9108 OCRNL: bool = false,
9109 ONOCR: bool = false,
9110 ONLRET: bool = false,
9111 OFILL: bool = false,
9112 NLDLY: u2 = 0,
9113 TABDLY: u2 = 0,
9114 CRDLY: u2 = 0,
9115 FFDLY: u1 = 0,
9116 BSDLY: u1 = 0,
9117 VTDLY: u1 = 0,
9118 OFDEL: bool = false,
9119 _: u46 = 0,
9120 },
9121 .netbsd => packed struct(u32) {
9122 OPOST: bool = false,
9123 ONLCR: bool = false,
9124 OXTABS: bool = false,
9125 ONOEOT: bool = false,
9126 OCRNL: bool = false,
9127 _5: u1 = 0,
9128 ONOCR: bool = false,
9129 ONLRET: bool = false,
9130 _: u24 = 0,
9131 },
9132 .openbsd => packed struct(u32) {
9133 OPOST: bool = false,
9134 ONLCR: bool = false,
9135 OXTABS: bool = false,
9136 ONOEOT: bool = false,
9137 OCRNL: bool = false,
9138 OLCUC: bool = false,
9139 ONOCR: bool = false,
9140 ONLRET: bool = false,
9141 _: u24 = 0,
9142 },
9143 .freebsd, .dragonfly => packed struct(u32) {
9144 OPOST: bool = false,
9145 ONLCR: bool = false,
9146 _2: u1 = 0,
9147 ONOEOT: bool = false,
9148 OCRNL: bool = false,
9149 ONOCR: bool = false,
9150 ONLRET: bool = false,
9151 _: u25 = 0,
9152 },
9153 .illumos => packed struct(u32) {
9154 OPOST: bool = false,
9155 OLCUC: bool = false,
9156 ONLCR: bool = false,
9157 OCRNL: bool = false,
9158 ONOCR: bool = false,
9159 ONLRET: bool = false,
9160 OFILL: bool = false,
9161 OFDEL: bool = false,
9162 NLDLY: u1 = 0,
9163 CRDLY: u2 = 0,
9164 TABDLY: u2 = 0,
9165 BSDLY: u1 = 0,
9166 VTDLY: u1 = 0,
9167 FFDLY: u1 = 0,
9168 PAGEOUT: bool = false,
9169 WRAP: bool = false,
9170 _: u14 = 0,
9171 },
9172 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L69-L97
9173 .haiku, .wasi, .emscripten, .serenity => packed struct(u32) {
9174 OPOST: bool = false,
9175 OLCUC: bool = false,
9176 ONLCR: bool = false,
9177 OCRNL: bool = false,
9178 ONOCR: bool = false,
9179 ONLRET: bool = false,
9180 OFILL: bool = false,
9181 OFDEL: bool = false,
9182 NLDLY: u1 = 0,
9183 CRDLY: u2 = 0,
9184 TABDLY: u2 = 0,
9185 BSDLY: u1 = 0,
9186 VTDLY: u1 = 0,
9187 FFDLY: u1 = 0,
9188 _: u16 = 0,
9189 },
9190 else => void,
9191};
9192
9193pub const CSIZE = switch (native_os) {
9194 .linux => linux.CSIZE,
9195 .haiku => enum(u1) { CS7, CS8 },
9196 else => enum(u2) { CS5, CS6, CS7, CS8 },
9197};
9198
9199pub const tc_cflag_t = switch (native_os) {
9200 .linux => linux.tc_cflag_t,
9201 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => packed struct(u64) {
9202 CIGNORE: bool = false,
9203 _1: u5 = 0,
9204 CSTOPB: bool = false,
9205 _7: u1 = 0,
9206 CSIZE: CSIZE = .CS5,
9207 _10: u1 = 0,
9208 CREAD: bool = false,
9209 PARENB: bool = false,
9210 PARODD: bool = false,
9211 HUPCL: bool = false,
9212 CLOCAL: bool = false,
9213 CCTS_OFLOW: bool = false,
9214 CRTS_IFLOW: bool = false,
9215 CDTR_IFLOW: bool = false,
9216 CDSR_OFLOW: bool = false,
9217 CCAR_OFLOW: bool = false,
9218 _: u43 = 0,
9219 },
9220 .freebsd => packed struct(u32) {
9221 CIGNORE: bool = false,
9222 _1: u7 = 0,
9223 CSIZE: CSIZE = .CS5,
9224 CSTOPB: bool = false,
9225 CREAD: bool = false,
9226 PARENB: bool = false,
9227 PARODD: bool = false,
9228 HUPCL: bool = false,
9229 CLOCAL: bool = false,
9230 CCTS_OFLOW: bool = false,
9231 CRTS_IFLOW: bool = false,
9232 CDTR_IFLOW: bool = false,
9233 CDSR_OFLOW: bool = false,
9234 CCAR_OFLOW: bool = false,
9235 CNO_RTSDTR: bool = false,
9236 _: u10 = 0,
9237 },
9238 .netbsd => packed struct(u32) {
9239 CIGNORE: bool = false,
9240 _1: u7 = 0,
9241 CSIZE: CSIZE = .CS5,
9242 CSTOPB: bool = false,
9243 CREAD: bool = false,
9244 PARENB: bool = false,
9245 PARODD: bool = false,
9246 HUPCL: bool = false,
9247 CLOCAL: bool = false,
9248 CRTSCTS: bool = false,
9249 CDTRCTS: bool = false,
9250 _18: u2 = 0,
9251 MDMBUF: bool = false,
9252 _: u11 = 0,
9253 },
9254 .dragonfly => packed struct(u32) {
9255 CIGNORE: bool = false,
9256 _1: u7 = 0,
9257 CSIZE: CSIZE = .CS5,
9258 CSTOPB: bool = false,
9259 CREAD: bool = false,
9260 PARENB: bool = false,
9261 PARODD: bool = false,
9262 HUPCL: bool = false,
9263 CLOCAL: bool = false,
9264 CCTS_OFLOW: bool = false,
9265 CRTS_IFLOW: bool = false,
9266 CDTR_IFLOW: bool = false,
9267 CDSR_OFLOW: bool = false,
9268 CCAR_OFLOW: bool = false,
9269 _: u11 = 0,
9270 },
9271 .openbsd => packed struct(u32) {
9272 CIGNORE: bool = false,
9273 _1: u7 = 0,
9274 CSIZE: CSIZE = .CS5,
9275 CSTOPB: bool = false,
9276 CREAD: bool = false,
9277 PARENB: bool = false,
9278 PARODD: bool = false,
9279 HUPCL: bool = false,
9280 CLOCAL: bool = false,
9281 CRTSCTS: bool = false,
9282 _17: u3 = 0,
9283 MDMBUF: bool = false,
9284 _: u11 = 0,
9285 },
9286 .haiku => packed struct(u32) {
9287 _0: u5 = 0,
9288 CSIZE: CSIZE = .CS7,
9289 CSTOPB: bool = false,
9290 CREAD: bool = false,
9291 PARENB: bool = false,
9292 PARODD: bool = false,
9293 HUPCL: bool = false,
9294 CLOCAL: bool = false,
9295 XLOBLK: bool = false,
9296 CTSFLOW: bool = false,
9297 RTSFLOW: bool = false,
9298 _: u17 = 0,
9299 },
9300 .illumos => packed struct(u32) {
9301 _0: u4 = 0,
9302 CSIZE: CSIZE = .CS5,
9303 CSTOPB: bool = false,
9304 CREAD: bool = false,
9305 PARENB: bool = false,
9306 PARODD: bool = false,
9307 HUPCL: bool = false,
9308 CLOCAL: bool = false,
9309 RCV1EN: bool = false,
9310 XMT1EN: bool = false,
9311 LOBLK: bool = false,
9312 XCLUDE: bool = false,
9313 _16: u4 = 0,
9314 PAREXT: bool = false,
9315 CBAUDEXT: bool = false,
9316 CIBAUDEXT: bool = false,
9317 _23: u7 = 0,
9318 CRTSXOFF: bool = false,
9319 CRTSCTS: bool = false,
9320 },
9321 .wasi, .emscripten => packed struct(u32) {
9322 _0: u4 = 0,
9323 CSIZE: CSIZE = .CS5,
9324 CSTOPB: bool = false,
9325 CREAD: bool = false,
9326 PARENB: bool = false,
9327 PARODD: bool = false,
9328 HUPCL: bool = false,
9329 CLOCAL: bool = false,
9330 _: u20 = 0,
9331 },
9332 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L131-L141
9333 .serenity => packed struct(u32) {
9334 _0: u4 = 0,
9335 CSIZE: CSIZE = .CS5,
9336 CSTOPB: bool = false,
9337 CREAD: bool = false,
9338 PARENB: bool = false,
9339 PARODD: bool = false,
9340 HUPCL: bool = false,
9341 CLOCAL: bool = false,
9342 CBAUDEX: bool = false,
9343 _: u19 = 0,
9344 },
9345 else => void,
9346};
9347
9348pub const tc_lflag_t = switch (native_os) {
9349 .linux => linux.tc_lflag_t,
9350 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => packed struct(u64) {
9351 ECHOKE: bool = false,
9352 ECHOE: bool = false,
9353 ECHOK: bool = false,
9354 ECHO: bool = false,
9355 ECHONL: bool = false,
9356 ECHOPRT: bool = false,
9357 ECHOCTL: bool = false,
9358 ISIG: bool = false,
9359 ICANON: bool = false,
9360 ALTWERASE: bool = false,
9361 IEXTEN: bool = false,
9362 EXTPROC: bool = false,
9363 _12: u10 = 0,
9364 TOSTOP: bool = false,
9365 FLUSHO: bool = false,
9366 _24: u1 = 0,
9367 NOKERNINFO: bool = false,
9368 _26: u3 = 0,
9369 PENDIN: bool = false,
9370 _30: u1 = 0,
9371 NOFLSH: bool = false,
9372 _: u32 = 0,
9373 },
9374 .netbsd, .freebsd, .dragonfly => packed struct(u32) {
9375 ECHOKE: bool = false,
9376 ECHOE: bool = false,
9377 ECHOK: bool = false,
9378 ECHO: bool = false,
9379 ECHONL: bool = false,
9380 ECHOPRT: bool = false,
9381 ECHOCTL: bool = false,
9382 ISIG: bool = false,
9383 ICANON: bool = false,
9384 ALTWERASE: bool = false,
9385 IEXTEN: bool = false,
9386 EXTPROC: bool = false,
9387 _12: u10 = 0,
9388 TOSTOP: bool = false,
9389 FLUSHO: bool = false,
9390 _24: u1 = 0,
9391 NOKERNINFO: bool = false,
9392 _26: u3 = 0,
9393 PENDIN: bool = false,
9394 _30: u1 = 0,
9395 NOFLSH: bool = false,
9396 },
9397 .openbsd => packed struct(u32) {
9398 ECHOKE: bool = false,
9399 ECHOE: bool = false,
9400 ECHOK: bool = false,
9401 ECHO: bool = false,
9402 ECHONL: bool = false,
9403 ECHOPRT: bool = false,
9404 ECHOCTL: bool = false,
9405 ISIG: bool = false,
9406 ICANON: bool = false,
9407 ALTWERASE: bool = false,
9408 IEXTEN: bool = false,
9409 EXTPROC: bool = false,
9410 _12: u10 = 0,
9411 TOSTOP: bool = false,
9412 FLUSHO: bool = false,
9413 XCASE: bool = false,
9414 NOKERNINFO: bool = false,
9415 _26: u3 = 0,
9416 PENDIN: bool = false,
9417 _30: u1 = 0,
9418 NOFLSH: bool = false,
9419 },
9420 .haiku => packed struct(u32) {
9421 ISIG: bool = false,
9422 ICANON: bool = false,
9423 XCASE: bool = false,
9424 ECHO: bool = false,
9425 ECHOE: bool = false,
9426 ECHOK: bool = false,
9427 ECHONL: bool = false,
9428 NOFLSH: bool = false,
9429 TOSTOP: bool = false,
9430 IEXTEN: bool = false,
9431 ECHOCTL: bool = false,
9432 ECHOPRT: bool = false,
9433 ECHOKE: bool = false,
9434 FLUSHO: bool = false,
9435 PENDIN: bool = false,
9436 _: u17 = 0,
9437 },
9438 .illumos => packed struct(u32) {
9439 ISIG: bool = false,
9440 ICANON: bool = false,
9441 XCASE: bool = false,
9442 ECHO: bool = false,
9443 ECHOE: bool = false,
9444 ECHOK: bool = false,
9445 ECHONL: bool = false,
9446 NOFLSH: bool = false,
9447 TOSTOP: bool = false,
9448 ECHOCTL: bool = false,
9449 ECHOPRT: bool = false,
9450 ECHOKE: bool = false,
9451 DEFECHO: bool = false,
9452 FLUSHO: bool = false,
9453 PENDIN: bool = false,
9454 IEXTEN: bool = false,
9455 _: u16 = 0,
9456 },
9457 .wasi, .emscripten => packed struct(u32) {
9458 ISIG: bool = false,
9459 ICANON: bool = false,
9460 _2: u1 = 0,
9461 ECHO: bool = false,
9462 ECHOE: bool = false,
9463 ECHOK: bool = false,
9464 ECHONL: bool = false,
9465 NOFLSH: bool = false,
9466 TOSTOP: bool = false,
9467 _9: u6 = 0,
9468 IEXTEN: bool = false,
9469 _: u16 = 0,
9470 },
9471 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L168-L189
9472 .serenity => packed struct(u32) {
9473 ISIG: bool = false,
9474 ICANON: bool = false,
9475 XCASE: bool = false,
9476 ECHO: bool = false,
9477 ECHOE: bool = false,
9478 ECHOK: bool = false,
9479 ECHONL: bool = false,
9480 NOFLSH: bool = false,
9481 TOSTOP: bool = false,
9482 ECHOCTL: bool = false,
9483 ECHOPRT: bool = false,
9484 ECHOKE: bool = false,
9485 FLUSHO: bool = false,
9486 _13: u1 = 0,
9487 PENDIN: bool = false,
9488 IEXTEN: bool = false,
9489 EXTPROC: bool = false,
9490 _: u15 = 0,
9491 },
9492 else => void,
9493};
9494
9495pub const speed_t = switch (native_os) {
9496 .linux => linux.speed_t,
9497 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .openbsd => enum(u64) {
9498 B0 = 0,
9499 B50 = 50,
9500 B75 = 75,
9501 B110 = 110,
9502 B134 = 134,
9503 B150 = 150,
9504 B200 = 200,
9505 B300 = 300,
9506 B600 = 600,
9507 B1200 = 1200,
9508 B1800 = 1800,
9509 B2400 = 2400,
9510 B4800 = 4800,
9511 B9600 = 9600,
9512 B19200 = 19200,
9513 B38400 = 38400,
9514 B7200 = 7200,
9515 B14400 = 14400,
9516 B28800 = 28800,
9517 B57600 = 57600,
9518 B76800 = 76800,
9519 B115200 = 115200,
9520 B230400 = 230400,
9521 },
9522 .freebsd, .netbsd => enum(c_uint) {
9523 B0 = 0,
9524 B50 = 50,
9525 B75 = 75,
9526 B110 = 110,
9527 B134 = 134,
9528 B150 = 150,
9529 B200 = 200,
9530 B300 = 300,
9531 B600 = 600,
9532 B1200 = 1200,
9533 B1800 = 1800,
9534 B2400 = 2400,
9535 B4800 = 4800,
9536 B9600 = 9600,
9537 B19200 = 19200,
9538 B38400 = 38400,
9539 B7200 = 7200,
9540 B14400 = 14400,
9541 B28800 = 28800,
9542 B57600 = 57600,
9543 B76800 = 76800,
9544 B115200 = 115200,
9545 B230400 = 230400,
9546 B460800 = 460800,
9547 B500000 = 500000,
9548 B921600 = 921600,
9549 B1000000 = 1000000,
9550 B1500000 = 1500000,
9551 B2000000 = 2000000,
9552 B2500000 = 2500000,
9553 B3000000 = 3000000,
9554 B3500000 = 3500000,
9555 B4000000 = 4000000,
9556 },
9557 .dragonfly => enum(c_uint) {
9558 B0 = 0,
9559 B50 = 50,
9560 B75 = 75,
9561 B110 = 110,
9562 B134 = 134,
9563 B150 = 150,
9564 B200 = 200,
9565 B300 = 300,
9566 B600 = 600,
9567 B1200 = 1200,
9568 B1800 = 1800,
9569 B2400 = 2400,
9570 B4800 = 4800,
9571 B9600 = 9600,
9572 B19200 = 19200,
9573 B38400 = 38400,
9574 B7200 = 7200,
9575 B14400 = 14400,
9576 B28800 = 28800,
9577 B57600 = 57600,
9578 B76800 = 76800,
9579 B115200 = 115200,
9580 B230400 = 230400,
9581 B460800 = 460800,
9582 B921600 = 921600,
9583 },
9584 .haiku => enum(u8) {
9585 B0 = 0x00,
9586 B50 = 0x01,
9587 B75 = 0x02,
9588 B110 = 0x03,
9589 B134 = 0x04,
9590 B150 = 0x05,
9591 B200 = 0x06,
9592 B300 = 0x07,
9593 B600 = 0x08,
9594 B1200 = 0x09,
9595 B1800 = 0x0A,
9596 B2400 = 0x0B,
9597 B4800 = 0x0C,
9598 B9600 = 0x0D,
9599 B19200 = 0x0E,
9600 B38400 = 0x0F,
9601 B57600 = 0x10,
9602 B115200 = 0x11,
9603 B230400 = 0x12,
9604 B31250 = 0x13,
9605 },
9606 .illumos => enum(c_uint) {
9607 B0 = 0,
9608 B50 = 1,
9609 B75 = 2,
9610 B110 = 3,
9611 B134 = 4,
9612 B150 = 5,
9613 B200 = 6,
9614 B300 = 7,
9615 B600 = 8,
9616 B1200 = 9,
9617 B1800 = 10,
9618 B2400 = 11,
9619 B4800 = 12,
9620 B9600 = 13,
9621 B19200 = 14,
9622 B38400 = 15,
9623 B57600 = 16,
9624 B76800 = 17,
9625 B115200 = 18,
9626 B153600 = 19,
9627 B230400 = 20,
9628 B307200 = 21,
9629 B460800 = 22,
9630 B921600 = 23,
9631 B1000000 = 24,
9632 B1152000 = 25,
9633 B1500000 = 26,
9634 B2000000 = 27,
9635 B2500000 = 28,
9636 B3000000 = 29,
9637 B3500000 = 30,
9638 B4000000 = 31,
9639 },
9640 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L111-L159
9641 .emscripten, .wasi, .serenity => enum(u32) {
9642 B0 = 0o0000000,
9643 B50 = 0o0000001,
9644 B75 = 0o0000002,
9645 B110 = 0o0000003,
9646 B134 = 0o0000004,
9647 B150 = 0o0000005,
9648 B200 = 0o0000006,
9649 B300 = 0o0000007,
9650 B600 = 0o0000010,
9651 B1200 = 0o0000011,
9652 B1800 = 0o0000012,
9653 B2400 = 0o0000013,
9654 B4800 = 0o0000014,
9655 B9600 = 0o0000015,
9656 B19200 = 0o0000016,
9657 B38400 = 0o0000017,
9658
9659 B57600 = 0o0010001,
9660 B115200 = 0o0010002,
9661 B230400 = 0o0010003,
9662 B460800 = 0o0010004,
9663 B500000 = 0o0010005,
9664 B576000 = 0o0010006,
9665 B921600 = 0o0010007,
9666 B1000000 = 0o0010010,
9667 B1152000 = 0o0010011,
9668 B1500000 = 0o0010012,
9669 B2000000 = 0o0010013,
9670 B2500000 = 0o0010014,
9671 B3000000 = 0o0010015,
9672 B3500000 = 0o0010016,
9673 B4000000 = 0o0010017,
9674 },
9675 else => void,
9676};
9677
9678pub const whence_t = if (native_os == .wasi) std.os.wasi.whence_t else c_int;
9679
9680pub const sig_atomic_t = switch (native_os) {
9681 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L20
9682 .serenity => u32,
9683 else => c_int,
9684};
9685
9686/// maximum signal number + 1
9687pub const NSIG = switch (native_os) {
9688 .linux => linux.NSIG,
9689 .windows => 23,
9690 .haiku => 65,
9691 .netbsd, .freebsd => 32,
9692 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => darwin.NSIG,
9693 .illumos => 75,
9694 // https://github.com/SerenityOS/serenity/blob/046c23f567a17758d762a33bdf04bacbfd088f9f/Kernel/API/POSIX/signal_numbers.h#L42
9695 .openbsd, .serenity => 33,
9696 .dragonfly => 64,
9697 else => {},
9698};
9699
9700pub const MINSIGSTKSZ = switch (native_os) {
9701 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => 32768,
9702 .freebsd => switch (builtin.cpu.arch) {
9703 .powerpc64, .powerpc64le, .x86, .x86_64 => 2048,
9704 .arm, .aarch64, .riscv64 => 4096,
9705 else => @compileError("unsupported arch"),
9706 },
9707 .illumos => 2048,
9708 .haiku, .netbsd => 8192,
9709 .openbsd => 1 << openbsd.MAX_PAGE_SHIFT,
9710 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L58
9711 .serenity => 4096,
9712 else => {},
9713};
9714pub const SIGSTKSZ = switch (native_os) {
9715 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => 131072,
9716 .netbsd, .freebsd => MINSIGSTKSZ + 32768,
9717 .illumos => 8192,
9718 .haiku => 16384,
9719 .openbsd => MINSIGSTKSZ + (1 << openbsd.MAX_PAGE_SHIFT) * 4,
9720 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L59
9721 .serenity => 32768,
9722 else => {},
9723};
9724pub const SS = switch (native_os) {
9725 .linux => linux.SS,
9726 .openbsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .netbsd, .freebsd => struct {
9727 pub const ONSTACK = 1;
9728 pub const DISABLE = 4;
9729 },
9730 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L54-L55
9731 .haiku, .illumos, .serenity => struct {
9732 pub const ONSTACK = 0x1;
9733 pub const DISABLE = 0x2;
9734 },
9735 else => void,
9736};
9737
9738pub const EV = switch (native_os) {
9739 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
9740 // https://github.com/apple-oss-distributions/xnu/blob/main/bsd/sys/event.h
9741 /// add event to kq (implies enable)
9742 pub const ADD = 0x0001;
9743 /// delete event from kq
9744 pub const DELETE = 0x0002;
9745 /// enable event
9746 pub const ENABLE = 0x0004;
9747 /// disable event (not reported)
9748 pub const DISABLE = 0x0008;
9749 /// only report one occurrence
9750 pub const ONESHOT = 0x0010;
9751 /// clear event state after reporting
9752 pub const CLEAR = 0x0020;
9753 /// force immediate event output
9754 /// ... with or without ERROR
9755 /// ... use KEVENT_FLAG_ERROR_EVENTS
9756 /// on syscalls supporting flags
9757 pub const RECEIPT = 0x0040;
9758 /// disable event after reporting
9759 pub const DISPATCH = 0x0080;
9760 /// unique kevent per udata value
9761 pub const UDATA_SPECIFIC = 0x0100;
9762 /// ... in combination with DELETE
9763 /// will defer delete until udata-specific
9764 /// event enabled. EINPROGRESS will be
9765 /// returned to indicate the deferral
9766 pub const DISPATCH2 = DISPATCH | UDATA_SPECIFIC;
9767 /// report that source has vanished
9768 /// ... only valid with DISPATCH2
9769 pub const VANISHED = 0x0200;
9770 /// reserved by system
9771 pub const SYSFLAGS = 0xF000;
9772 /// filter-specific flag
9773 pub const FLAG0 = 0x1000;
9774 /// filter-specific flag
9775 pub const FLAG1 = 0x2000;
9776 /// EOF detected (return value)
9777 pub const EOF = 0x8000;
9778 /// error, data contains errno (return value)
9779 pub const ERROR = 0x4000;
9780 /// use poll(2) semantics for EVFILT.READ
9781 pub const POLL = FLAG0;
9782 /// on input, filter should actively return in the presence of OOB on the descriptor
9783 /// on output, indicates the presence of OOB data on the descriptor
9784 pub const OOBAND = FLAG1;
9785 },
9786 .dragonfly => struct {
9787 pub const ADD = 1;
9788 pub const DELETE = 2;
9789 pub const ENABLE = 4;
9790 pub const DISABLE = 8;
9791 pub const ONESHOT = 16;
9792 pub const CLEAR = 32;
9793 pub const RECEIPT = 64;
9794 pub const DISPATCH = 128;
9795 pub const NODATA = 4096;
9796 pub const FLAG1 = 8192;
9797 pub const ERROR = 16384;
9798 pub const EOF = 32768;
9799 pub const SYSFLAGS = 61440;
9800 },
9801 .netbsd => struct {
9802 /// add event to kq (implies enable)
9803 pub const ADD = 0x0001;
9804 /// delete event from kq
9805 pub const DELETE = 0x0002;
9806 /// enable event
9807 pub const ENABLE = 0x0004;
9808 /// disable event (not reported)
9809 pub const DISABLE = 0x0008;
9810 /// only report one occurrence
9811 pub const ONESHOT = 0x0010;
9812 /// clear event state after reporting
9813 pub const CLEAR = 0x0020;
9814 /// force EV_ERROR on success, data=0
9815 pub const RECEIPT = 0x0040;
9816 /// disable event after reporting
9817 pub const DISPATCH = 0x0080;
9818 /// filter-specific flag
9819 pub const FLAG1 = 0x2000;
9820 /// error, data contains errno
9821 pub const ERROR = 0x4000;
9822 /// EOF detected
9823 pub const EOF = 0x8000;
9824 },
9825 .freebsd => struct {
9826 // https://cgit.freebsd.org/src/tree/sys/sys/event.h
9827 /// add event to kq (implies enable)
9828 pub const ADD = 0x0001;
9829 /// delete event from kq
9830 pub const DELETE = 0x0002;
9831 /// enable event
9832 pub const ENABLE = 0x0004;
9833 /// disable event (not reported)
9834 pub const DISABLE = 0x0008;
9835 /// enable _ONESHOT and force trigger
9836 pub const FORCEONESHOT = 0x0100;
9837 /// do not update the udata field
9838 pub const KEEPUDATA = 0x0200;
9839 /// only report one occurrence
9840 pub const ONESHOT = 0x0010;
9841 /// clear event state after reporting
9842 pub const CLEAR = 0x0020;
9843 /// force immediate event output
9844 /// ... with or without ERROR
9845 /// ... use KEVENT_FLAG_ERROR_EVENTS
9846 /// on syscalls supporting flags
9847 pub const RECEIPT = 0x0040;
9848 /// disable event after reporting
9849 pub const DISPATCH = 0x0080;
9850 /// reserved by system
9851 pub const SYSFLAGS = 0xF000;
9852 /// note should be dropped
9853 pub const DROP = 0x1000;
9854 /// filter-specific flag 1
9855 pub const FLAG1 = 0x2000;
9856 /// filter-specific flag 2
9857 pub const FLAG2 = 0x4000;
9858 /// EOF detected (return value)
9859 pub const EOF = 0x8000;
9860 /// error, event data contains errno (return value)
9861 pub const ERROR = 0x4000;
9862 },
9863 .openbsd => struct {
9864 pub const ADD = 0x0001;
9865 pub const DELETE = 0x0002;
9866 pub const ENABLE = 0x0004;
9867 pub const DISABLE = 0x0008;
9868 pub const ONESHOT = 0x0010;
9869 pub const CLEAR = 0x0020;
9870 pub const RECEIPT = 0x0040;
9871 pub const DISPATCH = 0x0080;
9872 pub const FLAG1 = 0x2000;
9873 pub const ERROR = 0x4000;
9874 pub const EOF = 0x8000;
9875 },
9876 .haiku => struct {
9877 /// add event to kq (implies enable)
9878 pub const ADD = 0x0001;
9879 /// delete event from kq
9880 pub const DELETE = 0x0002;
9881 /// enable event
9882 pub const ENABLE = 0x0004;
9883 /// disable event (not reported)
9884 pub const DISABLE = 0x0008;
9885 /// only report one occurrence
9886 pub const ONESHOT = 0x0010;
9887 /// clear event state after reporting
9888 pub const CLEAR = 0x0020;
9889 /// force immediate event output
9890 /// ... with or without ERROR
9891 /// ... use KEVENT_FLAG_ERROR_EVENTS
9892 /// on syscalls supporting flags
9893 pub const RECEIPT = 0x0040;
9894 /// disable event after reporting
9895 pub const DISPATCH = 0x0080;
9896 },
9897 else => void,
9898};
9899
9900pub const EVFILT = switch (native_os) {
9901 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
9902 pub const READ = -1;
9903 pub const WRITE = -2;
9904 /// attached to aio requests
9905 pub const AIO = -3;
9906 /// attached to vnodes
9907 pub const VNODE = -4;
9908 /// attached to struct proc
9909 pub const PROC = -5;
9910 /// attached to struct proc
9911 pub const SIGNAL = -6;
9912 /// timers
9913 pub const TIMER = -7;
9914 /// Mach portsets
9915 pub const MACHPORT = -8;
9916 /// Filesystem events
9917 pub const FS = -9;
9918 /// User events
9919 pub const USER = -10;
9920 /// Virtual memory events
9921 pub const VM = -12;
9922 /// Exception events
9923 pub const EXCEPT = -15;
9924 pub const SYSCOUNT = 17;
9925 },
9926 .haiku => struct {
9927 pub const READ = -1;
9928 pub const WRITE = -2;
9929 /// attached to aio requests
9930 pub const AIO = -3;
9931 /// attached to vnodes
9932 pub const VNODE = -4;
9933 /// attached to struct proc
9934 pub const PROC = -5;
9935 /// attached to struct proc
9936 pub const SIGNAL = -6;
9937 /// timers
9938 pub const TIMER = -7;
9939 /// Process descriptors
9940 pub const PROCDESC = -8;
9941 /// Filesystem events
9942 pub const FS = -9;
9943 pub const LIO = -10;
9944 /// User events
9945 pub const USER = -11;
9946 /// Sendfile events
9947 pub const SENDFILE = -12;
9948 pub const EMPTY = -13;
9949 },
9950 .dragonfly => struct {
9951 pub const FS = -10;
9952 pub const USER = -9;
9953 pub const EXCEPT = -8;
9954 pub const TIMER = -7;
9955 pub const SIGNAL = -6;
9956 pub const PROC = -5;
9957 pub const VNODE = -4;
9958 pub const AIO = -3;
9959 pub const WRITE = -2;
9960 pub const READ = -1;
9961 pub const SYSCOUNT = 10;
9962 pub const MARKER = 15;
9963 },
9964 .netbsd => struct {
9965 pub const READ = 0;
9966 pub const WRITE = 1;
9967 /// attached to aio requests
9968 pub const AIO = 2;
9969 /// attached to vnodes
9970 pub const VNODE = 3;
9971 /// attached to struct proc
9972 pub const PROC = 4;
9973 /// attached to struct proc
9974 pub const SIGNAL = 5;
9975 /// timers
9976 pub const TIMER = 6;
9977 /// Filesystem events
9978 pub const FS = 7;
9979 /// User events
9980 pub const USER = 8;
9981 /// Empty filter
9982 pub const EMPTY = 9;
9983 },
9984 .freebsd => struct {
9985 // https://cgit.freebsd.org/src/tree/sys/sys/event.h
9986 pub const READ = -1;
9987 pub const WRITE = -2;
9988 /// attached to aio requests
9989 pub const AIO = -3;
9990 /// attached to vnodes
9991 pub const VNODE = -4;
9992 /// attached to struct proc
9993 pub const PROC = -5;
9994 /// attached to struct proc
9995 pub const SIGNAL = -6;
9996 /// timers
9997 pub const TIMER = -7;
9998 /// Process descriptors
9999 pub const PROCDESC = -8;
10000 /// Filesystem events
10001 pub const FS = -9;
10002 /// attached to lio requests
10003 pub const LIO = -10;
10004 /// User events
10005 pub const USER = -11;
10006 /// Sendfile events
10007 pub const SENDFILE = -12;
10008 /// empty send socket buf
10009 pub const EMPTY = -13;
10010 /// attached to struct prison
10011 pub const JAIL = -14;
10012 /// attached to jail descriptors
10013 pub const JAILDESC = -15;
10014 },
10015 .openbsd => struct {
10016 pub const READ = -1;
10017 pub const WRITE = -2;
10018 pub const AIO = -3;
10019 pub const VNODE = -4;
10020 pub const PROC = -5;
10021 pub const SIGNAL = -6;
10022 pub const TIMER = -7;
10023 pub const DEVICE = -8;
10024 pub const EXCEPT = -9;
10025 pub const USER = -10;
10026 },
10027 else => void,
10028};
10029
10030pub const NOTE = switch (native_os) {
10031 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct {
10032 // https://github.com/apple-oss-distributions/xnu/blob/main/bsd/sys/event.h
10033 /// On input, TRIGGER causes the event to be triggered for output.
10034 pub const TRIGGER = 0x01000000;
10035 /// ignore input fflags
10036 pub const FFNOP = 0x00000000;
10037 /// and fflags
10038 pub const FFAND = 0x40000000;
10039 /// or fflags
10040 pub const FFOR = 0x80000000;
10041 /// copy fflags
10042 pub const FFCOPY = 0xc0000000;
10043 /// mask for operations
10044 pub const FFCTRLMASK = 0xc0000000;
10045 pub const FFLAGSMASK = 0x00ffffff;
10046 /// low water mark
10047 pub const LOWAT = 0x00000001;
10048 /// OOB data
10049 pub const OOB = 0x00000002;
10050 /// vnode was removed
10051 pub const DELETE = 0x00000001;
10052 /// data contents changed
10053 pub const WRITE = 0x00000002;
10054 /// size increased
10055 pub const EXTEND = 0x00000004;
10056 /// attributes changed
10057 pub const ATTRIB = 0x00000008;
10058 /// link count changed
10059 pub const LINK = 0x00000010;
10060 /// vnode was renamed
10061 pub const RENAME = 0x00000020;
10062 /// vnode access was revoked
10063 pub const REVOKE = 0x00000040;
10064 /// No specific vnode event: to test for EVFILT_READ activation
10065 pub const NONE = 0x00000080;
10066 /// vnode was unlocked by flock(2)
10067 pub const FUNLOCK = 0x00000100;
10068 /// process exited
10069 pub const EXIT = 0x80000000;
10070 /// process forked
10071 pub const FORK = 0x40000000;
10072 /// process exec'd
10073 pub const EXEC = 0x20000000;
10074 /// shared with EVFILT_SIGNAL
10075 pub const SIGNAL = 0x08000000;
10076 /// exit status to be returned, valid for child process only
10077 pub const EXITSTATUS = 0x04000000;
10078 /// provide details on reasons for exit
10079 pub const EXIT_DETAIL = 0x02000000;
10080 /// mask for signal & exit status
10081 pub const PDATAMASK = 0x000fffff;
10082 pub const PCTRLMASK = 0xf0000000;
10083 pub const EXIT_DETAIL_MASK = 0x00070000;
10084 pub const EXIT_DECRYPTFAIL = 0x00010000;
10085 pub const EXIT_MEMORY = 0x00020000;
10086 pub const EXIT_CSERROR = 0x00040000;
10087 /// will react on memory pressure
10088 pub const VM_PRESSURE = 0x80000000;
10089 /// will quit on memory pressure, possibly after cleaning up dirty state
10090 pub const VM_PRESSURE_TERMINATE = 0x40000000;
10091 /// will quit immediately on memory pressure
10092 pub const VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000;
10093 /// there was an error
10094 pub const VM_ERROR = 0x10000000;
10095 /// data is seconds
10096 pub const SECONDS = 0x00000001;
10097 /// data is microseconds
10098 pub const USECONDS = 0x00000002;
10099 /// data is nanoseconds
10100 pub const NSECONDS = 0x00000004;
10101 /// absolute timeout
10102 pub const ABSOLUTE = 0x00000008;
10103 /// ext[1] holds leeway for power aware timers
10104 pub const LEEWAY = 0x00000010;
10105 /// system does minimal timer coalescing
10106 pub const CRITICAL = 0x00000020;
10107 /// system does maximum timer coalescing
10108 pub const BACKGROUND = 0x00000040;
10109 /// with ABSOLUTE: causes the timer to continue to tick across sleep, still uses gettimeofday epoch
10110 /// with MACHTIME and ABSOLUTE: uses mach continuous time epoch
10111 /// without ABSOLUTE: continues to tick across sleep
10112 pub const MACH_CONTINUOUS_TIME = 0x00000080;
10113 /// data is mach absolute time units
10114 pub const MACHTIME = 0x00000100;
10115 },
10116 .dragonfly => struct {
10117 pub const FFNOP = 0;
10118 pub const TRACK = 1;
10119 pub const DELETE = 1;
10120 pub const LOWAT = 1;
10121 pub const TRACKERR = 2;
10122 pub const OOB = 2;
10123 pub const WRITE = 2;
10124 pub const EXTEND = 4;
10125 pub const CHILD = 4;
10126 pub const ATTRIB = 8;
10127 pub const LINK = 16;
10128 pub const RENAME = 32;
10129 pub const REVOKE = 64;
10130 pub const PDATAMASK = 1048575;
10131 pub const FFLAGSMASK = 16777215;
10132 pub const TRIGGER = 16777216;
10133 pub const EXEC = 536870912;
10134 pub const FFAND = 1073741824;
10135 pub const FORK = 1073741824;
10136 pub const EXIT = 2147483648;
10137 pub const FFOR = 2147483648;
10138 pub const FFCTRLMASK = 3221225472;
10139 pub const FFCOPY = 3221225472;
10140 pub const PCTRLMASK = 4026531840;
10141 },
10142 .netbsd => struct {
10143 /// ignore input fflags
10144 pub const FFNOP = 0x00000000;
10145 /// AND fflags
10146 pub const FFAND = 0x40000000;
10147 /// OR fflags
10148 pub const FFOR = 0x80000000;
10149 /// copy fflags
10150 pub const FFCOPY = 0xc0000000;
10151 /// masks for operations
10152 pub const FFCTRLMASK = 0xc0000000;
10153 pub const FFLAGSMASK = 0x00ffffff;
10154 /// On input, TRIGGER causes the event to be triggered for output.
10155 pub const TRIGGER = 0x01000000;
10156 /// low water mark
10157 pub const LOWAT = 0x00000001;
10158 /// vnode was removed
10159 pub const DELETE = 0x00000001;
10160 /// data contents changed
10161 pub const WRITE = 0x00000002;
10162 /// size increased
10163 pub const EXTEND = 0x00000004;
10164 /// attributes changed
10165 pub const ATTRIB = 0x00000008;
10166 /// link count changed
10167 pub const LINK = 0x00000010;
10168 /// vnode was renamed
10169 pub const RENAME = 0x00000020;
10170 /// vnode access was revoked
10171 pub const REVOKE = 0x00000040;
10172 /// vnode was opened
10173 pub const OPEN = 0x00000080;
10174 /// file closed (no FWRITE)
10175 pub const CLOSE = 0x00000100;
10176 /// file closed (FWRITE)
10177 pub const CLOSE_WRITE = 0x00000200;
10178 /// file was read
10179 pub const READ = 0x00000400;
10180 /// process exited
10181 pub const EXIT = 0x80000000;
10182 /// process forked
10183 pub const FORK = 0x40000000;
10184 /// process exec'd
10185 pub const EXEC = 0x20000000;
10186 /// mask for signal & exit status
10187 pub const PDATAMASK = 0x000fffff;
10188 pub const PCTRLMASK = 0xf0000000;
10189 /// follow across forks
10190 pub const TRACK = 0x00000001;
10191 /// could not track child
10192 pub const TRACKERR = 0x00000002;
10193 /// am a child process
10194 pub const CHILD = 0x00000004;
10195 /// shared with EVFILT_SIGNAL
10196 pub const SIGNAL = 0x08000000;
10197 /// data is milliseconds
10198 pub const MSECONDS = 0x00000000;
10199 /// data is seconds
10200 pub const SECONDS = 0x00000001;
10201 /// data is microseconds
10202 pub const USECONDS = 0x00000002;
10203 /// data is nanoseconds
10204 pub const NSECONDS = 0x00000003;
10205 /// timeout is absolute
10206 pub const ABSTIME = 0x00000010;
10207 },
10208 .freebsd => struct {
10209 /// On input, TRIGGER causes the event to be triggered for output.
10210 pub const TRIGGER = 0x01000000;
10211 /// ignore input fflags
10212 pub const FFNOP = 0x00000000;
10213 /// and fflags
10214 pub const FFAND = 0x40000000;
10215 /// or fflags
10216 pub const FFOR = 0x80000000;
10217 /// copy fflags
10218 pub const FFCOPY = 0xc0000000;
10219 /// mask for operations
10220 pub const FFCTRLMASK = 0xc0000000;
10221 pub const FFLAGSMASK = 0x00ffffff;
10222 /// low water mark
10223 pub const LOWAT = 0x00000001;
10224 /// behave like poll()
10225 pub const FILE_POLL = 0x00000002;
10226 /// vnode was removed
10227 pub const DELETE = 0x00000001;
10228 /// data contents changed
10229 pub const WRITE = 0x00000002;
10230 /// size increased
10231 pub const EXTEND = 0x00000004;
10232 /// attributes changed
10233 pub const ATTRIB = 0x00000008;
10234 /// link count changed
10235 pub const LINK = 0x00000010;
10236 /// vnode was renamed
10237 pub const RENAME = 0x00000020;
10238 /// vnode access was revoked
10239 pub const REVOKE = 0x00000040;
10240 /// vnode was opened
10241 pub const OPEN = 0x00000080;
10242 /// file closed, fd did not allow write
10243 pub const CLOSE = 0x00000100;
10244 /// file closed, fd did allow write
10245 pub const CLOSE_WRITE = 0x00000200;
10246 /// file was read
10247 pub const READ = 0x00000400;
10248 /// process exited
10249 pub const EXIT = 0x80000000;
10250 /// process forked
10251 pub const FORK = 0x40000000;
10252 /// process exec'd
10253 pub const EXEC = 0x20000000;
10254 /// mask for signal & exit status
10255 pub const PDATAMASK = 0x000fffff;
10256 pub const PCTRLMASK = 0xf0000000;
10257 /// data is seconds
10258 pub const SECONDS = 0x00000001;
10259 /// data is milliseconds
10260 pub const MSECONDS = 0x00000002;
10261 /// data is microseconds
10262 pub const USECONDS = 0x00000004;
10263 /// data is nanoseconds
10264 pub const NSECONDS = 0x00000008;
10265 /// timeout is absolute
10266 pub const ABSTIME = 0x00000010;
10267 },
10268 .openbsd => struct {
10269 // data/hint flags for EVFILT.{READ|WRITE}
10270 pub const LOWAT = 0x0001;
10271 pub const EOF = 0x0002;
10272 // data/hint flags for EVFILT.EXCEPT and EVFILT.{READ|WRITE}
10273 pub const OOB = 0x0004;
10274 // data/hint flags for EVFILT.VNODE
10275 pub const DELETE = 0x0001;
10276 pub const WRITE = 0x0002;
10277 pub const EXTEND = 0x0004;
10278 pub const ATTRIB = 0x0008;
10279 pub const LINK = 0x0010;
10280 pub const RENAME = 0x0020;
10281 pub const REVOKE = 0x0040;
10282 pub const TRUNCATE = 0x0080;
10283 // data/hint flags for EVFILT.PROC
10284 pub const EXIT = 0x80000000;
10285 pub const FORK = 0x40000000;
10286 pub const EXEC = 0x20000000;
10287 pub const PDATAMASK = 0x000fffff;
10288 pub const PCTRLMASK = 0xf0000000;
10289 pub const TRACK = 0x00000001;
10290 pub const TRACKERR = 0x00000002;
10291 pub const CHILD = 0x00000004;
10292 // data/hint flags for EVFILT.DEVICE
10293 pub const CHANGE = 0x00000001;
10294 // data/hint flags for EVFILT_USER
10295 pub const FFNOP = 0x00000000;
10296 pub const FFAND = 0x40000000;
10297 pub const FFOR = 0x80000000;
10298 pub const FFCOPY = 0xc0000000;
10299 pub const FFCTRLMASK = 0xc0000000;
10300 pub const FFLAGSMASK = 0x00ffffff;
10301 pub const TRIGGER = 0x01000000;
10302 },
10303 else => void,
10304};
10305
10306pub const FUTEX = switch (native_os) {
10307 .openbsd => openbsd.FUTEX,
10308 .serenity => serenity.FUTEX,
10309 else => void,
10310};
10311
10312pub const MFD = switch (native_os) {
10313 .linux => linux.MFD,
10314 .freebsd => freebsd.MFD,
10315 else => void,
10316};
10317
10318// Unix-like systems
10319pub const DIR = opaque {};
10320pub extern "c" fn opendir(pathname: [*:0]const u8) ?*DIR;
10321pub extern "c" fn fdopendir(fd: c_int) ?*DIR;
10322pub extern "c" fn rewinddir(dp: *DIR) void;
10323pub extern "c" fn closedir(dp: *DIR) c_int;
10324pub extern "c" fn telldir(dp: *DIR) c_long;
10325pub extern "c" fn seekdir(dp: *DIR, loc: c_long) void;
10326
10327pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
10328
10329pub extern "c" fn alarm(seconds: c_uint) c_uint;
10330
10331pub const close = switch (native_os) {
10332 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => darwin.@"close$NOCANCEL",
10333 else => private.close,
10334};
10335
10336pub const clock_getres = switch (native_os) {
10337 .netbsd => private.__clock_getres50,
10338 else => private.clock_getres,
10339};
10340
10341pub const clock_gettime = switch (native_os) {
10342 .netbsd => private.__clock_gettime50,
10343 else => private.clock_gettime,
10344};
10345
10346pub const fstat = switch (native_os) {
10347 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => switch (native_arch) {
10348 .x86_64 => private.@"fstat$INODE64",
10349 else => private.fstat,
10350 },
10351 .netbsd => private.__fstat50,
10352 .linux => {},
10353 else => private.fstat,
10354};
10355
10356pub const fstatat = switch (native_os) {
10357 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => switch (native_arch) {
10358 .x86_64 => private.@"fstatat$INODE64",
10359 else => private.fstatat,
10360 },
10361 .linux => {},
10362 else => private.fstatat,
10363};
10364
10365pub extern "c" fn statx(dirfd: fd_t, path: [*:0]const u8, flags: u32, mask: linux.STATX, buf: *linux.Statx) c_int;
10366
10367pub extern "c" fn getpwent() ?*passwd;
10368pub extern "c" fn endpwent() void;
10369pub extern "c" fn setpwent() void;
10370pub extern "c" fn getpwnam(name: [*:0]const u8) ?*passwd;
10371pub extern "c" fn getpwnam_r(name: [*:0]const u8, pwd: *passwd, buf: [*]u8, buflen: usize, result: *?*passwd) c_int;
10372pub extern "c" fn getpwuid(uid: uid_t) ?*passwd;
10373pub extern "c" fn getpwuid_r(uid: uid_t, pwd: *passwd, buf: [*]u8, buflen: usize, result: *?*passwd) c_int;
10374pub extern "c" fn getgrent() ?*group;
10375pub extern "c" fn setgrent() void;
10376pub extern "c" fn endgrent() void;
10377pub extern "c" fn getgrnam(name: [*:0]const u8) ?*group;
10378pub extern "c" fn getgrnam_r(name: [*:0]const u8, grp: *group, buf: [*]u8, buflen: usize, result: *?*group) c_int;
10379pub extern "c" fn getgrgid(gid: gid_t) ?*group;
10380pub extern "c" fn getgrgid_r(gid: gid_t, grp: *group, buf: [*]u8, buflen: usize, result: *?*group) c_int;
10381pub extern "c" fn getrlimit64(resource: rlimit_resource, rlim: *rlimit) c_int;
10382pub extern "c" fn lseek64(fd: fd_t, offset: i64, whence: c_int) i64;
10383pub extern "c" fn mmap64(addr: ?*align(page_size) anyopaque, len: usize, prot: PROT, flags: MAP, fd: fd_t, offset: i64) *anyopaque;
10384pub extern "c" fn open64(path: [*:0]const u8, oflag: O, ...) c_int;
10385pub extern "c" fn openat64(fd: c_int, path: [*:0]const u8, oflag: O, ...) c_int;
10386pub extern "c" fn pread64(fd: fd_t, buf: [*]u8, nbyte: usize, offset: i64) isize;
10387pub extern "c" fn preadv64(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: i64) isize;
10388pub extern "c" fn pwrite64(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: i64) isize;
10389pub extern "c" fn pwritev64(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: i64) isize;
10390pub extern "c" fn sendfile64(out_fd: fd_t, in_fd: fd_t, offset: ?*i64, count: usize) isize;
10391pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_int;
10392
10393pub const arc4random_buf = switch (native_os) {
10394 .linux => if (builtin.abi.isAndroid() or
10395 (builtin.abi.isGnu() and versionCheck(.{ .major = 2, .minor = 36, .patch = 0 })))
10396 private.arc4random_buf
10397 else {},
10398 .dragonfly, .netbsd, .freebsd, .illumos, .openbsd, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => private.arc4random_buf,
10399 else => {},
10400};
10401pub const getentropy = switch (native_os) {
10402 .linux => if (builtin.abi.isAndroid() and versionCheck(.{ .major = 28, .minor = 0, .patch = 0 })) private.getentropy else {},
10403 .emscripten => private.getentropy,
10404 else => {},
10405};
10406pub const getrandom = switch (native_os) {
10407 .freebsd => private.getrandom,
10408 .linux => if (builtin.abi.isMusl() or
10409 (builtin.abi.isGnu() and versionCheck(.{ .major = 2, .minor = 25, .patch = 0 })) or
10410 (builtin.abi.isAndroid() and versionCheck(.{ .major = 28, .minor = 0, .patch = 0 })))
10411 private.getrandom
10412 else {},
10413 else => {},
10414};
10415
10416pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;
10417pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
10418
10419pub extern "c" fn epoll_ctl(epfd: fd_t, op: c_uint, fd: fd_t, event: ?*epoll_event) c_int;
10420pub extern "c" fn epoll_create1(flags: c_uint) c_int;
10421pub extern "c" fn epoll_wait(epfd: fd_t, events: [*]epoll_event, maxevents: c_uint, timeout: c_int) c_int;
10422pub extern "c" fn epoll_pwait(
10423 epfd: fd_t,
10424 events: [*]epoll_event,
10425 maxevents: c_int,
10426 timeout: c_int,
10427 sigmask: *const sigset_t,
10428) c_int;
10429
10430pub extern "c" fn timerfd_create(clockid: timerfd_clockid_t, flags: c_int) c_int;
10431pub extern "c" fn timerfd_settime(
10432 fd: c_int,
10433 flags: c_int,
10434 new_value: *const itimerspec,
10435 old_value: ?*itimerspec,
10436) c_int;
10437pub extern "c" fn timerfd_gettime(fd: c_int, curr_value: *itimerspec) c_int;
10438
10439pub extern "c" fn inotify_init1(flags: c_uint) c_int;
10440pub extern "c" fn inotify_add_watch(fd: fd_t, pathname: [*:0]const u8, mask: u32) c_int;
10441pub extern "c" fn inotify_rm_watch(fd: fd_t, wd: c_int) c_int;
10442
10443pub extern "c" fn fallocate64(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int;
10444pub extern "c" fn fopen64(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;
10445pub extern "c" fn ftruncate64(fd: c_int, length: off_t) c_int;
10446pub extern "c" fn fallocate(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int;
10447pub const sendfile = switch (native_os) {
10448 .freebsd => freebsd.sendfile,
10449 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => darwin.sendfile,
10450 .linux => private.sendfile,
10451 else => {},
10452};
10453/// See std.elf for constants for this
10454pub extern "c" fn getauxval(__type: c_ulong) c_ulong;
10455
10456pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*anyopaque) c_int;
10457
10458pub const sigaltstack = switch (native_os) {
10459 .netbsd => private.__sigaltstack14,
10460 else => private.sigaltstack,
10461};
10462
10463pub extern "c" fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int;
10464pub const pipe2 = switch (native_os) {
10465 .dragonfly, .emscripten, .netbsd, .freebsd, .illumos, .openbsd, .linux, .serenity => private.pipe2,
10466 else => {},
10467};
10468pub const copy_file_range = switch (native_os) {
10469 .linux => private.copy_file_range,
10470 .freebsd => freebsd.copy_file_range,
10471 else => {},
10472};
10473
10474pub extern "c" fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) c_int;
10475
10476pub extern "c" fn prlimit(pid: pid_t, resource: rlimit_resource, new_limit: *const rlimit, old_limit: *rlimit) c_int;
10477pub extern "c" fn mincore(
10478 addr: *align(page_size) anyopaque,
10479 length: usize,
10480 vec: [*]u8,
10481) c_int;
10482
10483pub extern "c" fn madvise(
10484 addr: *align(page_size) anyopaque,
10485 length: usize,
10486 advice: u32,
10487) c_int;
10488
10489pub const getdirentries = switch (native_os) {
10490 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => private.__getdirentries64,
10491 else => private.getdirentries,
10492};
10493
10494pub const getdents = switch (native_os) {
10495 .netbsd => private.__getdents30,
10496 else => private.getdents,
10497};
10498
10499pub const getrusage = switch (native_os) {
10500 .netbsd => private.__getrusage50,
10501 else => private.getrusage,
10502};
10503
10504pub const gettimeofday = switch (native_os) {
10505 .netbsd => private.__gettimeofday50,
10506 else => private.gettimeofday,
10507};
10508
10509pub const mlock = switch (native_os) {
10510 .windows, .wasi => {},
10511 else => private.mlock,
10512};
10513
10514pub const mlock2 = switch (native_os) {
10515 .linux => private.mlock2,
10516 else => {},
10517};
10518
10519pub const munlock = switch (native_os) {
10520 .windows, .wasi => {},
10521 else => private.munlock,
10522};
10523
10524pub const mlockall = switch (native_os) {
10525 .linux, .freebsd, .dragonfly, .netbsd, .openbsd, .illumos => private.mlockall,
10526 else => {},
10527};
10528
10529pub const munlockall = switch (native_os) {
10530 .linux, .freebsd, .dragonfly, .netbsd, .openbsd, .illumos => private.munlockall,
10531 else => {},
10532};
10533
10534pub const msync = switch (native_os) {
10535 .netbsd => private.__msync13,
10536 else => private.msync,
10537};
10538
10539pub const nanosleep = switch (native_os) {
10540 .netbsd => private.__nanosleep50,
10541 else => private.nanosleep,
10542};
10543
10544pub const readdir = switch (native_os) {
10545 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => switch (native_arch) {
10546 .x86_64 => private.@"readdir$INODE64",
10547 else => private.readdir,
10548 },
10549 .windows => {},
10550 else => private.readdir,
10551};
10552
10553pub const realpath = switch (native_os) {
10554 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => private.@"realpath$DARWIN_EXTSN",
10555 else => private.realpath,
10556};
10557
10558pub const sched_yield = switch (native_os) {
10559 .netbsd => private.__libc_thr_yield,
10560 else => private.sched_yield,
10561};
10562
10563pub const sigaction = switch (native_os) {
10564 .netbsd => private.__sigaction14,
10565 else => private.sigaction,
10566};
10567
10568/// Zig's version of SIGRTMIN. Actually a function.
10569pub const sigrtmin = switch (native_os) {
10570 .openbsd => {},
10571 else => sigrt_private.sigrtmin,
10572};
10573
10574/// Zig's version of SIGRTMAX. Actually a function.
10575pub const sigrtmax = switch (native_os) {
10576 .openbsd => {},
10577 else => sigrt_private.sigrtmax,
10578};
10579
10580const sigrt_private = struct {
10581 pub fn sigrtmin() u8 {
10582 return switch (native_os) {
10583 .freebsd => 65,
10584 .netbsd => 33,
10585 .illumos => @truncate(sysconf(@backingInt(_SC.SIGRT_MIN))),
10586 .haiku => @truncate(@as(c_uint, @bitCast(private.__signal_get_sigrtmin()))),
10587 else => @truncate(@as(c_uint, @bitCast(private.__libc_current_sigrtmin()))),
10588 };
10589 }
10590
10591 pub fn sigrtmax() u8 {
10592 return switch (native_os) {
10593 .freebsd => 126,
10594 .netbsd => 63,
10595 .illumos => @truncate(sysconf(@backingInt(_SC.SIGRT_MAX))),
10596 .haiku => @truncate(@as(c_uint, @bitCast(private.__signal_get_sigrtmax()))),
10597 else => @truncate(@as(c_uint, @bitCast(private.__libc_current_sigrtmax()))),
10598 };
10599 }
10600};
10601
10602pub const sigfillset = switch (native_os) {
10603 .netbsd => private.__sigfillset14,
10604 else => private.sigfillset,
10605};
10606
10607pub const sigaddset = private.sigaddset;
10608pub const sigemptyset = switch (native_os) {
10609 .netbsd => private.__sigemptyset14,
10610 else => private.sigemptyset,
10611};
10612pub const sigdelset = private.sigdelset;
10613pub const sigismember = private.sigismember;
10614
10615pub const sigprocmask = switch (native_os) {
10616 .netbsd => private.__sigprocmask14,
10617 else => private.sigprocmask,
10618};
10619
10620pub const socket = switch (native_os) {
10621 .netbsd => private.__socket30,
10622 else => private.socket,
10623};
10624
10625pub const socketpair = switch (native_os) {
10626 // https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/#unsupported\unavailable:
10627 .windows => {},
10628 else => private.socketpair,
10629};
10630
10631pub const stat = switch (native_os) {
10632 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => switch (native_arch) {
10633 .x86_64 => private.@"stat$INODE64",
10634 else => private.stat,
10635 },
10636 else => private.stat,
10637};
10638
10639pub const _msize = switch (native_os) {
10640 .windows => private._msize,
10641 else => {},
10642};
10643pub const malloc_size = switch (native_os) {
10644 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .serenity => private.malloc_size,
10645 else => {},
10646};
10647pub const malloc_usable_size = switch (native_os) {
10648 .freebsd, .linux, .serenity => private.malloc_usable_size,
10649 else => {},
10650};
10651pub const posix_memalign = switch (native_os) {
10652 .dragonfly, .netbsd, .freebsd, .illumos, .openbsd, .linux, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .serenity => private.posix_memalign,
10653 else => {},
10654};
10655pub const sysconf = switch (native_os) {
10656 .illumos => illumos.sysconf,
10657 else => private.sysconf,
10658};
10659
10660pub const sf_hdtr = switch (native_os) {
10661 .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
10662 headers: ?[*]const iovec_const,
10663 hdr_cnt: c_int,
10664 trailers: ?[*]const iovec_const,
10665 trl_cnt: c_int,
10666 },
10667 else => void,
10668};
10669
10670pub const flock = switch (native_os) {
10671 .windows, .wasi => {},
10672 else => private.flock,
10673};
10674
10675pub const futex = switch (native_os) {
10676 .openbsd => openbsd.futex,
10677 .serenity => serenity.futex,
10678 else => {},
10679};
10680
10681pub extern "c" var environ: [*:null]?[*:0]u8;
10682
10683pub extern "c" fn fopen(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;
10684pub extern "c" fn fclose(stream: *FILE) c_int;
10685pub extern "c" fn fwrite(noalias ptr: [*]const u8, size_of_type: usize, item_count: usize, noalias stream: *FILE) usize;
10686pub extern "c" fn fread(noalias ptr: [*]u8, size_of_type: usize, item_count: usize, noalias stream: *FILE) usize;
10687
10688pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;
10689pub extern "c" fn abort() noreturn;
10690pub extern "c" fn exit(code: c_int) noreturn;
10691pub extern "c" fn _Exit(code: c_int) noreturn;
10692pub extern "c" fn _exit(code: c_int) noreturn;
10693pub extern "c" fn isatty(fd: fd_t) c_int;
10694pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: whence_t) off_t;
10695pub extern "c" fn open(path: [*:0]const u8, oflag: O, ...) c_int;
10696pub extern "c" fn openat(fd: c_int, path: [*:0]const u8, oflag: O, ...) c_int;
10697pub extern "c" fn ftruncate(fd: c_int, length: off_t) c_int;
10698pub extern "c" fn raise(sig: SIG) c_int;
10699pub extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize;
10700pub extern "c" fn readv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint) isize;
10701pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: off_t) isize;
10702pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: off_t) isize;
10703pub extern "c" fn writev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint) isize;
10704pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: off_t) isize;
10705pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize;
10706pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: off_t) isize;
10707pub extern "c" fn mmap(addr: ?*align(page_size) anyopaque, len: usize, prot: PROT, flags: MAP, fd: fd_t, offset: off_t) *anyopaque;
10708pub extern "c" fn munmap(addr: *align(page_size) const anyopaque, len: usize) c_int;
10709pub extern "c" fn mremap(addr: ?*align(page_size) const anyopaque, old_len: usize, new_len: usize, flags: MREMAP, ...) *anyopaque;
10710pub extern "c" fn mprotect(addr: *align(page_size) anyopaque, len: usize, prot: PROT) c_int;
10711pub extern "c" fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8) c_int;
10712pub extern "c" fn linkat(oldfd: fd_t, oldpath: [*:0]const u8, newfd: fd_t, newpath: [*:0]const u8, flags: c_uint) c_int;
10713pub extern "c" fn unlink(path: [*:0]const u8) c_int;
10714pub extern "c" fn unlinkat(dirfd: fd_t, path: [*:0]const u8, flags: c_uint) c_int;
10715pub extern "c" fn getcwd(buf: [*]u8, size: usize) ?[*]u8;
10716pub extern "c" fn waitpid(pid: pid_t, status: ?*c_int, options: c_int) pid_t;
10717
10718pub const wait4 = switch (native_os) {
10719 .netbsd => private.__wait450,
10720 else => private.wait4,
10721};
10722
10723pub const fork = switch (native_os) {
10724 .dragonfly,
10725 .freebsd,
10726 .linux,
10727 .driverkit,
10728 .ios,
10729 .maccatalyst,
10730 .macos,
10731 .tvos,
10732 .visionos,
10733 .watchos,
10734 .netbsd,
10735 .openbsd,
10736 .illumos,
10737 .haiku,
10738 .serenity,
10739 => private.fork,
10740 else => {},
10741};
10742pub extern "c" fn access(path: [*:0]const u8, mode: c_uint) c_int;
10743pub extern "c" fn faccessat(dirfd: fd_t, path: [*:0]const u8, mode: c_uint, flags: c_uint) c_int;
10744pub extern "c" fn pipe(fds: *[2]fd_t) c_int;
10745pub extern "c" fn mkdir(path: [*:0]const u8, mode: mode_t) c_int;
10746pub extern "c" fn mkdirat(dirfd: fd_t, path: [*:0]const u8, mode: mode_t) c_int;
10747pub extern "c" fn symlink(existing: [*:0]const u8, new: [*:0]const u8) c_int;
10748pub extern "c" fn symlinkat(oldpath: [*:0]const u8, newdirfd: fd_t, newpath: [*:0]const u8) c_int;
10749pub extern "c" fn rename(old: [*:0]const u8, new: [*:0]const u8) c_int;
10750pub extern "c" fn renameat(olddirfd: fd_t, old: [*:0]const u8, newdirfd: fd_t, new: [*:0]const u8) c_int;
10751pub extern "c" fn chdir(path: [*:0]const u8) c_int;
10752pub extern "c" fn fchdir(fd: fd_t) c_int;
10753pub extern "c" fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8) c_int;
10754pub extern "c" fn dup(fd: fd_t) c_int;
10755pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int;
10756pub extern "c" fn dup3(old: c_int, new: c_int, flags: c_uint) c_int;
10757pub extern "c" fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
10758pub extern "c" fn readlinkat(dirfd: fd_t, noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
10759pub extern "c" fn chmod(path: [*:0]const u8, mode: mode_t) c_int;
10760pub extern "c" fn fchmod(fd: fd_t, mode: mode_t) c_int;
10761pub extern "c" fn fchmodat(fd: fd_t, path: [*:0]const u8, mode: mode_t, flags: c_uint) c_int;
10762pub extern "c" fn fchown(fd: fd_t, owner: uid_t, group: gid_t) c_int;
10763pub extern "c" fn fchownat(fd: fd_t, path: [*:0]const u8, owner: uid_t, group: gid_t, flags: c_uint) c_int;
10764pub extern "c" fn umask(mode: mode_t) mode_t;
10765
10766pub extern "c" fn rmdir(path: [*:0]const u8) c_int;
10767pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;
10768pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*anyopaque, oldlenp: ?*usize, newp: ?*anyopaque, newlen: usize) c_int;
10769pub extern "c" fn sysctlbyname(name: [*:0]const u8, oldp: ?*anyopaque, oldlenp: ?*usize, newp: ?*anyopaque, newlen: usize) c_int;
10770pub extern "c" fn sysctlnametomib(name: [*:0]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
10771pub extern "c" fn tcgetattr(fd: fd_t, termios_p: *termios) c_int;
10772pub extern "c" fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) c_int;
10773pub extern "c" fn fcntl(fd: fd_t, cmd: c_int, ...) c_int;
10774pub extern "c" fn uname(buf: *utsname) c_int;
10775
10776pub extern "c" fn gethostname(name: [*]u8, len: usize) c_int;
10777pub extern "c" fn shutdown(socket: fd_t, how: c_int) c_int;
10778pub extern "c" fn bind(socket: fd_t, address: ?*const sockaddr, address_len: socklen_t) c_int;
10779pub extern "c" fn listen(sockfd: fd_t, backlog: c_uint) c_int;
10780pub extern "c" fn getsockname(sockfd: fd_t, noalias addr: *sockaddr, noalias addrlen: *socklen_t) c_int;
10781pub extern "c" fn getpeername(sockfd: fd_t, noalias addr: *sockaddr, noalias addrlen: *socklen_t) c_int;
10782pub extern "c" fn connect(sockfd: fd_t, sock_addr: *const sockaddr, addrlen: socklen_t) c_int;
10783pub extern "c" fn accept(sockfd: fd_t, noalias addr: ?*sockaddr, noalias addrlen: ?*socklen_t) c_int;
10784pub extern "c" fn accept4(sockfd: fd_t, noalias addr: ?*sockaddr, noalias addrlen: ?*socklen_t, flags: c_uint) c_int;
10785pub extern "c" fn getsockopt(sockfd: fd_t, level: i32, optname: u32, noalias optval: ?*anyopaque, noalias optlen: *socklen_t) c_int;
10786pub extern "c" fn setsockopt(sockfd: fd_t, level: i32, optname: u32, optval: ?*const anyopaque, optlen: socklen_t) c_int;
10787pub extern "c" fn send(sockfd: fd_t, buf: *const anyopaque, len: usize, flags: u32) isize;
10788pub extern "c" fn sendto(
10789 sockfd: fd_t,
10790 buf: *const anyopaque,
10791 len: usize,
10792 flags: u32,
10793 dest_addr: ?*const sockaddr,
10794 addrlen: socklen_t,
10795) isize;
10796pub extern "c" fn sendmsg(sockfd: fd_t, msg: *const msghdr_const, flags: u32) isize;
10797pub extern "c" fn sendmmsg(sockfd: fd_t, msgvec: [*]mmsghdr, n: c_uint, flags: u32) c_int;
10798
10799pub extern "c" fn recv(
10800 sockfd: fd_t,
10801 arg1: ?*anyopaque,
10802 arg2: usize,
10803 arg3: c_int,
10804) if (native_os == .windows) c_int else isize;
10805pub extern "c" fn recvfrom(
10806 sockfd: fd_t,
10807 noalias buf: *anyopaque,
10808 len: usize,
10809 flags: u32,
10810 noalias src_addr: ?*sockaddr,
10811 noalias addrlen: ?*socklen_t,
10812) if (native_os == .windows) c_int else isize;
10813
10814pub const recvmsg = switch (native_os) {
10815 .windows => {},
10816 else => private.recvmsg,
10817};
10818
10819pub extern "c" fn kill(pid: pid_t, sig: SIG) c_int;
10820
10821pub extern "c" fn setuid(uid: uid_t) c_int;
10822pub extern "c" fn setgid(gid: gid_t) c_int;
10823pub extern "c" fn seteuid(euid: uid_t) c_int;
10824pub extern "c" fn setegid(egid: gid_t) c_int;
10825pub extern "c" fn setreuid(ruid: uid_t, euid: uid_t) c_int;
10826pub extern "c" fn setregid(rgid: gid_t, egid: gid_t) c_int;
10827pub extern "c" fn setresuid(ruid: uid_t, euid: uid_t, suid: uid_t) c_int;
10828pub extern "c" fn setresgid(rgid: gid_t, egid: gid_t, sgid: gid_t) c_int;
10829pub extern "c" fn setpgid(pid: pid_t, pgid: pid_t) c_int;
10830pub extern "c" fn getuid() uid_t;
10831pub extern "c" fn getgid() gid_t;
10832pub extern "c" fn geteuid() uid_t;
10833pub extern "c" fn getegid() gid_t;
10834pub extern "c" fn getresuid(ruid: *uid_t, euid: *uid_t, suid: *uid_t) c_int;
10835pub extern "c" fn getresgid(rgid: *gid_t, egid: *gid_t, sgid: *gid_t) c_int;
10836
10837pub extern "c" fn malloc(usize) ?*anyopaque;
10838pub extern "c" fn calloc(usize, usize) ?*anyopaque;
10839pub extern "c" fn realloc(?*anyopaque, usize) ?*anyopaque;
10840pub extern "c" fn free(?*anyopaque) void;
10841
10842pub extern "c" fn futimes(fd: fd_t, times: ?*[2]timeval) c_int;
10843pub extern "c" fn utimes(path: [*:0]const u8, times: ?*[2]timeval) c_int;
10844
10845pub extern "c" fn utimensat(dirfd: fd_t, pathname: [*:0]const u8, times: ?*const [2]timespec, flags: u32) c_int;
10846pub extern "c" fn futimens(fd: fd_t, times: ?*const [2]timespec) c_int;
10847
10848pub extern "c" fn pthread_create(
10849 noalias newthread: *pthread_t,
10850 noalias attr: ?*const pthread_attr_t,
10851 start_routine: *const fn (?*anyopaque) callconv(.c) ?*anyopaque,
10852 noalias arg: ?*anyopaque,
10853) E;
10854pub const pthread_cancelstate = switch (native_os) {
10855 .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => enum(c_int) {
10856 ENABLE = 1,
10857 DISABLE = 0,
10858 },
10859 .linux => if (native_abi.isMusl()) enum(c_int) {
10860 ENABLE = 0,
10861 DISABLE = 1,
10862 MASKED = 2,
10863 } else if (native_abi.isGnu()) enum(c_int) {
10864 ENABLE = 0,
10865 DISABLE = 1,
10866 },
10867 else => void,
10868};
10869pub extern "c" fn pthread_setcancelstate(pthread_cancelstate, ?*pthread_cancelstate) E;
10870pub extern "c" fn pthread_cancel(pthread_t) E;
10871pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) E;
10872pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *anyopaque, stacksize: usize) E;
10873pub extern "c" fn pthread_attr_setstacksize(attr: *pthread_attr_t, stacksize: usize) E;
10874pub extern "c" fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) E;
10875pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) E;
10876pub extern "c" fn pthread_self() pthread_t;
10877pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*anyopaque) E;
10878pub extern "c" fn pthread_detach(thread: pthread_t) E;
10879pub extern "c" fn pthread_atfork(
10880 prepare: ?*const fn () callconv(.c) void,
10881 parent: ?*const fn () callconv(.c) void,
10882 child: ?*const fn () callconv(.c) void,
10883) c_int;
10884pub extern "c" fn pthread_key_create(
10885 key: *pthread_key_t,
10886 destructor: ?*const fn (value: *anyopaque) callconv(.c) void,
10887) E;
10888pub extern "c" fn pthread_key_delete(key: pthread_key_t) E;
10889pub extern "c" fn pthread_getspecific(key: pthread_key_t) ?*anyopaque;
10890pub extern "c" fn pthread_setspecific(key: pthread_key_t, value: ?*anyopaque) c_int;
10891pub extern "c" fn pthread_sigmask(how: c_int, set: *const sigset_t, oldset: *sigset_t) c_int;
10892pub const pthread_setname_np = switch (native_os) {
10893 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => darwin.pthread_setname_np,
10894 .illumos => illumos.pthread_setname_np,
10895 .netbsd => netbsd.pthread_setname_np,
10896 else => private.pthread_setname_np,
10897};
10898
10899pub extern "c" fn pthread_getname_np(thread: pthread_t, name: [*:0]u8, len: usize) c_int;
10900pub extern "c" fn pthread_kill(pthread_t, signal: SIG) c_int;
10901pub extern "c" fn pthread_exit(ptr: ?*anyopaque) noreturn;
10902
10903pub const pthread_threadid_np = switch (native_os) {
10904 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => private.pthread_threadid_np,
10905 else => {},
10906};
10907
10908pub const caddr_t = ?[*]u8;
10909
10910pub const ptrace = switch (native_os) {
10911 .linux, .serenity => private.ptrace,
10912 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => darwin.ptrace,
10913 .dragonfly => dragonfly.ptrace,
10914 .freebsd => freebsd.ptrace,
10915 .netbsd => netbsd.ptrace,
10916 .openbsd => openbsd.ptrace,
10917 else => {},
10918};
10919
10920pub extern "c" fn sem_init(sem: *sem_t, pshared: c_int, value: c_uint) c_int;
10921pub extern "c" fn sem_destroy(sem: *sem_t) c_int;
10922pub extern "c" fn sem_open(name: [*:0]const u8, flag: c_int, mode: mode_t, value: c_uint) *sem_t;
10923pub extern "c" fn sem_close(sem: *sem_t) c_int;
10924pub extern "c" fn sem_post(sem: *sem_t) c_int;
10925pub extern "c" fn sem_wait(sem: *sem_t) c_int;
10926pub extern "c" fn sem_trywait(sem: *sem_t) c_int;
10927pub extern "c" fn sem_timedwait(sem: *sem_t, abs_timeout: *const timespec) c_int;
10928pub extern "c" fn sem_getvalue(sem: *sem_t, sval: *c_int) c_int;
10929
10930pub const shm_open = switch (native_os) {
10931 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => darwin.shm_open,
10932 else => private.shm_open,
10933};
10934pub extern "c" fn shm_unlink(name: [*:0]const u8) c_int;
10935
10936pub extern "c" fn kqueue() c_int;
10937pub extern "c" fn kevent(
10938 kq: c_int,
10939 changelist: [*]const Kevent,
10940 nchanges: c_int,
10941 eventlist: [*]Kevent,
10942 nevents: c_int,
10943 timeout: ?*const timespec,
10944) c_int;
10945
10946pub extern "c" fn port_create() port_t;
10947pub extern "c" fn port_associate(
10948 port: port_t,
10949 source: u32,
10950 object: usize,
10951 events: u32,
10952 user_var: ?*anyopaque,
10953) c_int;
10954pub extern "c" fn port_dissociate(port: port_t, source: u32, object: usize) c_int;
10955pub extern "c" fn port_send(port: port_t, events: u32, user_var: ?*anyopaque) c_int;
10956pub extern "c" fn port_sendn(
10957 ports: [*]port_t,
10958 errors: []u32,
10959 num_ports: u32,
10960 events: u32,
10961 user_var: ?*anyopaque,
10962) c_int;
10963pub extern "c" fn port_get(port: port_t, event: *port_event, timeout: ?*timespec) c_int;
10964pub extern "c" fn port_getn(
10965 port: port_t,
10966 event_list: []port_event,
10967 max_events: u32,
10968 events_retrieved: *u32,
10969 timeout: ?*timespec,
10970) c_int;
10971pub extern "c" fn port_alert(port: port_t, flags: u32, events: u32, user_var: ?*anyopaque) c_int;
10972
10973pub extern "c" fn getaddrinfo(
10974 noalias node: ?[*:0]const u8,
10975 noalias service: ?[*:0]const u8,
10976 noalias hints: ?*const addrinfo,
10977 /// On Linux, `res` will not be modified on error and `freeaddrinfo` will
10978 /// potentially crash if you pass it an undefined pointer
10979 noalias res: *?*addrinfo,
10980) EAI;
10981
10982pub extern "c" fn freeaddrinfo(res: *addrinfo) void;
10983
10984pub extern "c" fn getnameinfo(
10985 noalias addr: *const sockaddr,
10986 addrlen: socklen_t,
10987 noalias host: ?[*]u8,
10988 hostlen: socklen_t,
10989 noalias serv: ?[*]u8,
10990 servlen: socklen_t,
10991 flags: NI,
10992) EAI;
10993
10994pub extern "c" fn gai_strerror(errcode: EAI) [*:0]const u8;
10995
10996pub extern "c" fn poll(fds: [*]pollfd, nfds: nfds_t, timeout: c_int) c_int;
10997pub extern "c" fn ppoll(fds: [*]pollfd, nfds: nfds_t, timeout: ?*const timespec, sigmask: ?*const sigset_t) c_int;
10998
10999pub extern "c" fn dn_expand(
11000 msg: [*:0]const u8,
11001 eomorig: [*:0]const u8,
11002 comp_dn: [*:0]const u8,
11003 exp_dn: [*:0]u8,
11004 length: c_int,
11005) c_int;
11006
11007pub const PTHREAD_PROCESS_PRIVATE: c_int = if (native_os.isDarwin())
11008 2
11009else
11010 0;
11011
11012pub const PTHREAD_PROCESS_SHARED: c_int = 1;
11013
11014pub extern "c" fn pthread_spin_init(spin: *pthread_spinlock_t, pshared: c_int) c_int;
11015pub extern "c" fn pthread_spin_lock(spin: *pthread_spinlock_t) c_int;
11016pub extern "c" fn pthread_spin_unlock(spin: *pthread_spinlock_t) c_int;
11017pub extern "c" fn pthread_spin_trylock(spin: *pthread_spinlock_t) c_int;
11018pub extern "c" fn pthread_spin_destroy(spin: *pthread_spinlock_t) c_int;
11019
11020pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = .{};
11021pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) E;
11022pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) E;
11023pub extern "c" fn pthread_mutex_trylock(mutex: *pthread_mutex_t) E;
11024pub extern "c" fn pthread_mutex_destroy(mutex: *pthread_mutex_t) E;
11025
11026pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = .{};
11027pub extern "c" fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) E;
11028pub extern "c" fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const timespec) E;
11029pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) E;
11030pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) E;
11031pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) E;
11032
11033pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.c) E;
11034pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.c) E;
11035pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.c) E;
11036pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.c) E;
11037pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.c) E;
11038pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.c) E;
11039
11040pub const pthread_t = switch (native_os) {
11041 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L64
11042 .serenity => c_int,
11043 else => *opaque {},
11044};
11045pub const FILE = opaque {};
11046
11047pub extern "c" fn dlopen(path: ?[*:0]const u8, mode: RTLD) ?*anyopaque;
11048pub extern "c" fn dlclose(handle: *anyopaque) c_int;
11049pub extern "c" fn dlsym(handle: ?*anyopaque, symbol: [*:0]const u8) ?*anyopaque;
11050pub extern "c" fn dlerror() ?[*:0]u8;
11051
11052pub const dladdr = if (native_os.isDarwin()) darwin.dladdr else {};
11053pub const dl_info = if (native_os.isDarwin()) darwin.dl_info else {};
11054
11055pub extern "c" fn sync() void;
11056pub extern "c" fn syncfs(fd: c_int) c_int;
11057pub extern "c" fn fsync(fd: c_int) c_int;
11058pub extern "c" fn fdatasync(fd: c_int) c_int;
11059
11060pub extern "c" fn prctl(option: c_int, ...) c_int;
11061
11062pub extern "c" fn getrlimit(resource: rlimit_resource, rlim: *rlimit) c_int;
11063pub extern "c" fn setrlimit(resource: rlimit_resource, rlim: *const rlimit) c_int;
11064
11065pub extern "c" fn fmemopen(noalias buf: ?*anyopaque, size: usize, noalias mode: [*:0]const u8) ?*FILE;
11066
11067pub extern "c" fn syslog(priority: c_int, message: [*:0]const u8, ...) void;
11068pub extern "c" fn openlog(ident: [*:0]const u8, logopt: c_int, facility: c_int) void;
11069pub extern "c" fn closelog() void;
11070pub extern "c" fn setlogmask(maskpri: c_int) c_int;
11071
11072pub extern "c" fn if_nametoindex([*:0]const u8) c_int;
11073
11074pub extern "c" fn getpid() pid_t;
11075pub extern "c" fn getppid() pid_t;
11076pub extern "c" fn setsid() pid_t;
11077
11078/// These are implementation defined but share identical values in at least musl and glibc:
11079/// - https://git.musl-libc.org/cgit/musl/tree/include/locale.h?id=ab31e9d6a0fa7c5c408856c89df2dfb12c344039#n18
11080/// - https://sourceware.org/git/?p=glibc.git;a=blob;f=locale/bits/locale.h;h=0fcbb66114be5fef0577dc9047256eb508c45919;hb=c90cfce849d010474e8cccf3e5bff49a2c8b141f#l26
11081pub const LC = enum(c_int) {
11082 CTYPE = 0,
11083 NUMERIC = 1,
11084 TIME = 2,
11085 COLLATE = 3,
11086 MONETARY = 4,
11087 MESSAGES = 5,
11088 ALL = 6,
11089 PAPER = 7,
11090 NAME = 8,
11091 ADDRESS = 9,
11092 TELEPHONE = 10,
11093 MEASUREMENT = 11,
11094 IDENTIFICATION = 12,
11095 _,
11096};
11097
11098pub extern "c" fn setlocale(category: LC, locale: ?[*:0]const u8) ?[*:0]const u8;
11099
11100pub const max_align_t = if (native_abi == .msvc or native_abi == .itanium)
11101 f64
11102else if (native_os.isDarwin())
11103 c_longdouble
11104else
11105 extern struct {
11106 a: c_longlong,
11107 b: c_longdouble,
11108 };
11109
11110pub const div_t = extern struct {
11111 quot: c_int,
11112 rem: c_int,
11113};
11114
11115pub const ldiv_t = extern struct {
11116 quot: c_long,
11117 rem: c_long,
11118};
11119
11120pub const lldiv_t = extern struct {
11121 quot: c_longlong,
11122 rem: c_longlong,
11123};
11124
11125pub const imaxdiv_t = extern struct {
11126 quot: intmax_t,
11127 rem: intmax_t,
11128};
11129
11130pub const intmax_t = i64;
11131pub const uintmax_t = u64;
11132
11133pub const wint_t = switch (builtin.target.os.tag) {
11134 .windows => u16,
11135 else => i32,
11136};
11137
11138pub const wchar_t = switch (builtin.target.os.tag) {
11139 .windows => u16,
11140 else => if (builtin.target.cpu.arch.isArm() or builtin.target.cpu.arch.isAARCH64()) u32 else i32,
11141};
11142
11143pub extern "c" fn pthread_getthreadid_np() c_int;
11144pub extern "c" fn pthread_set_name_np(thread: pthread_t, name: [*:0]const u8) void;
11145pub extern "c" fn pthread_get_name_np(thread: pthread_t, name: [*:0]u8, len: usize) void;
11146
11147pub const TIMER = switch (native_os) {
11148 .linux, .emscripten => std.os.linux.TIMER,
11149 .openbsd, .netbsd, .wasi, .windows, .freebsd, .serenity => packed struct(u32) {
11150 ABSTIME: bool,
11151 _: u31 = 0,
11152 },
11153 else => void,
11154};
11155
11156pub const clock_nanosleep = switch (native_os) {
11157 .linux, .emscripten, .netbsd, .wasi, .windows, .freebsd, .serenity => private.clock_nanosleep,
11158 else => {},
11159};
11160
11161pub const ioctl = switch (native_os) {
11162 .windows, .wasi => {},
11163 else => private.ioctl,
11164};
11165
11166pub extern "c" fn bzero(s: *anyopaque, n: usize) void;
11167
11168pub const swab = switch (builtin.abi) {
11169 .msvc => private._swab,
11170 else => private.swab,
11171};
11172
11173pub extern "c" fn strncmp(a: [*:0]const c_char, b: [*:0]const c_char, max: usize) c_int;
11174pub extern "c" fn strcasecmp(a: [*:0]const c_char, b: [*:0]const c_char) c_int;
11175pub extern "c" fn strncasecmp(a: [*:0]const c_char, b: [*:0]const c_char, max: usize) c_int;
11176pub const strdup = switch (builtin.abi) {
11177 .msvc => private._strdup,
11178 else => private.strdup,
11179};
11180pub extern "c" fn strndup(s: [*:0]const c_char, n: usize) ?[*:0]c_char;
11181pub const wcsdup = switch (builtin.abi) {
11182 .msvc => private._wcsdup,
11183 else => private.wcsdup,
11184};
11185
11186pub extern "c" fn ffs(i: c_int) c_int;
11187pub extern "c" fn ffsl(i: c_long) c_long;
11188pub extern "c" fn ffsll(i: c_longlong) c_longlong;
11189
11190pub extern "c" fn erand48(xsubi: *[3]c_ushort) f64;
11191pub extern "c" fn jrand48(xsubi: *[3]c_ushort) c_long;
11192pub extern "c" fn nrand48(xsubi: *[3]c_ushort) c_long;
11193
11194pub extern "c" fn insque(element: *anyopaque, pred: ?*anyopaque) void;
11195pub extern "c" fn remque(element: *anyopaque) void;
11196
11197pub extern "c" fn imaxabs(a: intmax_t) intmax_t;
11198pub extern "c" fn imaxdiv(a: intmax_t, b: intmax_t) imaxdiv_t;
11199
11200pub extern "c" fn abs(a: c_int) c_int;
11201pub extern "c" fn labs(a: c_long) c_long;
11202pub extern "c" fn llabs(a: c_longlong) c_longlong;
11203
11204pub extern "c" fn div(a: c_int, b: c_int) div_t;
11205pub extern "c" fn ldiv(a: c_long, b: c_long) ldiv_t;
11206pub extern "c" fn lldiv(a: c_longlong, b: c_longlong) lldiv_t;
11207
11208pub extern "c" fn atoi(str: [*:0]const c_char) c_int;
11209pub extern "c" fn atol(str: [*:0]const c_char) c_long;
11210pub extern "c" fn atoll(str: [*:0]const c_char) c_longlong;
11211
11212pub extern "c" fn strtol(noalias str: [*:0]const c_char, noalias str_end: ?*[*:0]c_char, base: c_int) callconv(.c) c_long;
11213pub extern "c" fn strtoll(noalias str: [*:0]const c_char, noalias str_end: ?*[*:0]c_char, base: c_int) callconv(.c) c_longlong;
11214pub extern "c" fn strtoul(noalias str: [*:0]const c_char, noalias str_end: ?*[*:0]c_char, base: c_int) callconv(.c) c_ulong;
11215pub extern "c" fn strtoull(noalias str: [*:0]const c_char, noalias str_end: ?*[*:0]c_char, base: c_int) callconv(.c) c_ulonglong;
11216pub extern "c" fn strtoimax(noalias str: [*:0]const c_char, noalias str_end: ?*[*:0]c_char, base: c_int) callconv(.c) intmax_t;
11217pub extern "c" fn strtoumax(noalias str: [*:0]const c_char, noalias str_end: ?*[*:0]c_char, base: c_int) callconv(.c) uintmax_t;
11218
11219pub extern "c" fn bsearch(
11220 key: *const anyopaque,
11221 base: *const anyopaque,
11222 n: usize,
11223 size: usize,
11224 compare: *const fn (a: *const anyopaque, b: *const anyopaque) callconv(.c) c_int,
11225) ?*anyopaque;
11226
11227// Math
11228pub extern "c" fn atan(x: f64) f64;
11229pub extern "c" fn copysign(x: f64, y: f64) f64;
11230pub extern "c" fn fdim(x: f64, y: f64) f64;
11231pub extern "c" fn frexp(x: f64, e: *c_int) f64;
11232pub extern "c" fn hypot(x: f64, y: f64) f64;
11233pub extern "c" fn modff(x: f32, iptr: *f32) f32;
11234pub extern "c" fn modf(x: f64, iptr: *f64) f64;
11235pub extern "c" fn modfl(x: c_longdouble, iptr: *c_longdouble) c_longdouble;
11236pub extern "c" fn rintf(x: f32) f32;
11237pub extern "c" fn rint(x: f64) f64;
11238pub extern "c" fn rintl(x: c_longdouble) c_longdouble;
11239
11240// OS-specific bits. These are protected from being used on the wrong OS by
11241// comptime assertions inside each OS-specific file.
11242
11243pub const AF_SUN = illumos.AF_SUN;
11244pub const AT_SUN = illumos.AT_SUN;
11245pub const FILE_EVENT = illumos.FILE_EVENT;
11246pub const GETCONTEXT = illumos.GETCONTEXT;
11247pub const GETUSTACK = illumos.GETUSTACK;
11248pub const PORT_ALERT = illumos.PORT_ALERT;
11249pub const PORT_SOURCE = illumos.PORT_SOURCE;
11250pub const POSIX_FADV = illumos.POSIX_FADV;
11251pub const SETCONTEXT = illumos.SETCONTEXT;
11252pub const SETUSTACK = illumos.GETUSTACK;
11253pub const SFD = illumos.SFD;
11254pub const ctid_t = illumos.ctid_t;
11255pub const file_obj = illumos.file_obj;
11256pub const id_t = illumos.id_t;
11257pub const lif_ifinfo_req = illumos.lif_ifinfo_req;
11258pub const lif_nd_req = illumos.lif_nd_req;
11259pub const lifreq = illumos.lifreq;
11260pub const major_t = illumos.major_t;
11261pub const minor_t = illumos.minor_t;
11262pub const poolid_t = illumos.poolid_t;
11263pub const port_notify = illumos.port_notify;
11264pub const priority = illumos.priority;
11265pub const procfs = illumos.procfs;
11266pub const projid_t = illumos.projid_t;
11267pub const signalfd_siginfo = illumos.signalfd_siginfo;
11268pub const taskid_t = illumos.taskid_t;
11269pub const zoneid_t = illumos.zoneid_t;
11270
11271pub const B_ABSOLUTE_TIMEOUT = haiku.B_ABSOLUTE_TIMEOUT;
11272pub const B_OS_NAME_LENGTH = haiku.B_OS_NAME_LENGTH;
11273pub const B_TIMEOUT_REAL_TIME_BASE = haiku.B_TIMEOUT_REAL_TIME_BASE;
11274pub const DirEnt = haiku.DirEnt;
11275pub const _kern_acquire_sem_etc = haiku._kern_acquire_sem_etc;
11276pub const _kern_create_sem = haiku._kern_create_sem;
11277pub const _kern_delete_sem = haiku._kern_delete_sem;
11278pub const _kern_open_dir = haiku._kern_open_dir;
11279pub const _kern_read_dir = haiku._kern_read_dir;
11280pub const _kern_read_stat = haiku._kern_read_stat;
11281pub const _kern_release_sem_etc = haiku._kern_release_sem_etc;
11282pub const _kern_rewind_dir = haiku._kern_rewind_dir;
11283pub const area_id = haiku.area_id;
11284pub const find_thread = haiku.find_thread;
11285pub const get_system_info = haiku.get_system_info;
11286pub const on_exit_thread = haiku.on_exit_thread;
11287pub const port_id = haiku.port_id;
11288pub const readv_pos = haiku.readv_pos;
11289pub const sem_id = haiku.sem_id;
11290pub const status_t = haiku.status_t;
11291pub const system_info = haiku.system_info;
11292pub const team_id = haiku.team_id;
11293pub const thread_id = haiku.thread_id;
11294pub const writev_pos = haiku.writev_pos;
11295
11296pub const AUTH = openbsd.AUTH;
11297pub const BI = openbsd.BI;
11298pub const HW = openbsd.HW;
11299pub const PTHREAD_STACK_MIN = openbsd.PTHREAD_STACK_MIN;
11300pub const TCFLUSH = openbsd.TCFLUSH;
11301pub const TCIO = openbsd.TCIO;
11302pub const auth_approval = openbsd.auth_approval;
11303pub const auth_call = openbsd.auth_call;
11304pub const auth_cat = openbsd.auth_cat;
11305pub const auth_challenge = openbsd.auth_challenge;
11306pub const auth_check_change = openbsd.auth_check_change;
11307pub const auth_check_expire = openbsd.auth_check_expire;
11308pub const auth_checknologin = openbsd.auth_checknologin;
11309pub const auth_clean = openbsd.auth_clean;
11310pub const auth_close = openbsd.auth_close;
11311pub const auth_clrenv = openbsd.auth_clrenv;
11312pub const auth_clroption = openbsd.auth_clroption;
11313pub const auth_clroptions = openbsd.auth_clroptions;
11314pub const auth_getitem = openbsd.auth_getitem;
11315pub const auth_getpwd = openbsd.auth_getpwd;
11316pub const auth_getstate = openbsd.auth_getstate;
11317pub const auth_getvalue = openbsd.auth_getvalue;
11318pub const auth_item_t = openbsd.auth_item_t;
11319pub const auth_mkvalue = openbsd.auth_mkvalue;
11320pub const auth_open = openbsd.auth_open;
11321pub const auth_session_t = openbsd.auth_session_t;
11322pub const auth_setdata = openbsd.auth_setdata;
11323pub const auth_setenv = openbsd.auth_setenv;
11324pub const auth_setitem = openbsd.auth_setitem;
11325pub const auth_setoption = openbsd.auth_setoption;
11326pub const auth_setpwd = openbsd.auth_setpwd;
11327pub const auth_setstate = openbsd.auth_setstate;
11328pub const auth_userchallenge = openbsd.auth_userchallenge;
11329pub const auth_usercheck = openbsd.auth_usercheck;
11330pub const auth_userokay = openbsd.auth_userokay;
11331pub const auth_userresponse = openbsd.auth_userresponse;
11332pub const auth_verify = openbsd.auth_verify;
11333pub const bcrypt = openbsd.bcrypt;
11334pub const bcrypt_checkpass = openbsd.bcrypt_checkpass;
11335pub const bcrypt_gensalt = openbsd.bcrypt_gensalt;
11336pub const bcrypt_newhash = openbsd.bcrypt_newhash;
11337pub const getpwnam_shadow = openbsd.getpwnam_shadow;
11338pub const getpwuid_shadow = openbsd.getpwuid_shadow;
11339pub const getthrid = openbsd.getthrid;
11340pub const login_cap_t = openbsd.login_cap_t;
11341pub const login_close = openbsd.login_close;
11342pub const login_getcapbool = openbsd.login_getcapbool;
11343pub const login_getcapnum = openbsd.login_getcapnum;
11344pub const login_getcapsize = openbsd.login_getcapsize;
11345pub const login_getcapstr = openbsd.login_getcapstr;
11346pub const login_getcaptime = openbsd.login_getcaptime;
11347pub const login_getclass = openbsd.login_getclass;
11348pub const login_getstyle = openbsd.login_getstyle;
11349pub const pledge = openbsd.pledge;
11350pub const pw_dup = openbsd.pw_dup;
11351pub const setclasscontext = openbsd.setclasscontext;
11352pub const setpassent = openbsd.setpassent;
11353pub const setusercontext = openbsd.setusercontext;
11354pub const uid_from_user = openbsd.uid_from_user;
11355pub const unveil = openbsd.unveil;
11356pub const user_from_uid = openbsd.user_from_uid;
11357
11358pub const CAP_RIGHTS_VERSION = freebsd.CAP_RIGHTS_VERSION;
11359pub const KINFO_FILE_SIZE = freebsd.KINFO_FILE_SIZE;
11360pub const UMTX_ABSTIME = freebsd.UMTX_ABSTIME;
11361pub const UMTX_OP = freebsd.UMTX_OP;
11362pub const _umtx_op = freebsd._umtx_op;
11363pub const _umtx_time = freebsd._umtx_time;
11364pub const cap_rights = freebsd.cap_rights;
11365pub const fflags_t = freebsd.fflags_t;
11366pub const fsblkcnt_t = freebsd.fsblkcnt_t;
11367pub const fsfilcnt_t = freebsd.fsfilcnt_t;
11368pub const kinfo_file = freebsd.kinfo_file;
11369pub const kinfo_getfile = freebsd.kinfo_getfile;
11370
11371pub const CALENDAR_CLOCK = darwin.CALENDAR_CLOCK;
11372pub const COPYFILE = darwin.COPYFILE;
11373pub const CPUFAMILY = darwin.CPUFAMILY;
11374pub const PT = darwin.PT;
11375pub const DB_RECORDTYPE = darwin.DB_RECORDTYPE;
11376pub const EXC = darwin.EXC;
11377pub const EXCEPTION = darwin.EXCEPTION;
11378pub const KEVENT = darwin.KEVENT;
11379pub const MACH = darwin.MACH;
11380pub const MACH_MSG_TYPE = darwin.MACH_MSG_TYPE;
11381pub const MACH_PORT_RIGHT = darwin.MACH_PORT_RIGHT;
11382pub const MACH_TASK_BASIC_INFO = darwin.MACH_TASK_BASIC_INFO;
11383pub const MACH_TASK_BASIC_INFO_COUNT = darwin.MACH_TASK_BASIC_INFO_COUNT;
11384pub const MATTR = darwin.MATTR;
11385pub const NSVersionOfRunTimeLibrary = darwin.NSVersionOfRunTimeLibrary;
11386pub const OPEN_MAX = darwin.OPEN_MAX;
11387pub const OS = darwin.OS;
11388pub const POSIX_SPAWN = darwin.POSIX_SPAWN;
11389pub const SYSPROTO_EVENT = darwin.SYSPROTO_EVENT;
11390pub const SYSPROTO_CONTROL = darwin.SYSPROTO_CONTROL;
11391pub const TASK = darwin.TASK;
11392pub const TASK_NULL = darwin.TASK_NULL;
11393pub const TASK_VM_INFO = darwin.TASK_VM_INFO;
11394pub const TASK_VM_INFO_COUNT = darwin.TASK_VM_INFO_COUNT;
11395pub const THREAD = darwin.THREAD;
11396pub const THREAD_BASIC_INFO = darwin.THREAD_BASIC_INFO;
11397pub const THREAD_BASIC_INFO_COUNT = darwin.THREAD_BASIC_INFO_COUNT;
11398pub const THREAD_IDENTIFIER_INFO_COUNT = darwin.THREAD_IDENTIFIER_INFO_COUNT;
11399pub const THREAD_NULL = darwin.THREAD_NULL;
11400pub const THREAD_STATE_NONE = darwin.THREAD_STATE_NONE;
11401pub const UL = darwin.UL;
11402pub const VM = darwin.VM;
11403pub const _NSGetExecutablePath = darwin._NSGetExecutablePath;
11404pub const __getdirentries64 = darwin.__getdirentries64;
11405pub const __ulock_wait = darwin.__ulock_wait;
11406pub const __ulock_wait2 = darwin.__ulock_wait2;
11407pub const __ulock_wake = darwin.__ulock_wake;
11408pub const _dyld_get_image_header = darwin._dyld_get_image_header;
11409pub const _dyld_get_image_name = darwin._dyld_get_image_name;
11410pub const _dyld_get_image_vmaddr_slide = darwin._dyld_get_image_vmaddr_slide;
11411pub const _dyld_image_count = darwin._dyld_image_count;
11412pub const _dyld_get_image_header_containing_address = darwin._dyld_get_image_header_containing_address;
11413pub const dyld_image_path_containing_address = darwin.dyld_image_path_containing_address;
11414pub const _host_page_size = darwin._host_page_size;
11415pub const boolean_t = darwin.boolean_t;
11416pub const clock_get_time = darwin.clock_get_time;
11417pub const clock_serv_t = darwin.clock_serv_t;
11418pub const clock_res_t = darwin.clock_res_t;
11419pub const @"close$NOCANCEL" = darwin.@"close$NOCANCEL";
11420pub const dispatch = darwin.dispatch;
11421pub const fcopyfile = darwin.fcopyfile;
11422pub const renameatx_np = darwin.renameatx_np;
11423pub const host_t = darwin.host_t;
11424pub const integer_t = darwin.integer_t;
11425pub const ipc_space_t = darwin.ipc_space_t;
11426pub const ipc_space_port_t = darwin.ipc_space_port_t;
11427pub const kern_return_t = darwin.kern_return_t;
11428pub const vm_size_t = darwin.vm_size_t;
11429pub const kevent64 = darwin.kevent64;
11430pub const kevent64_s = darwin.kevent64_s;
11431pub const mach_absolute_time = darwin.mach_absolute_time;
11432pub const mach_continuous_time = darwin.mach_continuous_time;
11433pub const mach_hdr = darwin.mach_hdr;
11434pub const mach_host_self = darwin.mach_host_self;
11435pub const mach_msg = darwin.mach_msg;
11436pub const mach_msg_return_t = darwin.mach_msg_return_t;
11437pub const mach_msg_type_number_t = darwin.mach_msg_type_number_t;
11438pub const mach_port_allocate = darwin.mach_port_allocate;
11439pub const mach_port_array_t = darwin.mach_port_array_t;
11440pub const mach_port_deallocate = darwin.mach_port_deallocate;
11441pub const mach_port_insert_right = darwin.mach_port_insert_right;
11442pub const mach_port_name_t = darwin.mach_port_name_t;
11443pub const mach_port_t = darwin.mach_port_t;
11444pub const mach_task_basic_info = darwin.mach_task_basic_info;
11445pub const mach_task_self = darwin.mach_task_self;
11446pub const mach_timebase_info = darwin.mach_timebase_info;
11447pub const mach_timebase_info_data = darwin.mach_timebase_info_data;
11448pub const mach_timespec_t = darwin.mach_timespec_t;
11449pub const mach_vm_address_t = darwin.mach_vm_address_t;
11450pub const mach_vm_protect = darwin.mach_vm_protect;
11451pub const mach_vm_read = darwin.mach_vm_read;
11452pub const mach_vm_region = darwin.mach_vm_region;
11453pub const mach_vm_region_recurse = darwin.mach_vm_region_recurse;
11454pub const mach_vm_size_t = darwin.mach_vm_size_t;
11455pub const mach_vm_write = darwin.mach_vm_write;
11456pub const natural_t = darwin.natural_t;
11457pub const os_log_create = darwin.os_log_create;
11458pub const os_log_t = darwin.os_log_t;
11459pub const os_log_type_enabled = darwin.os_log_type_enabled;
11460pub const os_log_type_t = darwin.os_log_type_t;
11461pub const os_signpost_enabled = darwin.os_signpost_enabled;
11462pub const os_signpost_id_generate = darwin.os_signpost_id_generate;
11463pub const os_signpost_id_make_with_pointer = darwin.os_signpost_id_make_with_pointer;
11464pub const os_signpost_id_t = darwin.os_signpost_id_t;
11465pub const os_signpost_interval_begin = darwin.os_signpost_interval_begin;
11466pub const os_signpost_interval_end = darwin.os_signpost_interval_end;
11467pub const os_unfair_lock = darwin.os_unfair_lock;
11468pub const os_unfair_lock_assert_not_owner = darwin.os_unfair_lock_assert_not_owner;
11469pub const os_unfair_lock_assert_owner = darwin.os_unfair_lock_assert_owner;
11470pub const os_unfair_lock_lock = darwin.os_unfair_lock_lock;
11471pub const os_unfair_lock_t = darwin.os_unfair_lock_t;
11472pub const os_unfair_lock_trylock = darwin.os_unfair_lock_trylock;
11473pub const os_unfair_lock_unlock = darwin.os_unfair_lock_unlock;
11474pub const pid_for_task = darwin.pid_for_task;
11475pub const posix_spawn = darwin.posix_spawn;
11476pub const posix_spawn_file_actions_addchdir_np = darwin.posix_spawn_file_actions_addchdir_np;
11477pub const posix_spawn_file_actions_addclose = darwin.posix_spawn_file_actions_addclose;
11478pub const posix_spawn_file_actions_adddup2 = darwin.posix_spawn_file_actions_adddup2;
11479pub const posix_spawn_file_actions_addfchdir_np = darwin.posix_spawn_file_actions_addfchdir_np;
11480pub const posix_spawn_file_actions_addinherit_np = darwin.posix_spawn_file_actions_addinherit_np;
11481pub const posix_spawn_file_actions_addopen = darwin.posix_spawn_file_actions_addopen;
11482pub const posix_spawn_file_actions_destroy = darwin.posix_spawn_file_actions_destroy;
11483pub const posix_spawn_file_actions_init = darwin.posix_spawn_file_actions_init;
11484pub const posix_spawn_file_actions_t = darwin.posix_spawn_file_actions_t;
11485pub const posix_spawnattr_destroy = darwin.posix_spawnattr_destroy;
11486pub const posix_spawnattr_getflags = darwin.posix_spawnattr_getflags;
11487pub const posix_spawnattr_init = darwin.posix_spawnattr_init;
11488pub const posix_spawnattr_setflags = darwin.posix_spawnattr_setflags;
11489pub const posix_spawnattr_t = darwin.posix_spawnattr_t;
11490pub const posix_spawnp = darwin.posix_spawnp;
11491pub const pthread_attr_get_qos_class_np = darwin.pthread_attr_get_qos_class_np;
11492pub const pthread_attr_set_qos_class_np = darwin.pthread_attr_set_qos_class_np;
11493pub const pthread_get_qos_class_np = darwin.pthread_get_qos_class_np;
11494pub const pthread_set_qos_class_self_np = darwin.pthread_set_qos_class_self_np;
11495pub const qos_class_t = darwin.qos_class_t;
11496pub const task_flavor_t = darwin.task_flavor_t;
11497pub const task_for_pid = darwin.task_for_pid;
11498pub const task_get_exception_ports = darwin.task_get_exception_ports;
11499pub const task_info = darwin.task_info;
11500pub const task_info_t = darwin.task_info_t;
11501pub const task_name_t = darwin.task_name_t;
11502pub const task_resume = darwin.task_resume;
11503pub const task_set_exception_ports = darwin.task_set_exception_ports;
11504pub const task_suspend = darwin.task_suspend;
11505pub const task_threads = darwin.task_threads;
11506pub const task_vm_info_data_t = darwin.task_vm_info_data_t;
11507pub const thread_basic_info = darwin.thread_basic_info;
11508pub const thread_get_state = darwin.thread_get_state;
11509pub const thread_identifier_info = darwin.thread_identifier_info;
11510pub const thread_info = darwin.thread_info;
11511pub const thread_info_t = darwin.thread_info_t;
11512pub const thread_resume = darwin.thread_resume;
11513pub const thread_set_state = darwin.thread_set_state;
11514pub const vm_address_t = darwin.vm_address_t;
11515pub const vm_deallocate = darwin.vm_deallocate;
11516pub const vm_machine_attribute = darwin.vm_machine_attribute;
11517pub const vm_machine_attribute_t = darwin.vm_machine_attribute_t;
11518pub const vm_machine_attribute_val_t = darwin.vm_machine_attribute_val_t;
11519pub const vm_map_t = darwin.vm_map_t;
11520pub const vm_offset_t = darwin.vm_offset_t;
11521pub const vm_prot_t = darwin.vm_prot_t;
11522pub const vm_region_basic_info_64 = darwin.vm_region_basic_info_64;
11523pub const vm_region_extended_info = darwin.vm_region_extended_info;
11524pub const vm_region_info_t = darwin.vm_region_info_t;
11525pub const vm_region_recurse_info_t = darwin.vm_region_recurse_info_t;
11526pub const vm_region_submap_info_64 = darwin.vm_region_submap_info_64;
11527pub const vm_region_submap_short_info_64 = darwin.vm_region_submap_short_info_64;
11528pub const vm_region_top_info = darwin.vm_region_top_info;
11529
11530pub const exception_behavior_array_t = darwin.exception_behavior_array_t;
11531pub const exception_behavior_t = darwin.exception_behavior_t;
11532pub const exception_data_t = darwin.exception_data_t;
11533pub const exception_data_type_t = darwin.exception_data_type_t;
11534pub const exception_flavor_array_t = darwin.exception_flavor_array_t;
11535pub const exception_handler_array_t = darwin.exception_handler_array_t;
11536pub const exception_handler_t = darwin.exception_handler_t;
11537pub const exception_mask_array_t = darwin.exception_mask_array_t;
11538pub const exception_mask_t = darwin.exception_mask_t;
11539pub const exception_port_array_t = darwin.exception_port_array_t;
11540pub const exception_port_t = darwin.exception_port_t;
11541pub const exception_type_t = darwin.exception_type_t;
11542pub const mach_exception_data_t = darwin.mach_exception_data_t;
11543pub const mach_exception_data_type_t = darwin.mach_exception_data_type_t;
11544pub const mach_msg_bits_t = darwin.mach_msg_bits_t;
11545pub const mach_msg_id_t = darwin.mach_msg_id_t;
11546pub const mach_msg_header_t = darwin.mach_msg_header_t;
11547pub const mach_msg_option_t = darwin.mach_msg_option_t;
11548pub const mach_msg_size_t = darwin.mach_msg_size_t;
11549pub const mach_msg_timeout_t = darwin.mach_msg_timeout_t;
11550pub const mach_msg_type_name_t = darwin.mach_msg_type_name_t;
11551pub const mach_port_right_t = darwin.mach_port_right_t;
11552pub const memory_object_offset_t = darwin.memory_object_offset_t;
11553pub const policy_t = darwin.policy_t;
11554pub const task_policy_flavor_t = darwin.task_policy_flavor_t;
11555pub const task_policy_t = darwin.task_policy_t;
11556pub const task_read_t = darwin.task_read_t;
11557pub const task_t = darwin.task_t;
11558pub const thread_act_t = darwin.thread_act_t;
11559pub const thread_flavor_t = darwin.thread_flavor_t;
11560pub const thread_port_t = darwin.thread_port_t;
11561pub const thread_state_flavor_t = darwin.thread_state_flavor_t;
11562pub const thread_state_t = darwin.thread_state_t;
11563pub const thread_t = darwin.thread_t;
11564pub const time_value_t = darwin.time_value_t;
11565pub const vm32_object_id_t = darwin.vm32_object_id_t;
11566pub const vm_behavior_t = darwin.vm_behavior_t;
11567pub const vm_inherit_t = darwin.vm_inherit_t;
11568pub const vm_map_read_t = darwin.vm_map_read_t;
11569pub const vm_object_id_t = darwin.vm_object_id_t;
11570pub const vm_region_flavor_t = darwin.vm_region_flavor_t;
11571
11572pub const _ksiginfo = netbsd._ksiginfo;
11573pub const _lwp_self = netbsd._lwp_self;
11574pub const _lwp_park = netbsd.___lwp_park60;
11575pub const _lwp_unpark = netbsd._lwp_unpark;
11576pub const _lwp_unpark_all = netbsd._lwp_unpark_all;
11577pub const lwpid_t = netbsd.lwpid_t;
11578
11579pub const lwp_gettid = dragonfly.lwp_gettid;
11580pub const umtx_sleep = dragonfly.umtx_sleep;
11581pub const umtx_wakeup = dragonfly.umtx_wakeup;
11582
11583pub const PERF_EVENT = serenity.PERF_EVENT;
11584pub const disown = serenity.disown;
11585pub const profiling_enable = serenity.profiling_enable;
11586pub const profiling_disable = serenity.profiling_disable;
11587pub const profiling_free_buffer = serenity.profiling_free_buffer;
11588pub const purge = serenity.purge;
11589pub const perf_event = serenity.perf_event;
11590pub const perf_register_string = serenity.perf_register_string;
11591pub const get_stack_bounds = serenity.get_stack_bounds;
11592pub const anon_create = serenity.anon_create;
11593pub const getkeymap = serenity.getkeymap;
11594pub const setkeymap = serenity.setkeymap;
11595
11596/// External definitions shared by two or more operating systems.
11597const private = struct {
11598 pub extern "c" fn strdup(s: [*:0]const c_char) ?[*:0]c_char;
11599 pub extern "c" fn _strdup(s: [*:0]const c_char) ?[*:0]c_char;
11600 pub extern "c" fn wcsdup(s: [*:0]const wchar_t) ?[*:0]wchar_t;
11601 pub extern "c" fn _wcsdup(s: [*:0]const wchar_t) ?[*:0]wchar_t;
11602
11603 pub extern "c" fn swab(noalias from: *const anyopaque, noalias to: *anyopaque, n: isize) void;
11604 pub extern "c" fn _swab(noalias from: *const anyopaque, noalias to: *anyopaque, n: isize) void;
11605
11606 extern "c" fn close(fd: fd_t) c_int;
11607 extern "c" fn clock_getres(clk_id: clockid_t, tp: *timespec) c_int;
11608 extern "c" fn clock_gettime(clk_id: clockid_t, tp: *timespec) c_int;
11609 extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: c_uint) isize;
11610 extern "c" fn flock(fd: fd_t, operation: c_int) c_int;
11611 extern "c" fn fork() c_int;
11612 extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
11613 extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, buf: *Stat, flag: u32) c_int;
11614 extern "c" fn getdirentries(fd: fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
11615 extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) switch (native_os) {
11616 .freebsd => isize,
11617 .illumos => usize,
11618 else => c_int,
11619 };
11620 extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
11621 extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
11622 extern "c" fn ioctl(fd: fd_t, request: c_int, ...) c_int;
11623 extern "c" fn msync(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int;
11624 extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
11625 extern "c" fn clock_nanosleep(clockid: clockid_t, flags: TIMER, t: *const timespec, remain: ?*timespec) c_int;
11626 extern "c" fn pipe2(fds: *[2]fd_t, flags: O) c_int;
11627 extern "c" fn readdir(dir: *DIR) ?*dirent;
11628 extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
11629 extern "c" fn recvmsg(sockfd: fd_t, msg: *msghdr, flags: u32) isize;
11630 extern "c" fn sched_yield() c_int;
11631 extern "c" fn sendfile(out_fd: fd_t, in_fd: fd_t, offset: ?*off_t, count: usize) isize;
11632 extern "c" fn sigaction(sig: SIG, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
11633 extern "c" fn sigdelset(set: ?*sigset_t, signo: SIG) c_int;
11634 extern "c" fn sigaddset(set: ?*sigset_t, signo: SIG) c_int;
11635 extern "c" fn sigfillset(set: ?*sigset_t) c_int;
11636 extern "c" fn sigemptyset(set: ?*sigset_t) c_int;
11637 extern "c" fn sigismember(set: ?*const sigset_t, signo: SIG) c_int;
11638 extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
11639 extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
11640 extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]fd_t) c_int;
11641 extern "c" fn sigaltstack(ss: ?*const stack_t, old_ss: ?*stack_t) c_int;
11642 extern "c" fn sysconf(sc: c_int) c_long;
11643 extern "c" fn shm_open(name: [*:0]const u8, flag: c_int, mode: mode_t) c_int;
11644 extern "c" fn wait4(pid: pid_t, status: ?*c_int, options: c_int, ru: ?*rusage) pid_t;
11645
11646 extern "c" fn pthread_setname_np(thread: pthread_t, name: [*:0]const u8) c_int;
11647
11648 extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
11649 extern "c" fn getentropy(buffer: [*]u8, size: usize) c_int;
11650 extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
11651
11652 extern "c" fn _msize(?*const anyopaque) usize;
11653 extern "c" fn malloc_size(?*const anyopaque) usize;
11654 extern "c" fn malloc_usable_size(?*const anyopaque) usize;
11655 extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
11656
11657 extern "c" fn mlock(addr: *align(page_size) const anyopaque, len: usize) c_int;
11658 extern "c" fn mlock2(addr: *align(page_size) const anyopaque, len: usize, flags: MLOCK) c_int;
11659 extern "c" fn munlock(addr: *align(page_size) const anyopaque, len: usize) c_int;
11660 extern "c" fn mlockall(flags: MCL) c_int;
11661 extern "c" fn munlockall() c_int;
11662
11663 // linux and https://github.com/SerenityOS/serenity/blob/502caef9a40bccc7459f9835f2174a601106299a/Userland/Libraries/LibC/sys/ptrace.cpp
11664 extern "c" fn ptrace(request: c_int, pid: pid_t, addr: ?*anyopaque, data: ?*anyopaque) c_long;
11665
11666 /// macos modernized symbols.
11667 /// x86_64 links to $INODE64 suffix for 64-bit support.
11668 /// Note these are not necessary on aarch64.
11669 extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;
11670 extern "c" fn @"fstatat$INODE64"(dirfd: fd_t, path: [*:0]const u8, buf: *Stat, flag: u32) c_int;
11671 extern "c" fn @"readdir$INODE64"(dir: *DIR) ?*dirent;
11672 extern "c" fn @"stat$INODE64"(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
11673 extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
11674
11675 /// macos modernized symbols.
11676 extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
11677 extern "c" fn __getdirentries64(fd: fd_t, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
11678
11679 extern "c" fn pthread_threadid_np(thread: ?pthread_t, thread_id: *u64) c_int;
11680
11681 /// netbsd modernized symbols.
11682 extern "c" fn __clock_getres50(clk_id: clockid_t, tp: *timespec) c_int;
11683 extern "c" fn __clock_gettime50(clk_id: clockid_t, tp: *timespec) c_int;
11684 extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int;
11685 extern "c" fn __getrusage50(who: c_int, usage: *rusage) c_int;
11686 extern "c" fn __gettimeofday50(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
11687 extern "c" fn __libc_thr_yield() c_int;
11688 extern "c" fn __msync13(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int;
11689 extern "c" fn __nanosleep50(rqtp: *const timespec, rmtp: ?*timespec) c_int;
11690 extern "c" fn __sigaction14(sig: SIG, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
11691 extern "c" fn __sigemptyset14(set: ?*sigset_t) c_int;
11692 extern "c" fn __sigfillset14(set: ?*sigset_t) c_int;
11693 extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
11694 extern "c" fn __socket30(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
11695 extern "c" fn __stat50(path: [*:0]const u8, buf: *Stat) c_int;
11696 extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
11697 extern "c" fn __sigaltstack14(ss: ?*const stack_t, old_ss: ?*stack_t) c_int;
11698 extern "c" fn __wait450(pid: pid_t, status: ?*c_int, options: c_int, ru: ?*rusage) pid_t;
11699
11700 extern "c" fn __libc_current_sigrtmin() c_int;
11701 extern "c" fn __libc_current_sigrtmax() c_int;
11702 extern "c" fn __signal_get_sigrtmin() c_int;
11703 extern "c" fn __signal_get_sigrtmax() c_int;
11704
11705 // Don't forget to add another clown when an OS picks yet another unique
11706 // symbol name for errno location!
11707 // 🤡🤡🤡🤡🤡🤡
11708
11709 extern "c" fn ___errno() *c_int;
11710 extern "c" fn __errno() *c_int;
11711 extern "c" fn __errno_location() *c_int;
11712 extern "c" fn __error() *c_int;
11713 extern "c" fn _errno() *c_int;
11714
11715 extern threadlocal var errno: c_int;
11716
11717 fn errnoFromThreadLocal() *c_int {
11718 return &private.errno;
11719 }
11720};