| ... | ... | @@ -0,0 +1,1052 @@ |
| 1 | // SPDX-License-Identifier: MIT |
| 2 | // Copyright (c) 2015-2020 Zig Contributors |
| 3 | // This file is part of [zig](https://ziglang.org/), which is MIT licensed. |
| 4 | // The MIT license requires this copyright notice to be included in all copies |
| 5 | // and substantial portions of the software. |
| 6 | const std = @import("../../std.zig"); |
| 7 | const builtin = std.builtin; |
| 8 | const maxInt = std.math.maxInt; |
| 9 | |
| 10 | pub const blkcnt_t = i64; |
| 11 | pub const blksize_t = i32; |
| 12 | pub const clock_t = i64; |
| 13 | pub const dev_t = i32; |
| 14 | pub const fd_t = c_int; |
| 15 | pub const gid_t = u32; |
| 16 | pub const ino_t = u64; |
| 17 | pub const mode_t = u32; |
| 18 | pub const nlink_t = u32; |
| 19 | pub const off_t = i64; |
| 20 | pub const pid_t = i32; |
| 21 | pub const socklen_t = u32; |
| 22 | pub const time_t = i64; |
| 23 | pub const uid_t = u32; |
| 24 | |
| 25 | /// Renamed from `kevent` to `Kevent` to avoid conflict with function name. |
| 26 | pub const Kevent = extern struct { |
| 27 | ident: usize, |
| 28 | filter: c_short, |
| 29 | flags: u16, |
| 30 | fflags: c_uint, |
| 31 | data: i64, |
| 32 | udata: usize, |
| 33 | }; |
| 34 | |
| 35 | pub const dl_phdr_info = extern struct { |
| 36 | dlpi_addr: usize, |
| 37 | dlpi_name: ?[*:0]const u8, |
| 38 | dlpi_phdr: [*]std.elf.Phdr, |
| 39 | dlpi_phnum: u16, |
| 40 | }; |
| 41 | |
| 42 | pub const Flock = extern struct { |
| 43 | l_start: off_t, |
| 44 | l_len: off_t, |
| 45 | l_pid: pid_t, |
| 46 | l_type: i16, |
| 47 | l_whence: i16, |
| 48 | }; |
| 49 | |
| 50 | pub const addrinfo = extern struct { |
| 51 | flags: i32, |
| 52 | family: i32, |
| 53 | socktype: i32, |
| 54 | protocol: i32, |
| 55 | addrlen: socklen_t, |
| 56 | canonname: ?[*:0]u8, |
| 57 | addr: ?*sockaddr, |
| 58 | next: ?*addrinfo, |
| 59 | }; |
| 60 | |
| 61 | pub const EAI = extern enum(c_int) { |
| 62 | /// address family for hostname not supported |
| 63 | ADDRFAMILY = -9, |
| 64 | |
| 65 | /// name could not be resolved at this time |
| 66 | AGAIN = -3, |
| 67 | |
| 68 | /// flags parameter had an invalid value |
| 69 | BADFLAGS = -1, |
| 70 | |
| 71 | /// non-recoverable failure in name resolution |
| 72 | FAIL = -4, |
| 73 | |
| 74 | /// address family not recognized |
| 75 | FAMILY = -6, |
| 76 | |
| 77 | /// memory allocation failure |
| 78 | MEMORY = -10, |
| 79 | |
| 80 | /// no address associated with hostname |
| 81 | NODATA = -5, |
| 82 | |
| 83 | /// name does not resolve |
| 84 | NONAME = -2, |
| 85 | |
| 86 | /// service not recognized for socket type |
| 87 | SERVICE = -8, |
| 88 | |
| 89 | /// intended socket type was not recognized |
| 90 | SOCKTYPE = -7, |
| 91 | |
| 92 | /// system error returned in errno |
| 93 | SYSTEM = -11, |
| 94 | |
| 95 | /// invalid value for hints |
| 96 | BADHINTS = -12, |
| 97 | |
| 98 | /// resolved protocol is unknown |
| 99 | PROTOCOL = -13, |
| 100 | |
| 101 | /// argument buffer overflow |
| 102 | OVERFLOW = -14, |
| 103 | |
| 104 | _, |
| 105 | }; |
| 106 | |
| 107 | pub const EAI_MAX = 15; |
| 108 | |
| 109 | pub const msghdr = extern struct { |
| 110 | /// optional address |
| 111 | msg_name: ?*sockaddr, |
| 112 | |
| 113 | /// size of address |
| 114 | msg_namelen: socklen_t, |
| 115 | |
| 116 | /// scatter/gather array |
| 117 | msg_iov: [*]iovec, |
| 118 | |
| 119 | /// # elements in msg_iov |
| 120 | msg_iovlen: i32, |
| 121 | |
| 122 | /// ancillary data |
| 123 | msg_control: ?*c_void, |
| 124 | |
| 125 | /// ancillary data buffer len |
| 126 | msg_controllen: socklen_t, |
| 127 | |
| 128 | /// flags on received message |
| 129 | msg_flags: i32, |
| 130 | }; |
| 131 | |
| 132 | pub const msghdr_const = extern struct { |
| 133 | /// optional address |
| 134 | msg_name: ?*const sockaddr, |
| 135 | |
| 136 | /// size of address |
| 137 | msg_namelen: socklen_t, |
| 138 | |
| 139 | /// scatter/gather array |
| 140 | msg_iov: [*]iovec_const, |
| 141 | |
| 142 | /// # elements in msg_iov |
| 143 | msg_iovlen: i32, |
| 144 | |
| 145 | /// ancillary data |
| 146 | msg_control: ?*c_void, |
| 147 | |
| 148 | /// ancillary data buffer len |
| 149 | msg_controllen: socklen_t, |
| 150 | |
| 151 | /// flags on received message |
| 152 | msg_flags: i32, |
| 153 | }; |
| 154 | |
| 155 | /// Renamed to Stat to not conflict with the stat function. |
| 156 | /// atime, mtime, and ctime have functions to return `timespec`, |
| 157 | /// because although this is a POSIX API, the layout and names of |
| 158 | /// the structs are inconsistent across operating systems, and |
| 159 | /// in C, macros are used to hide the differences. Here we use |
| 160 | /// methods to accomplish this. |
| 161 | pub const Stat = extern struct { |
| 162 | mode: mode_t, |
| 163 | dev: dev_t, |
| 164 | ino: ino_t, |
| 165 | nlink: nlink_t, |
| 166 | uid: uid_t, |
| 167 | gid: gid_t, |
| 168 | rdev: dev_t, |
| 169 | atim: timespec, |
| 170 | mtim: timespec, |
| 171 | ctim: timespec, |
| 172 | size: off_t, |
| 173 | blocks: blkcnt_t, |
| 174 | blksize: blksize_t, |
| 175 | flags: u32, |
| 176 | gen: u32, |
| 177 | birthtim: timespec, |
| 178 | |
| 179 | pub fn atime(self: Stat) timespec { |
| 180 | return self.atim; |
| 181 | } |
| 182 | |
| 183 | pub fn mtime(self: Stat) timespec { |
| 184 | return self.mtim; |
| 185 | } |
| 186 | |
| 187 | pub fn ctime(self: Stat) timespec { |
| 188 | return self.ctim; |
| 189 | } |
| 190 | }; |
| 191 | |
| 192 | pub const timespec = extern struct { |
| 193 | tv_sec: time_t, |
| 194 | tv_nsec: isize, |
| 195 | }; |
| 196 | |
| 197 | pub const MAXNAMLEN = 255; |
| 198 | |
| 199 | pub const dirent = extern struct { |
| 200 | d_fileno: ino_t, |
| 201 | d_off: off_t, |
| 202 | d_reclen: u16, |
| 203 | d_type: u8, |
| 204 | d_namlen: u8, |
| 205 | __d_padding: [4]u8, |
| 206 | d_name: [MAXNAMLEN + 1]u8, |
| 207 | |
| 208 | pub fn reclen(self: dirent) u16 { |
| 209 | return self.d_reclen; |
| 210 | } |
| 211 | }; |
| 212 | |
| 213 | pub const in_port_t = u16; |
| 214 | pub const sa_family_t = u8; |
| 215 | |
| 216 | pub const sockaddr = extern struct { |
| 217 | /// total length |
| 218 | len: u8, |
| 219 | |
| 220 | /// address family |
| 221 | family: sa_family_t, |
| 222 | |
| 223 | /// actually longer; address value |
| 224 | data: [14]u8, |
| 225 | }; |
| 226 | |
| 227 | pub const sockaddr_in = extern struct { |
| 228 | len: u8 = @sizeOf(sockaddr_in), |
| 229 | family: sa_family_t = AF_INET, |
| 230 | port: in_port_t, |
| 231 | addr: u32, |
| 232 | zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 233 | }; |
| 234 | |
| 235 | pub const sockaddr_in6 = extern struct { |
| 236 | len: u8 = @sizeOf(sockaddr_in6), |
| 237 | family: sa_family_t = AF_INET6, |
| 238 | port: in_port_t, |
| 239 | flowinfo: u32, |
| 240 | addr: [16]u8, |
| 241 | scope_id: u32, |
| 242 | }; |
| 243 | |
| 244 | /// Definitions for UNIX IPC domain. |
| 245 | pub const sockaddr_un = extern struct { |
| 246 | /// total sockaddr length |
| 247 | len: u8 = @sizeOf(sockaddr_un), |
| 248 | |
| 249 | /// AF_LOCAL |
| 250 | family: sa_family_t = AF_LOCAL, |
| 251 | |
| 252 | /// path name |
| 253 | path: [104]u8, |
| 254 | }; |
| 255 | |
| 256 | /// get address to use bind() |
| 257 | pub const AI_PASSIVE = 1; |
| 258 | |
| 259 | /// fill ai_canonname |
| 260 | pub const AI_CANONNAME = 2; |
| 261 | |
| 262 | /// prevent host name resolution |
| 263 | pub const AI_NUMERICHOST = 4; |
| 264 | |
| 265 | /// prevent service name resolution |
| 266 | pub const AI_NUMERICSERV = 16; |
| 267 | |
| 268 | /// only if any address is assigned |
| 269 | pub const AI_ADDRCONFIG = 64; |
| 270 | |
| 271 | pub const CTL_KERN = 1; |
| 272 | pub const CTL_DEBUG = 5; |
| 273 | |
| 274 | pub const KERN_PROC_ARGS = 55; |
| 275 | pub const KERN_PROC_ARGV = 1; |
| 276 | |
| 277 | pub const PATH_MAX = 1024; |
| 278 | |
| 279 | pub const STDIN_FILENO = 0; |
| 280 | pub const STDOUT_FILENO = 1; |
| 281 | pub const STDERR_FILENO = 2; |
| 282 | |
| 283 | pub const PROT_NONE = 0; |
| 284 | pub const PROT_READ = 1; |
| 285 | pub const PROT_WRITE = 2; |
| 286 | pub const PROT_EXEC = 4; |
| 287 | |
| 288 | pub const CLOCK_REALTIME = 0; |
| 289 | pub const CLOCK_PROCESS_CPUTIME_ID = 2; |
| 290 | pub const CLOCK_MONOTONIC = 3; |
| 291 | pub const CLOCK_THREAD_CPUTIME_ID = 4; |
| 292 | |
| 293 | pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize)); |
| 294 | pub const MAP_SHARED = 0x0001; |
| 295 | pub const MAP_PRIVATE = 0x0002; |
| 296 | pub const MAP_FIXED = 0x0010; |
| 297 | pub const MAP_RENAME = 0; |
| 298 | pub const MAP_NORESERVE = 0; |
| 299 | pub const MAP_INHERIT = 0; |
| 300 | pub const MAP_HASSEMAPHORE = 0; |
| 301 | pub const MAP_TRYFIXED = 0; |
| 302 | |
| 303 | pub const MAP_FILE = 0; |
| 304 | pub const MAP_ANON = 0x1000; |
| 305 | pub const MAP_ANONYMOUS = MAP_ANON; |
| 306 | pub const MAP_STACK = 0x4000; |
| 307 | pub const MAP_CONCEAL = 0x8000; |
| 308 | |
| 309 | pub const WNOHANG = 1; |
| 310 | pub const WUNTRACED = 2; |
| 311 | pub const WCONTINUED = 8; |
| 312 | |
| 313 | pub const SA_ONSTACK = 0x0001; |
| 314 | pub const SA_RESTART = 0x0002; |
| 315 | pub const SA_RESETHAND = 0x0004; |
| 316 | pub const SA_NOCLDSTOP = 0x0008; |
| 317 | pub const SA_NODEFER = 0x0010; |
| 318 | pub const SA_NOCLDWAIT = 0x0020; |
| 319 | pub const SA_SIGINFO = 0x0040; |
| 320 | |
| 321 | pub const SIGHUP = 1; |
| 322 | pub const SIGINT = 2; |
| 323 | pub const SIGQUIT = 3; |
| 324 | pub const SIGILL = 4; |
| 325 | pub const SIGTRAP = 5; |
| 326 | pub const SIGABRT = 6; |
| 327 | pub const SIGIOT = SIGABRT; |
| 328 | pub const SIGEMT = 7; |
| 329 | pub const SIGFPE = 8; |
| 330 | pub const SIGKILL = 9; |
| 331 | pub const SIGBUS = 10; |
| 332 | pub const SIGSEGV = 11; |
| 333 | pub const SIGSYS = 12; |
| 334 | pub const SIGPIPE = 13; |
| 335 | pub const SIGALRM = 14; |
| 336 | pub const SIGTERM = 15; |
| 337 | pub const SIGURG = 16; |
| 338 | pub const SIGSTOP = 17; |
| 339 | pub const SIGTSTP = 18; |
| 340 | pub const SIGCONT = 19; |
| 341 | pub const SIGCHLD = 20; |
| 342 | pub const SIGTTIN = 21; |
| 343 | pub const SIGTTOU = 22; |
| 344 | pub const SIGIO = 23; |
| 345 | pub const SIGXCPU = 24; |
| 346 | pub const SIGXFSZ = 25; |
| 347 | pub const SIGVTALRM = 26; |
| 348 | pub const SIGPROF = 27; |
| 349 | pub const SIGWINCH = 28; |
| 350 | pub const SIGINFO = 29; |
| 351 | pub const SIGUSR1 = 30; |
| 352 | pub const SIGUSR2 = 31; |
| 353 | pub const SIGPWR = 32; |
| 354 | |
| 355 | // access function |
| 356 | pub const F_OK = 0; // test for existence of file |
| 357 | pub const X_OK = 1; // test for execute or search permission |
| 358 | pub const W_OK = 2; // test for write permission |
| 359 | pub const R_OK = 4; // test for read permission |
| 360 | |
| 361 | /// open for reading only |
| 362 | pub const O_RDONLY = 0x00000000; |
| 363 | |
| 364 | /// open for writing only |
| 365 | pub const O_WRONLY = 0x00000001; |
| 366 | |
| 367 | /// open for reading and writing |
| 368 | pub const O_RDWR = 0x00000002; |
| 369 | |
| 370 | /// mask for above modes |
| 371 | pub const O_ACCMODE = 0x00000003; |
| 372 | |
| 373 | /// no delay |
| 374 | pub const O_NONBLOCK = 0x00000004; |
| 375 | |
| 376 | /// set append mode |
| 377 | pub const O_APPEND = 0x00000008; |
| 378 | |
| 379 | /// open with shared file lock |
| 380 | pub const O_SHLOCK = 0x00000010; |
| 381 | |
| 382 | /// open with exclusive file lock |
| 383 | pub const O_EXLOCK = 0x00000020; |
| 384 | |
| 385 | /// signal pgrp when data ready |
| 386 | pub const O_ASYNC = 0x00000040; |
| 387 | |
| 388 | /// synchronous writes |
| 389 | pub const O_SYNC = 0x00000080; |
| 390 | |
| 391 | /// don't follow symlinks on the last |
| 392 | pub const O_NOFOLLOW = 0x00000100; |
| 393 | |
| 394 | /// create if nonexistent |
| 395 | pub const O_CREAT = 0x00000200; |
| 396 | |
| 397 | /// truncate to zero length |
| 398 | pub const O_TRUNC = 0x00000400; |
| 399 | |
| 400 | /// error if already exists |
| 401 | pub const O_EXCL = 0x00000800; |
| 402 | |
| 403 | /// don't assign controlling terminal |
| 404 | pub const O_NOCTTY = 0x00008000; |
| 405 | |
| 406 | /// write: I/O data completion |
| 407 | pub const O_DSYNC = O_SYNC; |
| 408 | |
| 409 | /// read: I/O completion as for write |
| 410 | pub const O_RSYNC = O_SYNC; |
| 411 | |
| 412 | /// fail if not a directory |
| 413 | pub const O_DIRECTORY = 0x20000; |
| 414 | |
| 415 | /// set close on exec |
| 416 | pub const O_CLOEXEC = 0x10000; |
| 417 | |
| 418 | pub const F_DUPFD = 0; |
| 419 | pub const F_GETFD = 1; |
| 420 | pub const F_SETFD = 2; |
| 421 | pub const F_GETFL = 3; |
| 422 | pub const F_SETFL = 4; |
| 423 | |
| 424 | pub const F_GETOWN = 5; |
| 425 | pub const F_SETOWN = 6; |
| 426 | |
| 427 | pub const F_GETLK = 7; |
| 428 | pub const F_SETLK = 8; |
| 429 | pub const F_SETLKW = 9; |
| 430 | |
| 431 | pub const F_RDLCK = 1; |
| 432 | pub const F_UNLCK = 2; |
| 433 | pub const F_WRLCK = 3; |
| 434 | |
| 435 | pub const LOCK_SH = 0x01; |
| 436 | pub const LOCK_EX = 0x02; |
| 437 | pub const LOCK_NB = 0x04; |
| 438 | pub const LOCK_UN = 0x08; |
| 439 | |
| 440 | pub const FD_CLOEXEC = 1; |
| 441 | |
| 442 | pub const SEEK_SET = 0; |
| 443 | pub const SEEK_CUR = 1; |
| 444 | pub const SEEK_END = 2; |
| 445 | |
| 446 | pub const SIG_BLOCK = 1; |
| 447 | pub const SIG_UNBLOCK = 2; |
| 448 | pub const SIG_SETMASK = 3; |
| 449 | |
| 450 | pub const SOCK_STREAM = 1; |
| 451 | pub const SOCK_DGRAM = 2; |
| 452 | pub const SOCK_RAW = 3; |
| 453 | pub const SOCK_RDM = 4; |
| 454 | pub const SOCK_SEQPACKET = 5; |
| 455 | |
| 456 | pub const SOCK_CLOEXEC = 0x8000; |
| 457 | pub const SOCK_NONBLOCK = 0x4000; |
| 458 | |
| 459 | pub const PF_UNSPEC = AF_UNSPEC; |
| 460 | pub const PF_LOCAL = AF_LOCAL; |
| 461 | pub const PF_UNIX = AF_UNIX; |
| 462 | pub const PF_INET = AF_INET; |
| 463 | pub const PF_APPLETALK = AF_APPLETALK; |
| 464 | pub const PF_INET6 = AF_INET6; |
| 465 | pub const PF_DECnet = AF_DECnet; |
| 466 | pub const PF_KEY = AF_KEY; |
| 467 | pub const PF_ROUTE = AF_ROUTE; |
| 468 | pub const PF_SNA = AF_SNA; |
| 469 | pub const PF_MPLS = AF_MPLS; |
| 470 | pub const PF_BLUETOOTH = AF_BLUETOOTH; |
| 471 | pub const PF_ISDN = AF_ISDN; |
| 472 | pub const PF_MAX = AF_MAX; |
| 473 | |
| 474 | pub const AF_UNSPEC = 0; |
| 475 | pub const AF_UNIX = 1; |
| 476 | pub const AF_LOCAL = AF_UNIX; |
| 477 | pub const AF_INET = 2; |
| 478 | pub const AF_APPLETALK = 16; |
| 479 | pub const AF_INET6 = 24; |
| 480 | pub const AF_KEY = 30; |
| 481 | pub const AF_ROUTE = 17; |
| 482 | pub const AF_SNA = 11; |
| 483 | pub const AF_MPLS = 33; |
| 484 | pub const AF_BLUETOOTH = 32; |
| 485 | pub const AF_ISDN = 26; |
| 486 | pub const AF_MAX = 36; |
| 487 | |
| 488 | pub const DT_UNKNOWN = 0; |
| 489 | pub const DT_FIFO = 1; |
| 490 | pub const DT_CHR = 2; |
| 491 | pub const DT_DIR = 4; |
| 492 | pub const DT_BLK = 6; |
| 493 | pub const DT_REG = 8; |
| 494 | pub const DT_LNK = 10; |
| 495 | pub const DT_SOCK = 12; |
| 496 | pub const DT_WHT = 14; // XXX |
| 497 | |
| 498 | /// add event to kq (implies enable) |
| 499 | pub const EV_ADD = 0x0001; |
| 500 | |
| 501 | /// delete event from kq |
| 502 | pub const EV_DELETE = 0x0002; |
| 503 | |
| 504 | /// enable event |
| 505 | pub const EV_ENABLE = 0x0004; |
| 506 | |
| 507 | /// disable event (not reported) |
| 508 | pub const EV_DISABLE = 0x0008; |
| 509 | |
| 510 | /// only report one occurrence |
| 511 | pub const EV_ONESHOT = 0x0010; |
| 512 | |
| 513 | /// clear event state after reporting |
| 514 | pub const EV_CLEAR = 0x0020; |
| 515 | |
| 516 | /// force immediate event output |
| 517 | /// ... with or without EV_ERROR |
| 518 | /// ... use KEVENT_FLAG_ERROR_EVENTS |
| 519 | /// on syscalls supporting flags |
| 520 | pub const EV_RECEIPT = 0x0040; |
| 521 | |
| 522 | /// disable event after reporting |
| 523 | pub const EV_DISPATCH = 0x0080; |
| 524 | |
| 525 | pub const EVFILT_READ = -1; |
| 526 | pub const EVFILT_WRITE = -2; |
| 527 | |
| 528 | /// attached to aio requests |
| 529 | pub const EVFILT_AIO = -3; |
| 530 | |
| 531 | /// attached to vnodes |
| 532 | pub const EVFILT_VNODE = -4; |
| 533 | |
| 534 | /// attached to struct proc |
| 535 | pub const EVFILT_PROC = -5; |
| 536 | |
| 537 | /// attached to struct proc |
| 538 | pub const EVFILT_SIGNAL = -6; |
| 539 | |
| 540 | /// timers |
| 541 | pub const EVFILT_TIMER = -7; |
| 542 | |
| 543 | /// devices |
| 544 | pub const EVFILT_DEVICE = -8; |
| 545 | |
| 546 | /// low water mark |
| 547 | pub const NOTE_LOWAT = 0x0001; |
| 548 | |
| 549 | /// return on EOF |
| 550 | pub const NOTE_EOF = 0x0002; |
| 551 | |
| 552 | /// vnode was removed |
| 553 | pub const NOTE_DELETE = 0x0001; |
| 554 | |
| 555 | /// data contents changed |
| 556 | pub const NOTE_WRITE = 0x0002; |
| 557 | |
| 558 | /// size increased |
| 559 | pub const NOTE_EXTEND = 0x0004; |
| 560 | |
| 561 | /// attributes changed |
| 562 | pub const NOTE_ATTRIB = 0x0008; |
| 563 | |
| 564 | /// link count changed |
| 565 | pub const NOTE_LINK = 0x0010; |
| 566 | |
| 567 | /// vnode was renamed |
| 568 | pub const NOTE_RENAME = 0x0020; |
| 569 | |
| 570 | /// vnode access was revoked |
| 571 | pub const NOTE_REVOKE = 0x0040; |
| 572 | |
| 573 | /// process exited |
| 574 | pub const NOTE_EXIT = 0x80000000; |
| 575 | |
| 576 | /// process forked |
| 577 | pub const NOTE_FORK = 0x40000000; |
| 578 | |
| 579 | /// process exec'd |
| 580 | pub const NOTE_EXEC = 0x20000000; |
| 581 | |
| 582 | /// mask for signal & exit status |
| 583 | pub const NOTE_PDATAMASK = 0x000fffff; |
| 584 | pub const NOTE_PCTRLMASK = 0xf0000000; |
| 585 | |
| 586 | pub const TIOCCBRK = 0x2000747a; |
| 587 | pub const TIOCCDTR = 0x20007478; |
| 588 | pub const TIOCCONS = 0x80047462; |
| 589 | pub const TIOCDCDTIMESTAMP = 0x40107458; |
| 590 | pub const TIOCDRAIN = 0x2000745e; |
| 591 | pub const TIOCEXCL = 0x2000740d; |
| 592 | pub const TIOCEXT = 0x80047460; |
| 593 | pub const TIOCFLAG_CDTRCTS = 0x10; |
| 594 | pub const TIOCFLAG_CLOCAL = 0x2; |
| 595 | pub const TIOCFLAG_CRTSCTS = 0x4; |
| 596 | pub const TIOCFLAG_MDMBUF = 0x8; |
| 597 | pub const TIOCFLAG_SOFTCAR = 0x1; |
| 598 | pub const TIOCFLUSH = 0x80047410; |
| 599 | pub const TIOCGETA = 0x402c7413; |
| 600 | pub const TIOCGETD = 0x4004741a; |
| 601 | pub const TIOCGFLAGS = 0x4004745d; |
| 602 | pub const TIOCGLINED = 0x40207442; |
| 603 | pub const TIOCGPGRP = 0x40047477; |
| 604 | pub const TIOCGQSIZE = 0x40047481; |
| 605 | pub const TIOCGRANTPT = 0x20007447; |
| 606 | pub const TIOCGSID = 0x40047463; |
| 607 | pub const TIOCGSIZE = 0x40087468; |
| 608 | pub const TIOCGWINSZ = 0x40087468; |
| 609 | pub const TIOCMBIC = 0x8004746b; |
| 610 | pub const TIOCMBIS = 0x8004746c; |
| 611 | pub const TIOCMGET = 0x4004746a; |
| 612 | pub const TIOCMSET = 0x8004746d; |
| 613 | pub const TIOCM_CAR = 0x40; |
| 614 | pub const TIOCM_CD = 0x40; |
| 615 | pub const TIOCM_CTS = 0x20; |
| 616 | pub const TIOCM_DSR = 0x100; |
| 617 | pub const TIOCM_DTR = 0x2; |
| 618 | pub const TIOCM_LE = 0x1; |
| 619 | pub const TIOCM_RI = 0x80; |
| 620 | pub const TIOCM_RNG = 0x80; |
| 621 | pub const TIOCM_RTS = 0x4; |
| 622 | pub const TIOCM_SR = 0x10; |
| 623 | pub const TIOCM_ST = 0x8; |
| 624 | pub const TIOCNOTTY = 0x20007471; |
| 625 | pub const TIOCNXCL = 0x2000740e; |
| 626 | pub const TIOCOUTQ = 0x40047473; |
| 627 | pub const TIOCPKT = 0x80047470; |
| 628 | pub const TIOCPKT_DATA = 0x0; |
| 629 | pub const TIOCPKT_DOSTOP = 0x20; |
| 630 | pub const TIOCPKT_FLUSHREAD = 0x1; |
| 631 | pub const TIOCPKT_FLUSHWRITE = 0x2; |
| 632 | pub const TIOCPKT_IOCTL = 0x40; |
| 633 | pub const TIOCPKT_NOSTOP = 0x10; |
| 634 | pub const TIOCPKT_START = 0x8; |
| 635 | pub const TIOCPKT_STOP = 0x4; |
| 636 | pub const TIOCPTMGET = 0x40287446; |
| 637 | pub const TIOCPTSNAME = 0x40287448; |
| 638 | pub const TIOCRCVFRAME = 0x80087445; |
| 639 | pub const TIOCREMOTE = 0x80047469; |
| 640 | pub const TIOCSBRK = 0x2000747b; |
| 641 | pub const TIOCSCTTY = 0x20007461; |
| 642 | pub const TIOCSDTR = 0x20007479; |
| 643 | pub const TIOCSETA = 0x802c7414; |
| 644 | pub const TIOCSETAF = 0x802c7416; |
| 645 | pub const TIOCSETAW = 0x802c7415; |
| 646 | pub const TIOCSETD = 0x8004741b; |
| 647 | pub const TIOCSFLAGS = 0x8004745c; |
| 648 | pub const TIOCSIG = 0x2000745f; |
| 649 | pub const TIOCSLINED = 0x80207443; |
| 650 | pub const TIOCSPGRP = 0x80047476; |
| 651 | pub const TIOCSQSIZE = 0x80047480; |
| 652 | pub const TIOCSSIZE = 0x80087467; |
| 653 | pub const TIOCSTART = 0x2000746e; |
| 654 | pub const TIOCSTAT = 0x80047465; |
| 655 | pub const TIOCSTI = 0x80017472; |
| 656 | pub const TIOCSTOP = 0x2000746f; |
| 657 | pub const TIOCSWINSZ = 0x80087467; |
| 658 | pub const TIOCUCNTL = 0x80047466; |
| 659 | pub const TIOCXMTFRAME = 0x80087444; |
| 660 | |
| 661 | pub fn WEXITSTATUS(s: u32) u32 { |
| 662 | return (s >> 8) & 0xff; |
| 663 | } |
| 664 | pub fn WTERMSIG(s: u32) u32 { |
| 665 | return (s & 0x7f); |
| 666 | } |
| 667 | pub fn WSTOPSIG(s: u32) u32 { |
| 668 | return WEXITSTATUS(s); |
| 669 | } |
| 670 | pub fn WIFEXITED(s: u32) bool { |
| 671 | return WTERMSIG(s) == 0; |
| 672 | } |
| 673 | |
| 674 | pub fn WIFCONTINUED(s: u32) bool { |
| 675 | return ((s & 0o177777) == 0o177777); |
| 676 | } |
| 677 | |
| 678 | pub fn WIFSTOPPED(s: u32) bool { |
| 679 | return (s & 0xff == 0o177); |
| 680 | } |
| 681 | |
| 682 | pub fn WIFSIGNALED(s: u32) bool { |
| 683 | return (((s) & 0o177) != 0o177) and (((s) & 0o177) != 0); |
| 684 | } |
| 685 | |
| 686 | pub const winsize = extern struct { |
| 687 | ws_row: u16, |
| 688 | ws_col: u16, |
| 689 | ws_xpixel: u16, |
| 690 | ws_ypixel: u16, |
| 691 | }; |
| 692 | |
| 693 | const NSIG = 33; |
| 694 | |
| 695 | pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); |
| 696 | pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0); |
| 697 | pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1); |
| 698 | |
| 699 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 700 | pub const Sigaction = extern struct { |
| 701 | pub const sigaction_fn = fn (c_int, *siginfo_t, ?*c_void) callconv(.C) void; |
| 702 | /// signal handler |
| 703 | sigaction: ?sigaction_fn, |
| 704 | /// signal mask to apply |
| 705 | mask: sigset_t, |
| 706 | /// signal options |
| 707 | flags: c_int, |
| 708 | }; |
| 709 | |
| 710 | pub const sigval = extern union { |
| 711 | int: c_int, |
| 712 | ptr: ?*c_void, |
| 713 | }; |
| 714 | |
| 715 | pub const siginfo_t = extern union { |
| 716 | pad: [128]u8, |
| 717 | info: _ksiginfo, |
| 718 | }; |
| 719 | |
| 720 | pub const _ksiginfo = extern struct { |
| 721 | signo: c_int, |
| 722 | code: c_int, |
| 723 | errno: c_int, |
| 724 | data: extern union { |
| 725 | proc: extern struct { |
| 726 | pid: pid_t, |
| 727 | uid: uid_t, |
| 728 | value: sigval, |
| 729 | utime: clock_t, |
| 730 | stime: clock_t, |
| 731 | status: c_int, |
| 732 | }, |
| 733 | fault: extern struct { |
| 734 | addr: ?*c_void, |
| 735 | trapno: c_int, |
| 736 | }, |
| 737 | } align(@sizeOf(usize)), |
| 738 | }; |
| 739 | |
| 740 | pub const sigset_t = c_uint; |
| 741 | pub const empty_sigset = sigset_t(0); |
| 742 | |
| 743 | pub const EPERM = 1; // Operation not permitted |
| 744 | pub const ENOENT = 2; // No such file or directory |
| 745 | pub const ESRCH = 3; // No such process |
| 746 | pub const EINTR = 4; // Interrupted system call |
| 747 | pub const EIO = 5; // Input/output error |
| 748 | pub const ENXIO = 6; // Device not configured |
| 749 | pub const E2BIG = 7; // Argument list too long |
| 750 | pub const ENOEXEC = 8; // Exec format error |
| 751 | pub const EBADF = 9; // Bad file descriptor |
| 752 | pub const ECHILD = 10; // No child processes |
| 753 | pub const EDEADLK = 11; // Resource deadlock avoided |
| 754 | // 11 was EAGAIN |
| 755 | pub const ENOMEM = 12; // Cannot allocate memory |
| 756 | pub const EACCES = 13; // Permission denied |
| 757 | pub const EFAULT = 14; // Bad address |
| 758 | pub const ENOTBLK = 15; // Block device required |
| 759 | pub const EBUSY = 16; // Device busy |
| 760 | pub const EEXIST = 17; // File exists |
| 761 | pub const EXDEV = 18; // Cross-device link |
| 762 | pub const ENODEV = 19; // Operation not supported by device |
| 763 | pub const ENOTDIR = 20; // Not a directory |
| 764 | pub const EISDIR = 21; // Is a directory |
| 765 | pub const EINVAL = 22; // Invalid argument |
| 766 | pub const ENFILE = 23; // Too many open files in system |
| 767 | pub const EMFILE = 24; // Too many open files |
| 768 | pub const ENOTTY = 25; // Inappropriate ioctl for device |
| 769 | pub const ETXTBSY = 26; // Text file busy |
| 770 | pub const EFBIG = 27; // File too large |
| 771 | pub const ENOSPC = 28; // No space left on device |
| 772 | pub const ESPIPE = 29; // Illegal seek |
| 773 | pub const EROFS = 30; // Read-only file system |
| 774 | pub const EMLINK = 31; // Too many links |
| 775 | pub const EPIPE = 32; // Broken pipe |
| 776 | |
| 777 | // math software |
| 778 | pub const EDOM = 33; // Numerical argument out of domain |
| 779 | pub const ERANGE = 34; // Result too large or too small |
| 780 | |
| 781 | // non-blocking and interrupt i/o |
| 782 | pub const EAGAIN = 35; // Resource temporarily unavailable |
| 783 | pub const EWOULDBLOCK = EAGAIN; // Operation would block |
| 784 | pub const EINPROGRESS = 36; // Operation now in progress |
| 785 | pub const EALREADY = 37; // Operation already in progress |
| 786 | |
| 787 | // ipc/network software -- argument errors |
| 788 | pub const ENOTSOCK = 38; // Socket operation on non-socket |
| 789 | pub const EDESTADDRREQ = 39; // Destination address required |
| 790 | pub const EMSGSIZE = 40; // Message too long |
| 791 | pub const EPROTOTYPE = 41; // Protocol wrong type for socket |
| 792 | pub const ENOPROTOOPT = 42; // Protocol option not available |
| 793 | pub const EPROTONOSUPPORT = 43; // Protocol not supported |
| 794 | pub const ESOCKTNOSUPPORT = 44; // Socket type not supported |
| 795 | pub const EOPNOTSUPP = 45; // Operation not supported |
| 796 | pub const EPFNOSUPPORT = 46; // Protocol family not supported |
| 797 | pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family |
| 798 | pub const EADDRINUSE = 48; // Address already in use |
| 799 | pub const EADDRNOTAVAIL = 49; // Can't assign requested address |
| 800 | |
| 801 | // ipc/network software -- operational errors |
| 802 | pub const ENETDOWN = 50; // Network is down |
| 803 | pub const ENETUNREACH = 51; // Network is unreachable |
| 804 | pub const ENETRESET = 52; // Network dropped connection on reset |
| 805 | pub const ECONNABORTED = 53; // Software caused connection abort |
| 806 | pub const ECONNRESET = 54; // Connection reset by peer |
| 807 | pub const ENOBUFS = 55; // No buffer space available |
| 808 | pub const EISCONN = 56; // Socket is already connected |
| 809 | pub const ENOTCONN = 57; // Socket is not connected |
| 810 | pub const ESHUTDOWN = 58; // Can't send after socket shutdown |
| 811 | pub const ETOOMANYREFS = 59; // Too many references: can't splice |
| 812 | pub const ETIMEDOUT = 60; // Operation timed out |
| 813 | pub const ECONNREFUSED = 61; // Connection refused |
| 814 | |
| 815 | pub const ELOOP = 62; // Too many levels of symbolic links |
| 816 | pub const ENAMETOOLONG = 63; // File name too long |
| 817 | |
| 818 | // should be rearranged |
| 819 | pub const EHOSTDOWN = 64; // Host is down |
| 820 | pub const EHOSTUNREACH = 65; // No route to host |
| 821 | pub const ENOTEMPTY = 66; // Directory not empty |
| 822 | |
| 823 | // quotas & mush |
| 824 | pub const EPROCLIM = 67; // Too many processes |
| 825 | pub const EUSERS = 68; // Too many users |
| 826 | pub const EDQUOT = 69; // Disc quota exceeded |
| 827 | |
| 828 | // Network File System |
| 829 | pub const ESTALE = 70; // Stale NFS file handle |
| 830 | pub const EREMOTE = 71; // Too many levels of remote in path |
| 831 | pub const EBADRPC = 72; // RPC struct is bad |
| 832 | pub const ERPCMISMATCH = 73; // RPC version wrong |
| 833 | pub const EPROGUNAVAIL = 74; // RPC prog. not avail |
| 834 | pub const EPROGMISMATCH = 75; // Program version wrong |
| 835 | pub const EPROCUNAVAIL = 76; // Bad procedure for program |
| 836 | |
| 837 | pub const ENOLCK = 77; // No locks available |
| 838 | pub const ENOSYS = 78; // Function not implemented |
| 839 | |
| 840 | pub const EFTYPE = 79; // Inappropriate file type or format |
| 841 | pub const EAUTH = 80; // Authentication error |
| 842 | pub const ENEEDAUTH = 81; // Need authenticator |
| 843 | pub const EIPSEC = 82; // IPsec processing failure |
| 844 | pub const ENOATTR = 83; // Attribute not found |
| 845 | |
| 846 | // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995 |
| 847 | pub const EILSEQ = 84; // Illegal byte sequence |
| 848 | |
| 849 | pub const ENOMEDIUM = 85; // No medium found |
| 850 | pub const EMEDIUMTYPE = 86; // Wrong medium type |
| 851 | pub const EOVERFLOW = 87; // Value too large to be stored in data type |
| 852 | pub const ECANCELED = 88; // Operation canceled |
| 853 | pub const EIDRM = 89; // Identifier removed |
| 854 | pub const ENOMSG = 90; // No message of desired type |
| 855 | pub const ENOTSUP = 91; // Not supported |
| 856 | pub const EBADMSG = 92; // Bad or Corrupt message |
| 857 | pub const ENOTRECOVERABLE = 93; // State not recoverable |
| 858 | pub const EOWNERDEAD = 94; // Previous owner died |
| 859 | pub const EPROTO = 95; // Protocol error |
| 860 | |
| 861 | pub const ELAST = 95; // Must equal largest errno |
| 862 | |
| 863 | const _MAX_PAGE_SHIFT = switch (builtin.arch) { |
| 864 | .i386 => 12, |
| 865 | .sparcv9 => 13, |
| 866 | }; |
| 867 | pub const MINSIGSTKSZ = 1 << _MAX_PAGE_SHIFT; |
| 868 | pub const SIGSTKSZ = MINSIGSTKSZ + (1 << _MAX_PAGE_SHIFT) * 4; |
| 869 | |
| 870 | pub const SS_ONSTACK = 0x0001; |
| 871 | pub const SS_DISABLE = 0x0004; |
| 872 | |
| 873 | pub const stack_t = extern struct { |
| 874 | ss_sp: [*]u8, |
| 875 | ss_size: usize, |
| 876 | ss_flags: c_int, |
| 877 | }; |
| 878 | |
| 879 | pub const S_IFMT = 0o170000; |
| 880 | |
| 881 | pub const S_IFIFO = 0o010000; |
| 882 | pub const S_IFCHR = 0o020000; |
| 883 | pub const S_IFDIR = 0o040000; |
| 884 | pub const S_IFBLK = 0o060000; |
| 885 | pub const S_IFREG = 0o100000; |
| 886 | pub const S_IFLNK = 0o120000; |
| 887 | pub const S_IFSOCK = 0o140000; |
| 888 | |
| 889 | pub const S_ISUID = 0o4000; |
| 890 | pub const S_ISGID = 0o2000; |
| 891 | pub const S_ISVTX = 0o1000; |
| 892 | pub const S_IRWXU = 0o700; |
| 893 | pub const S_IRUSR = 0o400; |
| 894 | pub const S_IWUSR = 0o200; |
| 895 | pub const S_IXUSR = 0o100; |
| 896 | pub const S_IRWXG = 0o070; |
| 897 | pub const S_IRGRP = 0o040; |
| 898 | pub const S_IWGRP = 0o020; |
| 899 | pub const S_IXGRP = 0o010; |
| 900 | pub const S_IRWXO = 0o007; |
| 901 | pub const S_IROTH = 0o004; |
| 902 | pub const S_IWOTH = 0o002; |
| 903 | pub const S_IXOTH = 0o001; |
| 904 | |
| 905 | pub fn S_ISFIFO(m: u32) bool { |
| 906 | return m & S_IFMT == S_IFIFO; |
| 907 | } |
| 908 | |
| 909 | pub fn S_ISCHR(m: u32) bool { |
| 910 | return m & S_IFMT == S_IFCHR; |
| 911 | } |
| 912 | |
| 913 | pub fn S_ISDIR(m: u32) bool { |
| 914 | return m & S_IFMT == S_IFDIR; |
| 915 | } |
| 916 | |
| 917 | pub fn S_ISBLK(m: u32) bool { |
| 918 | return m & S_IFMT == S_IFBLK; |
| 919 | } |
| 920 | |
| 921 | pub fn S_ISREG(m: u32) bool { |
| 922 | return m & S_IFMT == S_IFREG; |
| 923 | } |
| 924 | |
| 925 | pub fn S_ISLNK(m: u32) bool { |
| 926 | return m & S_IFMT == S_IFLNK; |
| 927 | } |
| 928 | |
| 929 | pub fn S_ISSOCK(m: u32) bool { |
| 930 | return m & S_IFMT == S_IFSOCK; |
| 931 | } |
| 932 | |
| 933 | /// Magic value that specify the use of the current working directory |
| 934 | /// to determine the target of relative file paths in the openat() and |
| 935 | /// similar syscalls. |
| 936 | pub const AT_FDCWD = -100; |
| 937 | |
| 938 | /// Check access using effective user and group ID |
| 939 | pub const AT_EACCESS = 0x01; |
| 940 | |
| 941 | /// Do not follow symbolic links |
| 942 | pub const AT_SYMLINK_NOFOLLOW = 0x02; |
| 943 | |
| 944 | /// Follow symbolic link |
| 945 | pub const AT_SYMLINK_FOLLOW = 0x04; |
| 946 | |
| 947 | /// Remove directory instead of file |
| 948 | pub const AT_REMOVEDIR = 0x08; |
| 949 | |
| 950 | pub const HOST_NAME_MAX = 255; |
| 951 | |
| 952 | /// dummy for IP |
| 953 | pub const IPPROTO_IP = 0; |
| 954 | |
| 955 | /// IP6 hop-by-hop options |
| 956 | pub const IPPROTO_HOPOPTS = IPPROTO_IP; |
| 957 | |
| 958 | /// control message protocol |
| 959 | pub const IPPROTO_ICMP = 1; |
| 960 | |
| 961 | /// group mgmt protocol |
| 962 | pub const IPPROTO_IGMP = 2; |
| 963 | |
| 964 | /// gateway^2 (deprecated) |
| 965 | pub const IPPROTO_GGP = 3; |
| 966 | |
| 967 | /// IP header |
| 968 | pub const IPPROTO_IPV4 = IPPROTO_IPIP; |
| 969 | |
| 970 | /// IP inside IP |
| 971 | pub const IPPROTO_IPIP = 4; |
| 972 | |
| 973 | /// tcp |
| 974 | pub const IPPROTO_TCP = 6; |
| 975 | |
| 976 | /// exterior gateway protocol |
| 977 | pub const IPPROTO_EGP = 8; |
| 978 | |
| 979 | /// pup |
| 980 | pub const IPPROTO_PUP = 12; |
| 981 | |
| 982 | /// user datagram protocol |
| 983 | pub const IPPROTO_UDP = 17; |
| 984 | |
| 985 | /// xns idp |
| 986 | pub const IPPROTO_IDP = 22; |
| 987 | |
| 988 | /// tp-4 w/ class negotiation |
| 989 | pub const IPPROTO_TP = 29; |
| 990 | |
| 991 | /// IP6 header |
| 992 | pub const IPPROTO_IPV6 = 41; |
| 993 | |
| 994 | /// IP6 routing header |
| 995 | pub const IPPROTO_ROUTING = 43; |
| 996 | |
| 997 | /// IP6 fragmentation header |
| 998 | pub const IPPROTO_FRAGMENT = 44; |
| 999 | |
| 1000 | /// resource reservation |
| 1001 | pub const IPPROTO_RSVP = 46; |
| 1002 | |
| 1003 | /// GRE encaps RFC 1701 |
| 1004 | pub const IPPROTO_GRE = 47; |
| 1005 | |
| 1006 | /// encap. security payload |
| 1007 | pub const IPPROTO_ESP = 50; |
| 1008 | |
| 1009 | /// authentication header |
| 1010 | pub const IPPROTO_AH = 51; |
| 1011 | |
| 1012 | /// IP Mobility RFC 2004 |
| 1013 | pub const IPPROTO_MOBILE = 55; |
| 1014 | |
| 1015 | /// IPv6 ICMP |
| 1016 | pub const IPPROTO_IPV6_ICMP = 58; |
| 1017 | |
| 1018 | /// ICMP6 |
| 1019 | pub const IPPROTO_ICMPV6 = 58; |
| 1020 | |
| 1021 | /// IP6 no next header |
| 1022 | pub const IPPROTO_NONE = 59; |
| 1023 | |
| 1024 | /// IP6 destination option |
| 1025 | pub const IPPROTO_DSTOPTS = 60; |
| 1026 | |
| 1027 | /// ISO cnlp |
| 1028 | pub const IPPROTO_EON = 80; |
| 1029 | |
| 1030 | /// Ethernet-in-IP |
| 1031 | pub const IPPROTO_ETHERIP = 97; |
| 1032 | |
| 1033 | /// encapsulation header |
| 1034 | pub const IPPROTO_ENCAP = 98; |
| 1035 | |
| 1036 | /// Protocol indep. multicast |
| 1037 | pub const IPPROTO_PIM = 103; |
| 1038 | |
| 1039 | /// IP Payload Comp. Protocol |
| 1040 | pub const IPPROTO_IPCOMP = 108; |
| 1041 | |
| 1042 | /// VRRP RFC 2338 |
| 1043 | pub const IPPROTO_VRRP = 112; |
| 1044 | |
| 1045 | /// Common Address Resolution Protocol |
| 1046 | pub const IPPROTO_CARP = 112; |
| 1047 | |
| 1048 | /// PFSYNC |
| 1049 | pub const IPPROTO_PFSYNC = 240; |
| 1050 | |
| 1051 | /// raw IP packet |
| 1052 | pub const IPPROTO_RAW = 255; |