types.ha (15859B)
1 // SPDX-License-Identifier: MPL-2.0 2 // (c) Hare authors <https://harelang.org> 3 4 export type time_t = i64; 5 export type suseconds_t = i64; 6 export type dev_t = u64; 7 export type ino_t = u64; 8 export type nlink_t = u64; 9 export type id_t = uint; 10 export type pid_t = u64; 11 export type uid_t = u32; 12 export type gid_t = u32; 13 export type off_t = i64; 14 export type blkcnt_t = i64; 15 export type blksize_t = i32; 16 export type fflags_t = u32; 17 export type mode_t = u32; 18 export type nfds_t = uint; 19 export type rlim_t = u64; 20 21 export type path = (str | []u8 | *const u8); 22 23 // Maximum length of a file path including the NUL terminator. 24 export def PATH_MAX = 1024z; 25 26 // Max bytes in a file name 27 export def NAME_MAX: int = 511; 28 29 export def NGROUPS_MAX: size = 1023; 30 export def NSIG: int = 32; 31 32 export type sigset = struct { 33 __bits: [4]u32, 34 }; 35 36 export def SA_ONSTACK: int = 0x0001; 37 export def SA_RESTART: int = 0x0002; 38 export def SA_RESETHAND: int = 0x0004; 39 export def SA_NOCLDSTOP: int = 0x0008; 40 export def SA_NODEFER: int = 0x0010; 41 export def SA_NOCLDWAIT: int = 0x0020; 42 export def SA_SIGINFO: int = 0x0040; 43 44 export def SIG_ERR: uintptr = -1; 45 export def SIG_DFL: uintptr = 0; 46 export def SIG_IGN: uintptr = 1; 47 export def SIG_CATCH: uintptr = 2; 48 export def SIG_HOLD: uintptr = 3; 49 50 export type sigact = struct { 51 union { 52 sa_handler: nullable *fn (int) void, 53 sa_sigaction: nullable *fn (int, *siginfo, *opaque) void, 54 }, 55 sa_mask: sigset, 56 sa_flags: int, 57 }; 58 59 export def SIG_BLOCK: int = 1; 60 export def SIG_UNBLOCK: int = 2; 61 export def SIG_SETMASK: int = 3; 62 63 export type sigval = union { 64 sival_t: int, 65 sival_ptr: *opaque, 66 }; 67 68 export type stack_t = struct { 69 ss_sp: *opaque, 70 ss_size: size, 71 ss_flags: int, 72 }; 73 74 export type pollfd = struct { 75 fd: int, 76 events: i16, 77 revents: i16, 78 }; 79 80 export type timespec = struct { 81 tv_sec: time_t, 82 tv_nsec: i64, 83 }; 84 85 export def UTIME_OMIT = -0x2; 86 87 export type timeval = struct { 88 tv_sec: time_t, 89 tv_usec: suseconds_t, 90 }; 91 92 export type st_flock = struct { 93 l_start: off_t, 94 l_len: off_t, 95 l_pid: pid_t, 96 l_type: i16, 97 l_whence: i16, 98 l_sysid: int, 99 }; 100 101 export type st = struct { 102 dev: dev_t, 103 ino: ino_t, 104 nlink: nlink_t, 105 mode: mode_t, 106 uid: uid_t, 107 gid: gid_t, 108 rdev: dev_t, 109 atime: timespec, 110 mtime: timespec, 111 ctime: timespec, 112 btime: timespec, 113 sz: off_t, 114 blocks: blkcnt_t, 115 blksz: blksize_t, 116 flags: fflags_t, 117 }; 118 119 export type stat = struct { 120 st_dev: u64, 121 st_mode: mode_t, 122 __pad0: u32, 123 st_ino: u64, 124 st_nlink: u32, 125 st_uid: uid_t, 126 st_gid: gid_t, 127 __pad1: u32, 128 st_rdev: u64, 129 st_atim: timespec, 130 st_mtim: timespec, 131 st_ctim: timespec, 132 st_birthtim: timespec, 133 st_size: off_t, 134 st_blocks: blkcnt_t, 135 st_blksize: blksize_t, 136 st_flags: fflags_t, 137 st_gen: u32, 138 st_spare: [2]u32, 139 }; 140 141 export type fsid_t = struct { 142 __fsid_val: [2]u32, 143 }; 144 145 export def VFS_NAMELEN: int = 32; 146 export def VFS_MNAMELEN: int = 1024; 147 148 export type statvfs = struct { 149 // copy of mount exported flags 150 f_flag: u64, 151 // file system block size 152 f_bsize: u64, 153 // fundamental file system block size 154 f_frsize: u64, 155 // optimal file system block size 156 f_iosize: u64, 157 158 // The following are in units of f_frsize 159 160 // number of blocks in file system, 161 f_blocks: u64, 162 // free blocks avail in file system 163 f_bfree: u64, 164 // free blocks avail to non-root 165 f_bavail: u64, 166 // blocks reserved for root 167 f_bresvd: u64, 168 169 // total file nodes in file system 170 f_files: u64, 171 // free file nodes in file system 172 f_ffree: u64, 173 // free file nodes avail to non-root 174 f_favail: u64, 175 // file nodes reserved for root 176 f_fresvd: u64, 177 178 // count of sync reads since mount 179 f_syncreads: u64, 180 // count of sync writes since mount 181 f_syncwrites: u64, 182 183 // count of async reads since mount 184 f_asyncreads: u64, 185 // count of async writes since mount 186 f_asyncwrites: u64, 187 188 // NetBSD compatible fsid 189 f_fsidx: fsid_t, 190 // Posix compatible fsid 191 f_fsid: u64, 192 // maximum filename length 193 f_namemax: u64, 194 // user that mounted the file system 195 f_owner: uid_t, 196 __pad0: u32, 197 198 // spare space 199 f_spare: [4]u64, 200 201 // fs type name 202 f_fstypename: [VFS_NAMELEN]u8, 203 // directory on which mounted 204 f_mntonname: [VFS_MNAMELEN]u8, 205 // mounted file system 206 f_mntfromname: [VFS_MNAMELEN]u8, 207 // disk label name if avail 208 f_mntfromlabel: [VFS_MNAMELEN]u8, 209 }; 210 211 export type dirent = struct { 212 // file number of entry 213 d_fileno: ino_t, 214 // length of this record 215 d_reclen: u16, 216 // length of d_name 217 d_namlen: u16, 218 // file type, see below 219 d_type: u8, 220 d_name: [NAME_MAX + 1]u8, 221 }; 222 223 export type iovec = struct { 224 iov_base: *opaque, 225 iov_len: size 226 }; 227 228 export type winsize = struct { 229 ws_row: u16, 230 ws_col: u16, 231 ws_xpixel: u16, 232 ws_ypixel: u16, 233 }; 234 235 export type termios = struct { 236 c_iflag: tcflag, 237 c_oflag: tcflag, 238 c_cflag: tcflag, 239 c_lflag: tcflag, 240 c_cc: [NCCS]cc, 241 }; 242 243 export def NCCS: size = 20; 244 245 export type tcflag = enum uint { 246 // c_iflag bits 247 IGNBRK = 0x00000001, 248 BRKINT = 0x00000002, 249 IGNPAR = 0x00000004, 250 PARMRK = 0x00000008, 251 INPCK = 0x00000010, 252 ISTRIP = 0x00000020, 253 INLCR = 0x00000040, 254 IGNCR = 0x00000080, 255 ICRNL = 0x00000100, 256 IXON = 0x00000200, 257 IXOFF = 0x00000400, 258 IXANY = 0x00000800, 259 IMAXBEL = 0x00002000, 260 261 // c_oflag bits 262 OPOST = 0x00000001, 263 ONLCR = 0x00000002, 264 TABDLY = 0x00000004, 265 TAB0 = 0x00000000, 266 TAB3 = 0x00000004, 267 ONOEOT = 0x00000008, 268 OCRNL = 0x00000010, 269 ONOCR = 0x00000020, 270 ONLRET = 0x00000040, 271 272 // c_cflag bits 273 CIGNORE = 0x00000001, 274 CSIZE = 0x00000300, 275 CS5 = 0x00000000, 276 CS6 = 0x00000100, 277 CS7 = 0x00000200, 278 CS8 = 0x00000300, 279 CSTOPB = 0x00000400, 280 CREAD = 0x00000800, 281 PARENB = 0x00001000, 282 PARODD = 0x00002000, 283 HUPCL = 0x00004000, 284 CLOCAL = 0x00008000, 285 CCTS_OFLOW = 0x00010000, 286 CRTS_IFLOW = 0x00020000, 287 CRTSCTS = (CCTS_OFLOW | CRTS_IFLOW), 288 CDTR_IFLOW = 0x00040000, 289 CDSR_OFLOW = 0x00080000, 290 CCAR_OFLOW = 0x00100000, 291 CNO_RTSDTR = 0x00200000, 292 293 // c_lflag bits 294 ECHOKE = 0x00000001, 295 ECHOE = 0x00000002, 296 ECHOK = 0x00000004, 297 ECHO = 0x00000008, 298 ECHONL = 0x00000010, 299 ECHOPRT = 0x00000020, 300 ECHOCTL = 0x00000040, 301 ISIG = 0x00000080, 302 ICANON = 0x00000100, 303 ALTWERASE = 0x00000200, 304 IEXTEN = 0x00000400, 305 EXTPROC = 0x00000800, 306 TOSTOP = 0x00400000, 307 FLUSHO = 0x00800000, 308 NOKERNINFO = 0x02000000, 309 PENDIN = 0x20000000, 310 NOFLSH = 0x80000000, 311 }; 312 313 export type cc = enum u8 { 314 VEOF = 0, 315 VEOL = 1, 316 VEOL2 = 2, 317 VERASE = 3, 318 VWERASE = 4, 319 VKILL = 5, 320 VREPRINT = 6, 321 VERASE2 = 7, 322 VINTR = 8, 323 VQUIT = 9, 324 VSUSP = 10, 325 VDSUSP = 11, 326 VSTART = 12, 327 VSTOP = 13, 328 VLNEXT = 14, 329 VDISCARD = 15, 330 VMIN = 16, 331 VTIME = 17, 332 VSTATUS = 18, 333 }; 334 335 export def TIOCGWINSZ: u64 = 0x40087468; 336 export def TIOCSWINSZ: u64 = 0x80087467; 337 export def TIOCGETA: u64 = 0x402c7413; 338 export def TIOCSETA: u64 = 0x802c7414; 339 export def TIOCPTSNAME: u64 = 0x48087448; 340 export def TIOCSPGRP: u64 = 0x80047476; 341 export def FIODGNAME: u64 = 0x80106678; 342 343 export type ptmget = struct { 344 cfd: int, 345 sfd: int, 346 cn: [PATH_MAX]u8, 347 sn: [PATH_MAX]u8, 348 }; 349 350 export type rusage = struct { 351 // user time used 352 ru_utime: timeval, 353 // system time used 354 ru_stime: timeval, 355 // max resident set size 356 ru_maxrss: i64, 357 // integral shared memory size 358 ru_ixrss: i64, 359 // integral unshared data " 360 ru_idrss: i64, 361 // integral unshared stack " 362 ru_isrss: i64, 363 // page reclaims 364 ru_minflt: i64, 365 // page faults 366 ru_majflt: i64, 367 // swaps 368 ru_nswap: i64, 369 // block input operations 370 ru_inblock: i64, 371 // block output operations 372 ru_oublock: i64, 373 // messages sent 374 ru_msgsnd: i64, 375 // messages received 376 ru_msgrcv: i64, 377 // signals received 378 ru_nsignals: i64, 379 // voluntary context switches 380 ru_nvcsw: i64, 381 // involuntary " 382 ru_nivcsw: i64, 383 }; 384 385 export def DT_UNKNOWN: u8 = 0; 386 export def DT_FIFO: u8 = 1; 387 export def DT_CHR: u8 = 2; 388 export def DT_DIR: u8 = 4; 389 export def DT_BLK: u8 = 6; 390 export def DT_REG: u8 = 8; 391 export def DT_LNK: u8 = 10; 392 export def DT_SOCK: u8 = 12; 393 export def DT_WHT: u8 = 14; 394 395 export def O_RDONLY: int = 0x0000; 396 export def O_WRONLY: int = 0x0001; 397 export def O_RDWR: int = 0x0002; 398 export def O_ACCMODE: int = 0x0003; 399 export def O_NONBLOCK: int = 0x0004; 400 export def O_APPEND: int = 0x0008; 401 export def O_SHLOCK: int = 0x0010; 402 export def O_EXLOCK: int = 0x0020; 403 export def O_ASYNC: int = 0x0040; 404 export def O_FSYNC: int = 0x0080; 405 export def O_SYNC: int = 0x0080; 406 export def O_NOFOLLOW: int = 0x0100; 407 export def O_CREAT: int = 0x0200; 408 export def O_TRUNC: int = 0x0400; 409 export def O_EXCL: int = 0x0800; 410 export def O_NOCTTY: int = 0x8000; 411 export def O_DIRECT: int = 0x00010000; 412 export def O_DIRECTORY: int = 0x00020000; 413 export def O_EXEC: int = 0x00040000; 414 export def O_TTY_INIT: int = 0x00080000; 415 export def O_CLOEXEC: int = 0x00400000; 416 export def O_DSYNC: int = 0x01000000; 417 export def O_RSYNC: int = 0x00020000; 418 419 export def AT_FDCWD: int = -100; 420 export def AT_EACCESS: int = 0x0100; 421 export def AT_SYMLINK_NOFOLLOW: int = 0x0200; 422 export def AT_SYMLINK_FOLLOW: int = 0x0400; 423 export def AT_REMOVEDIR: int = 0x0800; 424 export def AT_RESOLVE_BENEATH: int = 0x2000; 425 426 // set user id on execution 427 export def S_ISUID: u64 = 0o004000; 428 // set group id on execution 429 export def S_ISGID: u64 = 0o002000; 430 // sticky bit 431 export def S_ISTXT: u64 = 0o001000; 432 // RWX mask for owner 433 export def S_IRWXU: u64 = 0o000700; 434 // R for owner 435 export def S_IRUSR: u64 = 0o000400; 436 // W for owner 437 export def S_IWUSR: u64 = 0o000200; 438 // X for owner 439 export def S_IXUSR: u64 = 0o000100; 440 export def S_IREAD: u64 = S_IRUSR; 441 export def S_IWRITE: u64 = S_IWUSR; 442 export def S_IEXEC: u64 = S_IXUSR; 443 // RWX mask for group 444 export def S_IRWXG: u64 = 0o000070; 445 // R for group 446 export def S_IRGRP: u64 = 0o000040; 447 // W for group 448 export def S_IWGRP: u64 = 0o000020; 449 // X for group 450 export def S_IXGRP: u64 = 0o000010; 451 // RWX mask for other 452 export def S_IRWXO: u64 = 0o000007; 453 // R for other 454 export def S_IROTH: u64 = 0o000004; 455 // W for other 456 export def S_IWOTH: u64 = 0o000002; 457 // X for other 458 export def S_IXOTH: u64 = 0o000001; 459 // type of file mask 460 export def S_IFMT: u64 = 0o170000; 461 // named pipe (fifo) 462 export def S_IFIFO: u64 = 0o010000; 463 // character special 464 export def S_IFCHR: u64 = 0o020000; 465 // directory 466 export def S_IFDIR: u64 = 0o040000; 467 // block special 468 export def S_IFBLK: u64 = 0o060000; 469 // regular 470 export def S_IFREG: u64 = 0o100000; 471 // symbolic link 472 export def S_IFLNK: u64 = 0o120000; 473 // save swapped text even after use 474 export def S_ISVTX: u64 = 0o001000; 475 // socket 476 export def S_IFSOCK: u64 = 0o140000; 477 // whiteout 478 export def S_IFWHT: u64 = 0o160000; 479 // Archive state 1, ls -l shows 'a' 480 export def S_ARCH1: u64 = 0o200000; 481 // Archive state 2, ls -l shows 'A' 482 export def S_ARCH2: u64 = 0o400000; 483 484 export def MAP_SHARED: uint = 0x0001; 485 export def MAP_PRIVATE: uint = 0x0002; 486 export def MAP_FIXED: uint = 0x0010; 487 export def MAP_HASSEMAPHORE: uint = 0x0200; 488 export def MAP_STACK: uint = 0x0400; 489 export def MAP_NOSYNC: uint = 0x0800; 490 export def MAP_FILE: uint = 0x0000; 491 export def MAP_ANON: uint = 0x1000; 492 export def MAP_GUARD: uint = 0x00002000; 493 export def MAP_EXCL: uint = 0x00004000; 494 export def MAP_NOCORE: uint = 0x00020000; 495 export def MAP_PREFAULT_READ: uint = 0x00040000; 496 export def MAP_32BIT: uint = 0x00080000; 497 498 export def PROT_NONE: uint = 0x00; 499 export def PROT_READ: uint = 0x01; 500 export def PROT_WRITE: uint = 0x02; 501 export def PROT_EXEC: uint = 0x04; 502 503 export def SIGHUP: int = 1; 504 export def SIGINT: int = 2; 505 export def SIGQUIT: int = 3; 506 export def SIGILL: int = 4; 507 export def SIGTRAP: int = 5; 508 export def SIGABRT: int = 6; 509 export def SIGIOT: int = SIGABRT; 510 export def SIGEMT: int = 7; 511 export def SIGFPE: int = 8; 512 export def SIGKILL: int = 9; 513 export def SIGBUS: int = 10; 514 export def SIGSEGV: int = 11; 515 export def SIGSYS: int = 12; 516 export def SIGPIPE: int = 13; 517 export def SIGALRM: int = 14; 518 export def SIGTERM: int = 15; 519 export def SIGURG: int = 16; 520 export def SIGSTOP: int = 17; 521 export def SIGTSTP: int = 18; 522 export def SIGCONT: int = 19; 523 export def SIGCHLD: int = 20; 524 export def SIGTTIN: int = 21; 525 export def SIGTTOU: int = 22; 526 export def SIGIO: int = 23; 527 export def SIGXCPU: int = 24; 528 export def SIGXFSZ: int = 25; 529 export def SIGVTALRM: int = 26; 530 export def SIGPROF: int = 27; 531 export def SIGWINCH: int = 28; 532 export def SIGINFO: int = 29; 533 export def SIGUSR1: int = 30; 534 export def SIGUSR2: int = 31; 535 export def SIGTHR: int = 32; 536 export def SIGLWP: int = SIGTHR; 537 export def SIGLIBRT: int = 33; 538 539 export def F_DUPFD: int = 0; 540 export def F_GETFD: int = 1; 541 export def F_SETFD: int = 2; 542 export def F_GETFL: int = 3; 543 export def F_SETFL: int = 4; 544 export def F_GETOWN: int = 5; 545 export def F_SETOWN: int = 6; 546 export def F_OGETLK: int = 7; 547 export def F_OSETLK: int = 8; 548 export def F_OSETLKW: int = 9; 549 export def F_DUP2FD: int = 10; 550 export def F_GETLK: int = 11; 551 export def F_SETLK: int = 12; 552 export def F_SETLKW: int = 13; 553 export def F_SETLK_REMOTE: int = 14; 554 export def F_READAHEAD: int = 15; 555 export def F_RDAHEAD: int = 16; 556 export def F_DUPFD_CLOEXEC: int = 12; 557 export def F_DUP2FD_CLOEXEC: int = 18; 558 export def F_ADD_SEALS: int = 16; 559 export def F_GET_SEALS: int = 17; 560 export def F_ISUNIONSTACK: int = 21; 561 562 export def F_SEAL_SEAL: int = 0x0001; 563 export def F_SEAL_SHRINK: int = 0x0002; 564 export def F_SEAL_GROW: int = 0x0004; 565 export def F_SEAL_WRITE: int = 0x0008; 566 567 export def FD_CLOEXEC: int = 1; 568 export def F_UNLCKSYS: int = 4; 569 export def F_CANCEL: int = 5; 570 571 export def F_RDLCK: i16 = 1; 572 export def F_UNLCK: i16 = 2; 573 export def F_WRLCK: i16 = 3; 574 575 export def PRIO_PROCESS: int = 0; 576 export def PRIO_PGRP: int = 1; 577 export def PRIO_USER: int = 2; 578 579 export def F_OK: int = 0; 580 export def X_OK: int = 0x01; 581 export def W_OK: int = 0x02; 582 export def R_OK: int = 0x04; 583 584 export def CLOCK_REALTIME: int = 0; 585 export def CLOCK_VIRTUAL: int = 1; 586 export def CLOCK_PROF: int = 2; 587 export def CLOCK_MONOTONIC: int = 3; 588 export def CLOCK_THREAD_CPUTIME_ID: int = 0x20000000; 589 export def CLOCK_PROCESS_CPUTIME_ID: int = 0x40000000; 590 591 export def WNOHANG: int = 1; 592 export def WUNTRACED: int = 2; 593 export def WSTOPPED: int = WUNTRACED; 594 export def WCONTINUED: int = 4; 595 export def WNOWAIT: int = 8; 596 export def WEXITED: int = 16; 597 export def WTRAPPED: int = 32; 598 599 export def STDIN_FILENO: int = 0; 600 export def STDOUT_FILENO: int = 1; 601 export def STDERR_FILENO: int = 2; 602 603 export def SEEK_SET: int = 0; 604 export def SEEK_CUR: int = 1; 605 export def SEEK_END: int = 2; 606 607 // Flock operations 608 export def LOCK_SH: int = 1; 609 export def LOCK_EX: int = 2; 610 export def LOCK_NB: int = 4; 611 export def LOCK_UN: int = 8; 612 613 export type rlimit = struct { 614 rlim_cur: rlim_t, 615 rlim_max: rlim_t, 616 }; 617 618 export def RLIM_INFINITY: rlim_t = -1; 619 620 export def RLIMIT_CPU: int = 0; 621 export def RLIMIT_FSIZE: int = 1; 622 export def RLIMIT_DATA: int = 2; 623 export def RLIMIT_STACK: int = 3; 624 export def RLIMIT_CORE: int = 4; 625 export def RLIMIT_RSS: int = 5; 626 export def RLIMIT_MEMLOCK: int = 6; 627 export def RLIMIT_NPROC: int = 7; 628 export def RLIMIT_NOFILE: int = 8; 629 export def RLIMIT_SBSIZE: int = 9; 630 export def RLIMIT_VMEM: int = 10; 631 export def RLIMIT_AS: int = RLIMIT_VMEM; 632 export def RLIMIT_NPTS: int = 11; 633 export def RLIMIT_SWAP: int = 12; 634 export def RLIMIT_KQUEUES: int = 13; 635 export def RLIMIT_UMTXP: int = 14; 636 // number of threads 637 export def RLIMIT_NTHR: int = 11; 638 639 export def SHUT_RD: int = 0; 640 export def SHUT_WR: int = 1; 641 export def SHUT_RDWR: int = 2; 642 643 // non-existent device 644 export def NODEV: int = -1; 645 646 // synchronously wait for I/O to complete 647 export def MNT_WAIT: int = 1; 648 // start all I/O, but do not wait for it 649 export def MNT_NOWAIT: int = 2; 650 // push data not written by filesystem syncer 651 export def MNT_LAZY: int = 3; 652 653 // Efficient memory file-system 654 export def MOUNT_TMPFS = "tmpfs"; 655 export def MOUNT_SHMFS = MOUNT_TMPFS; 656 657 // Shared memory objects are supported using tmpfs. 658 export def SHMFS_DIR_PATH = "/var/shm"; 659 export def SHMFS_DIR_MODE = (S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO); 660 export def SHMFS_OBJ_PREFIX = ".shmobj_"; 661 662 // Signal 663 export def __SIGTRAMP_SIGINFO_VERSION = 2;