authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-04-06 17:47:54-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-04-08 13:20:14-04:00
log0c83fa2fd03fec86c4e36075978646f202deec32
treecda13cb2e89e04e24bcc707cefbd0ea73d199a15
parent23ee39116c783908420d7d9e58a9344042c823fa

haiku: fix directory iteration


2 files changed, 880 insertions(+), 712 deletions(-)

lib/std/c/haiku.zig+808-681
......@@ -5,28 +5,18 @@ const maxInt = std.math.maxInt;
55const iovec = std.posix.iovec;
66const iovec_const = std.posix.iovec_const;
77
8extern "c" fn _errnop() *c_int;
8pub extern "root" fn find_directory(which: directory_which, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) u64;
99
10pub const _errno = _errnop;
11
12pub extern "c" fn find_directory(which: directory_which, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) u64;
10pub extern "root" fn find_thread(thread_name: ?*anyopaque) i32;
1311
14pub extern "c" fn find_thread(thread_name: ?*anyopaque) i32;
12pub extern "root" fn get_system_info(system_info: *system_info) usize;
1513
16pub extern "c" fn get_system_info(system_info: *system_info) usize;
14pub extern "root" fn _get_team_info(team: i32, team_info: *team_info, size: usize) i32;
1715
18pub extern "c" fn _get_team_info(team: c_int, team_info: *team_info, size: usize) i32;
19
20pub extern "c" fn _get_next_area_info(team: c_int, cookie: *i64, area_info: *area_info, size: usize) i32;
16pub extern "root" fn _get_next_area_info(team: i32, cookie: *i64, area_info: *area_info, size: usize) i32;
2117
2218// TODO revisit if abi changes or better option becomes apparent
23pub extern "c" fn _get_next_image_info(team: c_int, cookie: *i32, image_info: *image_info, size: usize) i32;
24
25pub extern "c" fn _kern_read_dir(fd: c_int, buf_ptr: [*]u8, nbytes: usize, maxcount: u32) usize;
26
27pub extern "c" fn _kern_read_stat(fd: c_int, path_ptr: [*]u8, traverse_link: bool, st: *Stat, stat_size: i32) usize;
28
29pub extern "c" fn _kern_get_current_team() i32;
19pub extern "root" fn _get_next_image_info(team: i32, cookie: *i32, image_info: *image_info, size: usize) i32;
3020
3121pub const sem_t = extern struct {
3222 type: i32,
......@@ -45,7 +35,7 @@ pub const pthread_attr_t = extern struct {
4535 __stack_address: ?*anyopaque,
4636};
4737
48pub const EAI = enum(c_int) {
38pub const EAI = enum(i32) {
4939 /// address family for hostname not supported
5040 ADDRFAMILY = 1,
5141
......@@ -99,11 +89,7 @@ pub const AI = struct {
9989
10090pub const AI_NUMERICSERV = AI.NUMERICSERV;
10191
102pub const fd_t = c_int;
103pub const pid_t = c_int;
104pub const uid_t = u32;
105pub const gid_t = u32;
106pub const mode_t = c_uint;
92pub const fd_t = i32;
10793
10894pub const socklen_t = u32;
10995
......@@ -129,8 +115,8 @@ pub const dl_phdr_info = extern struct {
129115};
130116
131117pub const Flock = extern struct {
132 type: c_short,
133 whence: c_short,
118 type: i16,
119 whence: i16,
134120 start: off_t,
135121 len: off_t,
136122 pid: pid_t,
......@@ -159,54 +145,6 @@ pub const msghdr = extern struct {
159145 msg_flags: i32,
160146};
161147
162pub const off_t = i64;
163pub const ino_t = u64;
164
165pub const Stat = extern struct {
166 dev: i32,
167 ino: u64,
168 mode: u32,
169 nlink: i32,
170 uid: i32,
171 gid: i32,
172 size: i64,
173 rdev: i32,
174 blksize: i32,
175 atim: timespec,
176 mtim: timespec,
177 ctim: timespec,
178 crtim: timespec,
179 st_type: u32,
180 blocks: i64,
181
182 pub fn atime(self: @This()) timespec {
183 return self.atim;
184 }
185 pub fn mtime(self: @This()) timespec {
186 return self.mtim;
187 }
188 pub fn ctime(self: @This()) timespec {
189 return self.ctim;
190 }
191 pub fn birthtime(self: @This()) timespec {
192 return self.crtim;
193 }
194};
195
196pub const timespec = extern struct {
197 tv_sec: isize,
198 tv_nsec: isize,
199};
200
201pub const dirent = extern struct {
202 dev: i32,
203 pdev: i32,
204 ino: i64,
205 pino: i64,
206 reclen: u16,
207 name: [256]u8,
208};
209
210148pub const B_OS_NAME_LENGTH = 32; // OS.h
211149
212150pub const area_info = extern struct {
......@@ -354,17 +292,6 @@ pub const PROT = struct {
354292 pub const NONE = 0x00;
355293};
356294
357pub const CLOCK = struct {
358 /// system-wide monotonic clock (aka system time)
359 pub const MONOTONIC = 0;
360 /// system-wide real time clock
361 pub const REALTIME = -1;
362 /// clock measuring the used CPU time of the current process
363 pub const PROCESS_CPUTIME_ID = -2;
364 /// clock measuring the used CPU time of the current thread
365 pub const THREAD_CPUTIME_ID = -3;
366};
367
368295pub const MSF = struct {
369296 pub const ASYNC = 1;
370297 pub const INVALIDATE = 2;
......@@ -404,159 +331,526 @@ pub const W = struct {
404331 }
405332};
406333
407// /system/develop/headers/posix/poll.h
408
409pub const nfds_t = usize;
334// access function
335pub const F_OK = 0; // test for existence of file
336pub const X_OK = 1; // test for execute or search permission
337pub const W_OK = 2; // test for write permission
338pub const R_OK = 4; // test for read permission
410339
411pub const pollfd = extern struct {
412 fd: i32,
413 events: i16,
414 revents: i16,
415};
340pub const F = struct {
341 pub const DUPFD = 0x0001;
342 pub const GETFD = 0x0002;
343 pub const SETFD = 0x0004;
344 pub const GETFL = 0x0008;
345 pub const SETFL = 0x0010;
416346
417pub const POLL = struct {
418 /// any readable data available
419 pub const IN = 0x0001;
420 /// file descriptor is writeable
421 pub const OUT = 0x0002;
422 pub const RDNORM = IN;
423 pub const WRNORM = OUT;
424 /// priority readable data
425 pub const RDBAND = 0x0008;
426 /// priority data can be written
427 pub const WRBAND = 0x0010;
428 /// high priority readable data
429 pub const PRI = 0x0020;
347 pub const GETLK = 0x0020;
348 pub const SETLK = 0x0080;
349 pub const SETLKW = 0x0100;
350 pub const DUPFD_CLOEXEC = 0x0200;
430351
431 /// errors pending
432 pub const ERR = 0x0004;
433 /// disconnected
434 pub const HUP = 0x0080;
435 /// invalid file descriptor
436 pub const NVAL = 0x1000;
352 pub const RDLCK = 0x0040;
353 pub const UNLCK = 0x0200;
354 pub const WRLCK = 0x0400;
437355};
438356
439// /system/develop/headers/posix/signal.h
440
441pub const sigset_t = u64;
442pub const empty_sigset: sigset_t = 0;
443pub const filled_sigset = ~@as(sigset_t, 0);
444
445pub const SIG = struct {
446 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
447 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
448 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
449
450 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);
451
452 pub const HUP = 1;
453 pub const INT = 2;
454 pub const QUIT = 3;
455 pub const ILL = 4;
456 pub const CHLD = 5;
457 pub const ABRT = 6;
458 pub const IOT = ABRT;
459 pub const PIPE = 7;
460 pub const FPE = 8;
461 pub const KILL = 9;
462 pub const STOP = 10;
463 pub const SEGV = 11;
464 pub const CONT = 12;
465 pub const TSTP = 13;
466 pub const ALRM = 14;
467 pub const TERM = 15;
468 pub const TTIN = 16;
469 pub const TTOU = 17;
470 pub const USR1 = 18;
471 pub const USR2 = 19;
472 pub const WINCH = 20;
473 pub const KILLTHR = 21;
474 pub const TRAP = 22;
475 pub const POLL = 23;
476 pub const PROF = 24;
477 pub const SYS = 25;
478 pub const URG = 26;
479 pub const VTALRM = 27;
480 pub const XCPU = 28;
481 pub const XFSZ = 29;
482 pub const BUS = 30;
483 pub const RESERVED1 = 31;
484 pub const RESERVED2 = 32;
485
486 pub const BLOCK = 1;
487 pub const UNBLOCK = 2;
488 pub const SETMASK = 3;
357pub const LOCK = struct {
358 pub const SH = 0x01;
359 pub const EX = 0x02;
360 pub const NB = 0x04;
361 pub const UN = 0x08;
489362};
490363
491pub const siginfo_t = extern struct {
492 signo: c_int,
493 code: c_int,
494 errno: c_int,
364pub const FD_CLOEXEC = 1;
495365
496 pid: pid_t,
497 uid: uid_t,
498 addr: *allowzero anyopaque,
366pub const SEEK = struct {
367 pub const SET = 0;
368 pub const CUR = 1;
369 pub const END = 2;
499370};
500371
501/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
502pub const Sigaction = extern struct {
503 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
504 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
505
506 /// signal handler
507 handler: extern union {
508 handler: handler_fn,
509 sigaction: sigaction_fn,
510 },
372pub const SOCK = struct {
373 pub const STREAM = 1;
374 pub const DGRAM = 2;
375 pub const RAW = 3;
376 pub const SEQPACKET = 5;
511377
512 /// signal mask to apply
513 mask: sigset_t,
378 /// WARNING: this flag is not supported by windows socket functions directly,
379 /// it is only supported by std.os.socket. Be sure that this value does
380 /// not share any bits with any of the `SOCK` values.
381 pub const CLOEXEC = 0x10000;
382 /// WARNING: this flag is not supported by windows socket functions directly,
383 /// it is only supported by std.os.socket. Be sure that this value does
384 /// not share any bits with any of the `SOCK` values.
385 pub const NONBLOCK = 0x20000;
386};
514387
515 /// see signal options
516 flags: c_int,
388pub const SO = struct {
389 pub const ACCEPTCONN = 0x00000001;
390 pub const BROADCAST = 0x00000002;
391 pub const DEBUG = 0x00000004;
392 pub const DONTROUTE = 0x00000008;
393 pub const KEEPALIVE = 0x00000010;
394 pub const OOBINLINE = 0x00000020;
395 pub const REUSEADDR = 0x00000040;
396 pub const REUSEPORT = 0x00000080;
397 pub const USELOOPBACK = 0x00000100;
398 pub const LINGER = 0x00000200;
517399
518 /// will be passed to the signal handler, BeOS extension
519 userdata: *allowzero anyopaque = undefined,
400 pub const SNDBUF = 0x40000001;
401 pub const SNDLOWAT = 0x40000002;
402 pub const SNDTIMEO = 0x40000003;
403 pub const RCVBUF = 0x40000004;
404 pub const RCVLOWAT = 0x40000005;
405 pub const RCVTIMEO = 0x40000006;
406 pub const ERROR = 0x40000007;
407 pub const TYPE = 0x40000008;
408 pub const NONBLOCK = 0x40000009;
409 pub const BINDTODEVICE = 0x4000000a;
410 pub const PEERCRED = 0x4000000b;
520411};
521412
522pub const SA = struct {
523 pub const NOCLDSTOP = 0x01;
524 pub const NOCLDWAIT = 0x02;
525 pub const RESETHAND = 0x04;
526 pub const NODEFER = 0x08;
527 pub const RESTART = 0x10;
528 pub const ONSTACK = 0x20;
529 pub const SIGINFO = 0x40;
530 pub const NOMASK = NODEFER;
531 pub const STACK = ONSTACK;
532 pub const ONESHOT = RESETHAND;
413pub const SOL = struct {
414 pub const SOCKET = -1;
533415};
534416
535pub const SS = struct {
536 pub const ONSTACK = 0x1;
537 pub const DISABLE = 0x2;
417pub const PF = struct {
418 pub const UNSPEC = AF.UNSPEC;
419 pub const INET = AF.INET;
420 pub const ROUTE = AF.ROUTE;
421 pub const LINK = AF.LINK;
422 pub const INET6 = AF.INET6;
423 pub const LOCAL = AF.LOCAL;
424 pub const UNIX = AF.UNIX;
425 pub const BLUETOOTH = AF.BLUETOOTH;
538426};
539427
540pub const MINSIGSTKSZ = 8192;
541pub const SIGSTKSZ = 16384;
542
543pub const stack_t = extern struct {
544 sp: [*]u8,
545 size: isize,
546 flags: i32,
428pub const AF = struct {
429 pub const UNSPEC = 0;
430 pub const INET = 1;
431 pub const APPLETALK = 2;
432 pub const ROUTE = 3;
433 pub const LINK = 4;
434 pub const INET6 = 5;
435 pub const DLI = 6;
436 pub const IPX = 7;
437 pub const NOTIFY = 8;
438 pub const LOCAL = 9;
439 pub const UNIX = LOCAL;
440 pub const BLUETOOTH = 10;
441 pub const MAX = 11;
547442};
548443
549pub const NSIG = 65;
444pub const DT = struct {};
550445
551pub const mcontext_t = vregs;
446/// add event to kq (implies enable)
447pub const EV_ADD = 0x0001;
552448
553pub const ucontext_t = extern struct {
554 link: ?*ucontext_t,
555 sigmask: sigset_t,
556 stack: stack_t,
557 mcontext: mcontext_t,
449/// delete event from kq
450pub const EV_DELETE = 0x0002;
451
452/// enable event
453pub const EV_ENABLE = 0x0004;
454
455/// disable event (not reported)
456pub const EV_DISABLE = 0x0008;
457
458/// only report one occurrence
459pub const EV_ONESHOT = 0x0010;
460
461/// clear event state after reporting
462pub const EV_CLEAR = 0x0020;
463
464/// force immediate event output
465/// ... with or without EV_ERROR
466/// ... use KEVENT_FLAG_ERROR_EVENTS
467/// on syscalls supporting flags
468pub const EV_RECEIPT = 0x0040;
469
470/// disable event after reporting
471pub const EV_DISPATCH = 0x0080;
472
473pub const EVFILT_READ = -1;
474pub const EVFILT_WRITE = -2;
475
476/// attached to aio requests
477pub const EVFILT_AIO = -3;
478
479/// attached to vnodes
480pub const EVFILT_VNODE = -4;
481
482/// attached to struct proc
483pub const EVFILT_PROC = -5;
484
485/// attached to struct proc
486pub const EVFILT_SIGNAL = -6;
487
488/// timers
489pub const EVFILT_TIMER = -7;
490
491/// Process descriptors
492pub const EVFILT_PROCDESC = -8;
493
494/// Filesystem events
495pub const EVFILT_FS = -9;
496
497pub const EVFILT_LIO = -10;
498
499/// User events
500pub const EVFILT_USER = -11;
501
502/// Sendfile events
503pub const EVFILT_SENDFILE = -12;
504
505pub const EVFILT_EMPTY = -13;
506
507pub const T = struct {
508 pub const CGETA = 0x8000;
509 pub const CSETA = 0x8001;
510 pub const CSETAF = 0x8002;
511 pub const CSETAW = 0x8003;
512 pub const CWAITEVENT = 0x8004;
513 pub const CSBRK = 0x8005;
514 pub const CFLSH = 0x8006;
515 pub const CXONC = 0x8007;
516 pub const CQUERYCONNECTED = 0x8008;
517 pub const CGETBITS = 0x8009;
518 pub const CSETDTR = 0x8010;
519 pub const CSETRTS = 0x8011;
520 pub const IOCGWINSZ = 0x8012;
521 pub const IOCSWINSZ = 0x8013;
522 pub const CVTIME = 0x8014;
523 pub const IOCGPGRP = 0x8015;
524 pub const IOCSPGRP = 0x8016;
525 pub const IOCSCTTY = 0x8017;
526 pub const IOCMGET = 0x8018;
527 pub const IOCMSET = 0x8019;
528 pub const IOCSBRK = 0x8020;
529 pub const IOCCBRK = 0x8021;
530 pub const IOCMBIS = 0x8022;
531 pub const IOCMBIC = 0x8023;
532 pub const IOCGSID = 0x8024;
533
534 pub const FIONREAD = 0xbe000001;
535 pub const FIONBIO = 0xbe000000;
536};
537
538pub const winsize = extern struct {
539 ws_row: u16,
540 ws_col: u16,
541 ws_xpixel: u16,
542 ws_ypixel: u16,
543};
544
545pub const S = struct {
546 pub const IFMT = 0o170000;
547 pub const IFSOCK = 0o140000;
548 pub const IFLNK = 0o120000;
549 pub const IFREG = 0o100000;
550 pub const IFBLK = 0o060000;
551 pub const IFDIR = 0o040000;
552 pub const IFCHR = 0o020000;
553 pub const IFIFO = 0o010000;
554 pub const INDEX_DIR = 0o4000000000;
555
556 pub const IUMSK = 0o7777;
557 pub const ISUID = 0o4000;
558 pub const ISGID = 0o2000;
559 pub const ISVTX = 0o1000;
560 pub const IRWXU = 0o700;
561 pub const IRUSR = 0o400;
562 pub const IWUSR = 0o200;
563 pub const IXUSR = 0o100;
564 pub const IRWXG = 0o070;
565 pub const IRGRP = 0o040;
566 pub const IWGRP = 0o020;
567 pub const IXGRP = 0o010;
568 pub const IRWXO = 0o007;
569 pub const IROTH = 0o004;
570 pub const IWOTH = 0o002;
571 pub const IXOTH = 0o001;
572
573 pub fn ISREG(m: u32) bool {
574 return m & IFMT == IFREG;
575 }
576
577 pub fn ISLNK(m: u32) bool {
578 return m & IFMT == IFLNK;
579 }
580
581 pub fn ISBLK(m: u32) bool {
582 return m & IFMT == IFBLK;
583 }
584
585 pub fn ISDIR(m: u32) bool {
586 return m & IFMT == IFDIR;
587 }
588
589 pub fn ISCHR(m: u32) bool {
590 return m & IFMT == IFCHR;
591 }
592
593 pub fn ISFIFO(m: u32) bool {
594 return m & IFMT == IFIFO;
595 }
596
597 pub fn ISSOCK(m: u32) bool {
598 return m & IFMT == IFSOCK;
599 }
600
601 pub fn ISINDEX(m: u32) bool {
602 return m & INDEX_DIR == INDEX_DIR;
603 }
604};
605
606pub const HOST_NAME_MAX = 255;
607
608pub const addrinfo = extern struct {
609 flags: i32,
610 family: i32,
611 socktype: i32,
612 protocol: i32,
613 addrlen: socklen_t,
614 canonname: ?[*:0]u8,
615 addr: ?*sockaddr,
616 next: ?*addrinfo,
617};
618
619pub const IPPROTO = struct {
620 pub const IP = 0;
621 pub const HOPOPTS = 0;
622 pub const ICMP = 1;
623 pub const IGMP = 2;
624 pub const TCP = 6;
625 pub const UDP = 17;
626 pub const IPV6 = 41;
627 pub const ROUTING = 43;
628 pub const FRAGMENT = 44;
629 pub const ESP = 50;
630 pub const AH = 51;
631 pub const ICMPV6 = 58;
632 pub const NONE = 59;
633 pub const DSTOPTS = 60;
634 pub const ETHERIP = 97;
635 pub const RAW = 255;
636 pub const MAX = 256;
637};
638
639pub const rlimit_resource = enum(i32) {
640 CORE = 0,
641 CPU = 1,
642 DATA = 2,
643 FSIZE = 3,
644 NOFILE = 4,
645 STACK = 5,
646 AS = 6,
647 NOVMON = 7,
648 _,
649};
650
651pub const rlim_t = i64;
652
653pub const RLIM = struct {
654 /// No limit
655 pub const INFINITY: rlim_t = (1 << 63) - 1;
656
657 pub const SAVED_MAX = INFINITY;
658 pub const SAVED_CUR = INFINITY;
659};
660
661pub const rlimit = extern struct {
662 /// Soft limit
663 cur: rlim_t,
664 /// Hard limit
665 max: rlim_t,
666};
667
668pub const SHUT = struct {
669 pub const RD = 0;
670 pub const WR = 1;
671 pub const RDWR = 2;
672};
673
674// TODO fill out if needed
675pub const directory_which = enum(i32) {
676 B_USER_SETTINGS_DIRECTORY = 0xbbe,
677
678 _,
679};
680
681pub const MSG_NOSIGNAL = 0x0800;
682
683// /system/develop/headers/os/kernel/OS.h
684
685pub const area_id = i32;
686pub const port_id = i32;
687pub const sem_id = i32;
688pub const team_id = i32;
689pub const thread_id = i32;
690
691// /system/develop/headers/os/support/Errors.h
692
693pub const E = enum(i32) {
694 pub const B_GENERAL_ERROR_BASE: i32 = std.math.minInt(i32);
695 pub const B_OS_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x1000;
696 pub const B_APP_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x2000;
697 pub const B_INTERFACE_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x3000;
698 pub const B_MEDIA_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x4000;
699 pub const B_TRANSLATION_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x4800;
700 pub const B_MIDI_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x5000;
701 pub const B_STORAGE_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x6000;
702 pub const B_POSIX_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x7000;
703 pub const B_MAIL_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x8000;
704 pub const B_PRINT_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x9000;
705 pub const B_DEVICE_ERROR_BASE = B_GENERAL_ERROR_BASE + 0xa000;
706
707 pub const B_ERRORS_END = B_GENERAL_ERROR_BASE + 0xffff;
708
709 pub const B_NO_MEMORY = B_GENERAL_ERROR_BASE + 0;
710 pub const B_IO_ERROR = B_GENERAL_ERROR_BASE + 1;
711 pub const B_PERMISSION_DENIED = B_GENERAL_ERROR_BASE + 2;
712 pub const B_BAD_INDEX = B_GENERAL_ERROR_BASE + 3;
713 pub const B_BAD_TYPE = B_GENERAL_ERROR_BASE + 4;
714 pub const B_BAD_VALUE = B_GENERAL_ERROR_BASE + 5;
715 pub const B_MISMATCHED_VALUES = B_GENERAL_ERROR_BASE + 6;
716 pub const B_NAME_NOT_FOUND = B_GENERAL_ERROR_BASE + 7;
717 pub const B_NAME_IN_USE = B_GENERAL_ERROR_BASE + 8;
718 pub const B_TIMED_OUT = B_GENERAL_ERROR_BASE + 9;
719 pub const B_INTERRUPTED = B_GENERAL_ERROR_BASE + 10;
720 pub const B_WOULD_BLOCK = B_GENERAL_ERROR_BASE + 11;
721 pub const B_CANCELED = B_GENERAL_ERROR_BASE + 12;
722 pub const B_NO_INIT = B_GENERAL_ERROR_BASE + 13;
723 pub const B_NOT_INITIALIZED = B_GENERAL_ERROR_BASE + 13;
724 pub const B_BUSY = B_GENERAL_ERROR_BASE + 14;
725 pub const B_NOT_ALLOWED = B_GENERAL_ERROR_BASE + 15;
726 pub const B_BAD_DATA = B_GENERAL_ERROR_BASE + 16;
727 pub const B_DONT_DO_THAT = B_GENERAL_ERROR_BASE + 17;
728
729 pub const B_BAD_IMAGE_ID = B_OS_ERROR_BASE + 0x300;
730 pub const B_BAD_ADDRESS = B_OS_ERROR_BASE + 0x301;
731 pub const B_NOT_AN_EXECUTABLE = B_OS_ERROR_BASE + 0x302;
732 pub const B_MISSING_LIBRARY = B_OS_ERROR_BASE + 0x303;
733 pub const B_MISSING_SYMBOL = B_OS_ERROR_BASE + 0x304;
734 pub const B_UNKNOWN_EXECUTABLE = B_OS_ERROR_BASE + 0x305;
735 pub const B_LEGACY_EXECUTABLE = B_OS_ERROR_BASE + 0x306;
736
737 pub const B_FILE_ERROR = B_STORAGE_ERROR_BASE + 0;
738 pub const B_FILE_EXISTS = B_STORAGE_ERROR_BASE + 2;
739 pub const B_ENTRY_NOT_FOUND = B_STORAGE_ERROR_BASE + 3;
740 pub const B_NAME_TOO_LONG = B_STORAGE_ERROR_BASE + 4;
741 pub const B_NOT_A_DIRECTORY = B_STORAGE_ERROR_BASE + 5;
742 pub const B_DIRECTORY_NOT_EMPTY = B_STORAGE_ERROR_BASE + 6;
743 pub const B_DEVICE_FULL = B_STORAGE_ERROR_BASE + 7;
744 pub const B_READ_ONLY_DEVICE = B_STORAGE_ERROR_BASE + 8;
745 pub const B_IS_A_DIRECTORY = B_STORAGE_ERROR_BASE + 9;
746 pub const B_NO_MORE_FDS = B_STORAGE_ERROR_BASE + 10;
747 pub const B_CROSS_DEVICE_LINK = B_STORAGE_ERROR_BASE + 11;
748 pub const B_LINK_LIMIT = B_STORAGE_ERROR_BASE + 12;
749 pub const B_BUSTED_PIPE = B_STORAGE_ERROR_BASE + 13;
750 pub const B_UNSUPPORTED = B_STORAGE_ERROR_BASE + 14;
751 pub const B_PARTITION_TOO_SMALL = B_STORAGE_ERROR_BASE + 15;
752 pub const B_PARTIAL_READ = B_STORAGE_ERROR_BASE + 16;
753 pub const B_PARTIAL_WRITE = B_STORAGE_ERROR_BASE + 17;
754
755 SUCCESS = 0,
756
757 @"2BIG" = B_POSIX_ERROR_BASE + 1,
758 CHILD = B_POSIX_ERROR_BASE + 2,
759 DEADLK = B_POSIX_ERROR_BASE + 3,
760 FBIG = B_POSIX_ERROR_BASE + 4,
761 MLINK = B_POSIX_ERROR_BASE + 5,
762 NFILE = B_POSIX_ERROR_BASE + 6,
763 NODEV = B_POSIX_ERROR_BASE + 7,
764 NOLCK = B_POSIX_ERROR_BASE + 8,
765 NOSYS = B_POSIX_ERROR_BASE + 9,
766 NOTTY = B_POSIX_ERROR_BASE + 10,
767 NXIO = B_POSIX_ERROR_BASE + 11,
768 SPIPE = B_POSIX_ERROR_BASE + 12,
769 SRCH = B_POSIX_ERROR_BASE + 13,
770 FPOS = B_POSIX_ERROR_BASE + 14,
771 SIGPARM = B_POSIX_ERROR_BASE + 15,
772 DOM = B_POSIX_ERROR_BASE + 16,
773 RANGE = B_POSIX_ERROR_BASE + 17,
774 PROTOTYPE = B_POSIX_ERROR_BASE + 18,
775 PROTONOSUPPORT = B_POSIX_ERROR_BASE + 19,
776 PFNOSUPPORT = B_POSIX_ERROR_BASE + 20,
777 AFNOSUPPORT = B_POSIX_ERROR_BASE + 21,
778 ADDRINUSE = B_POSIX_ERROR_BASE + 22,
779 ADDRNOTAVAIL = B_POSIX_ERROR_BASE + 23,
780 NETDOWN = B_POSIX_ERROR_BASE + 24,
781 NETUNREACH = B_POSIX_ERROR_BASE + 25,
782 NETRESET = B_POSIX_ERROR_BASE + 26,
783 CONNABORTED = B_POSIX_ERROR_BASE + 27,
784 CONNRESET = B_POSIX_ERROR_BASE + 28,
785 ISCONN = B_POSIX_ERROR_BASE + 29,
786 NOTCONN = B_POSIX_ERROR_BASE + 30,
787 SHUTDOWN = B_POSIX_ERROR_BASE + 31,
788 CONNREFUSED = B_POSIX_ERROR_BASE + 32,
789 HOSTUNREACH = B_POSIX_ERROR_BASE + 33,
790 NOPROTOOPT = B_POSIX_ERROR_BASE + 34,
791 NOBUFS = B_POSIX_ERROR_BASE + 35,
792 INPROGRESS = B_POSIX_ERROR_BASE + 36,
793 ALREADY = B_POSIX_ERROR_BASE + 37,
794 ILSEQ = B_POSIX_ERROR_BASE + 38,
795 NOMSG = B_POSIX_ERROR_BASE + 39,
796 STALE = B_POSIX_ERROR_BASE + 40,
797 OVERFLOW = B_POSIX_ERROR_BASE + 41,
798 MSGSIZE = B_POSIX_ERROR_BASE + 42,
799 OPNOTSUPP = B_POSIX_ERROR_BASE + 43,
800 NOTSOCK = B_POSIX_ERROR_BASE + 44,
801 HOSTDOWN = B_POSIX_ERROR_BASE + 45,
802 BADMSG = B_POSIX_ERROR_BASE + 46,
803 CANCELED = B_POSIX_ERROR_BASE + 47,
804 DESTADDRREQ = B_POSIX_ERROR_BASE + 48,
805 DQUOT = B_POSIX_ERROR_BASE + 49,
806 IDRM = B_POSIX_ERROR_BASE + 50,
807 MULTIHOP = B_POSIX_ERROR_BASE + 51,
808 NODATA = B_POSIX_ERROR_BASE + 52,
809 NOLINK = B_POSIX_ERROR_BASE + 53,
810 NOSR = B_POSIX_ERROR_BASE + 54,
811 NOSTR = B_POSIX_ERROR_BASE + 55,
812 NOTSUP = B_POSIX_ERROR_BASE + 56,
813 PROTO = B_POSIX_ERROR_BASE + 57,
814 TIME = B_POSIX_ERROR_BASE + 58,
815 TXTBSY = B_POSIX_ERROR_BASE + 59,
816 NOATTR = B_POSIX_ERROR_BASE + 60,
817 NOTRECOVERABLE = B_POSIX_ERROR_BASE + 61,
818 OWNERDEAD = B_POSIX_ERROR_BASE + 62,
819
820 NOMEM = B_NO_MEMORY,
821
822 ACCES = B_PERMISSION_DENIED,
823 INTR = B_INTERRUPTED,
824 IO = B_IO_ERROR,
825 BUSY = B_BUSY,
826 FAULT = B_BAD_ADDRESS,
827 TIMEDOUT = B_TIMED_OUT,
828 /// Also used for WOULDBLOCK
829 AGAIN = B_WOULD_BLOCK,
830 BADF = B_FILE_ERROR,
831 EXIST = B_FILE_EXISTS,
832 INVAL = B_BAD_VALUE,
833 NAMETOOLONG = B_NAME_TOO_LONG,
834 NOENT = B_ENTRY_NOT_FOUND,
835 PERM = B_NOT_ALLOWED,
836 NOTDIR = B_NOT_A_DIRECTORY,
837 ISDIR = B_IS_A_DIRECTORY,
838 NOTEMPTY = B_DIRECTORY_NOT_EMPTY,
839 NOSPC = B_DEVICE_FULL,
840 ROFS = B_READ_ONLY_DEVICE,
841 MFILE = B_NO_MORE_FDS,
842 XDEV = B_CROSS_DEVICE_LINK,
843 LOOP = B_LINK_LIMIT,
844 NOEXEC = B_NOT_AN_EXECUTABLE,
845 PIPE = B_BUSTED_PIPE,
846
847 _,
558848};
559849
850// /system/develop/headers/os/support/SupportDefs.h
851
852pub const status_t = i32;
853
560854// /system/develop/headers/posix/arch/*/signal.h
561855
562856pub const vregs = switch (builtin.cpu.arch) {
......@@ -736,531 +1030,364 @@ pub const vregs = switch (builtin.cpu.arch) {
7361030 reserved2: u16,
7371031 mxcsr: u32,
7381032 reserved3: u32,
739 fp_mmx: [8]fp_register,
740 xmmx: [8]xmm_register,
741 reserved4: [224]u8,
742 };
743
744 pub const extended_regs = extern struct {
745 state: extern union {
746 old_format: old_extended_regs,
747 new_format: new_extended_regs,
748 },
749 format: u32,
750 };
751
752 eip: u32,
753 eflags: u32,
754 eax: u32,
755 ecx: u32,
756 edx: u32,
757 esp: u32,
758 ebp: u32,
759 reserved: u32,
760 xregs: extended_regs,
761 edi: u32,
762 esi: u32,
763 ebx: u32,
764 },
765 .x86_64 => extern struct {
766 pub const fp_register = extern struct {
767 value: [10]u8,
768 reserved: [6]u8,
769 };
770
771 pub const xmm_register = extern struct {
772 value: [16]u8,
773 };
774
775 pub const fpu_state = extern struct {
776 control: u16,
777 status: u16,
778 tag: u16,
779 opcode: u16,
780 rip: u64,
781 rdp: u64,
782 mxcsr: u32,
783 mscsr_mask: u32,
784
785 fp_mmx: [8]fp_register,
786 xmm: [16]xmm_register,
787 reserved: [96]u8,
788 };
789
790 pub const xstate_hdr = extern struct {
791 bv: u64,
792 xcomp_bv: u64,
793 reserved: [48]u8,
794 };
795
796 pub const savefpu = extern struct {
797 fxsave: fpu_state,
798 xstate: xstate_hdr,
799 ymm: [16]xmm_register,
800 };
801
802 rax: u64,
803 rbx: u64,
804 rcx: u64,
805 rdx: u64,
806 rdi: u64,
807 rsi: u64,
808 rbp: u64,
809 r8: u64,
810 r9: u64,
811 r10: u64,
812 r11: u64,
813 r12: u64,
814 r13: u64,
815 r14: u64,
816 r15: u64,
817 rsp: u64,
818 rip: u64,
819 rflags: u64,
820 fpu: savefpu,
821 },
822 else => void,
823};
824
825// access function
826pub const F_OK = 0; // test for existence of file
827pub const X_OK = 1; // test for execute or search permission
828pub const W_OK = 2; // test for write permission
829pub const R_OK = 4; // test for read permission
830
831pub const F = struct {
832 pub const DUPFD = 0x0001;
833 pub const GETFD = 0x0002;
834 pub const SETFD = 0x0004;
835 pub const GETFL = 0x0008;
836 pub const SETFL = 0x0010;
837
838 pub const GETLK = 0x0020;
839 pub const SETLK = 0x0080;
840 pub const SETLKW = 0x0100;
841 pub const DUPFD_CLOEXEC = 0x0200;
842
843 pub const RDLCK = 0x0040;
844 pub const UNLCK = 0x0200;
845 pub const WRLCK = 0x0400;
846};
847
848pub const LOCK = struct {
849 pub const SH = 0x01;
850 pub const EX = 0x02;
851 pub const NB = 0x04;
852 pub const UN = 0x08;
853};
854
855pub const FD_CLOEXEC = 1;
856
857pub const SEEK = struct {
858 pub const SET = 0;
859 pub const CUR = 1;
860 pub const END = 2;
861};
862
863pub const SOCK = struct {
864 pub const STREAM = 1;
865 pub const DGRAM = 2;
866 pub const RAW = 3;
867 pub const SEQPACKET = 5;
868
869 /// WARNING: this flag is not supported by windows socket functions directly,
870 /// it is only supported by std.os.socket. Be sure that this value does
871 /// not share any bits with any of the `SOCK` values.
872 pub const CLOEXEC = 0x10000;
873 /// WARNING: this flag is not supported by windows socket functions directly,
874 /// it is only supported by std.os.socket. Be sure that this value does
875 /// not share any bits with any of the `SOCK` values.
876 pub const NONBLOCK = 0x20000;
877};
878
879pub const SO = struct {
880 pub const ACCEPTCONN = 0x00000001;
881 pub const BROADCAST = 0x00000002;
882 pub const DEBUG = 0x00000004;
883 pub const DONTROUTE = 0x00000008;
884 pub const KEEPALIVE = 0x00000010;
885 pub const OOBINLINE = 0x00000020;
886 pub const REUSEADDR = 0x00000040;
887 pub const REUSEPORT = 0x00000080;
888 pub const USELOOPBACK = 0x00000100;
889 pub const LINGER = 0x00000200;
890
891 pub const SNDBUF = 0x40000001;
892 pub const SNDLOWAT = 0x40000002;
893 pub const SNDTIMEO = 0x40000003;
894 pub const RCVBUF = 0x40000004;
895 pub const RCVLOWAT = 0x40000005;
896 pub const RCVTIMEO = 0x40000006;
897 pub const ERROR = 0x40000007;
898 pub const TYPE = 0x40000008;
899 pub const NONBLOCK = 0x40000009;
900 pub const BINDTODEVICE = 0x4000000a;
901 pub const PEERCRED = 0x4000000b;
902};
1033 fp_mmx: [8]fp_register,
1034 xmmx: [8]xmm_register,
1035 reserved4: [224]u8,
1036 };
9031037
904pub const SOL = struct {
905 pub const SOCKET = -1;
906};
1038 pub const extended_regs = extern struct {
1039 state: extern union {
1040 old_format: old_extended_regs,
1041 new_format: new_extended_regs,
1042 },
1043 format: u32,
1044 };
9071045
908pub const PF = struct {
909 pub const UNSPEC = AF.UNSPEC;
910 pub const INET = AF.INET;
911 pub const ROUTE = AF.ROUTE;
912 pub const LINK = AF.LINK;
913 pub const INET6 = AF.INET6;
914 pub const LOCAL = AF.LOCAL;
915 pub const UNIX = AF.UNIX;
916 pub const BLUETOOTH = AF.BLUETOOTH;
917};
1046 eip: u32,
1047 eflags: u32,
1048 eax: u32,
1049 ecx: u32,
1050 edx: u32,
1051 esp: u32,
1052 ebp: u32,
1053 reserved: u32,
1054 xregs: extended_regs,
1055 edi: u32,
1056 esi: u32,
1057 ebx: u32,
1058 },
1059 .x86_64 => extern struct {
1060 pub const fp_register = extern struct {
1061 value: [10]u8,
1062 reserved: [6]u8,
1063 };
9181064
919pub const AF = struct {
920 pub const UNSPEC = 0;
921 pub const INET = 1;
922 pub const APPLETALK = 2;
923 pub const ROUTE = 3;
924 pub const LINK = 4;
925 pub const INET6 = 5;
926 pub const DLI = 6;
927 pub const IPX = 7;
928 pub const NOTIFY = 8;
929 pub const LOCAL = 9;
930 pub const UNIX = LOCAL;
931 pub const BLUETOOTH = 10;
932 pub const MAX = 11;
933};
1065 pub const xmm_register = extern struct {
1066 value: [16]u8,
1067 };
9341068
935pub const DT = struct {};
1069 pub const fpu_state = extern struct {
1070 control: u16,
1071 status: u16,
1072 tag: u16,
1073 opcode: u16,
1074 rip: u64,
1075 rdp: u64,
1076 mxcsr: u32,
1077 mscsr_mask: u32,
9361078
937/// add event to kq (implies enable)
938pub const EV_ADD = 0x0001;
1079 fp_mmx: [8]fp_register,
1080 xmm: [16]xmm_register,
1081 reserved: [96]u8,
1082 };
9391083
940/// delete event from kq
941pub const EV_DELETE = 0x0002;
1084 pub const xstate_hdr = extern struct {
1085 bv: u64,
1086 xcomp_bv: u64,
1087 reserved: [48]u8,
1088 };
9421089
943/// enable event
944pub const EV_ENABLE = 0x0004;
1090 pub const savefpu = extern struct {
1091 fxsave: fpu_state,
1092 xstate: xstate_hdr,
1093 ymm: [16]xmm_register,
1094 };
9451095
946/// disable event (not reported)
947pub const EV_DISABLE = 0x0008;
1096 rax: u64,
1097 rbx: u64,
1098 rcx: u64,
1099 rdx: u64,
1100 rdi: u64,
1101 rsi: u64,
1102 rbp: u64,
1103 r8: u64,
1104 r9: u64,
1105 r10: u64,
1106 r11: u64,
1107 r12: u64,
1108 r13: u64,
1109 r14: u64,
1110 r15: u64,
1111 rsp: u64,
1112 rip: u64,
1113 rflags: u64,
1114 fpu: savefpu,
1115 },
1116 else => void,
1117};
9481118
949/// only report one occurrence
950pub const EV_ONESHOT = 0x0010;
1119// /system/develop/headers/posix/dirent.h
1120
1121pub const DirEnt = extern struct {
1122 /// device
1123 dev: dev_t,
1124 /// parent device (only for queries)
1125 pdev: dev_t,
1126 /// inode number
1127 ino: ino_t,
1128 /// parent inode (only for queries)
1129 pino: ino_t,
1130 /// length of this record, not the name
1131 reclen: u16,
1132 /// name of the entry (null byte terminated)
1133 name: [0]u8,
1134 pub fn getName(dirent: *const DirEnt) [*:0]const u8 {
1135 return @ptrCast(&dirent.name);
1136 }
1137};
9511138
952/// clear event state after reporting
953pub const EV_CLEAR = 0x0020;
1139// /system/develop/headers/posix/errno.h
9541140
955/// force immediate event output
956/// ... with or without EV_ERROR
957/// ... use KEVENT_FLAG_ERROR_EVENTS
958/// on syscalls supporting flags
959pub const EV_RECEIPT = 0x0040;
1141extern "root" fn _errnop() *i32;
1142pub const _errno = _errnop;
9601143
961/// disable event after reporting
962pub const EV_DISPATCH = 0x0080;
1144// /system/develop/headers/posix/poll.h
9631145
964pub const EVFILT_READ = -1;
965pub const EVFILT_WRITE = -2;
1146pub const nfds_t = usize;
9661147
967/// attached to aio requests
968pub const EVFILT_AIO = -3;
1148pub const pollfd = extern struct {
1149 fd: i32,
1150 events: i16,
1151 revents: i16,
1152};
9691153
970/// attached to vnodes
971pub const EVFILT_VNODE = -4;
1154pub const POLL = struct {
1155 /// any readable data available
1156 pub const IN = 0x0001;
1157 /// file descriptor is writeable
1158 pub const OUT = 0x0002;
1159 pub const RDNORM = IN;
1160 pub const WRNORM = OUT;
1161 /// priority readable data
1162 pub const RDBAND = 0x0008;
1163 /// priority data can be written
1164 pub const WRBAND = 0x0010;
1165 /// high priority readable data
1166 pub const PRI = 0x0020;
9721167
973/// attached to struct proc
974pub const EVFILT_PROC = -5;
1168 /// errors pending
1169 pub const ERR = 0x0004;
1170 /// disconnected
1171 pub const HUP = 0x0080;
1172 /// invalid file descriptor
1173 pub const NVAL = 0x1000;
1174};
9751175
976/// attached to struct proc
977pub const EVFILT_SIGNAL = -6;
1176// /system/develop/headers/posix/signal.h
9781177
979/// timers
980pub const EVFILT_TIMER = -7;
1178pub const sigset_t = u64;
1179pub const empty_sigset: sigset_t = 0;
1180pub const filled_sigset = ~@as(sigset_t, 0);
9811181
982/// Process descriptors
983pub const EVFILT_PROCDESC = -8;
1182pub const SIG = struct {
1183 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
1184 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
1185 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
9841186
985/// Filesystem events
986pub const EVFILT_FS = -9;
1187 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);
9871188
988pub const EVFILT_LIO = -10;
1189 pub const HUP = 1;
1190 pub const INT = 2;
1191 pub const QUIT = 3;
1192 pub const ILL = 4;
1193 pub const CHLD = 5;
1194 pub const ABRT = 6;
1195 pub const IOT = ABRT;
1196 pub const PIPE = 7;
1197 pub const FPE = 8;
1198 pub const KILL = 9;
1199 pub const STOP = 10;
1200 pub const SEGV = 11;
1201 pub const CONT = 12;
1202 pub const TSTP = 13;
1203 pub const ALRM = 14;
1204 pub const TERM = 15;
1205 pub const TTIN = 16;
1206 pub const TTOU = 17;
1207 pub const USR1 = 18;
1208 pub const USR2 = 19;
1209 pub const WINCH = 20;
1210 pub const KILLTHR = 21;
1211 pub const TRAP = 22;
1212 pub const POLL = 23;
1213 pub const PROF = 24;
1214 pub const SYS = 25;
1215 pub const URG = 26;
1216 pub const VTALRM = 27;
1217 pub const XCPU = 28;
1218 pub const XFSZ = 29;
1219 pub const BUS = 30;
1220 pub const RESERVED1 = 31;
1221 pub const RESERVED2 = 32;
9891222
990/// User events
991pub const EVFILT_USER = -11;
1223 pub const BLOCK = 1;
1224 pub const UNBLOCK = 2;
1225 pub const SETMASK = 3;
1226};
9921227
993/// Sendfile events
994pub const EVFILT_SENDFILE = -12;
1228pub const siginfo_t = extern struct {
1229 signo: i32,
1230 code: i32,
1231 errno: i32,
9951232
996pub const EVFILT_EMPTY = -13;
1233 pid: pid_t,
1234 uid: uid_t,
1235 addr: *allowzero anyopaque,
1236};
9971237
998pub const T = struct {
999 pub const CGETA = 0x8000;
1000 pub const CSETA = 0x8001;
1001 pub const CSETAF = 0x8002;
1002 pub const CSETAW = 0x8003;
1003 pub const CWAITEVENT = 0x8004;
1004 pub const CSBRK = 0x8005;
1005 pub const CFLSH = 0x8006;
1006 pub const CXONC = 0x8007;
1007 pub const CQUERYCONNECTED = 0x8008;
1008 pub const CGETBITS = 0x8009;
1009 pub const CSETDTR = 0x8010;
1010 pub const CSETRTS = 0x8011;
1011 pub const IOCGWINSZ = 0x8012;
1012 pub const IOCSWINSZ = 0x8013;
1013 pub const CVTIME = 0x8014;
1014 pub const IOCGPGRP = 0x8015;
1015 pub const IOCSPGRP = 0x8016;
1016 pub const IOCSCTTY = 0x8017;
1017 pub const IOCMGET = 0x8018;
1018 pub const IOCMSET = 0x8019;
1019 pub const IOCSBRK = 0x8020;
1020 pub const IOCCBRK = 0x8021;
1021 pub const IOCMBIS = 0x8022;
1022 pub const IOCMBIC = 0x8023;
1023 pub const IOCGSID = 0x8024;
1238/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
1239pub const Sigaction = extern struct {
1240 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
1241 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
10241242
1025 pub const FIONREAD = 0xbe000001;
1026 pub const FIONBIO = 0xbe000000;
1243 /// signal handler
1244 handler: extern union {
1245 handler: handler_fn,
1246 sigaction: sigaction_fn,
1247 },
1248
1249 /// signal mask to apply
1250 mask: sigset_t,
1251
1252 /// see signal options
1253 flags: i32,
1254
1255 /// will be passed to the signal handler, BeOS extension
1256 userdata: *allowzero anyopaque = undefined,
10271257};
10281258
1029pub const winsize = extern struct {
1030 ws_row: u16,
1031 ws_col: u16,
1032 ws_xpixel: u16,
1033 ws_ypixel: u16,
1259pub const SA = struct {
1260 pub const NOCLDSTOP = 0x01;
1261 pub const NOCLDWAIT = 0x02;
1262 pub const RESETHAND = 0x04;
1263 pub const NODEFER = 0x08;
1264 pub const RESTART = 0x10;
1265 pub const ONSTACK = 0x20;
1266 pub const SIGINFO = 0x40;
1267 pub const NOMASK = NODEFER;
1268 pub const STACK = ONSTACK;
1269 pub const ONESHOT = RESETHAND;
10341270};
10351271
1036const B_POSIX_ERROR_BASE = -2147454976;
1272pub const SS = struct {
1273 pub const ONSTACK = 0x1;
1274 pub const DISABLE = 0x2;
1275};
10371276
1038pub const E = enum(i32) {
1039 @"2BIG" = B_POSIX_ERROR_BASE + 1,
1040 CHILD = B_POSIX_ERROR_BASE + 2,
1041 DEADLK = B_POSIX_ERROR_BASE + 3,
1042 FBIG = B_POSIX_ERROR_BASE + 4,
1043 MLINK = B_POSIX_ERROR_BASE + 5,
1044 NFILE = B_POSIX_ERROR_BASE + 6,
1045 NODEV = B_POSIX_ERROR_BASE + 7,
1046 NOLCK = B_POSIX_ERROR_BASE + 8,
1047 NOSYS = B_POSIX_ERROR_BASE + 9,
1048 NOTTY = B_POSIX_ERROR_BASE + 10,
1049 NXIO = B_POSIX_ERROR_BASE + 11,
1050 SPIPE = B_POSIX_ERROR_BASE + 12,
1051 SRCH = B_POSIX_ERROR_BASE + 13,
1052 FPOS = B_POSIX_ERROR_BASE + 14,
1053 SIGPARM = B_POSIX_ERROR_BASE + 15,
1054 DOM = B_POSIX_ERROR_BASE + 16,
1055 RANGE = B_POSIX_ERROR_BASE + 17,
1056 PROTOTYPE = B_POSIX_ERROR_BASE + 18,
1057 PROTONOSUPPORT = B_POSIX_ERROR_BASE + 19,
1058 PFNOSUPPORT = B_POSIX_ERROR_BASE + 20,
1059 AFNOSUPPORT = B_POSIX_ERROR_BASE + 21,
1060 ADDRINUSE = B_POSIX_ERROR_BASE + 22,
1061 ADDRNOTAVAIL = B_POSIX_ERROR_BASE + 23,
1062 NETDOWN = B_POSIX_ERROR_BASE + 24,
1063 NETUNREACH = B_POSIX_ERROR_BASE + 25,
1064 NETRESET = B_POSIX_ERROR_BASE + 26,
1065 CONNABORTED = B_POSIX_ERROR_BASE + 27,
1066 CONNRESET = B_POSIX_ERROR_BASE + 28,
1067 ISCONN = B_POSIX_ERROR_BASE + 29,
1068 NOTCONN = B_POSIX_ERROR_BASE + 30,
1069 SHUTDOWN = B_POSIX_ERROR_BASE + 31,
1070 CONNREFUSED = B_POSIX_ERROR_BASE + 32,
1071 HOSTUNREACH = B_POSIX_ERROR_BASE + 33,
1072 NOPROTOOPT = B_POSIX_ERROR_BASE + 34,
1073 NOBUFS = B_POSIX_ERROR_BASE + 35,
1074 INPROGRESS = B_POSIX_ERROR_BASE + 36,
1075 ALREADY = B_POSIX_ERROR_BASE + 37,
1076 ILSEQ = B_POSIX_ERROR_BASE + 38,
1077 NOMSG = B_POSIX_ERROR_BASE + 39,
1078 STALE = B_POSIX_ERROR_BASE + 40,
1079 OVERFLOW = B_POSIX_ERROR_BASE + 41,
1080 MSGSIZE = B_POSIX_ERROR_BASE + 42,
1081 OPNOTSUPP = B_POSIX_ERROR_BASE + 43,
1082 NOTSOCK = B_POSIX_ERROR_BASE + 44,
1083 HOSTDOWN = B_POSIX_ERROR_BASE + 45,
1084 BADMSG = B_POSIX_ERROR_BASE + 46,
1085 CANCELED = B_POSIX_ERROR_BASE + 47,
1086 DESTADDRREQ = B_POSIX_ERROR_BASE + 48,
1087 DQUOT = B_POSIX_ERROR_BASE + 49,
1088 IDRM = B_POSIX_ERROR_BASE + 50,
1089 MULTIHOP = B_POSIX_ERROR_BASE + 51,
1090 NODATA = B_POSIX_ERROR_BASE + 52,
1091 NOLINK = B_POSIX_ERROR_BASE + 53,
1092 NOSR = B_POSIX_ERROR_BASE + 54,
1093 NOSTR = B_POSIX_ERROR_BASE + 55,
1094 NOTSUP = B_POSIX_ERROR_BASE + 56,
1095 PROTO = B_POSIX_ERROR_BASE + 57,
1096 TIME = B_POSIX_ERROR_BASE + 58,
1097 TXTBSY = B_POSIX_ERROR_BASE + 59,
1098 NOATTR = B_POSIX_ERROR_BASE + 60,
1099 NOTRECOVERABLE = B_POSIX_ERROR_BASE + 61,
1100 OWNERDEAD = B_POSIX_ERROR_BASE + 62,
1277pub const MINSIGSTKSZ = 8192;
1278pub const SIGSTKSZ = 16384;
11011279
1102 ACCES = -0x7ffffffe, // Permission denied
1103 INTR = -0x7ffffff6, // Interrupted system call
1104 IO = -0x7fffffff, // Input/output error
1105 BUSY = -0x7ffffff2, // Device busy
1106 FAULT = -0x7fffecff, // Bad address
1107 TIMEDOUT = -2147483639, // Operation timed out
1108 AGAIN = -0x7ffffff5,
1109 BADF = -0x7fffa000, // Bad file descriptor
1110 EXIST = -0x7fff9ffe, // File exists
1111 INVAL = -0x7ffffffb, // Invalid argument
1112 NAMETOOLONG = -2147459068, // File name too long
1113 NOENT = -0x7fff9ffd, // No such file or directory
1114 PERM = -0x7ffffff1, // Operation not permitted
1115 NOTDIR = -0x7fff9ffb, // Not a directory
1116 ISDIR = -0x7fff9ff7, // Is a directory
1117 NOTEMPTY = -2147459066, // Directory not empty
1118 NOSPC = -0x7fff9ff9, // No space left on device
1119 ROFS = -0x7fff9ff8, // Read-only filesystem
1120 MFILE = -0x7fff9ff6, // Too many open files
1121 XDEV = -0x7fff9ff5, // Cross-device link
1122 NOEXEC = -0x7fffecfe, // Exec format error
1123 PIPE = -0x7fff9ff3, // Broken pipe
1124 NOMEM = -0x80000000, // Cannot allocate memory
1125 LOOP = -2147459060, // Too many levels of symbolic links
1126 SUCCESS = 0,
1127 _,
1280pub const stack_t = extern struct {
1281 sp: [*]u8,
1282 size: isize,
1283 flags: i32,
11281284};
11291285
1130pub const S = struct {
1131 pub const IFMT = 0o170000;
1132 pub const IFSOCK = 0o140000;
1133 pub const IFLNK = 0o120000;
1134 pub const IFREG = 0o100000;
1135 pub const IFBLK = 0o060000;
1136 pub const IFDIR = 0o040000;
1137 pub const IFCHR = 0o020000;
1138 pub const IFIFO = 0o010000;
1139 pub const INDEX_DIR = 0o4000000000;
1140
1141 pub const IUMSK = 0o7777;
1142 pub const ISUID = 0o4000;
1143 pub const ISGID = 0o2000;
1144 pub const ISVTX = 0o1000;
1145 pub const IRWXU = 0o700;
1146 pub const IRUSR = 0o400;
1147 pub const IWUSR = 0o200;
1148 pub const IXUSR = 0o100;
1149 pub const IRWXG = 0o070;
1150 pub const IRGRP = 0o040;
1151 pub const IWGRP = 0o020;
1152 pub const IXGRP = 0o010;
1153 pub const IRWXO = 0o007;
1154 pub const IROTH = 0o004;
1155 pub const IWOTH = 0o002;
1156 pub const IXOTH = 0o001;
1286pub const NSIG = 65;
11571287
1158 pub fn ISREG(m: u32) bool {
1159 return m & IFMT == IFREG;
1160 }
1288pub const mcontext_t = vregs;
11611289
1162 pub fn ISLNK(m: u32) bool {
1163 return m & IFMT == IFLNK;
1164 }
1290pub const ucontext_t = extern struct {
1291 link: ?*ucontext_t,
1292 sigmask: sigset_t,
1293 stack: stack_t,
1294 mcontext: mcontext_t,
1295};
11651296
1166 pub fn ISBLK(m: u32) bool {
1167 return m & IFMT == IFBLK;
1168 }
1297// /system/develop/headers/posix/sys/stat.h
11691298
1170 pub fn ISDIR(m: u32) bool {
1171 return m & IFMT == IFDIR;
1172 }
1299pub const Stat = extern struct {
1300 dev: dev_t,
1301 ino: ino_t,
1302 mode: mode_t,
1303 nlink: nlink_t,
1304 uid: uid_t,
1305 gid: gid_t,
1306 size: off_t,
1307 rdev: dev_t,
1308 blksize: blksize_t,
1309 atim: timespec,
1310 mtim: timespec,
1311 ctim: timespec,
1312 crtim: timespec,
1313 type: u32,
1314 blocks: blkcnt_t,
11731315
1174 pub fn ISCHR(m: u32) bool {
1175 return m & IFMT == IFCHR;
1316 pub fn atime(self: @This()) timespec {
1317 return self.atim;
11761318 }
1177
1178 pub fn ISFIFO(m: u32) bool {
1179 return m & IFMT == IFIFO;
1319 pub fn mtime(self: @This()) timespec {
1320 return self.mtim;
11801321 }
1181
1182 pub fn ISSOCK(m: u32) bool {
1183 return m & IFMT == IFSOCK;
1322 pub fn ctime(self: @This()) timespec {
1323 return self.ctim;
11841324 }
1185
1186 pub fn ISINDEX(m: u32) bool {
1187 return m & INDEX_DIR == INDEX_DIR;
1325 pub fn birthtime(self: @This()) timespec {
1326 return self.crtim;
11881327 }
11891328};
11901329
1191pub const HOST_NAME_MAX = 255;
1330// /system/develop/headers/posix/sys/types.h
11921331
1193pub const addrinfo = extern struct {
1194 flags: i32,
1195 family: i32,
1196 socktype: i32,
1197 protocol: i32,
1198 addrlen: socklen_t,
1199 canonname: ?[*:0]u8,
1200 addr: ?*sockaddr,
1201 next: ?*addrinfo,
1202};
1332pub const blkcnt_t = i64;
1333pub const blksize_t = i32;
1334pub const fsblkcnt_t = i64;
1335pub const fsfilcnt_t = i64;
1336pub const off_t = i64;
1337pub const ino_t = i64;
1338pub const cnt_t = i32;
1339pub const dev_t = i32;
1340pub const pid_t = i32;
1341pub const id_t = i32;
12031342
1204pub const IPPROTO = struct {
1205 pub const IP = 0;
1206 pub const HOPOPTS = 0;
1207 pub const ICMP = 1;
1208 pub const IGMP = 2;
1209 pub const TCP = 6;
1210 pub const UDP = 17;
1211 pub const IPV6 = 41;
1212 pub const ROUTING = 43;
1213 pub const FRAGMENT = 44;
1214 pub const ESP = 50;
1215 pub const AH = 51;
1216 pub const ICMPV6 = 58;
1217 pub const NONE = 59;
1218 pub const DSTOPTS = 60;
1219 pub const ETHERIP = 97;
1220 pub const RAW = 255;
1221 pub const MAX = 256;
1222};
1343pub const uid_t = u32;
1344pub const gid_t = u32;
1345pub const mode_t = u32;
1346pub const umode_t = u32;
1347pub const nlink_t = i32;
12231348
1224pub const rlimit_resource = enum(c_int) {
1225 CORE = 0,
1226 CPU = 1,
1227 DATA = 2,
1228 FSIZE = 3,
1229 NOFILE = 4,
1230 STACK = 5,
1231 AS = 6,
1232 NOVMON = 7,
1233 _,
1234};
1349pub const clockid_t = i32;
1350pub const timer_t = *opaque {};
12351351
1236pub const rlim_t = i64;
1352// /system/develop/headers/posix/time.h
12371353
1238pub const RLIM = struct {
1239 /// No limit
1240 pub const INFINITY: rlim_t = (1 << 63) - 1;
1354pub const clock_t = i32;
1355pub const suseconds_t = i32;
1356pub const useconds_t = u32;
12411357
1242 pub const SAVED_MAX = INFINITY;
1243 pub const SAVED_CUR = INFINITY;
1244};
1358pub const time_t = isize;
12451359
1246pub const rlimit = extern struct {
1247 /// Soft limit
1248 cur: rlim_t,
1249 /// Hard limit
1250 max: rlim_t,
1251};
1360pub const CLOCKS_PER_SEC = 1_000_000;
1361pub const CLK_TCK = CLOCKS_PER_SEC;
1362pub const TIME_UTC = 1;
12521363
1253pub const SHUT = struct {
1254 pub const RD = 0;
1255 pub const WR = 1;
1256 pub const RDWR = 2;
1364pub const CLOCK = struct {
1365 /// system-wide monotonic clock (aka system time)
1366 pub const MONOTONIC: clockid_t = 0;
1367 /// system-wide real time clock
1368 pub const REALTIME: clockid_t = -1;
1369 /// clock measuring the used CPU time of the current process
1370 pub const PROCESS_CPUTIME_ID: clockid_t = -2;
1371 /// clock measuring the used CPU time of the current thread
1372 pub const THREAD_CPUTIME_ID: clockid_t = -3;
12571373};
12581374
1259// TODO fill out if needed
1260pub const directory_which = enum(c_int) {
1261 B_USER_SETTINGS_DIRECTORY = 0xbbe,
1375pub const timespec = extern struct {
1376 /// seconds
1377 tv_sec: time_t,
1378 /// and nanoseconds
1379 tv_nsec: isize,
1380};
12621381
1263 _,
1382pub const itimerspec = extern struct {
1383 interval: timespec,
1384 value: timespec,
12641385};
12651386
1266pub const MSG_NOSIGNAL = 0x0800;
1387// /system/develop/headers/private/system/syscalls.h
1388
1389pub extern "root" fn _kern_get_current_team() team_id;
1390pub extern "root" fn _kern_open_dir(fd: fd_t, path: [*:0]const u8) fd_t;
1391pub extern "root" fn _kern_read_dir(fd: fd_t, buffer: [*]u8, bufferSize: usize, maxCount: u32) isize;
1392pub extern "root" fn _kern_rewind_dir(fd: fd_t) status_t;
1393pub extern "root" fn _kern_read_stat(fd: fd_t, path: [*:0]const u8, traverseLink: bool, stat: *Stat, statSize: usize) status_t;
lib/std/fs/Dir.zig+72-31
......@@ -220,71 +220,83 @@ pub const Iterator = switch (native_os) {
220220 },
221221 .haiku => struct {
222222 dir: Dir,
223 buf: [1024]u8, // TODO align(@alignOf(posix.dirent64)),
223 buf: [@sizeOf(DirEnt) + posix.PATH_MAX]u8 align(@alignOf(DirEnt)),
224 offset: usize,
224225 index: usize,
225226 end_index: usize,
226227 first_iter: bool,
227228
228229 const Self = @This();
230 const DirEnt = posix.system.DirEnt;
229231
230232 pub const Error = IteratorError;
231233
232234 /// Memory such as file names referenced in this returned entry becomes invalid
233235 /// with subsequent calls to `next`, as well as when this `Dir` is deinitialized.
234236 pub fn next(self: *Self) Error!?Entry {
235 start_over: while (true) {
236 // TODO: find a better max
237 const HAIKU_MAX_COUNT = 10000;
237 while (true) {
238238 if (self.index >= self.end_index) {
239239 if (self.first_iter) {
240 posix.lseek_SET(self.dir.fd, 0) catch unreachable; // EBADF here likely means that the Dir was not opened with iteration permissions
240 switch (@as(posix.E, @enumFromInt(posix.system._kern_rewind_dir(self.dir.fd)))) {
241 .SUCCESS => {},
242 .BADF => unreachable, // Dir is invalid
243 .FAULT => unreachable,
244 .NOTDIR => unreachable,
245 .INVAL => unreachable,
246 .ACCES => return error.AccessDenied,
247 .PERM => return error.AccessDenied,
248 else => |err| return posix.unexpectedErrno(err),
249 }
241250 self.first_iter = false;
242251 }
243252 const rc = posix.system._kern_read_dir(
244253 self.dir.fd,
245254 &self.buf,
246255 self.buf.len,
247 HAIKU_MAX_COUNT,
256 self.buf.len / @sizeOf(DirEnt),
248257 );
249258 if (rc == 0) return null;
250259 if (rc < 0) {
251 switch (posix.errno(rc)) {
252 .BADF => unreachable, // Dir is invalid or was opened without iteration ability
260 switch (@as(posix.E, @enumFromInt(rc))) {
261 .BADF => unreachable, // Dir is invalid
253262 .FAULT => unreachable,
254263 .NOTDIR => unreachable,
255264 .INVAL => unreachable,
265 .OVERFLOW => unreachable,
266 .ACCES => return error.AccessDenied,
267 .PERM => return error.AccessDenied,
256268 else => |err| return posix.unexpectedErrno(err),
257269 }
258270 }
271 self.offset = 0;
259272 self.index = 0;
260 self.end_index = @as(usize, @intCast(rc));
261 }
262 const haiku_entry = @as(*align(1) posix.system.dirent, @ptrCast(&self.buf[self.index]));
263 const next_index = self.index + haiku_entry.reclen;
264 self.index = next_index;
265 const name = mem.sliceTo(@as([*:0]u8, @ptrCast(&haiku_entry.name)), 0);
266
267 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or (haiku_entry.ino == 0)) {
268 continue :start_over;
273 self.end_index = @intCast(rc);
269274 }
275 const dirent: *DirEnt = @ptrCast(@alignCast(&self.buf[self.offset]));
276 self.offset += dirent.reclen;
277 self.index += 1;
278 const name = mem.span(dirent.getName());
279 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or dirent.ino == 0) continue;
270280
271281 var stat_info: posix.Stat = undefined;
272 const rc = posix.system._kern_read_stat(
282 switch (@as(posix.E, @enumFromInt(posix.system._kern_read_stat(
273283 self.dir.fd,
274 &haiku_entry.name,
284 name,
275285 false,
276286 &stat_info,
277287 0,
278 );
279 if (rc != 0) {
280 switch (posix.errno(rc)) {
281 .SUCCESS => {},
282 .BADF => unreachable, // Dir is invalid or was opened without iteration ability
283 .FAULT => unreachable,
284 .NOTDIR => unreachable,
285 .INVAL => unreachable,
286 else => |err| return posix.unexpectedErrno(err),
287 }
288 )))) {
289 .SUCCESS => {},
290 .INVAL => unreachable,
291 .BADF => unreachable, // Dir is invalid
292 .NOMEM => return error.SystemResources,
293 .ACCES => return error.AccessDenied,
294 .PERM => return error.AccessDenied,
295 .FAULT => unreachable,
296 .NAMETOOLONG => unreachable,
297 .LOOP => unreachable,
298 .NOENT => continue,
299 else => |err| return posix.unexpectedErrno(err),
288300 }
289301 const statmode = stat_info.mode & posix.S.IFMT;
290302
......@@ -315,7 +327,7 @@ pub const Iterator = switch (native_os) {
315327 dir: Dir,
316328 // The if guard is solely there to prevent compile errors from missing `linux.dirent64`
317329 // definition when compiling for other OSes. It doesn't do anything when compiling for Linux.
318 buf: [1024]u8 align(if (native_os != .linux) 1 else @alignOf(linux.dirent64)),
330 buf: [1024]u8 align(@alignOf(linux.dirent64)),
319331 index: usize,
320332 end_index: usize,
321333 first_iter: bool,
......@@ -599,13 +611,21 @@ fn iterateImpl(self: Dir, first_iter_start_value: bool) Iterator {
599611 .buf = undefined,
600612 .first_iter = first_iter_start_value,
601613 },
602 .linux, .haiku => return Iterator{
614 .linux => return Iterator{
603615 .dir = self,
604616 .index = 0,
605617 .end_index = 0,
606618 .buf = undefined,
607619 .first_iter = first_iter_start_value,
608620 },
621 .haiku => return Iterator{
622 .dir = self,
623 .offset = 0,
624 .index = 0,
625 .end_index = 0,
626 .buf = undefined,
627 .first_iter = first_iter_start_value,
628 },
609629 .windows => return Iterator{
610630 .dir = self,
611631 .index = 0,
......@@ -1429,6 +1449,27 @@ pub fn openDirZ(self: Dir, sub_path_c: [*:0]const u8, args: OpenDirOptions) Open
14291449 .wasi => {
14301450 return openDir(self, mem.sliceTo(sub_path_c, 0), args);
14311451 },
1452 .haiku => {
1453 const rc = posix.system._kern_open_dir(self.fd, sub_path_c);
1454 if (rc >= 0) return .{ .fd = rc };
1455 switch (@as(posix.E, @enumFromInt(rc))) {
1456 .FAULT => unreachable,
1457 .INVAL => unreachable,
1458 .BADF => unreachable,
1459 .ACCES => return error.AccessDenied,
1460 .LOOP => return error.SymLinkLoop,
1461 .MFILE => return error.ProcessFdQuotaExceeded,
1462 .NAMETOOLONG => return error.NameTooLong,
1463 .NFILE => return error.SystemFdQuotaExceeded,
1464 .NODEV => return error.NoDevice,
1465 .NOENT => return error.FileNotFound,
1466 .NOMEM => return error.SystemResources,
1467 .NOTDIR => return error.NotDir,
1468 .PERM => return error.AccessDenied,
1469 .BUSY => return error.DeviceBusy,
1470 else => |err| return posix.unexpectedErrno(err),
1471 }
1472 },
14321473 else => {
14331474 var symlink_flags: posix.O = .{
14341475 .ACCMODE = .RDONLY,