1const std = @import("std");
2const builtin = @import("builtin");
3const wasi = std.os.wasi;
4const linux = std.os.linux;
5const iovec = std.posix.iovec;
6const iovec_const = std.posix.iovec_const;
7const c = std.c;
8
9// TODO: go through this file and delete all the bits that are identical to linux because they can
10// be merged in the std.c namespace.
11
12pub const FILE = c.FILE;
13
14pub const PF = linux.PF;
15pub const AF = linux.AF;
16pub const CLOCK = linux.CLOCK;
17
18pub const CPU_SETSIZE = 128;
19pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;
20pub const cpu_count_t = @Int(.unsigned, std.math.log2(CPU_SETSIZE * 8));
21
22pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
23 var sum: cpu_count_t = 0;
24 for (set) |x| {
25 sum += @popCount(x);
26 }
27 return sum;
28}
29
30pub const E = enum(u16) {
31 SUCCESS = @backingInt(wasi.errno_t.SUCCESS),
32 @"2BIG" = @backingInt(wasi.errno_t.@"2BIG"),
33 ACCES = @backingInt(wasi.errno_t.ACCES),
34 ADDRINUSE = @backingInt(wasi.errno_t.ADDRINUSE),
35 ADDRNOTAVAIL = @backingInt(wasi.errno_t.ADDRNOTAVAIL),
36 AFNOSUPPORT = @backingInt(wasi.errno_t.AFNOSUPPORT),
37 /// This is also the error code used for `WOULDBLOCK`.
38 AGAIN = @backingInt(wasi.errno_t.AGAIN),
39 ALREADY = @backingInt(wasi.errno_t.ALREADY),
40 BADF = @backingInt(wasi.errno_t.BADF),
41 BADMSG = @backingInt(wasi.errno_t.BADMSG),
42 BUSY = @backingInt(wasi.errno_t.BUSY),
43 CANCELED = @backingInt(wasi.errno_t.CANCELED),
44 CHILD = @backingInt(wasi.errno_t.CHILD),
45 CONNABORTED = @backingInt(wasi.errno_t.CONNABORTED),
46 CONNREFUSED = @backingInt(wasi.errno_t.CONNREFUSED),
47 CONNRESET = @backingInt(wasi.errno_t.CONNRESET),
48 DEADLK = @backingInt(wasi.errno_t.DEADLK),
49 DESTADDRREQ = @backingInt(wasi.errno_t.DESTADDRREQ),
50 DOM = @backingInt(wasi.errno_t.DOM),
51 DQUOT = @backingInt(wasi.errno_t.DQUOT),
52 EXIST = @backingInt(wasi.errno_t.EXIST),
53 FAULT = @backingInt(wasi.errno_t.FAULT),
54 FBIG = @backingInt(wasi.errno_t.FBIG),
55 HOSTUNREACH = @backingInt(wasi.errno_t.HOSTUNREACH),
56 IDRM = @backingInt(wasi.errno_t.IDRM),
57 ILSEQ = @backingInt(wasi.errno_t.ILSEQ),
58 INPROGRESS = @backingInt(wasi.errno_t.INPROGRESS),
59 INTR = @backingInt(wasi.errno_t.INTR),
60 INVAL = @backingInt(wasi.errno_t.INVAL),
61 IO = @backingInt(wasi.errno_t.IO),
62 ISCONN = @backingInt(wasi.errno_t.ISCONN),
63 ISDIR = @backingInt(wasi.errno_t.ISDIR),
64 LOOP = @backingInt(wasi.errno_t.LOOP),
65 MFILE = @backingInt(wasi.errno_t.MFILE),
66 MLINK = @backingInt(wasi.errno_t.MLINK),
67 MSGSIZE = @backingInt(wasi.errno_t.MSGSIZE),
68 MULTIHOP = @backingInt(wasi.errno_t.MULTIHOP),
69 NAMETOOLONG = @backingInt(wasi.errno_t.NAMETOOLONG),
70 NETDOWN = @backingInt(wasi.errno_t.NETDOWN),
71 NETRESET = @backingInt(wasi.errno_t.NETRESET),
72 NETUNREACH = @backingInt(wasi.errno_t.NETUNREACH),
73 NFILE = @backingInt(wasi.errno_t.NFILE),
74 NOBUFS = @backingInt(wasi.errno_t.NOBUFS),
75 NODEV = @backingInt(wasi.errno_t.NODEV),
76 NOENT = @backingInt(wasi.errno_t.NOENT),
77 NOEXEC = @backingInt(wasi.errno_t.NOEXEC),
78 NOLCK = @backingInt(wasi.errno_t.NOLCK),
79 NOLINK = @backingInt(wasi.errno_t.NOLINK),
80 NOMEM = @backingInt(wasi.errno_t.NOMEM),
81 NOMSG = @backingInt(wasi.errno_t.NOMSG),
82 NOPROTOOPT = @backingInt(wasi.errno_t.NOPROTOOPT),
83 NOSPC = @backingInt(wasi.errno_t.NOSPC),
84 NOSYS = @backingInt(wasi.errno_t.NOSYS),
85 NOTCONN = @backingInt(wasi.errno_t.NOTCONN),
86 NOTDIR = @backingInt(wasi.errno_t.NOTDIR),
87 NOTEMPTY = @backingInt(wasi.errno_t.NOTEMPTY),
88 NOTRECOVERABLE = @backingInt(wasi.errno_t.NOTRECOVERABLE),
89 NOTSOCK = @backingInt(wasi.errno_t.NOTSOCK),
90 /// This is also the code used for `NOTSUP`.
91 OPNOTSUPP = @backingInt(wasi.errno_t.OPNOTSUPP),
92 NOTTY = @backingInt(wasi.errno_t.NOTTY),
93 NXIO = @backingInt(wasi.errno_t.NXIO),
94 OVERFLOW = @backingInt(wasi.errno_t.OVERFLOW),
95 OWNERDEAD = @backingInt(wasi.errno_t.OWNERDEAD),
96 PERM = @backingInt(wasi.errno_t.PERM),
97 PIPE = @backingInt(wasi.errno_t.PIPE),
98 PROTO = @backingInt(wasi.errno_t.PROTO),
99 PROTONOSUPPORT = @backingInt(wasi.errno_t.PROTONOSUPPORT),
100 PROTOTYPE = @backingInt(wasi.errno_t.PROTOTYPE),
101 RANGE = @backingInt(wasi.errno_t.RANGE),
102 ROFS = @backingInt(wasi.errno_t.ROFS),
103 SPIPE = @backingInt(wasi.errno_t.SPIPE),
104 SRCH = @backingInt(wasi.errno_t.SRCH),
105 STALE = @backingInt(wasi.errno_t.STALE),
106 TIMEDOUT = @backingInt(wasi.errno_t.TIMEDOUT),
107 TXTBSY = @backingInt(wasi.errno_t.TXTBSY),
108 XDEV = @backingInt(wasi.errno_t.XDEV),
109 NOTCAPABLE = @backingInt(wasi.errno_t.NOTCAPABLE),
110
111 ENOSTR = 100,
112 EBFONT = 101,
113 EBADSLT = 102,
114 EBADRQC = 103,
115 ENOANO = 104,
116 ENOTBLK = 105,
117 ECHRNG = 106,
118 EL3HLT = 107,
119 EL3RST = 108,
120 ELNRNG = 109,
121 EUNATCH = 110,
122 ENOCSI = 111,
123 EL2HLT = 112,
124 EBADE = 113,
125 EBADR = 114,
126 EXFULL = 115,
127 ENODATA = 116,
128 ETIME = 117,
129 ENOSR = 118,
130 ENONET = 119,
131 ENOPKG = 120,
132 EREMOTE = 121,
133 EADV = 122,
134 ESRMNT = 123,
135 ECOMM = 124,
136 EDOTDOT = 125,
137 ENOTUNIQ = 126,
138 EBADFD = 127,
139 EREMCHG = 128,
140 ELIBACC = 129,
141 ELIBBAD = 130,
142 ELIBSCN = 131,
143 ELIBMAX = 132,
144 ELIBEXEC = 133,
145 ERESTART = 134,
146 ESTRPIPE = 135,
147 EUSERS = 136,
148 ESOCKTNOSUPPORT = 137,
149 EOPNOTSUPP = 138,
150 EPFNOSUPPORT = 139,
151 ESHUTDOWN = 140,
152 ETOOMANYREFS = 141,
153 EHOSTDOWN = 142,
154 EUCLEAN = 143,
155 ENOTNAM = 144,
156 ENAVAIL = 145,
157 EISNAM = 146,
158 EREMOTEIO = 147,
159 ENOMEDIUM = 148,
160 EMEDIUMTYPE = 149,
161 ENOKEY = 150,
162 EKEYEXPIRED = 151,
163 EKEYREVOKED = 152,
164 EKEYREJECTED = 153,
165 ERFKILL = 154,
166 EHWPOISON = 155,
167 EL2NSYNC = 156,
168 _,
169};
170
171pub const F = struct {
172 pub const DUPFD = 0;
173 pub const GETFD = 1;
174 pub const SETFD = 2;
175 pub const GETFL = 3;
176 pub const SETFL = 4;
177 pub const SETOWN = 8;
178 pub const GETOWN = 9;
179 pub const SETSIG = 10;
180 pub const GETSIG = 11;
181 pub const GETLK = 12;
182 pub const SETLK = 13;
183 pub const SETLKW = 14;
184 pub const SETOWN_EX = 15;
185 pub const GETOWN_EX = 16;
186 pub const GETOWNER_UIDS = 17;
187
188 pub const RDLCK = 0;
189 pub const WRLCK = 1;
190 pub const UNLCK = 2;
191};
192
193pub const FD_CLOEXEC = 1;
194
195pub const F_OK = 0;
196pub const X_OK = 1;
197pub const W_OK = 2;
198pub const R_OK = 4;
199
200pub const W = struct {
201 pub const NOHANG = 1;
202 pub const UNTRACED = 2;
203 pub const STOPPED = 2;
204 pub const EXITED = 4;
205 pub const CONTINUED = 8;
206 pub const NOWAIT = 0x1000000;
207
208 pub fn EXITSTATUS(s: u32) u8 {
209 return @as(u8, @intCast((s & 0xff00) >> 8));
210 }
211 pub fn TERMSIG(s: u32) SIG {
212 return @fromBackingInt(@intCast(s & 0x7f));
213 }
214 pub fn STOPSIG(s: u32) SIG {
215 return @fromBackingInt(@intCast(EXITSTATUS(s)));
216 }
217 pub fn IFEXITED(s: u32) bool {
218 return (s & 0x7f) == 0;
219 }
220 pub fn IFSTOPPED(s: u32) bool {
221 return @as(u16, @truncate(((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
222 }
223 pub fn IFSIGNALED(s: u32) bool {
224 return (s & 0xffff) -% 1 < 0xff;
225 }
226};
227
228pub const Flock = extern struct {
229 type: i16,
230 whence: i16,
231 start: off_t,
232 len: off_t,
233 pid: pid_t,
234};
235
236pub const IFNAMESIZE = 16;
237
238pub const NAME_MAX = 255;
239pub const PATH_MAX = 4096;
240pub const IOV_MAX = 1024;
241
242pub const IPPORT_RESERVED = 1024;
243
244pub const IPPROTO = linux.IPPROTO;
245
246pub const LOCK = struct {
247 pub const SH = 1;
248 pub const EX = 2;
249 pub const NB = 4;
250 pub const UN = 8;
251};
252
253pub const MADV = struct {
254 pub const NORMAL = 0;
255 pub const RANDOM = 1;
256 pub const SEQUENTIAL = 2;
257 pub const WILLNEED = 3;
258 pub const DONTNEED = 4;
259 pub const FREE = 8;
260 pub const REMOVE = 9;
261 pub const DONTFORK = 10;
262 pub const DOFORK = 11;
263 pub const MERGEABLE = 12;
264 pub const UNMERGEABLE = 13;
265 pub const HUGEPAGE = 14;
266 pub const NOHUGEPAGE = 15;
267 pub const DONTDUMP = 16;
268 pub const DODUMP = 17;
269 pub const WIPEONFORK = 18;
270 pub const KEEPONFORK = 19;
271 pub const COLD = 20;
272 pub const PAGEOUT = 21;
273 pub const HWPOISON = 100;
274 pub const SOFT_OFFLINE = 101;
275};
276
277pub const MSF = struct {
278 pub const ASYNC = 1;
279 pub const INVALIDATE = 2;
280 pub const SYNC = 4;
281};
282
283pub const MSG = struct {
284 pub const OOB = 0x0001;
285 pub const PEEK = 0x0002;
286 pub const DONTROUTE = 0x0004;
287 pub const CTRUNC = 0x0008;
288 pub const PROXY = 0x0010;
289 pub const TRUNC = 0x0020;
290 pub const DONTWAIT = 0x0040;
291 pub const EOR = 0x0080;
292 pub const WAITALL = 0x0100;
293 pub const FIN = 0x0200;
294 pub const SYN = 0x0400;
295 pub const CONFIRM = 0x0800;
296 pub const RST = 0x1000;
297 pub const ERRQUEUE = 0x2000;
298 pub const NOSIGNAL = 0x4000;
299 pub const MORE = 0x8000;
300 pub const WAITFORONE = 0x10000;
301 pub const BATCH = 0x40000;
302 pub const ZEROCOPY = 0x4000000;
303 pub const FASTOPEN = 0x20000000;
304 pub const CMSG_CLOEXEC = 0x40000000;
305};
306
307pub const POLL = struct {
308 pub const IN = 0x001;
309 pub const PRI = 0x002;
310 pub const OUT = 0x004;
311 pub const ERR = 0x008;
312 pub const HUP = 0x010;
313 pub const NVAL = 0x020;
314 pub const RDNORM = 0x040;
315 pub const RDBAND = 0x080;
316};
317
318pub const PROT = packed struct(u32) {
319 READ: bool = false,
320 WRITE: bool = false,
321 EXEC: bool = false,
322 _: u21 = 0,
323 GROWSDOWN: bool = false,
324 GROWSUP: bool = false,
325 __: u6 = 0,
326};
327
328pub const rlim_t = u64;
329
330pub const RLIM = struct {
331 pub const INFINITY = ~@as(rlim_t, 0);
332
333 pub const SAVED_MAX = INFINITY;
334 pub const SAVED_CUR = INFINITY;
335};
336
337pub const rlimit = c.rlimit;
338
339pub const rlimit_resource = enum(c_int) {
340 CPU,
341 FSIZE,
342 DATA,
343 STACK,
344 CORE,
345 RSS,
346 NPROC,
347 NOFILE,
348 MEMLOCK,
349 AS,
350 LOCKS,
351 SIGPENDING,
352 MSGQUEUE,
353 NICE,
354 RTPRIO,
355 RTTIME,
356 _,
357};
358
359pub const rusage = extern struct {
360 utime: timeval,
361 stime: timeval,
362 maxrss: isize,
363 ixrss: isize,
364 idrss: isize,
365 isrss: isize,
366 minflt: isize,
367 majflt: isize,
368 nswap: isize,
369 inblock: isize,
370 oublock: isize,
371 msgsnd: isize,
372 msgrcv: isize,
373 nsignals: isize,
374 nvcsw: isize,
375 nivcsw: isize,
376 __reserved: [16]isize = @splat(0),
377
378 pub const SELF = 0;
379 pub const CHILDREN = -1;
380 pub const THREAD = 1;
381};
382
383pub const timeval = extern struct {
384 sec: i64,
385 usec: i32,
386};
387
388pub const S = struct {
389 pub const IFMT = 0o170000;
390
391 pub const IFDIR = 0o040000;
392 pub const IFCHR = 0o020000;
393 pub const IFBLK = 0o060000;
394 pub const IFREG = 0o100000;
395 pub const IFIFO = 0o010000;
396 pub const IFLNK = 0o120000;
397 pub const IFSOCK = 0o140000;
398
399 pub const ISUID = 0o4000;
400 pub const ISGID = 0o2000;
401 pub const ISVTX = 0o1000;
402 pub const IRUSR = 0o400;
403 pub const IWUSR = 0o200;
404 pub const IXUSR = 0o100;
405 pub const IRWXU = 0o700;
406 pub const IRGRP = 0o040;
407 pub const IWGRP = 0o020;
408 pub const IXGRP = 0o010;
409 pub const IRWXG = 0o070;
410 pub const IROTH = 0o004;
411 pub const IWOTH = 0o002;
412 pub const IXOTH = 0o001;
413 pub const IRWXO = 0o007;
414
415 pub fn ISREG(m: mode_t) bool {
416 return m & IFMT == IFREG;
417 }
418
419 pub fn ISDIR(m: mode_t) bool {
420 return m & IFMT == IFDIR;
421 }
422
423 pub fn ISCHR(m: mode_t) bool {
424 return m & IFMT == IFCHR;
425 }
426
427 pub fn ISBLK(m: mode_t) bool {
428 return m & IFMT == IFBLK;
429 }
430
431 pub fn ISFIFO(m: mode_t) bool {
432 return m & IFMT == IFIFO;
433 }
434
435 pub fn ISLNK(m: mode_t) bool {
436 return m & IFMT == IFLNK;
437 }
438
439 pub fn ISSOCK(m: mode_t) bool {
440 return m & IFMT == IFSOCK;
441 }
442};
443
444pub const SA = struct {
445 pub const NOCLDSTOP = 1;
446 pub const NOCLDWAIT = 2;
447 pub const SIGINFO = 4;
448 pub const RESTART = 0x10000000;
449 pub const RESETHAND = 0x80000000;
450 pub const ONSTACK = 0x08000000;
451 pub const NODEFER = 0x40000000;
452 pub const RESTORER = 0x04000000;
453};
454
455pub const SEEK = struct {
456 pub const SET = 0;
457 pub const CUR = 1;
458 pub const END = 2;
459};
460
461pub const SHUT = struct {
462 pub const RD = 0;
463 pub const WR = 1;
464 pub const RDWR = 2;
465};
466
467pub const SIG = linux.SIG;
468
469pub const Sigaction = extern struct {
470 pub const handler_fn = *align(1) const fn (SIG) callconv(.c) void;
471 pub const sigaction_fn = *const fn (SIG, *const siginfo_t, ?*anyopaque) callconv(.c) void;
472
473 handler: extern union {
474 handler: ?handler_fn,
475 sigaction: ?sigaction_fn,
476 },
477 mask: sigset_t,
478 flags: c_uint,
479 restorer: ?*const fn () callconv(.c) void = null,
480};
481
482pub const sigset_t = [1024 / 32]u32;
483pub fn sigemptyset() sigset_t {
484 return @splat(0);
485}
486pub const siginfo_t = extern struct {
487 signo: SIG,
488 errno: i32,
489 code: i32,
490 fields: siginfo_fields_union,
491};
492const siginfo_fields_union = extern union {
493 pad: [128 - 2 * @sizeOf(c_int) - @sizeOf(c_long)]u8,
494 common: extern struct {
495 first: extern union {
496 piduid: extern struct {
497 pid: pid_t,
498 uid: uid_t,
499 },
500 timer: extern struct {
501 timerid: i32,
502 overrun: i32,
503 },
504 },
505 second: extern union {
506 value: sigval,
507 sigchld: extern struct {
508 status: i32,
509 utime: clock_t,
510 stime: clock_t,
511 },
512 },
513 },
514 sigfault: extern struct {
515 addr: *allowzero anyopaque,
516 addr_lsb: i16,
517 first: extern union {
518 addr_bnd: extern struct {
519 lower: *anyopaque,
520 upper: *anyopaque,
521 },
522 pkey: u32,
523 },
524 },
525 sigpoll: extern struct {
526 band: isize,
527 fd: i32,
528 },
529 sigsys: extern struct {
530 call_addr: *anyopaque,
531 syscall: i32,
532 native_arch: u32,
533 },
534};
535pub const sigval = extern union {
536 int: i32,
537 ptr: *anyopaque,
538};
539
540pub const SIOCGIFINDEX = 0x8933;
541
542pub const SO = struct {
543 pub const DEBUG = 1;
544 pub const REUSEADDR = 2;
545 pub const TYPE = 3;
546 pub const ERROR = 4;
547 pub const DONTROUTE = 5;
548 pub const BROADCAST = 6;
549 pub const SNDBUF = 7;
550 pub const RCVBUF = 8;
551 pub const KEEPALIVE = 9;
552 pub const OOBINLINE = 10;
553 pub const NO_CHECK = 11;
554 pub const PRIORITY = 12;
555 pub const LINGER = 13;
556 pub const BSDCOMPAT = 14;
557 pub const REUSEPORT = 15;
558 pub const PASSCRED = 16;
559 pub const PEERCRED = 17;
560 pub const RCVLOWAT = 18;
561 pub const SNDLOWAT = 19;
562 pub const RCVTIMEO = 20;
563 pub const SNDTIMEO = 21;
564 pub const ACCEPTCONN = 30;
565 pub const PEERSEC = 31;
566 pub const SNDBUFFORCE = 32;
567 pub const RCVBUFFORCE = 33;
568 pub const PROTOCOL = 38;
569 pub const DOMAIN = 39;
570 pub const SECURITY_AUTHENTICATION = 22;
571 pub const SECURITY_ENCRYPTION_TRANSPORT = 23;
572 pub const SECURITY_ENCRYPTION_NETWORK = 24;
573 pub const BINDTODEVICE = 25;
574 pub const ATTACH_FILTER = 26;
575 pub const DETACH_FILTER = 27;
576 pub const GET_FILTER = ATTACH_FILTER;
577 pub const PEERNAME = 28;
578 pub const TIMESTAMP_OLD = 29;
579 pub const PASSSEC = 34;
580 pub const TIMESTAMPNS_OLD = 35;
581 pub const MARK = 36;
582 pub const TIMESTAMPING_OLD = 37;
583 pub const RXQ_OVFL = 40;
584 pub const WIFI_STATUS = 41;
585 pub const PEEK_OFF = 42;
586 pub const NOFCS = 43;
587 pub const LOCK_FILTER = 44;
588 pub const SELECT_ERR_QUEUE = 45;
589 pub const BUSY_POLL = 46;
590 pub const MAX_PACING_RATE = 47;
591 pub const BPF_EXTENSIONS = 48;
592 pub const INCOMING_CPU = 49;
593 pub const ATTACH_BPF = 50;
594 pub const DETACH_BPF = DETACH_FILTER;
595 pub const ATTACH_REUSEPORT_CBPF = 51;
596 pub const ATTACH_REUSEPORT_EBPF = 52;
597 pub const CNX_ADVICE = 53;
598 pub const MEMINFO = 55;
599 pub const INCOMING_NAPI_ID = 56;
600 pub const COOKIE = 57;
601 pub const PEERGROUPS = 59;
602 pub const ZEROCOPY = 60;
603 pub const TXTIME = 61;
604 pub const BINDTOIFINDEX = 62;
605 pub const TIMESTAMP_NEW = 63;
606 pub const TIMESTAMPNS_NEW = 64;
607 pub const TIMESTAMPING_NEW = 65;
608 pub const RCVTIMEO_NEW = 66;
609 pub const SNDTIMEO_NEW = 67;
610 pub const DETACH_REUSEPORT_BPF = 68;
611};
612
613pub const SOCK = struct {
614 pub const STREAM = 1;
615 pub const DGRAM = 2;
616 pub const RAW = 3;
617 pub const RDM = 4;
618 pub const SEQPACKET = 5;
619 pub const DCCP = 6;
620 pub const PACKET = 10;
621 pub const CLOEXEC = 0o2000000;
622 pub const NONBLOCK = 0o4000;
623};
624
625pub const SOL = struct {
626 pub const SOCKET = 1;
627
628 pub const IP = 0;
629 pub const IPV6 = 41;
630 pub const ICMPV6 = 58;
631
632 pub const RAW = 255;
633 pub const DECNET = 261;
634 pub const X25 = 262;
635 pub const PACKET = 263;
636 pub const ATM = 264;
637 pub const AAL = 265;
638 pub const IRDA = 266;
639 pub const NETBEUI = 267;
640 pub const LLC = 268;
641 pub const DCCP = 269;
642 pub const NETLINK = 270;
643 pub const TIPC = 271;
644 pub const RXRPC = 272;
645 pub const PPPOL2TP = 273;
646 pub const BLUETOOTH = 274;
647 pub const PNPIPE = 275;
648 pub const RDS = 276;
649 pub const IUCV = 277;
650 pub const CAIF = 278;
651 pub const ALG = 279;
652 pub const NFC = 280;
653 pub const KCM = 281;
654 pub const TLS = 282;
655 pub const XDP = 283;
656};
657
658pub const STDIN_FILENO = 0;
659pub const STDOUT_FILENO = 1;
660pub const STDERR_FILENO = 2;
661
662pub const TCP = struct {
663 pub const NODELAY = 1;
664 pub const MAXSEG = 2;
665 pub const CORK = 3;
666 pub const KEEPIDLE = 4;
667 pub const KEEPINTVL = 5;
668 pub const KEEPCNT = 6;
669 pub const SYNCNT = 7;
670 pub const LINGER2 = 8;
671 pub const DEFER_ACCEPT = 9;
672 pub const WINDOW_CLAMP = 10;
673 pub const INFO = 11;
674 pub const QUICKACK = 12;
675 pub const CONGESTION = 13;
676 pub const MD5SIG = 14;
677 pub const THIN_LINEAR_TIMEOUTS = 16;
678 pub const THIN_DUPACK = 17;
679 pub const USER_TIMEOUT = 18;
680 pub const REPAIR = 19;
681 pub const REPAIR_QUEUE = 20;
682 pub const QUEUE_SEQ = 21;
683 pub const REPAIR_OPTIONS = 22;
684 pub const FASTOPEN = 23;
685 pub const TIMESTAMP = 24;
686 pub const NOTSENT_LOWAT = 25;
687 pub const CC_INFO = 26;
688 pub const SAVE_SYN = 27;
689 pub const SAVED_SYN = 28;
690 pub const REPAIR_WINDOW = 29;
691 pub const FASTOPEN_CONNECT = 30;
692 pub const ULP = 31;
693 pub const MD5SIG_EXT = 32;
694 pub const FASTOPEN_KEY = 33;
695 pub const FASTOPEN_NO_COOKIE = 34;
696 pub const ZEROCOPY_RECEIVE = 35;
697 pub const INQ = 36;
698 pub const CM_INQ = INQ;
699 pub const TX_DELAY = 37;
700
701 pub const REPAIR_ON = 1;
702 pub const REPAIR_OFF = 0;
703 pub const REPAIR_OFF_NO_WP = -1;
704};
705
706pub const TCSA = std.posix.TCSA;
707pub const addrinfo = c.addrinfo;
708
709pub const in_port_t = c.in_port_t;
710pub const sa_family_t = c.sa_family_t;
711pub const socklen_t = c.socklen_t;
712pub const sockaddr = c.sockaddr;
713
714pub const blksize_t = i32;
715pub const nlink_t = u32;
716// https://github.com/emscripten-core/emscripten/blob/946ab574ae39401b51e75cd5257d894ae732ab54/system/lib/libc/musl/arch/emscripten/bits/alltypes.h#L140
717pub const time_t = c_longlong;
718pub const mode_t = u32;
719pub const off_t = i64;
720pub const ino_t = u64;
721pub const dev_t = u32;
722pub const blkcnt_t = i32;
723
724pub const pid_t = i32;
725pub const fd_t = c.fd_t;
726pub const uid_t = u32;
727pub const gid_t = u32;
728pub const clock_t = i32;
729
730pub const dl_phdr_info = extern struct {
731 addr: usize,
732 name: ?[*:0]const u8,
733 phdr: [*]std.elf.ElfN.Phdr,
734 phnum: u16,
735};
736
737pub const msghdr = std.c.msghdr;
738pub const msghdr_const = std.c.msghdr;
739
740pub const nfds_t = usize;
741pub const pollfd = extern struct {
742 fd: fd_t,
743 events: i16,
744 revents: i16 = undefined,
745};
746
747pub const stack_t = extern struct {
748 sp: [*]u8,
749 flags: i32,
750 size: usize,
751};
752
753/// For use with `utimensat` and `futimens`.
754// https://github.com/emscripten-core/emscripten/blob/d72d7226f4733af8ff993dec70198cf09a24142d/system/lib/libc/musl/include/sys/stat.h#L77-L78
755pub const UTIME = struct {
756 pub const NOW: timespec = .{ .sec = 0, .nsec = 0x3fffffff };
757 pub const OMIT: timespec = .{ .sec = 0, .nsec = 0x3ffffffe };
758};
759
760// https://github.com/emscripten-core/emscripten/blob/946ab574ae39401b51e75cd5257d894ae732ab54/system/lib/libc/musl/arch/emscripten/bits/alltypes.h#L284
761pub const timespec = extern struct {
762 sec: time_t,
763 nsec: c_long,
764};
765
766pub const timezone = extern struct {
767 minuteswest: c_int,
768 dsttime: c_int,
769};
770
771pub const utsname = extern struct {
772 sysname: [64:0]u8,
773 nodename: [64:0]u8,
774 release: [64:0]u8,
775 version: [64:0]u8,
776 machine: [64:0]u8,
777 domainname: [64:0]u8,
778};
779
780pub const Stat = extern struct {
781 dev: dev_t,
782 mode: mode_t,
783 nlink: nlink_t,
784 uid: uid_t,
785 gid: gid_t,
786 rdev: dev_t,
787 size: off_t,
788 blksize: blksize_t,
789 blocks: blkcnt_t,
790 atim: timespec,
791 mtim: timespec,
792 ctim: timespec,
793 ino: ino_t,
794
795 pub fn atime(self: @This()) timespec {
796 return self.atim;
797 }
798
799 pub fn mtime(self: @This()) timespec {
800 return self.mtim;
801 }
802
803 pub fn ctime(self: @This()) timespec {
804 return self.ctim;
805 }
806};
807
808pub const TIMING = struct {
809 pub const SETTIMEOUT = 0;
810 pub const RAF = 1;
811 pub const SETIMMEDIATE = 2;
812};
813
814pub const LOG = struct {
815 pub const CONSOLE = 1;
816 pub const WARN = 2;
817 pub const ERROR = 4;
818 pub const C_STACK = 8;
819 pub const JS_STACK = 16;
820 pub const DEMANGLE = 32;
821 pub const NO_PATHS = 64;
822 pub const FUNC_PARAMS = 128;
823 pub const DEBUG = 256;
824 pub const INFO = 512;
825};
826
827pub const em_callback_func = ?*const fn () callconv(.c) void;
828pub const em_arg_callback_func = ?*const fn (?*anyopaque) callconv(.c) void;
829pub const em_str_callback_func = ?*const fn ([*:0]const u8) callconv(.c) void;
830
831pub extern "c" fn emscripten_async_wget(url: [*:0]const u8, file: [*:0]const u8, onload: em_str_callback_func, onerror: em_str_callback_func) void;
832
833pub const em_async_wget_onload_func = ?*const fn (?*anyopaque, ?*anyopaque, c_int) callconv(.c) void;
834pub extern "c" fn emscripten_async_wget_data(url: [*:0]const u8, arg: ?*anyopaque, onload: em_async_wget_onload_func, onerror: em_arg_callback_func) void;
835
836pub const em_async_wget2_onload_func = ?*const fn (c_uint, ?*anyopaque, [*:0]const u8) callconv(.c) void;
837pub const em_async_wget2_onstatus_func = ?*const fn (c_uint, ?*anyopaque, c_int) callconv(.c) void;
838
839pub extern "c" fn emscripten_async_wget2(url: [*:0]const u8, file: [*:0]const u8, requesttype: [*:0]const u8, param: [*:0]const u8, arg: ?*anyopaque, onload: em_async_wget2_onload_func, onerror: em_async_wget2_onstatus_func, onprogress: em_async_wget2_onstatus_func) c_int;
840
841pub const em_async_wget2_data_onload_func = ?*const fn (c_uint, ?*anyopaque, ?*anyopaque, c_uint) callconv(.c) void;
842pub const em_async_wget2_data_onerror_func = ?*const fn (c_uint, ?*anyopaque, c_int, [*:0]const u8) callconv(.c) void;
843pub const em_async_wget2_data_onprogress_func = ?*const fn (c_uint, ?*anyopaque, c_int, c_int) callconv(.c) void;
844
845pub extern "c" fn emscripten_async_wget2_data(url: [*:0]const u8, requesttype: [*:0]const u8, param: [*:0]const u8, arg: ?*anyopaque, free: c_int, onload: em_async_wget2_data_onload_func, onerror: em_async_wget2_data_onerror_func, onprogress: em_async_wget2_data_onprogress_func) c_int;
846pub extern "c" fn emscripten_async_wget2_abort(handle: c_int) void;
847pub extern "c" fn emscripten_wget(url: [*:0]const u8, file: [*:0]const u8) c_int;
848pub extern "c" fn emscripten_wget_data(url: [*:0]const u8, pbuffer: *(?*anyopaque), pnum: *c_int, perror: *c_int) void;
849pub extern "c" fn emscripten_run_script(script: [*:0]const u8) void;
850pub extern "c" fn emscripten_run_script_int(script: [*:0]const u8) c_int;
851pub extern "c" fn emscripten_run_script_string(script: [*:0]const u8) ?[*:0]u8;
852pub extern "c" fn emscripten_async_run_script(script: [*:0]const u8, millis: c_int) void;
853pub extern "c" fn emscripten_async_load_script(script: [*:0]const u8, onload: em_callback_func, onerror: em_callback_func) void;
854pub extern "c" fn emscripten_set_main_loop(func: em_callback_func, fps: c_int, simulate_infinite_loop: c_int) void;
855pub extern "c" fn emscripten_set_main_loop_timing(mode: c_int, value: c_int) c_int;
856pub extern "c" fn emscripten_get_main_loop_timing(mode: *c_int, value: *c_int) void;
857pub extern "c" fn emscripten_set_main_loop_arg(func: em_arg_callback_func, arg: ?*anyopaque, fps: c_int, simulate_infinite_loop: c_int) void;
858pub extern "c" fn emscripten_pause_main_loop() void;
859pub extern "c" fn emscripten_resume_main_loop() void;
860pub extern "c" fn emscripten_cancel_main_loop() void;
861
862pub const em_socket_callback = ?*const fn (c_int, ?*anyopaque) callconv(.c) void;
863pub const em_socket_error_callback = ?*const fn (c_int, c_int, [*:0]const u8, ?*anyopaque) callconv(.c) void;
864
865pub extern "c" fn emscripten_set_socket_error_callback(userData: ?*anyopaque, callback: em_socket_error_callback) void;
866pub extern "c" fn emscripten_set_socket_open_callback(userData: ?*anyopaque, callback: em_socket_callback) void;
867pub extern "c" fn emscripten_set_socket_listen_callback(userData: ?*anyopaque, callback: em_socket_callback) void;
868pub extern "c" fn emscripten_set_socket_connection_callback(userData: ?*anyopaque, callback: em_socket_callback) void;
869pub extern "c" fn emscripten_set_socket_message_callback(userData: ?*anyopaque, callback: em_socket_callback) void;
870pub extern "c" fn emscripten_set_socket_close_callback(userData: ?*anyopaque, callback: em_socket_callback) void;
871pub extern "c" fn _emscripten_push_main_loop_blocker(func: em_arg_callback_func, arg: ?*anyopaque, name: [*:0]const u8) void;
872pub extern "c" fn _emscripten_push_uncounted_main_loop_blocker(func: em_arg_callback_func, arg: ?*anyopaque, name: [*:0]const u8) void;
873pub extern "c" fn emscripten_set_main_loop_expected_blockers(num: c_int) void;
874pub extern "c" fn emscripten_async_call(func: em_arg_callback_func, arg: ?*anyopaque, millis: c_int) void;
875pub extern "c" fn emscripten_exit_with_live_runtime() noreturn;
876pub extern "c" fn emscripten_force_exit(status: c_int) noreturn;
877pub extern "c" fn emscripten_get_device_pixel_ratio() f64;
878pub extern "c" fn emscripten_get_window_title() [*:0]u8;
879pub extern "c" fn emscripten_set_window_title([*:0]const u8) void;
880pub extern "c" fn emscripten_get_screen_size(width: *c_int, height: *c_int) void;
881pub extern "c" fn emscripten_hide_mouse() void;
882pub extern "c" fn emscripten_set_canvas_size(width: c_int, height: c_int) void;
883pub extern "c" fn emscripten_get_canvas_size(width: *c_int, height: *c_int, isFullscreen: *c_int) void;
884pub extern "c" fn emscripten_get_now() f64;
885pub extern "c" fn emscripten_num_logical_cores() c_int;
886pub extern "c" fn emscripten_random() f32;
887pub const em_idb_onload_func = ?*const fn (?*anyopaque, ?*anyopaque, c_int) callconv(.c) void;
888pub extern "c" fn emscripten_idb_async_load(db_name: [*:0]const u8, file_id: [*:0]const u8, arg: ?*anyopaque, onload: em_idb_onload_func, onerror: em_arg_callback_func) void;
889pub extern "c" fn emscripten_idb_async_store(db_name: [*:0]const u8, file_id: [*:0]const u8, ptr: ?*anyopaque, num: c_int, arg: ?*anyopaque, onstore: em_arg_callback_func, onerror: em_arg_callback_func) void;
890pub extern "c" fn emscripten_idb_async_delete(db_name: [*:0]const u8, file_id: [*:0]const u8, arg: ?*anyopaque, ondelete: em_arg_callback_func, onerror: em_arg_callback_func) void;
891pub const em_idb_exists_func = ?*const fn (?*anyopaque, c_int) callconv(.c) void;
892pub extern "c" fn emscripten_idb_async_exists(db_name: [*:0]const u8, file_id: [*:0]const u8, arg: ?*anyopaque, oncheck: em_idb_exists_func, onerror: em_arg_callback_func) void;
893pub extern "c" fn emscripten_idb_load(db_name: [*:0]const u8, file_id: [*:0]const u8, pbuffer: *?*anyopaque, pnum: *c_int, perror: *c_int) void;
894pub extern "c" fn emscripten_idb_store(db_name: [*:0]const u8, file_id: [*:0]const u8, buffer: *anyopaque, num: c_int, perror: *c_int) void;
895pub extern "c" fn emscripten_idb_delete(db_name: [*:0]const u8, file_id: [*:0]const u8, perror: *c_int) void;
896pub extern "c" fn emscripten_idb_exists(db_name: [*:0]const u8, file_id: [*:0]const u8, pexists: *c_int, perror: *c_int) void;
897pub extern "c" fn emscripten_idb_load_blob(db_name: [*:0]const u8, file_id: [*:0]const u8, pblob: *c_int, perror: *c_int) void;
898pub extern "c" fn emscripten_idb_store_blob(db_name: [*:0]const u8, file_id: [*:0]const u8, buffer: *anyopaque, num: c_int, perror: *c_int) void;
899pub extern "c" fn emscripten_idb_read_from_blob(blob: c_int, start: c_int, num: c_int, buffer: ?*anyopaque) void;
900pub extern "c" fn emscripten_idb_free_blob(blob: c_int) void;
901pub extern "c" fn emscripten_run_preload_plugins(file: [*:0]const u8, onload: em_str_callback_func, onerror: em_str_callback_func) c_int;
902pub const em_run_preload_plugins_data_onload_func = ?*const fn (?*anyopaque, [*:0]const u8) callconv(.c) void;
903pub extern "c" fn emscripten_run_preload_plugins_data(data: [*]u8, size: c_int, suffix: [*:0]const u8, arg: ?*anyopaque, onload: em_run_preload_plugins_data_onload_func, onerror: em_arg_callback_func) void;
904pub extern "c" fn emscripten_lazy_load_code() void;
905pub const worker_handle = c_int;
906pub extern "c" fn emscripten_create_worker(url: [*:0]const u8) worker_handle;
907pub extern "c" fn emscripten_destroy_worker(worker: worker_handle) void;
908pub const em_worker_callback_func = ?*const fn ([*]u8, c_int, ?*anyopaque) callconv(.c) void;
909pub extern "c" fn emscripten_call_worker(worker: worker_handle, funcname: [*:0]const u8, data: [*]u8, size: c_int, callback: em_worker_callback_func, arg: ?*anyopaque) void;
910pub extern "c" fn emscripten_worker_respond(data: [*]u8, size: c_int) void;
911pub extern "c" fn emscripten_worker_respond_provisionally(data: [*]u8, size: c_int) void;
912pub extern "c" fn emscripten_get_worker_queue_size(worker: worker_handle) c_int;
913pub extern "c" fn emscripten_get_compiler_setting(name: [*:0]const u8) c_long;
914pub extern "c" fn emscripten_has_asyncify() c_int;
915pub extern "c" fn emscripten_debugger() void;
916
917pub extern "c" fn emscripten_get_preloaded_image_data(path: [*:0]const u8, w: *c_int, h: *c_int) ?[*]u8;
918pub extern "c" fn emscripten_get_preloaded_image_data_from_FILE(file: *FILE, w: *c_int, h: *c_int) ?[*]u8;
919pub extern "c" fn emscripten_log(flags: c_int, format: [*:0]const u8, ...) void;
920pub extern "c" fn emscripten_get_callstack(flags: c_int, out: ?[*]u8, maxbytes: c_int) c_int;
921pub extern "c" fn emscripten_print_double(x: f64, to: ?[*]u8, max: c_int) c_int;
922pub const em_scan_func = ?*const fn (?*anyopaque, ?*anyopaque) callconv(.c) void;
923pub extern "c" fn emscripten_scan_registers(func: em_scan_func) void;
924pub extern "c" fn emscripten_scan_stack(func: em_scan_func) void;
925pub const em_dlopen_callback = ?*const fn (?*anyopaque, ?*anyopaque) callconv(.c) void;
926pub extern "c" fn emscripten_dlopen(filename: [*:0]const u8, flags: c_int, user_data: ?*anyopaque, onsuccess: em_dlopen_callback, onerror: em_arg_callback_func) void;
927pub extern "c" fn emscripten_dlopen_promise(filename: [*:0]const u8, flags: c_int) em_promise_t;
928pub extern "c" fn emscripten_throw_number(number: f64) void;
929pub extern "c" fn emscripten_throw_string(utf8String: [*:0]const u8) void;
930pub extern "c" fn emscripten_sleep(ms: c_uint) void;
931
932pub const PROMISE = struct {
933 pub const FULFILL = 0;
934 pub const MATCH = 1;
935 pub const MATCH_RELEASE = 2;
936 pub const REJECT = 3;
937};
938
939pub const struct__em_promise = opaque {};
940pub const em_promise_t = ?*struct__em_promise;
941pub const enum_em_promise_result_t = c_uint;
942pub const em_promise_result_t = enum_em_promise_result_t;
943pub const em_promise_callback_t = ?*const fn (?*?*anyopaque, ?*anyopaque, ?*anyopaque) callconv(.c) em_promise_result_t;
944
945pub extern "c" fn emscripten_promise_create() em_promise_t;
946pub extern "c" fn emscripten_promise_destroy(promise: em_promise_t) void;
947pub extern "c" fn emscripten_promise_resolve(promise: em_promise_t, result: em_promise_result_t, value: ?*anyopaque) void;
948pub extern "c" fn emscripten_promise_then(promise: em_promise_t, on_fulfilled: em_promise_callback_t, on_rejected: em_promise_callback_t, data: ?*anyopaque) em_promise_t;
949pub extern "c" fn emscripten_promise_all(promises: [*]em_promise_t, results: ?[*]?*anyopaque, num_promises: usize) em_promise_t;
950
951pub const struct_em_settled_result_t = extern struct {
952 result: em_promise_result_t,
953 value: ?*anyopaque,
954};
955pub const em_settled_result_t = struct_em_settled_result_t;