| ... | ... | @@ -0,0 +1,1382 @@ |
| 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); |
| 3 | const wasi = std.os.wasi; |
| 4 | const iovec = std.os.iovec; |
| 5 | const iovec_const = std.os.iovec_const; |
| 6 | const c = std.c; |
| 7 | |
| 8 | pub const FILE = c.FILE; |
| 9 | |
| 10 | var __stack_chk_guard: usize = 0; |
| 11 | fn __stack_chk_fail() callconv(.C) void { |
| 12 | std.debug.print("stack smashing detected: terminated\n", .{}); |
| 13 | emscripten_force_exit(127); |
| 14 | } |
| 15 | |
| 16 | comptime { |
| 17 | if (builtin.os.tag == .emscripten) { |
| 18 | if (builtin.mode == .Debug or builtin.mode == .ReleaseSafe) { |
| 19 | // Emscripten does not provide these symbols, so we must export our own |
| 20 | @export(__stack_chk_guard, .{ .name = "__stack_chk_guard", .linkage = .Strong }); |
| 21 | @export(__stack_chk_fail, .{ .name = "__stack_chk_fail", .linkage = .Strong }); |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | pub const PF = struct { |
| 27 | pub const UNSPEC = 0; |
| 28 | pub const LOCAL = 1; |
| 29 | pub const UNIX = LOCAL; |
| 30 | pub const FILE = LOCAL; |
| 31 | pub const INET = 2; |
| 32 | pub const AX25 = 3; |
| 33 | pub const IPX = 4; |
| 34 | pub const APPLETALK = 5; |
| 35 | pub const NETROM = 6; |
| 36 | pub const BRIDGE = 7; |
| 37 | pub const ATMPVC = 8; |
| 38 | pub const X25 = 9; |
| 39 | pub const INET6 = 10; |
| 40 | pub const ROSE = 11; |
| 41 | pub const DECnet = 12; |
| 42 | pub const NETBEUI = 13; |
| 43 | pub const SECURITY = 14; |
| 44 | pub const KEY = 15; |
| 45 | pub const NETLINK = 16; |
| 46 | pub const ROUTE = PF.NETLINK; |
| 47 | pub const PACKET = 17; |
| 48 | pub const ASH = 18; |
| 49 | pub const ECONET = 19; |
| 50 | pub const ATMSVC = 20; |
| 51 | pub const RDS = 21; |
| 52 | pub const SNA = 22; |
| 53 | pub const IRDA = 23; |
| 54 | pub const PPPOX = 24; |
| 55 | pub const WANPIPE = 25; |
| 56 | pub const LLC = 26; |
| 57 | pub const IB = 27; |
| 58 | pub const MPLS = 28; |
| 59 | pub const CAN = 29; |
| 60 | pub const TIPC = 30; |
| 61 | pub const BLUETOOTH = 31; |
| 62 | pub const IUCV = 32; |
| 63 | pub const RXRPC = 33; |
| 64 | pub const ISDN = 34; |
| 65 | pub const PHONET = 35; |
| 66 | pub const IEEE802154 = 36; |
| 67 | pub const CAIF = 37; |
| 68 | pub const ALG = 38; |
| 69 | pub const NFC = 39; |
| 70 | pub const VSOCK = 40; |
| 71 | pub const KCM = 41; |
| 72 | pub const QIPCRTR = 42; |
| 73 | pub const SMC = 43; |
| 74 | pub const XDP = 44; |
| 75 | pub const MAX = 45; |
| 76 | }; |
| 77 | |
| 78 | pub const AF = struct { |
| 79 | pub const UNSPEC = PF.UNSPEC; |
| 80 | pub const LOCAL = PF.LOCAL; |
| 81 | pub const UNIX = AF.LOCAL; |
| 82 | pub const FILE = AF.LOCAL; |
| 83 | pub const INET = PF.INET; |
| 84 | pub const AX25 = PF.AX25; |
| 85 | pub const IPX = PF.IPX; |
| 86 | pub const APPLETALK = PF.APPLETALK; |
| 87 | pub const NETROM = PF.NETROM; |
| 88 | pub const BRIDGE = PF.BRIDGE; |
| 89 | pub const ATMPVC = PF.ATMPVC; |
| 90 | pub const X25 = PF.X25; |
| 91 | pub const INET6 = PF.INET6; |
| 92 | pub const ROSE = PF.ROSE; |
| 93 | pub const DECnet = PF.DECnet; |
| 94 | pub const NETBEUI = PF.NETBEUI; |
| 95 | pub const SECURITY = PF.SECURITY; |
| 96 | pub const KEY = PF.KEY; |
| 97 | pub const NETLINK = PF.NETLINK; |
| 98 | pub const ROUTE = PF.ROUTE; |
| 99 | pub const PACKET = PF.PACKET; |
| 100 | pub const ASH = PF.ASH; |
| 101 | pub const ECONET = PF.ECONET; |
| 102 | pub const ATMSVC = PF.ATMSVC; |
| 103 | pub const RDS = PF.RDS; |
| 104 | pub const SNA = PF.SNA; |
| 105 | pub const IRDA = PF.IRDA; |
| 106 | pub const PPPOX = PF.PPPOX; |
| 107 | pub const WANPIPE = PF.WANPIPE; |
| 108 | pub const LLC = PF.LLC; |
| 109 | pub const IB = PF.IB; |
| 110 | pub const MPLS = PF.MPLS; |
| 111 | pub const CAN = PF.CAN; |
| 112 | pub const TIPC = PF.TIPC; |
| 113 | pub const BLUETOOTH = PF.BLUETOOTH; |
| 114 | pub const IUCV = PF.IUCV; |
| 115 | pub const RXRPC = PF.RXRPC; |
| 116 | pub const ISDN = PF.ISDN; |
| 117 | pub const PHONET = PF.PHONET; |
| 118 | pub const IEEE802154 = PF.IEEE802154; |
| 119 | pub const CAIF = PF.CAIF; |
| 120 | pub const ALG = PF.ALG; |
| 121 | pub const NFC = PF.NFC; |
| 122 | pub const VSOCK = PF.VSOCK; |
| 123 | pub const KCM = PF.KCM; |
| 124 | pub const QIPCRTR = PF.QIPCRTR; |
| 125 | pub const SMC = PF.SMC; |
| 126 | pub const XDP = PF.XDP; |
| 127 | pub const MAX = PF.MAX; |
| 128 | }; |
| 129 | |
| 130 | pub const AT = struct { |
| 131 | pub const FDCWD = -100; |
| 132 | pub const SYMLINK_NOFOLLOW = 0x100; |
| 133 | pub const REMOVEDIR = 0x200; |
| 134 | pub const SYMLINK_FOLLOW = 0x400; |
| 135 | pub const NO_AUTOMOUNT = 0x800; |
| 136 | pub const EMPTY_PATH = 0x1000; |
| 137 | pub const STATX_SYNC_TYPE = 0x6000; |
| 138 | pub const STATX_SYNC_AS_STAT = 0x0000; |
| 139 | pub const STATX_FORCE_SYNC = 0x2000; |
| 140 | pub const STATX_DONT_SYNC = 0x4000; |
| 141 | pub const RECURSIVE = 0x8000; |
| 142 | }; |
| 143 | |
| 144 | pub const CLOCK = struct { |
| 145 | pub const REALTIME = 0; |
| 146 | pub const MONOTONIC = 1; |
| 147 | pub const PROCESS_CPUTIME_ID = 2; |
| 148 | pub const THREAD_CPUTIME_ID = 3; |
| 149 | pub const MONOTONIC_RAW = 4; |
| 150 | pub const REALTIME_COARSE = 5; |
| 151 | pub const MONOTONIC_COARSE = 6; |
| 152 | pub const BOOTTIME = 7; |
| 153 | pub const REALTIME_ALARM = 8; |
| 154 | pub const BOOTTIME_ALARM = 9; |
| 155 | pub const SGI_CYCLE = 10; |
| 156 | pub const TAI = 11; |
| 157 | }; |
| 158 | |
| 159 | pub const CPU_SETSIZE = 128; |
| 160 | pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize; |
| 161 | pub const cpu_count_t = std.meta.Int(.unsigned, std.math.log2(CPU_SETSIZE * 8)); |
| 162 | |
| 163 | pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t { |
| 164 | var sum: cpu_count_t = 0; |
| 165 | for (set) |x| { |
| 166 | sum += @popCount(x); |
| 167 | } |
| 168 | return sum; |
| 169 | } |
| 170 | |
| 171 | pub const E = enum(u16) { |
| 172 | SUCCESS = @intFromEnum(wasi.E.SUCCESS), |
| 173 | @"2BIG" = @intFromEnum(wasi.E.@"2BIG"), |
| 174 | ACCES = @intFromEnum(wasi.E.ACCES), |
| 175 | ADDRINUSE = @intFromEnum(wasi.E.ADDRINUSE), |
| 176 | ADDRNOTAVAIL = @intFromEnum(wasi.E.ADDRNOTAVAIL), |
| 177 | AFNOSUPPORT = @intFromEnum(wasi.E.AFNOSUPPORT), |
| 178 | /// This is also the error code used for `WOULDBLOCK`. |
| 179 | AGAIN = @intFromEnum(wasi.E.AGAIN), |
| 180 | ALREADY = @intFromEnum(wasi.E.ALREADY), |
| 181 | BADF = @intFromEnum(wasi.E.BADF), |
| 182 | BADMSG = @intFromEnum(wasi.E.BADMSG), |
| 183 | BUSY = @intFromEnum(wasi.E.BUSY), |
| 184 | CANCELED = @intFromEnum(wasi.E.CANCELED), |
| 185 | CHILD = @intFromEnum(wasi.E.CHILD), |
| 186 | CONNABORTED = @intFromEnum(wasi.E.CONNABORTED), |
| 187 | CONNREFUSED = @intFromEnum(wasi.E.CONNREFUSED), |
| 188 | CONNRESET = @intFromEnum(wasi.E.CONNRESET), |
| 189 | DEADLK = @intFromEnum(wasi.E.DEADLK), |
| 190 | DESTADDRREQ = @intFromEnum(wasi.E.DESTADDRREQ), |
| 191 | DOM = @intFromEnum(wasi.E.DOM), |
| 192 | DQUOT = @intFromEnum(wasi.E.DQUOT), |
| 193 | EXIST = @intFromEnum(wasi.E.EXIST), |
| 194 | FAULT = @intFromEnum(wasi.E.FAULT), |
| 195 | FBIG = @intFromEnum(wasi.E.FBIG), |
| 196 | HOSTUNREACH = @intFromEnum(wasi.E.HOSTUNREACH), |
| 197 | IDRM = @intFromEnum(wasi.E.IDRM), |
| 198 | ILSEQ = @intFromEnum(wasi.E.ILSEQ), |
| 199 | INPROGRESS = @intFromEnum(wasi.E.INPROGRESS), |
| 200 | INTR = @intFromEnum(wasi.E.INTR), |
| 201 | INVAL = @intFromEnum(wasi.E.INVAL), |
| 202 | IO = @intFromEnum(wasi.E.IO), |
| 203 | ISCONN = @intFromEnum(wasi.E.ISCONN), |
| 204 | ISDIR = @intFromEnum(wasi.E.ISDIR), |
| 205 | LOOP = @intFromEnum(wasi.E.LOOP), |
| 206 | MFILE = @intFromEnum(wasi.E.MFILE), |
| 207 | MLINK = @intFromEnum(wasi.E.MLINK), |
| 208 | MSGSIZE = @intFromEnum(wasi.E.MSGSIZE), |
| 209 | MULTIHOP = @intFromEnum(wasi.E.MULTIHOP), |
| 210 | NAMETOOLONG = @intFromEnum(wasi.E.NAMETOOLONG), |
| 211 | NETDOWN = @intFromEnum(wasi.E.NETDOWN), |
| 212 | NETRESET = @intFromEnum(wasi.E.NETRESET), |
| 213 | NETUNREACH = @intFromEnum(wasi.E.NETUNREACH), |
| 214 | NFILE = @intFromEnum(wasi.E.NFILE), |
| 215 | NOBUFS = @intFromEnum(wasi.E.NOBUFS), |
| 216 | NODEV = @intFromEnum(wasi.E.NODEV), |
| 217 | NOENT = @intFromEnum(wasi.E.NOENT), |
| 218 | NOEXEC = @intFromEnum(wasi.E.NOEXEC), |
| 219 | NOLCK = @intFromEnum(wasi.E.NOLCK), |
| 220 | NOLINK = @intFromEnum(wasi.E.NOLINK), |
| 221 | NOMEM = @intFromEnum(wasi.E.NOMEM), |
| 222 | NOMSG = @intFromEnum(wasi.E.NOMSG), |
| 223 | NOPROTOOPT = @intFromEnum(wasi.E.NOPROTOOPT), |
| 224 | NOSPC = @intFromEnum(wasi.E.NOSPC), |
| 225 | NOSYS = @intFromEnum(wasi.E.NOSYS), |
| 226 | NOTCONN = @intFromEnum(wasi.E.NOTCONN), |
| 227 | NOTDIR = @intFromEnum(wasi.E.NOTDIR), |
| 228 | NOTEMPTY = @intFromEnum(wasi.E.NOTEMPTY), |
| 229 | NOTRECOVERABLE = @intFromEnum(wasi.E.NOTRECOVERABLE), |
| 230 | NOTSOCK = @intFromEnum(wasi.E.NOTSOCK), |
| 231 | /// This is also the code used for `NOTSUP`. |
| 232 | OPNOTSUPP = @intFromEnum(wasi.E.OPNOTSUPP), |
| 233 | NOTTY = @intFromEnum(wasi.E.NOTTY), |
| 234 | NXIO = @intFromEnum(wasi.E.NXIO), |
| 235 | OVERFLOW = @intFromEnum(wasi.E.OVERFLOW), |
| 236 | OWNERDEAD = @intFromEnum(wasi.E.OWNERDEAD), |
| 237 | PERM = @intFromEnum(wasi.E.PERM), |
| 238 | PIPE = @intFromEnum(wasi.E.PIPE), |
| 239 | PROTO = @intFromEnum(wasi.E.PROTO), |
| 240 | PROTONOSUPPORT = @intFromEnum(wasi.E.PROTONOSUPPORT), |
| 241 | PROTOTYPE = @intFromEnum(wasi.E.PROTOTYPE), |
| 242 | RANGE = @intFromEnum(wasi.E.RANGE), |
| 243 | ROFS = @intFromEnum(wasi.E.ROFS), |
| 244 | SPIPE = @intFromEnum(wasi.E.SPIPE), |
| 245 | SRCH = @intFromEnum(wasi.E.SRCH), |
| 246 | STALE = @intFromEnum(wasi.E.STALE), |
| 247 | TIMEDOUT = @intFromEnum(wasi.E.TIMEDOUT), |
| 248 | TXTBSY = @intFromEnum(wasi.E.TXTBSY), |
| 249 | XDEV = @intFromEnum(wasi.E.XDEV), |
| 250 | NOTCAPABLE = @intFromEnum(wasi.E.NOTCAPABLE), |
| 251 | |
| 252 | ENOSTR = 100, |
| 253 | EBFONT = 101, |
| 254 | EBADSLT = 102, |
| 255 | EBADRQC = 103, |
| 256 | ENOANO = 104, |
| 257 | ENOTBLK = 105, |
| 258 | ECHRNG = 106, |
| 259 | EL3HLT = 107, |
| 260 | EL3RST = 108, |
| 261 | ELNRNG = 109, |
| 262 | EUNATCH = 110, |
| 263 | ENOCSI = 111, |
| 264 | EL2HLT = 112, |
| 265 | EBADE = 113, |
| 266 | EBADR = 114, |
| 267 | EXFULL = 115, |
| 268 | ENODATA = 116, |
| 269 | ETIME = 117, |
| 270 | ENOSR = 118, |
| 271 | ENONET = 119, |
| 272 | ENOPKG = 120, |
| 273 | EREMOTE = 121, |
| 274 | EADV = 122, |
| 275 | ESRMNT = 123, |
| 276 | ECOMM = 124, |
| 277 | EDOTDOT = 125, |
| 278 | ENOTUNIQ = 126, |
| 279 | EBADFD = 127, |
| 280 | EREMCHG = 128, |
| 281 | ELIBACC = 129, |
| 282 | ELIBBAD = 130, |
| 283 | ELIBSCN = 131, |
| 284 | ELIBMAX = 132, |
| 285 | ELIBEXEC = 133, |
| 286 | ERESTART = 134, |
| 287 | ESTRPIPE = 135, |
| 288 | EUSERS = 136, |
| 289 | ESOCKTNOSUPPORT = 137, |
| 290 | EOPNOTSUPP = 138, |
| 291 | EPFNOSUPPORT = 139, |
| 292 | ESHUTDOWN = 140, |
| 293 | ETOOMANYREFS = 141, |
| 294 | EHOSTDOWN = 142, |
| 295 | EUCLEAN = 143, |
| 296 | ENOTNAM = 144, |
| 297 | ENAVAIL = 145, |
| 298 | EISNAM = 146, |
| 299 | EREMOTEIO = 147, |
| 300 | ENOMEDIUM = 148, |
| 301 | EMEDIUMTYPE = 149, |
| 302 | ENOKEY = 150, |
| 303 | EKEYEXPIRED = 151, |
| 304 | EKEYREVOKED = 152, |
| 305 | EKEYREJECTED = 153, |
| 306 | ERFKILL = 154, |
| 307 | EHWPOISON = 155, |
| 308 | EL2NSYNC = 156, |
| 309 | _, |
| 310 | }; |
| 311 | |
| 312 | pub const F = struct { |
| 313 | pub const DUPFD = 0; |
| 314 | pub const GETFD = 1; |
| 315 | pub const SETFD = 2; |
| 316 | pub const GETFL = 3; |
| 317 | pub const SETFL = 4; |
| 318 | pub const SETOWN = 8; |
| 319 | pub const GETOWN = 9; |
| 320 | pub const SETSIG = 10; |
| 321 | pub const GETSIG = 11; |
| 322 | pub const GETLK = 12; |
| 323 | pub const SETLK = 13; |
| 324 | pub const SETLKW = 14; |
| 325 | pub const SETOWN_EX = 15; |
| 326 | pub const GETOWN_EX = 16; |
| 327 | pub const GETOWNER_UIDS = 17; |
| 328 | |
| 329 | pub const RDLCK = 0; |
| 330 | pub const WRLCK = 1; |
| 331 | pub const UNLCK = 2; |
| 332 | }; |
| 333 | |
| 334 | pub const FD_CLOEXEC = 1; |
| 335 | |
| 336 | pub const F_OK = 0; |
| 337 | pub const X_OK = 1; |
| 338 | pub const W_OK = 2; |
| 339 | pub const R_OK = 4; |
| 340 | |
| 341 | pub const W = struct { |
| 342 | pub const NOHANG = 1; |
| 343 | pub const UNTRACED = 2; |
| 344 | pub const STOPPED = 2; |
| 345 | pub const EXITED = 4; |
| 346 | pub const CONTINUED = 8; |
| 347 | pub const NOWAIT = 0x1000000; |
| 348 | |
| 349 | pub fn EXITSTATUS(s: u32) u8 { |
| 350 | return @as(u8, @intCast((s & 0xff00) >> 8)); |
| 351 | } |
| 352 | pub fn TERMSIG(s: u32) u32 { |
| 353 | return s & 0x7f; |
| 354 | } |
| 355 | pub fn STOPSIG(s: u32) u32 { |
| 356 | return EXITSTATUS(s); |
| 357 | } |
| 358 | pub fn IFEXITED(s: u32) bool { |
| 359 | return TERMSIG(s) == 0; |
| 360 | } |
| 361 | pub fn IFSTOPPED(s: u32) bool { |
| 362 | return @as(u16, @truncate(((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00; |
| 363 | } |
| 364 | pub fn IFSIGNALED(s: u32) bool { |
| 365 | return (s & 0xffff) -% 1 < 0xff; |
| 366 | } |
| 367 | }; |
| 368 | |
| 369 | pub const Flock = extern struct { |
| 370 | type: i16, |
| 371 | whence: i16, |
| 372 | start: off_t, |
| 373 | len: off_t, |
| 374 | pid: pid_t, |
| 375 | }; |
| 376 | |
| 377 | pub const IFNAMESIZE = 16; |
| 378 | |
| 379 | pub const NAME_MAX = 255; |
| 380 | pub const PATH_MAX = 4096; |
| 381 | pub const IOV_MAX = 1024; |
| 382 | |
| 383 | pub const IPPORT_RESERVED = 1024; |
| 384 | |
| 385 | pub const IPPROTO = struct { |
| 386 | pub const IP = 0; |
| 387 | pub const HOPOPTS = 0; |
| 388 | pub const ICMP = 1; |
| 389 | pub const IGMP = 2; |
| 390 | pub const IPIP = 4; |
| 391 | pub const TCP = 6; |
| 392 | pub const EGP = 8; |
| 393 | pub const PUP = 12; |
| 394 | pub const UDP = 17; |
| 395 | pub const IDP = 22; |
| 396 | pub const TP = 29; |
| 397 | pub const DCCP = 33; |
| 398 | pub const IPV6 = 41; |
| 399 | pub const ROUTING = 43; |
| 400 | pub const FRAGMENT = 44; |
| 401 | pub const RSVP = 46; |
| 402 | pub const GRE = 47; |
| 403 | pub const ESP = 50; |
| 404 | pub const AH = 51; |
| 405 | pub const ICMPV6 = 58; |
| 406 | pub const NONE = 59; |
| 407 | pub const DSTOPTS = 60; |
| 408 | pub const MTP = 92; |
| 409 | pub const BEETPH = 94; |
| 410 | pub const ENCAP = 98; |
| 411 | pub const PIM = 103; |
| 412 | pub const COMP = 108; |
| 413 | pub const SCTP = 132; |
| 414 | pub const MH = 135; |
| 415 | pub const UDPLITE = 136; |
| 416 | pub const MPLS = 137; |
| 417 | pub const RAW = 255; |
| 418 | pub const MAX = 256; |
| 419 | }; |
| 420 | |
| 421 | pub const LOCK = struct { |
| 422 | pub const SH = 1; |
| 423 | pub const EX = 2; |
| 424 | pub const NB = 4; |
| 425 | pub const UN = 8; |
| 426 | }; |
| 427 | |
| 428 | pub const MADV = struct { |
| 429 | pub const NORMAL = 0; |
| 430 | pub const RANDOM = 1; |
| 431 | pub const SEQUENTIAL = 2; |
| 432 | pub const WILLNEED = 3; |
| 433 | pub const DONTNEED = 4; |
| 434 | pub const FREE = 8; |
| 435 | pub const REMOVE = 9; |
| 436 | pub const DONTFORK = 10; |
| 437 | pub const DOFORK = 11; |
| 438 | pub const MERGEABLE = 12; |
| 439 | pub const UNMERGEABLE = 13; |
| 440 | pub const HUGEPAGE = 14; |
| 441 | pub const NOHUGEPAGE = 15; |
| 442 | pub const DONTDUMP = 16; |
| 443 | pub const DODUMP = 17; |
| 444 | pub const WIPEONFORK = 18; |
| 445 | pub const KEEPONFORK = 19; |
| 446 | pub const COLD = 20; |
| 447 | pub const PAGEOUT = 21; |
| 448 | pub const HWPOISON = 100; |
| 449 | pub const SOFT_OFFLINE = 101; |
| 450 | }; |
| 451 | |
| 452 | pub const MAP = struct { |
| 453 | pub const SHARED = 0x01; |
| 454 | pub const PRIVATE = 0x02; |
| 455 | pub const SHARED_VALIDATE = 0x03; |
| 456 | pub const TYPE = 0x0f; |
| 457 | pub const FIXED = 0x10; |
| 458 | pub const ANON = 0x20; |
| 459 | pub const ANONYMOUS = ANON; |
| 460 | pub const NORESERVE = 0x4000; |
| 461 | pub const GROWSDOWN = 0x0100; |
| 462 | pub const DENYWRITE = 0x0800; |
| 463 | pub const EXECUTABLE = 0x1000; |
| 464 | pub const LOCKED = 0x2000; |
| 465 | pub const POPULATE = 0x8000; |
| 466 | pub const NONBLOCK = 0x10000; |
| 467 | pub const STACK = 0x20000; |
| 468 | pub const HUGETLB = 0x40000; |
| 469 | pub const SYNC = 0x80000; |
| 470 | pub const FIXED_NOREPLACE = 0x100000; |
| 471 | }; |
| 472 | |
| 473 | pub const MSF = struct { |
| 474 | pub const ASYNC = 1; |
| 475 | pub const INVALIDATE = 2; |
| 476 | pub const SYNC = 4; |
| 477 | }; |
| 478 | |
| 479 | pub const MSG = struct { |
| 480 | pub const OOB = 0x0001; |
| 481 | pub const PEEK = 0x0002; |
| 482 | pub const DONTROUTE = 0x0004; |
| 483 | pub const CTRUNC = 0x0008; |
| 484 | pub const PROXY = 0x0010; |
| 485 | pub const TRUNC = 0x0020; |
| 486 | pub const DONTWAIT = 0x0040; |
| 487 | pub const EOR = 0x0080; |
| 488 | pub const WAITALL = 0x0100; |
| 489 | pub const FIN = 0x0200; |
| 490 | pub const SYN = 0x0400; |
| 491 | pub const CONFIRM = 0x0800; |
| 492 | pub const RST = 0x1000; |
| 493 | pub const ERRQUEUE = 0x2000; |
| 494 | pub const NOSIGNAL = 0x4000; |
| 495 | pub const MORE = 0x8000; |
| 496 | pub const WAITFORONE = 0x10000; |
| 497 | pub const BATCH = 0x40000; |
| 498 | pub const ZEROCOPY = 0x4000000; |
| 499 | pub const FASTOPEN = 0x20000000; |
| 500 | pub const CMSG_CLOEXEC = 0x40000000; |
| 501 | }; |
| 502 | |
| 503 | pub const O = struct { |
| 504 | pub const RDONLY = 0o0; |
| 505 | pub const WRONLY = 0o1; |
| 506 | pub const RDWR = 0o2; |
| 507 | |
| 508 | pub const CREAT = 0o100; |
| 509 | pub const EXCL = 0o200; |
| 510 | pub const NOCTTY = 0o400; |
| 511 | pub const TRUNC = 0o1000; |
| 512 | pub const APPEND = 0o2000; |
| 513 | pub const NONBLOCK = 0o4000; |
| 514 | pub const DSYNC = 0o10000; |
| 515 | pub const SYNC = 0o4010000; |
| 516 | pub const RSYNC = 0o4010000; |
| 517 | pub const DIRECTORY = 0o200000; |
| 518 | pub const NOFOLLOW = 0o400000; |
| 519 | pub const CLOEXEC = 0o2000000; |
| 520 | |
| 521 | pub const ASYNC = 0o20000; |
| 522 | pub const DIRECT = 0o40000; |
| 523 | pub const LARGEFILE = 0o100000; |
| 524 | pub const NOATIME = 0o1000000; |
| 525 | pub const PATH = 0o10000000; |
| 526 | pub const TMPFILE = 0o20200000; |
| 527 | pub const NDELAY = NONBLOCK; |
| 528 | }; |
| 529 | |
| 530 | pub const POLL = struct { |
| 531 | pub const IN = 0x001; |
| 532 | pub const PRI = 0x002; |
| 533 | pub const OUT = 0x004; |
| 534 | pub const ERR = 0x008; |
| 535 | pub const HUP = 0x010; |
| 536 | pub const NVAL = 0x020; |
| 537 | pub const RDNORM = 0x040; |
| 538 | pub const RDBAND = 0x080; |
| 539 | }; |
| 540 | |
| 541 | pub const PROT = struct { |
| 542 | pub const NONE = 0x0; |
| 543 | pub const READ = 0x1; |
| 544 | pub const WRITE = 0x2; |
| 545 | pub const EXEC = 0x4; |
| 546 | pub const GROWSDOWN = 0x01000000; |
| 547 | pub const GROWSUP = 0x02000000; |
| 548 | }; |
| 549 | |
| 550 | pub const rlim_t = u64; |
| 551 | |
| 552 | pub const RLIM = struct { |
| 553 | pub const INFINITY = ~@as(rlim_t, 0); |
| 554 | |
| 555 | pub const SAVED_MAX = INFINITY; |
| 556 | pub const SAVED_CUR = INFINITY; |
| 557 | }; |
| 558 | |
| 559 | pub const rlimit = extern struct { |
| 560 | cur: rlim_t, |
| 561 | max: rlim_t, |
| 562 | }; |
| 563 | |
| 564 | pub const rlimit_resource = enum(c_int) { |
| 565 | CPU, |
| 566 | FSIZE, |
| 567 | DATA, |
| 568 | STACK, |
| 569 | CORE, |
| 570 | RSS, |
| 571 | NPROC, |
| 572 | NOFILE, |
| 573 | MEMLOCK, |
| 574 | AS, |
| 575 | LOCKS, |
| 576 | SIGPENDING, |
| 577 | MSGQUEUE, |
| 578 | NICE, |
| 579 | RTPRIO, |
| 580 | RTTIME, |
| 581 | _, |
| 582 | }; |
| 583 | |
| 584 | pub const rusage = extern struct { |
| 585 | utime: timeval, |
| 586 | stime: timeval, |
| 587 | maxrss: isize, |
| 588 | ixrss: isize, |
| 589 | idrss: isize, |
| 590 | isrss: isize, |
| 591 | minflt: isize, |
| 592 | majflt: isize, |
| 593 | nswap: isize, |
| 594 | inblock: isize, |
| 595 | oublock: isize, |
| 596 | msgsnd: isize, |
| 597 | msgrcv: isize, |
| 598 | nsignals: isize, |
| 599 | nvcsw: isize, |
| 600 | nivcsw: isize, |
| 601 | __reserved: [16]isize = [1]isize{0} ** 16, |
| 602 | |
| 603 | pub const SELF = 0; |
| 604 | pub const CHILDREN = -1; |
| 605 | pub const THREAD = 1; |
| 606 | }; |
| 607 | |
| 608 | pub const timeval = extern struct { |
| 609 | tv_sec: i64, |
| 610 | tv_usec: i32, |
| 611 | }; |
| 612 | |
| 613 | pub const REG = struct { |
| 614 | pub const GS = 0; |
| 615 | pub const FS = 1; |
| 616 | pub const ES = 2; |
| 617 | pub const DS = 3; |
| 618 | pub const EDI = 4; |
| 619 | pub const ESI = 5; |
| 620 | pub const EBP = 6; |
| 621 | pub const ESP = 7; |
| 622 | pub const EBX = 8; |
| 623 | pub const EDX = 9; |
| 624 | pub const ECX = 10; |
| 625 | pub const EAX = 11; |
| 626 | pub const TRAPNO = 12; |
| 627 | pub const ERR = 13; |
| 628 | pub const EIP = 14; |
| 629 | pub const CS = 15; |
| 630 | pub const EFL = 16; |
| 631 | pub const UESP = 17; |
| 632 | pub const SS = 18; |
| 633 | }; |
| 634 | |
| 635 | pub const S = struct { |
| 636 | pub const IFMT = 0o170000; |
| 637 | |
| 638 | pub const IFDIR = 0o040000; |
| 639 | pub const IFCHR = 0o020000; |
| 640 | pub const IFBLK = 0o060000; |
| 641 | pub const IFREG = 0o100000; |
| 642 | pub const IFIFO = 0o010000; |
| 643 | pub const IFLNK = 0o120000; |
| 644 | pub const IFSOCK = 0o140000; |
| 645 | |
| 646 | pub const ISUID = 0o4000; |
| 647 | pub const ISGID = 0o2000; |
| 648 | pub const ISVTX = 0o1000; |
| 649 | pub const IRUSR = 0o400; |
| 650 | pub const IWUSR = 0o200; |
| 651 | pub const IXUSR = 0o100; |
| 652 | pub const IRWXU = 0o700; |
| 653 | pub const IRGRP = 0o040; |
| 654 | pub const IWGRP = 0o020; |
| 655 | pub const IXGRP = 0o010; |
| 656 | pub const IRWXG = 0o070; |
| 657 | pub const IROTH = 0o004; |
| 658 | pub const IWOTH = 0o002; |
| 659 | pub const IXOTH = 0o001; |
| 660 | pub const IRWXO = 0o007; |
| 661 | |
| 662 | pub fn ISREG(m: mode_t) bool { |
| 663 | return m & IFMT == IFREG; |
| 664 | } |
| 665 | |
| 666 | pub fn ISDIR(m: mode_t) bool { |
| 667 | return m & IFMT == IFDIR; |
| 668 | } |
| 669 | |
| 670 | pub fn ISCHR(m: mode_t) bool { |
| 671 | return m & IFMT == IFCHR; |
| 672 | } |
| 673 | |
| 674 | pub fn ISBLK(m: mode_t) bool { |
| 675 | return m & IFMT == IFBLK; |
| 676 | } |
| 677 | |
| 678 | pub fn ISFIFO(m: mode_t) bool { |
| 679 | return m & IFMT == IFIFO; |
| 680 | } |
| 681 | |
| 682 | pub fn ISLNK(m: mode_t) bool { |
| 683 | return m & IFMT == IFLNK; |
| 684 | } |
| 685 | |
| 686 | pub fn ISSOCK(m: mode_t) bool { |
| 687 | return m & IFMT == IFSOCK; |
| 688 | } |
| 689 | }; |
| 690 | |
| 691 | pub const SA = struct { |
| 692 | pub const NOCLDSTOP = 1; |
| 693 | pub const NOCLDWAIT = 2; |
| 694 | pub const SIGINFO = 4; |
| 695 | pub const RESTART = 0x10000000; |
| 696 | pub const RESETHAND = 0x80000000; |
| 697 | pub const ONSTACK = 0x08000000; |
| 698 | pub const NODEFER = 0x40000000; |
| 699 | pub const RESTORER = 0x04000000; |
| 700 | }; |
| 701 | |
| 702 | pub const SEEK = struct { |
| 703 | pub const SET = 0; |
| 704 | pub const CUR = 1; |
| 705 | pub const END = 2; |
| 706 | }; |
| 707 | |
| 708 | pub const SHUT = struct { |
| 709 | pub const RD = 0; |
| 710 | pub const WR = 1; |
| 711 | pub const RDWR = 2; |
| 712 | }; |
| 713 | |
| 714 | pub const SIG = struct { |
| 715 | pub const BLOCK = 0; |
| 716 | pub const UNBLOCK = 1; |
| 717 | pub const SETMASK = 2; |
| 718 | |
| 719 | pub const HUP = 1; |
| 720 | pub const INT = 2; |
| 721 | pub const QUIT = 3; |
| 722 | pub const ILL = 4; |
| 723 | pub const TRAP = 5; |
| 724 | pub const ABRT = 6; |
| 725 | pub const IOT = ABRT; |
| 726 | pub const BUS = 7; |
| 727 | pub const FPE = 8; |
| 728 | pub const KILL = 9; |
| 729 | pub const USR1 = 10; |
| 730 | pub const SEGV = 11; |
| 731 | pub const USR2 = 12; |
| 732 | pub const PIPE = 13; |
| 733 | pub const ALRM = 14; |
| 734 | pub const TERM = 15; |
| 735 | pub const STKFLT = 16; |
| 736 | pub const CHLD = 17; |
| 737 | pub const CONT = 18; |
| 738 | pub const STOP = 19; |
| 739 | pub const TSTP = 20; |
| 740 | pub const TTIN = 21; |
| 741 | pub const TTOU = 22; |
| 742 | pub const URG = 23; |
| 743 | pub const XCPU = 24; |
| 744 | pub const XFSZ = 25; |
| 745 | pub const VTALRM = 26; |
| 746 | pub const PROF = 27; |
| 747 | pub const WINCH = 28; |
| 748 | pub const IO = 29; |
| 749 | pub const POLL = 29; |
| 750 | pub const PWR = 30; |
| 751 | pub const SYS = 31; |
| 752 | pub const UNUSED = SIG.SYS; |
| 753 | |
| 754 | pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(std.math.maxInt(usize))); |
| 755 | pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0)); |
| 756 | pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1)); |
| 757 | }; |
| 758 | |
| 759 | pub const Sigaction = extern struct { |
| 760 | pub const handler_fn = *const fn (c_int) align(1) callconv(.C) void; |
| 761 | pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void; |
| 762 | |
| 763 | handler: extern union { |
| 764 | handler: ?handler_fn, |
| 765 | sigaction: ?sigaction_fn, |
| 766 | }, |
| 767 | mask: sigset_t, |
| 768 | flags: c_uint, |
| 769 | restorer: ?*const fn () callconv(.C) void = null, |
| 770 | }; |
| 771 | |
| 772 | pub const sigset_t = [1024 / 32]u32; |
| 773 | pub const empty_sigset = [_]u32{0} ** @typeInfo(sigset_t).Array.len; |
| 774 | pub const siginfo_t = extern struct { |
| 775 | signo: i32, |
| 776 | errno: i32, |
| 777 | code: i32, |
| 778 | fields: siginfo_fields_union, |
| 779 | }; |
| 780 | const siginfo_fields_union = extern union { |
| 781 | pad: [128 - 2 * @sizeOf(c_int) - @sizeOf(c_long)]u8, |
| 782 | common: extern struct { |
| 783 | first: extern union { |
| 784 | piduid: extern struct { |
| 785 | pid: pid_t, |
| 786 | uid: uid_t, |
| 787 | }, |
| 788 | timer: extern struct { |
| 789 | timerid: i32, |
| 790 | overrun: i32, |
| 791 | }, |
| 792 | }, |
| 793 | second: extern union { |
| 794 | value: sigval, |
| 795 | sigchld: extern struct { |
| 796 | status: i32, |
| 797 | utime: clock_t, |
| 798 | stime: clock_t, |
| 799 | }, |
| 800 | }, |
| 801 | }, |
| 802 | sigfault: extern struct { |
| 803 | addr: *anyopaque, |
| 804 | addr_lsb: i16, |
| 805 | first: extern union { |
| 806 | addr_bnd: extern struct { |
| 807 | lower: *anyopaque, |
| 808 | upper: *anyopaque, |
| 809 | }, |
| 810 | pkey: u32, |
| 811 | }, |
| 812 | }, |
| 813 | sigpoll: extern struct { |
| 814 | band: isize, |
| 815 | fd: i32, |
| 816 | }, |
| 817 | sigsys: extern struct { |
| 818 | call_addr: *anyopaque, |
| 819 | syscall: i32, |
| 820 | native_arch: u32, |
| 821 | }, |
| 822 | }; |
| 823 | pub const sigval = extern union { |
| 824 | int: i32, |
| 825 | ptr: *anyopaque, |
| 826 | }; |
| 827 | |
| 828 | pub const SIOCGIFINDEX = 0x8933; |
| 829 | |
| 830 | pub const SO = struct { |
| 831 | pub const DEBUG = 1; |
| 832 | pub const REUSEADDR = 2; |
| 833 | pub const TYPE = 3; |
| 834 | pub const ERROR = 4; |
| 835 | pub const DONTROUTE = 5; |
| 836 | pub const BROADCAST = 6; |
| 837 | pub const SNDBUF = 7; |
| 838 | pub const RCVBUF = 8; |
| 839 | pub const KEEPALIVE = 9; |
| 840 | pub const OOBINLINE = 10; |
| 841 | pub const NO_CHECK = 11; |
| 842 | pub const PRIORITY = 12; |
| 843 | pub const LINGER = 13; |
| 844 | pub const BSDCOMPAT = 14; |
| 845 | pub const REUSEPORT = 15; |
| 846 | pub const PASSCRED = 16; |
| 847 | pub const PEERCRED = 17; |
| 848 | pub const RCVLOWAT = 18; |
| 849 | pub const SNDLOWAT = 19; |
| 850 | pub const RCVTIMEO = 20; |
| 851 | pub const SNDTIMEO = 21; |
| 852 | pub const ACCEPTCONN = 30; |
| 853 | pub const PEERSEC = 31; |
| 854 | pub const SNDBUFFORCE = 32; |
| 855 | pub const RCVBUFFORCE = 33; |
| 856 | pub const PROTOCOL = 38; |
| 857 | pub const DOMAIN = 39; |
| 858 | pub const SECURITY_AUTHENTICATION = 22; |
| 859 | pub const SECURITY_ENCRYPTION_TRANSPORT = 23; |
| 860 | pub const SECURITY_ENCRYPTION_NETWORK = 24; |
| 861 | pub const BINDTODEVICE = 25; |
| 862 | pub const ATTACH_FILTER = 26; |
| 863 | pub const DETACH_FILTER = 27; |
| 864 | pub const GET_FILTER = ATTACH_FILTER; |
| 865 | pub const PEERNAME = 28; |
| 866 | pub const TIMESTAMP_OLD = 29; |
| 867 | pub const PASSSEC = 34; |
| 868 | pub const TIMESTAMPNS_OLD = 35; |
| 869 | pub const MARK = 36; |
| 870 | pub const TIMESTAMPING_OLD = 37; |
| 871 | pub const RXQ_OVFL = 40; |
| 872 | pub const WIFI_STATUS = 41; |
| 873 | pub const PEEK_OFF = 42; |
| 874 | pub const NOFCS = 43; |
| 875 | pub const LOCK_FILTER = 44; |
| 876 | pub const SELECT_ERR_QUEUE = 45; |
| 877 | pub const BUSY_POLL = 46; |
| 878 | pub const MAX_PACING_RATE = 47; |
| 879 | pub const BPF_EXTENSIONS = 48; |
| 880 | pub const INCOMING_CPU = 49; |
| 881 | pub const ATTACH_BPF = 50; |
| 882 | pub const DETACH_BPF = DETACH_FILTER; |
| 883 | pub const ATTACH_REUSEPORT_CBPF = 51; |
| 884 | pub const ATTACH_REUSEPORT_EBPF = 52; |
| 885 | pub const CNX_ADVICE = 53; |
| 886 | pub const MEMINFO = 55; |
| 887 | pub const INCOMING_NAPI_ID = 56; |
| 888 | pub const COOKIE = 57; |
| 889 | pub const PEERGROUPS = 59; |
| 890 | pub const ZEROCOPY = 60; |
| 891 | pub const TXTIME = 61; |
| 892 | pub const BINDTOIFINDEX = 62; |
| 893 | pub const TIMESTAMP_NEW = 63; |
| 894 | pub const TIMESTAMPNS_NEW = 64; |
| 895 | pub const TIMESTAMPING_NEW = 65; |
| 896 | pub const RCVTIMEO_NEW = 66; |
| 897 | pub const SNDTIMEO_NEW = 67; |
| 898 | pub const DETACH_REUSEPORT_BPF = 68; |
| 899 | }; |
| 900 | |
| 901 | pub const SOCK = struct { |
| 902 | pub const STREAM = 1; |
| 903 | pub const DGRAM = 2; |
| 904 | pub const RAW = 3; |
| 905 | pub const RDM = 4; |
| 906 | pub const SEQPACKET = 5; |
| 907 | pub const DCCP = 6; |
| 908 | pub const PACKET = 10; |
| 909 | pub const CLOEXEC = 0o2000000; |
| 910 | pub const NONBLOCK = 0o4000; |
| 911 | }; |
| 912 | |
| 913 | pub const SOL = struct { |
| 914 | pub const SOCKET = 1; |
| 915 | |
| 916 | pub const IP = 0; |
| 917 | pub const IPV6 = 41; |
| 918 | pub const ICMPV6 = 58; |
| 919 | |
| 920 | pub const RAW = 255; |
| 921 | pub const DECNET = 261; |
| 922 | pub const X25 = 262; |
| 923 | pub const PACKET = 263; |
| 924 | pub const ATM = 264; |
| 925 | pub const AAL = 265; |
| 926 | pub const IRDA = 266; |
| 927 | pub const NETBEUI = 267; |
| 928 | pub const LLC = 268; |
| 929 | pub const DCCP = 269; |
| 930 | pub const NETLINK = 270; |
| 931 | pub const TIPC = 271; |
| 932 | pub const RXRPC = 272; |
| 933 | pub const PPPOL2TP = 273; |
| 934 | pub const BLUETOOTH = 274; |
| 935 | pub const PNPIPE = 275; |
| 936 | pub const RDS = 276; |
| 937 | pub const IUCV = 277; |
| 938 | pub const CAIF = 278; |
| 939 | pub const ALG = 279; |
| 940 | pub const NFC = 280; |
| 941 | pub const KCM = 281; |
| 942 | pub const TLS = 282; |
| 943 | pub const XDP = 283; |
| 944 | }; |
| 945 | |
| 946 | pub const STDIN_FILENO = 0; |
| 947 | pub const STDOUT_FILENO = 1; |
| 948 | pub const STDERR_FILENO = 2; |
| 949 | |
| 950 | pub const TCP = struct { |
| 951 | pub const NODELAY = 1; |
| 952 | pub const MAXSEG = 2; |
| 953 | pub const CORK = 3; |
| 954 | pub const KEEPIDLE = 4; |
| 955 | pub const KEEPINTVL = 5; |
| 956 | pub const KEEPCNT = 6; |
| 957 | pub const SYNCNT = 7; |
| 958 | pub const LINGER2 = 8; |
| 959 | pub const DEFER_ACCEPT = 9; |
| 960 | pub const WINDOW_CLAMP = 10; |
| 961 | pub const INFO = 11; |
| 962 | pub const QUICKACK = 12; |
| 963 | pub const CONGESTION = 13; |
| 964 | pub const MD5SIG = 14; |
| 965 | pub const THIN_LINEAR_TIMEOUTS = 16; |
| 966 | pub const THIN_DUPACK = 17; |
| 967 | pub const USER_TIMEOUT = 18; |
| 968 | pub const REPAIR = 19; |
| 969 | pub const REPAIR_QUEUE = 20; |
| 970 | pub const QUEUE_SEQ = 21; |
| 971 | pub const REPAIR_OPTIONS = 22; |
| 972 | pub const FASTOPEN = 23; |
| 973 | pub const TIMESTAMP = 24; |
| 974 | pub const NOTSENT_LOWAT = 25; |
| 975 | pub const CC_INFO = 26; |
| 976 | pub const SAVE_SYN = 27; |
| 977 | pub const SAVED_SYN = 28; |
| 978 | pub const REPAIR_WINDOW = 29; |
| 979 | pub const FASTOPEN_CONNECT = 30; |
| 980 | pub const ULP = 31; |
| 981 | pub const MD5SIG_EXT = 32; |
| 982 | pub const FASTOPEN_KEY = 33; |
| 983 | pub const FASTOPEN_NO_COOKIE = 34; |
| 984 | pub const ZEROCOPY_RECEIVE = 35; |
| 985 | pub const INQ = 36; |
| 986 | pub const CM_INQ = INQ; |
| 987 | pub const TX_DELAY = 37; |
| 988 | |
| 989 | pub const REPAIR_ON = 1; |
| 990 | pub const REPAIR_OFF = 0; |
| 991 | pub const REPAIR_OFF_NO_WP = -1; |
| 992 | }; |
| 993 | |
| 994 | pub const TCSA = enum(c_uint) { |
| 995 | NOW, |
| 996 | DRAIN, |
| 997 | FLUSH, |
| 998 | _, |
| 999 | }; |
| 1000 | |
| 1001 | pub const addrinfo = extern struct { |
| 1002 | flags: i32, |
| 1003 | family: i32, |
| 1004 | socktype: i32, |
| 1005 | protocol: i32, |
| 1006 | addrlen: socklen_t, |
| 1007 | addr: ?*sockaddr, |
| 1008 | canonname: ?[*:0]u8, |
| 1009 | next: ?*addrinfo, |
| 1010 | }; |
| 1011 | |
| 1012 | pub const in_port_t = u16; |
| 1013 | pub const sa_family_t = u16; |
| 1014 | pub const socklen_t = u32; |
| 1015 | |
| 1016 | pub const sockaddr = extern struct { |
| 1017 | family: sa_family_t, |
| 1018 | data: [14]u8, |
| 1019 | |
| 1020 | pub const SS_MAXSIZE = 128; |
| 1021 | pub const storage = extern struct { |
| 1022 | family: sa_family_t align(8), |
| 1023 | padding: [SS_MAXSIZE - @sizeOf(sa_family_t)]u8 = undefined, |
| 1024 | |
| 1025 | comptime { |
| 1026 | std.debug.assert(@sizeOf(storage) == SS_MAXSIZE); |
| 1027 | std.debug.assert(@alignOf(storage) == 8); |
| 1028 | } |
| 1029 | }; |
| 1030 | |
| 1031 | /// IPv4 socket address |
| 1032 | pub const in = extern struct { |
| 1033 | family: sa_family_t = AF.INET, |
| 1034 | port: in_port_t, |
| 1035 | addr: u32, |
| 1036 | zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1037 | }; |
| 1038 | |
| 1039 | /// IPv6 socket address |
| 1040 | pub const in6 = extern struct { |
| 1041 | family: sa_family_t = AF.INET6, |
| 1042 | port: in_port_t, |
| 1043 | flowinfo: u32, |
| 1044 | addr: [16]u8, |
| 1045 | scope_id: u32, |
| 1046 | }; |
| 1047 | |
| 1048 | /// UNIX domain socket address |
| 1049 | pub const un = extern struct { |
| 1050 | family: sa_family_t = AF.UNIX, |
| 1051 | path: [108]u8, |
| 1052 | }; |
| 1053 | |
| 1054 | /// Packet socket address |
| 1055 | pub const ll = extern struct { |
| 1056 | family: sa_family_t = AF.PACKET, |
| 1057 | protocol: u16, |
| 1058 | ifindex: i32, |
| 1059 | hatype: u16, |
| 1060 | pkttype: u8, |
| 1061 | halen: u8, |
| 1062 | addr: [8]u8, |
| 1063 | }; |
| 1064 | |
| 1065 | /// Netlink socket address |
| 1066 | pub const nl = extern struct { |
| 1067 | family: sa_family_t = AF.NETLINK, |
| 1068 | __pad1: c_ushort = 0, |
| 1069 | |
| 1070 | /// port ID |
| 1071 | pid: u32, |
| 1072 | |
| 1073 | /// multicast groups mask |
| 1074 | groups: u32, |
| 1075 | }; |
| 1076 | |
| 1077 | pub const xdp = extern struct { |
| 1078 | family: u16 = AF.XDP, |
| 1079 | flags: u16, |
| 1080 | ifindex: u32, |
| 1081 | queue_id: u32, |
| 1082 | shared_umem_fd: u32, |
| 1083 | }; |
| 1084 | |
| 1085 | /// Address structure for vSockets |
| 1086 | pub const vm = extern struct { |
| 1087 | family: sa_family_t = AF.VSOCK, |
| 1088 | reserved1: u16 = 0, |
| 1089 | port: u32, |
| 1090 | cid: u32, |
| 1091 | flags: u8, |
| 1092 | |
| 1093 | /// The total size of this structure should be exactly the same as that of struct sockaddr. |
| 1094 | zero: [3]u8 = [_]u8{0} ** 3, |
| 1095 | comptime { |
| 1096 | std.debug.assert(@sizeOf(vm) == @sizeOf(sockaddr)); |
| 1097 | } |
| 1098 | }; |
| 1099 | }; |
| 1100 | |
| 1101 | pub const blksize_t = i32; |
| 1102 | pub const nlink_t = u32; |
| 1103 | pub const time_t = i64; |
| 1104 | pub const mode_t = u32; |
| 1105 | pub const off_t = i64; |
| 1106 | pub const ino_t = u64; |
| 1107 | pub const dev_t = u32; |
| 1108 | pub const blkcnt_t = i32; |
| 1109 | |
| 1110 | pub const pid_t = i32; |
| 1111 | pub const fd_t = i32; |
| 1112 | pub const uid_t = u32; |
| 1113 | pub const gid_t = u32; |
| 1114 | pub const clock_t = i32; |
| 1115 | |
| 1116 | pub const dl_phdr_info = extern struct { |
| 1117 | dlpi_addr: usize, |
| 1118 | dlpi_name: ?[*:0]const u8, |
| 1119 | dlpi_phdr: [*]std.elf.Phdr, |
| 1120 | dlpi_phnum: u16, |
| 1121 | }; |
| 1122 | |
| 1123 | pub const mcontext_t = extern struct { |
| 1124 | gregs: [19]usize, |
| 1125 | fpregs: [*]u8, |
| 1126 | oldmask: usize, |
| 1127 | cr2: usize, |
| 1128 | }; |
| 1129 | |
| 1130 | pub const msghdr = extern struct { |
| 1131 | name: ?*sockaddr, |
| 1132 | namelen: socklen_t, |
| 1133 | iov: [*]iovec, |
| 1134 | iovlen: i32, |
| 1135 | control: ?*anyopaque, |
| 1136 | controllen: socklen_t, |
| 1137 | flags: i32, |
| 1138 | }; |
| 1139 | |
| 1140 | pub const msghdr_const = extern struct { |
| 1141 | name: ?*const sockaddr, |
| 1142 | namelen: socklen_t, |
| 1143 | iov: [*]const iovec_const, |
| 1144 | iovlen: i32, |
| 1145 | control: ?*const anyopaque, |
| 1146 | controllen: socklen_t, |
| 1147 | flags: i32, |
| 1148 | }; |
| 1149 | |
| 1150 | pub const nfds_t = usize; |
| 1151 | pub const pollfd = extern struct { |
| 1152 | fd: fd_t, |
| 1153 | events: i16, |
| 1154 | revents: i16, |
| 1155 | }; |
| 1156 | |
| 1157 | pub const stack_t = extern struct { |
| 1158 | sp: [*]u8, |
| 1159 | flags: i32, |
| 1160 | size: usize, |
| 1161 | }; |
| 1162 | |
| 1163 | pub const cc_t = u8; |
| 1164 | pub const speed_t = u32; |
| 1165 | pub const tcflag_t = u32; |
| 1166 | |
| 1167 | pub const NCCS = 32; |
| 1168 | |
| 1169 | pub const termios = extern struct { |
| 1170 | iflag: tcflag_t, |
| 1171 | oflag: tcflag_t, |
| 1172 | cflag: tcflag_t, |
| 1173 | lflag: tcflag_t, |
| 1174 | line: cc_t, |
| 1175 | cc: [NCCS]cc_t, |
| 1176 | ispeed: speed_t, |
| 1177 | ospeed: speed_t, |
| 1178 | }; |
| 1179 | |
| 1180 | pub const timespec = extern struct { |
| 1181 | tv_sec: time_t, |
| 1182 | tv_nsec: isize, |
| 1183 | }; |
| 1184 | |
| 1185 | pub const timezone = extern struct { |
| 1186 | tz_minuteswest: i32, |
| 1187 | tz_dsttime: i32, |
| 1188 | }; |
| 1189 | |
| 1190 | pub const ucontext_t = extern struct { |
| 1191 | flags: usize, |
| 1192 | link: ?*ucontext_t, |
| 1193 | stack: stack_t, |
| 1194 | mcontext: mcontext_t, |
| 1195 | sigmask: sigset_t, |
| 1196 | regspace: [28]usize, |
| 1197 | }; |
| 1198 | |
| 1199 | pub const utsname = extern struct { |
| 1200 | sysname: [64:0]u8, |
| 1201 | nodename: [64:0]u8, |
| 1202 | release: [64:0]u8, |
| 1203 | version: [64:0]u8, |
| 1204 | machine: [64:0]u8, |
| 1205 | domainname: [64:0]u8, |
| 1206 | }; |
| 1207 | |
| 1208 | pub const Stat = extern struct { |
| 1209 | dev: dev_t, |
| 1210 | mode: mode_t, |
| 1211 | nlink: nlink_t, |
| 1212 | uid: uid_t, |
| 1213 | gid: gid_t, |
| 1214 | rdev: dev_t, |
| 1215 | size: off_t, |
| 1216 | blksize: blksize_t, |
| 1217 | blocks: blkcnt_t, |
| 1218 | atim: timespec, |
| 1219 | mtim: timespec, |
| 1220 | ctim: timespec, |
| 1221 | ino: ino_t, |
| 1222 | |
| 1223 | pub fn atime(self: @This()) timespec { |
| 1224 | return self.atim; |
| 1225 | } |
| 1226 | |
| 1227 | pub fn mtime(self: @This()) timespec { |
| 1228 | return self.mtim; |
| 1229 | } |
| 1230 | |
| 1231 | pub fn ctime(self: @This()) timespec { |
| 1232 | return self.ctim; |
| 1233 | } |
| 1234 | }; |
| 1235 | |
| 1236 | pub const TIMING = struct { |
| 1237 | pub const SETTIMEOUT = 0; |
| 1238 | pub const RAF = 1; |
| 1239 | pub const SETIMMEDIATE = 2; |
| 1240 | }; |
| 1241 | |
| 1242 | pub const LOG = struct { |
| 1243 | pub const CONSOLE = 1; |
| 1244 | pub const WARN = 2; |
| 1245 | pub const ERROR = 4; |
| 1246 | pub const C_STACK = 8; |
| 1247 | pub const JS_STACK = 16; |
| 1248 | pub const DEMANGLE = 32; |
| 1249 | pub const NO_PATHS = 64; |
| 1250 | pub const FUNC_PARAMS = 128; |
| 1251 | pub const DEBUG = 256; |
| 1252 | pub const INFO = 512; |
| 1253 | }; |
| 1254 | |
| 1255 | pub const em_callback_func = ?*const fn () callconv(.C) void; |
| 1256 | pub const em_arg_callback_func = ?*const fn (?*anyopaque) callconv(.C) void; |
| 1257 | pub const em_str_callback_func = ?*const fn ([*:0]const u8) callconv(.C) void; |
| 1258 | |
| 1259 | pub 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; |
| 1260 | |
| 1261 | pub const em_async_wget_onload_func = ?*const fn (?*anyopaque, ?*anyopaque, c_int) callconv(.C) void; |
| 1262 | pub 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; |
| 1263 | |
| 1264 | pub const em_async_wget2_onload_func = ?*const fn (c_uint, ?*anyopaque, [*:0]const u8) callconv(.C) void; |
| 1265 | pub const em_async_wget2_onstatus_func = ?*const fn (c_uint, ?*anyopaque, c_int) callconv(.C) void; |
| 1266 | |
| 1267 | pub 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; |
| 1268 | |
| 1269 | pub const em_async_wget2_data_onload_func = ?*const fn (c_uint, ?*anyopaque, ?*anyopaque, c_uint) callconv(.C) void; |
| 1270 | pub const em_async_wget2_data_onerror_func = ?*const fn (c_uint, ?*anyopaque, c_int, [*:0]const u8) callconv(.C) void; |
| 1271 | pub const em_async_wget2_data_onprogress_func = ?*const fn (c_uint, ?*anyopaque, c_int, c_int) callconv(.C) void; |
| 1272 | |
| 1273 | pub 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; |
| 1274 | pub extern "c" fn emscripten_async_wget2_abort(handle: c_int) void; |
| 1275 | pub extern "c" fn emscripten_wget(url: [*:0]const u8, file: [*:0]const u8) c_int; |
| 1276 | pub extern "c" fn emscripten_wget_data(url: [*:0]const u8, pbuffer: *(?*anyopaque), pnum: *c_int, perror: *c_int) void; |
| 1277 | pub extern "c" fn emscripten_run_script(script: [*:0]const u8) void; |
| 1278 | pub extern "c" fn emscripten_run_script_int(script: [*:0]const u8) c_int; |
| 1279 | pub extern "c" fn emscripten_run_script_string(script: [*:0]const u8) [*:0]u8; |
| 1280 | pub extern "c" fn emscripten_async_run_script(script: [*:0]const u8, millis: c_int) void; |
| 1281 | pub extern "c" fn emscripten_async_load_script(script: [*:0]const u8, onload: em_callback_func, onerror: em_callback_func) void; |
| 1282 | pub extern "c" fn emscripten_set_main_loop(func: em_callback_func, fps: c_int, simulate_infinite_loop: c_int) void; |
| 1283 | pub extern "c" fn emscripten_set_main_loop_timing(mode: c_int, value: c_int) c_int; |
| 1284 | pub extern "c" fn emscripten_get_main_loop_timing(mode: *c_int, value: *c_int) void; |
| 1285 | pub extern "c" fn emscripten_set_main_loop_arg(func: em_arg_callback_func, arg: ?*anyopaque, fps: c_int, simulate_infinite_loop: c_int) void; |
| 1286 | pub extern "c" fn emscripten_pause_main_loop() void; |
| 1287 | pub extern "c" fn emscripten_resume_main_loop() void; |
| 1288 | pub extern "c" fn emscripten_cancel_main_loop() void; |
| 1289 | |
| 1290 | pub const em_socket_callback = ?*const fn (c_int, ?*anyopaque) callconv(.C) void; |
| 1291 | pub const em_socket_error_callback = ?*const fn (c_int, c_int, [*:0]const u8, ?*anyopaque) callconv(.C) void; |
| 1292 | |
| 1293 | pub extern "c" fn emscripten_set_socket_error_callback(userData: ?*anyopaque, callback: em_socket_error_callback) void; |
| 1294 | pub extern "c" fn emscripten_set_socket_open_callback(userData: ?*anyopaque, callback: em_socket_callback) void; |
| 1295 | pub extern "c" fn emscripten_set_socket_listen_callback(userData: ?*anyopaque, callback: em_socket_callback) void; |
| 1296 | pub extern "c" fn emscripten_set_socket_connection_callback(userData: ?*anyopaque, callback: em_socket_callback) void; |
| 1297 | pub extern "c" fn emscripten_set_socket_message_callback(userData: ?*anyopaque, callback: em_socket_callback) void; |
| 1298 | pub extern "c" fn emscripten_set_socket_close_callback(userData: ?*anyopaque, callback: em_socket_callback) void; |
| 1299 | pub extern "c" fn _emscripten_push_main_loop_blocker(func: em_arg_callback_func, arg: ?*anyopaque, name: [*:0]const u8) void; |
| 1300 | pub extern "c" fn _emscripten_push_uncounted_main_loop_blocker(func: em_arg_callback_func, arg: ?*anyopaque, name: [*:0]const u8) void; |
| 1301 | pub extern "c" fn emscripten_set_main_loop_expected_blockers(num: c_int) void; |
| 1302 | pub extern "c" fn emscripten_async_call(func: em_arg_callback_func, arg: ?*anyopaque, millis: c_int) void; |
| 1303 | pub extern "c" fn emscripten_exit_with_live_runtime() noreturn; |
| 1304 | pub extern "c" fn emscripten_force_exit(status: c_int) noreturn; |
| 1305 | pub extern "c" fn emscripten_get_device_pixel_ratio() f64; |
| 1306 | pub extern "c" fn emscripten_get_window_title() [*:0]u8; |
| 1307 | pub extern "c" fn emscripten_set_window_title([*:0]const u8) void; |
| 1308 | pub extern "c" fn emscripten_get_screen_size(width: *c_int, height: *c_int) void; |
| 1309 | pub extern "c" fn emscripten_hide_mouse() void; |
| 1310 | pub extern "c" fn emscripten_set_canvas_size(width: c_int, height: c_int) void; |
| 1311 | pub extern "c" fn emscripten_get_canvas_size(width: *c_int, height: *c_int, isFullscreen: *c_int) void; |
| 1312 | pub extern "c" fn emscripten_get_now() f64; |
| 1313 | pub extern "c" fn emscripten_random() f32; |
| 1314 | pub const em_idb_onload_func = ?*const fn (?*anyopaque, ?*anyopaque, c_int) callconv(.C) void; |
| 1315 | pub 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; |
| 1316 | pub 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; |
| 1317 | pub 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; |
| 1318 | pub const em_idb_exists_func = ?*const fn (?*anyopaque, c_int) callconv(.C) void; |
| 1319 | pub 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; |
| 1320 | pub 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; |
| 1321 | pub 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; |
| 1322 | pub extern "c" fn emscripten_idb_delete(db_name: [*:0]const u8, file_id: [*:0]const u8, perror: *c_int) void; |
| 1323 | pub extern "c" fn emscripten_idb_exists(db_name: [*:0]const u8, file_id: [*:0]const u8, pexists: *c_int, perror: *c_int) void; |
| 1324 | pub extern "c" fn emscripten_idb_load_blob(db_name: [*:0]const u8, file_id: [*:0]const u8, pblob: *c_int, perror: *c_int) void; |
| 1325 | pub 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; |
| 1326 | pub extern "c" fn emscripten_idb_read_from_blob(blob: c_int, start: c_int, num: c_int, buffer: ?*anyopaque) void; |
| 1327 | pub extern "c" fn emscripten_idb_free_blob(blob: c_int) void; |
| 1328 | pub extern "c" fn emscripten_run_preload_plugins(file: [*:0]const u8, onload: em_str_callback_func, onerror: em_str_callback_func) c_int; |
| 1329 | pub const em_run_preload_plugins_data_onload_func = ?*const fn (?*anyopaque, [*:0]const u8) callconv(.C) void; |
| 1330 | pub 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; |
| 1331 | pub extern "c" fn emscripten_lazy_load_code() void; |
| 1332 | pub const worker_handle = c_int; |
| 1333 | pub extern "c" fn emscripten_create_worker(url: [*:0]const u8) worker_handle; |
| 1334 | pub extern "c" fn emscripten_destroy_worker(worker: worker_handle) void; |
| 1335 | pub const em_worker_callback_func = ?*const fn ([*]u8, c_int, ?*anyopaque) callconv(.C) void; |
| 1336 | pub 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; |
| 1337 | pub extern "c" fn emscripten_worker_respond(data: [*]u8, size: c_int) void; |
| 1338 | pub extern "c" fn emscripten_worker_respond_provisionally(data: [*]u8, size: c_int) void; |
| 1339 | pub extern "c" fn emscripten_get_worker_queue_size(worker: worker_handle) c_int; |
| 1340 | pub extern "c" fn emscripten_get_compiler_setting(name: [*:0]const u8) c_long; |
| 1341 | pub extern "c" fn emscripten_has_asyncify() c_int; |
| 1342 | pub extern "c" fn emscripten_debugger() void; |
| 1343 | |
| 1344 | pub extern "c" fn emscripten_get_preloaded_image_data(path: [*:0]const u8, w: *c_int, h: *c_int) ?[*]u8; |
| 1345 | pub extern "c" fn emscripten_get_preloaded_image_data_from_FILE(file: *FILE, w: *c_int, h: *c_int) ?[*]u8; |
| 1346 | pub extern "c" fn emscripten_log(flags: c_int, format: [*:0]const u8, ...) void; |
| 1347 | pub extern "c" fn emscripten_get_callstack(flags: c_int, out: ?[*]u8, maxbytes: c_int) c_int; |
| 1348 | pub extern "c" fn emscripten_print_double(x: f64, to: ?[*]u8, max: c_int) c_int; |
| 1349 | pub const em_scan_func = ?*const fn (?*anyopaque, ?*anyopaque) callconv(.C) void; |
| 1350 | pub extern "c" fn emscripten_scan_registers(func: em_scan_func) void; |
| 1351 | pub extern "c" fn emscripten_scan_stack(func: em_scan_func) void; |
| 1352 | pub const em_dlopen_callback = ?*const fn (?*anyopaque, ?*anyopaque) callconv(.C) void; |
| 1353 | pub 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; |
| 1354 | pub extern "c" fn emscripten_dlopen_promise(filename: [*:0]const u8, flags: c_int) em_promise_t; |
| 1355 | pub extern "c" fn emscripten_throw_number(number: f64) void; |
| 1356 | pub extern "c" fn emscripten_throw_string(utf8String: [*:0]const u8) void; |
| 1357 | pub extern "c" fn emscripten_sleep(ms: c_uint) void; |
| 1358 | |
| 1359 | pub const PROMISE = struct { |
| 1360 | pub const FULFILL = 0; |
| 1361 | pub const MATCH = 1; |
| 1362 | pub const MATCH_RELEASE = 2; |
| 1363 | pub const REJECT = 3; |
| 1364 | }; |
| 1365 | |
| 1366 | pub const struct__em_promise = opaque {}; |
| 1367 | pub const em_promise_t = ?*struct__em_promise; |
| 1368 | pub const enum_em_promise_result_t = c_uint; |
| 1369 | pub const em_promise_result_t = enum_em_promise_result_t; |
| 1370 | pub const em_promise_callback_t = ?*const fn (?*?*anyopaque, ?*anyopaque, ?*anyopaque) callconv(.C) em_promise_result_t; |
| 1371 | |
| 1372 | pub extern "c" fn emscripten_promise_create() em_promise_t; |
| 1373 | pub extern "c" fn emscripten_promise_destroy(promise: em_promise_t) void; |
| 1374 | pub extern "c" fn emscripten_promise_resolve(promise: em_promise_t, result: em_promise_result_t, value: ?*anyopaque) void; |
| 1375 | pub 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; |
| 1376 | pub extern "c" fn emscripten_promise_all(promises: [*]em_promise_t, results: ?[*]?*anyopaque, num_promises: usize) em_promise_t; |
| 1377 | |
| 1378 | pub const struct_em_settled_result_t = extern struct { |
| 1379 | result: em_promise_result_t, |
| 1380 | value: ?*anyopaque, |
| 1381 | }; |
| 1382 | pub const em_settled_result_t = struct_em_settled_result_t; |