/
haiku.zig
1375 lines (1090 loc) · 30.2 KB
/
haiku.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const std = @import("../../std.zig");
const maxInt = std.math.maxInt;
pub usingnamespace @import("posix.zig");
pub const fd_t = c_int;
pub const pid_t = c_int;
pub const uid_t = u32;
pub const gid_t = u32;
pub const mode_t = c_uint;
pub const socklen_t = u32;
/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
pub const Kevent = extern struct {
ident: usize,
filter: i16,
flags: u16,
fflags: u32,
data: i64,
udata: usize,
// TODO ext
};
// Modes and flags for dlopen()
// include/dlfcn.h
pub const POLLIN = 0x0001;
pub const POLLERR = 0x0004;
pub const POLLNVAL = 0x1000;
pub const POLLHUP = 0x0080;
/// Bind function calls lazily.
pub const RTLD_LAZY = 1;
/// Bind function calls immediately.
pub const RTLD_NOW = 2;
pub const RTLD_MODEMASK = 0x3;
/// Make symbols globally available.
pub const RTLD_GLOBAL = 0x100;
/// Opposite of RTLD_GLOBAL, and the default.
pub const RTLD_LOCAL = 0;
/// Trace loaded objects and exit.
pub const RTLD_TRACE = 0x200;
/// Do not remove members.
pub const RTLD_NODELETE = 0x01000;
/// Do not load if not already loaded.
pub const RTLD_NOLOAD = 0x02000;
pub const dl_phdr_info = extern struct {
dlpi_addr: usize,
dlpi_name: ?[*:0]const u8,
dlpi_phdr: [*]std.elf.Phdr,
dlpi_phnum: u16,
};
pub const Flock = extern struct {
l_start: off_t,
l_len: off_t,
l_pid: pid_t,
l_type: i16,
l_whence: i16,
l_sysid: i32,
__unused: [4]u8,
};
pub const msghdr = extern struct {
/// optional address
msg_name: ?*sockaddr,
/// size of address
msg_namelen: socklen_t,
/// scatter/gather array
msg_iov: [*]iovec,
/// # elements in msg_iov
msg_iovlen: i32,
/// ancillary data
msg_control: ?*c_void,
/// ancillary data buffer len
msg_controllen: socklen_t,
/// flags on received message
msg_flags: i32,
};
pub const msghdr_const = extern struct {
/// optional address
msg_name: ?*const sockaddr,
/// size of address
msg_namelen: socklen_t,
/// scatter/gather array
msg_iov: [*]iovec_const,
/// # elements in msg_iov
msg_iovlen: i32,
/// ancillary data
msg_control: ?*c_void,
/// ancillary data buffer len
msg_controllen: socklen_t,
/// flags on received message
msg_flags: i32,
};
pub const off_t = i64;
pub const ino_t = u64;
pub const nfds_t = u32;
pub const pollfd = extern struct {
fd: i32,
events: i16,
revents: i16,
};
pub const libc_stat = extern struct {
dev: i32,
ino: u64,
mode: u32,
nlink: i32,
uid: i32,
gid: i32,
size: i64,
rdev: i32,
blksize: i32,
atim: timespec,
mtim: timespec,
ctim: timespec,
crtim: timespec,
st_type: u32,
blocks: i64,
pub fn atime(self: @This()) timespec {
return self.atim;
}
pub fn mtime(self: @This()) timespec {
return self.mtim;
}
pub fn ctime(self: @This()) timespec {
return self.ctim;
}
pub fn crtime(self: @This()) timespec {
return self.crtim;
}
};
pub const timespec = extern struct {
tv_sec: isize,
tv_nsec: isize,
};
pub const dirent = extern struct {
d_dev: i32,
d_pdev: i32,
d_ino: i64,
d_pino: i64,
d_reclen: u16,
d_name: [256]u8,
pub fn reclen(self: dirent) u16 {
return self.d_reclen;
}
};
pub const image_info = extern struct {
id: u32,
type: u32,
sequence: i32,
init_order: i32,
init_routine: *c_void,
term_routine: *c_void,
device: i32,
node: i32,
name: [1024]u8,
text: *c_void,
data: *c_void,
text_size: i32,
data_size: i32,
api_version: i32,
abi: i32,
};
pub const system_info = extern struct {
boot_time: i64,
cpu_count: u32,
max_pages: u64,
used_pages: u64,
cached_pages: u64,
block_cache_pages: u64,
ignored_pages: u64,
needed_memory: u64,
free_memory: u64,
max_swap_pages: u64,
free_swap_pages: u64,
page_faults: u32,
max_sems: u32,
used_sems: u32,
max_ports: u32,
used_ports: u32,
max_threads: u32,
used_threads: u32,
max_teams: u32,
used_teams: u32,
kernel_name: [256]u8,
kernel_build_date: [32]u8,
kernel_build_time: [32]u8,
kernel_version: i64,
abi: u32,
};
pub const in_port_t = u16;
pub const sa_family_t = u8;
pub const sockaddr = extern struct {
/// total length
len: u8,
/// address family
family: sa_family_t,
/// actually longer; address value
data: [14]u8,
};
pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
pub const sockaddr_in = extern struct {
len: u8 = @sizeOf(sockaddr_in),
family: sa_family_t = AF_INET,
port: in_port_t,
addr: u32,
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
};
pub const sockaddr_in6 = extern struct {
len: u8 = @sizeOf(sockaddr_in6),
family: sa_family_t = AF_INET6,
port: in_port_t,
flowinfo: u32,
addr: [16]u8,
scope_id: u32,
};
pub const sockaddr_un = extern struct {
len: u8 = @sizeOf(sockaddr_un),
family: sa_family_t = AF_UNIX,
path: [104]u8,
};
pub const CTL_KERN = 1;
pub const CTL_DEBUG = 5;
pub const KERN_PROC = 14; // struct: process entries
pub const KERN_PROC_PATHNAME = 12; // path to executable
pub const PATH_MAX = 1024;
pub const STDIN_FILENO = 0;
pub const STDOUT_FILENO = 1;
pub const STDERR_FILENO = 2;
pub const PROT_NONE = 0;
pub const PROT_READ = 1;
pub const PROT_WRITE = 2;
pub const PROT_EXEC = 4;
pub const CLOCK_MONOTONIC = 0;
pub const CLOCK_REALTIME = -1;
pub const CLOCK_PROCESS_CPUTIME_ID = -2;
pub const CLOCK_THREAD_CPUTIME_ID = -3;
pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
pub const MAP_SHARED = 0x0001;
pub const MAP_PRIVATE = 0x0002;
pub const MAP_FIXED = 0x0010;
pub const MAP_STACK = 0x0400;
pub const MAP_NOSYNC = 0x0800;
pub const MAP_ANON = 0x1000;
pub const MAP_ANONYMOUS = MAP_ANON;
pub const MAP_FILE = 0;
pub const MAP_GUARD = 0x00002000;
pub const MAP_EXCL = 0x00004000;
pub const MAP_NOCORE = 0x00020000;
pub const MAP_PREFAULT_READ = 0x00040000;
pub const MAP_32BIT = 0x00080000;
pub const WNOHANG = 0x1;
pub const WUNTRACED = 0x2;
pub const WSTOPPED = 0x10;
pub const WCONTINUED = 0x4;
pub const WNOWAIT = 0x20;
pub const WEXITED = 0x08;
pub const SA_ONSTACK = 0x20;
pub const SA_RESTART = 0x10;
pub const SA_RESETHAND = 0x04;
pub const SA_NOCLDSTOP = 0x01;
pub const SA_NODEFER = 0x08;
pub const SA_NOCLDWAIT = 0x02;
pub const SA_SIGINFO = 0x40;
pub const SA_NOMASK = SA_NODEFER;
pub const SA_STACK = SA_ONSTACK;
pub const SA_ONESHOT = SA_RESETHAND;
pub const SIGHUP = 1;
pub const SIGINT = 2;
pub const SIGQUIT = 3;
pub const SIGILL = 4;
pub const SIGCHLD = 5;
pub const SIGABRT = 6;
pub const SIGIOT = SIGABRT;
pub const SIGPIPE = 7;
pub const SIGFPE = 8;
pub const SIGKILL = 9;
pub const SIGSTOP = 10;
pub const SIGSEGV = 11;
pub const SIGCONT = 12;
pub const SIGTSTP = 13;
pub const SIGALRM = 14;
pub const SIGTERM = 15;
pub const SIGTTIN = 16;
pub const SIGTTOU = 17;
pub const SIGUSR1 = 18;
pub const SIGUSR2 = 19;
pub const SIGWINCH = 20;
pub const SIGKILLTHR = 21;
pub const SIGTRAP = 22;
pub const SIGPOLL = 23;
pub const SIGPROF = 24;
pub const SIGSYS = 25;
pub const SIGURG = 26;
pub const SIGVTALRM = 27;
pub const SIGXCPU = 28;
pub const SIGXFSZ = 29;
pub const SIGBUS = 30;
pub const SIGRESERVED1 = 31;
pub const SIGRESERVED2 = 32;
// TODO: check
pub const SIGRTMIN = 65;
pub const SIGRTMAX = 126;
// access function
pub const F_OK = 0; // test for existence of file
pub const X_OK = 1; // test for execute or search permission
pub const W_OK = 2; // test for write permission
pub const R_OK = 4; // test for read permission
pub const O_RDONLY = 0x0000;
pub const O_WRONLY = 0x0001;
pub const O_RDWR = 0x0002;
pub const O_ACCMODE = 0x0003;
pub const O_SHLOCK = 0x0010;
pub const O_EXLOCK = 0x0020;
pub const O_CREAT = 0x0200;
pub const O_EXCL = 0x0800;
pub const O_NOCTTY = 0x8000;
pub const O_TRUNC = 0x0400;
pub const O_APPEND = 0x0008;
pub const O_NONBLOCK = 0x0004;
pub const O_DSYNC = 0o10000;
pub const O_SYNC = 0x0080;
pub const O_RSYNC = 0o4010000;
pub const O_DIRECTORY = 0x20000;
pub const O_NOFOLLOW = 0x0100;
pub const O_CLOEXEC = 0x00100000;
pub const O_ASYNC = 0x0040;
pub const O_DIRECT = 0x00010000;
pub const O_NOATIME = 0o1000000;
pub const O_PATH = 0o10000000;
pub const O_TMPFILE = 0o20200000;
pub const O_NDELAY = O_NONBLOCK;
pub const F_DUPFD = 0;
pub const F_GETFD = 1;
pub const F_SETFD = 2;
pub const F_GETFL = 3;
pub const F_SETFL = 4;
pub const F_GETOWN = 5;
pub const F_SETOWN = 6;
pub const F_GETLK = 11;
pub const F_SETLK = 12;
pub const F_SETLKW = 13;
pub const F_RDLCK = 1;
pub const F_WRLCK = 3;
pub const F_UNLCK = 2;
pub const LOCK_SH = 1;
pub const LOCK_EX = 2;
pub const LOCK_UN = 8;
pub const LOCK_NB = 4;
pub const F_SETOWN_EX = 15;
pub const F_GETOWN_EX = 16;
pub const F_GETOWNER_UIDS = 17;
pub const FD_CLOEXEC = 1;
pub const SEEK_SET = 0;
pub const SEEK_CUR = 1;
pub const SEEK_END = 2;
pub const SIG_BLOCK = 1;
pub const SIG_UNBLOCK = 2;
pub const SIG_SETMASK = 3;
pub const SOCK_STREAM = 1;
pub const SOCK_DGRAM = 2;
pub const SOCK_RAW = 3;
pub const SOCK_RDM = 4;
pub const SOCK_SEQPACKET = 5;
pub const SOCK_CLOEXEC = 0x10000000;
pub const SOCK_NONBLOCK = 0x20000000;
pub const SO_DEBUG = 0x00000001;
pub const SO_ACCEPTCONN = 0x00000002;
pub const SO_REUSEADDR = 0x00000004;
pub const SO_KEEPALIVE = 0x00000008;
pub const SO_DONTROUTE = 0x00000010;
pub const SO_BROADCAST = 0x00000020;
pub const SO_USELOOPBACK = 0x00000040;
pub const SO_LINGER = 0x00000080;
pub const SO_OOBINLINE = 0x00000100;
pub const SO_REUSEPORT = 0x00000200;
pub const SO_TIMESTAMP = 0x00000400;
pub const SO_NOSIGPIPE = 0x00000800;
pub const SO_ACCEPTFILTER = 0x00001000;
pub const SO_BINTIME = 0x00002000;
pub const SO_NO_OFFLOAD = 0x00004000;
pub const SO_NO_DDP = 0x00008000;
pub const SO_REUSEPORT_LB = 0x00010000;
pub const SO_SNDBUF = 0x1001;
pub const SO_RCVBUF = 0x1002;
pub const SO_SNDLOWAT = 0x1003;
pub const SO_RCVLOWAT = 0x1004;
pub const SO_SNDTIMEO = 0x1005;
pub const SO_RCVTIMEO = 0x1006;
pub const SO_ERROR = 0x1007;
pub const SO_TYPE = 0x1008;
pub const SO_LABEL = 0x1009;
pub const SO_PEERLABEL = 0x1010;
pub const SO_LISTENQLIMIT = 0x1011;
pub const SO_LISTENQLEN = 0x1012;
pub const SO_LISTENINCQLEN = 0x1013;
pub const SO_SETFIB = 0x1014;
pub const SO_USER_COOKIE = 0x1015;
pub const SO_PROTOCOL = 0x1016;
pub const SO_PROTOTYPE = SO_PROTOCOL;
pub const SO_TS_CLOCK = 0x1017;
pub const SO_MAX_PACING_RATE = 0x1018;
pub const SO_DOMAIN = 0x1019;
pub const SOL_SOCKET = 0xffff;
pub const PF_UNSPEC = AF_UNSPEC;
pub const PF_LOCAL = AF_LOCAL;
pub const PF_UNIX = PF_LOCAL;
pub const PF_INET = AF_INET;
pub const PF_IMPLINK = AF_IMPLINK;
pub const PF_PUP = AF_PUP;
pub const PF_CHAOS = AF_CHAOS;
pub const PF_NETBIOS = AF_NETBIOS;
pub const PF_ISO = AF_ISO;
pub const PF_OSI = AF_ISO;
pub const PF_ECMA = AF_ECMA;
pub const PF_DATAKIT = AF_DATAKIT;
pub const PF_CCITT = AF_CCITT;
pub const PF_DECnet = AF_DECnet;
pub const PF_DLI = AF_DLI;
pub const PF_LAT = AF_LAT;
pub const PF_HYLINK = AF_HYLINK;
pub const PF_APPLETALK = AF_APPLETALK;
pub const PF_ROUTE = AF_ROUTE;
pub const PF_LINK = AF_LINK;
pub const PF_XTP = pseudo_AF_XTP;
pub const PF_COIP = AF_COIP;
pub const PF_CNT = AF_CNT;
pub const PF_SIP = AF_SIP;
pub const PF_IPX = AF_IPX;
pub const PF_RTIP = pseudo_AF_RTIP;
pub const PF_PIP = psuedo_AF_PIP;
pub const PF_ISDN = AF_ISDN;
pub const PF_KEY = pseudo_AF_KEY;
pub const PF_INET6 = pseudo_AF_INET6;
pub const PF_NATM = AF_NATM;
pub const PF_ATM = AF_ATM;
pub const PF_NETGRAPH = AF_NETGRAPH;
pub const PF_SLOW = AF_SLOW;
pub const PF_SCLUSTER = AF_SCLUSTER;
pub const PF_ARP = AF_ARP;
pub const PF_BLUETOOTH = AF_BLUETOOTH;
pub const PF_IEEE80211 = AF_IEEE80211;
pub const PF_INET_SDP = AF_INET_SDP;
pub const PF_INET6_SDP = AF_INET6_SDP;
pub const PF_MAX = AF_MAX;
pub const AF_UNSPEC = 0;
pub const AF_UNIX = 1;
pub const AF_LOCAL = AF_UNIX;
pub const AF_FILE = AF_LOCAL;
pub const AF_INET = 2;
pub const AF_IMPLINK = 3;
pub const AF_PUP = 4;
pub const AF_CHAOS = 5;
pub const AF_NETBIOS = 6;
pub const AF_ISO = 7;
pub const AF_OSI = AF_ISO;
pub const AF_ECMA = 8;
pub const AF_DATAKIT = 9;
pub const AF_CCITT = 10;
pub const AF_SNA = 11;
pub const AF_DECnet = 12;
pub const AF_DLI = 13;
pub const AF_LAT = 14;
pub const AF_HYLINK = 15;
pub const AF_APPLETALK = 16;
pub const AF_ROUTE = 17;
pub const AF_LINK = 18;
pub const pseudo_AF_XTP = 19;
pub const AF_COIP = 20;
pub const AF_CNT = 21;
pub const pseudo_AF_RTIP = 22;
pub const AF_IPX = 23;
pub const AF_SIP = 24;
pub const pseudo_AF_PIP = 25;
pub const AF_ISDN = 26;
pub const AF_E164 = AF_ISDN;
pub const pseudo_AF_KEY = 27;
pub const AF_INET6 = 28;
pub const AF_NATM = 29;
pub const AF_ATM = 30;
pub const pseudo_AF_HDRCMPLT = 31;
pub const AF_NETGRAPH = 32;
pub const AF_SLOW = 33;
pub const AF_SCLUSTER = 34;
pub const AF_ARP = 35;
pub const AF_BLUETOOTH = 36;
pub const AF_IEEE80211 = 37;
pub const AF_INET_SDP = 40;
pub const AF_INET6_SDP = 42;
pub const AF_MAX = 42;
pub const DT_UNKNOWN = 0;
pub const DT_FIFO = 1;
pub const DT_CHR = 2;
pub const DT_DIR = 4;
pub const DT_BLK = 6;
pub const DT_REG = 8;
pub const DT_LNK = 10;
pub const DT_SOCK = 12;
pub const DT_WHT = 14;
/// add event to kq (implies enable)
pub const EV_ADD = 0x0001;
/// delete event from kq
pub const EV_DELETE = 0x0002;
/// enable event
pub const EV_ENABLE = 0x0004;
/// disable event (not reported)
pub const EV_DISABLE = 0x0008;
/// only report one occurrence
pub const EV_ONESHOT = 0x0010;
/// clear event state after reporting
pub const EV_CLEAR = 0x0020;
/// force immediate event output
/// ... with or without EV_ERROR
/// ... use KEVENT_FLAG_ERROR_EVENTS
/// on syscalls supporting flags
pub const EV_RECEIPT = 0x0040;
/// disable event after reporting
pub const EV_DISPATCH = 0x0080;
pub const EVFILT_READ = -1;
pub const EVFILT_WRITE = -2;
/// attached to aio requests
pub const EVFILT_AIO = -3;
/// attached to vnodes
pub const EVFILT_VNODE = -4;
/// attached to struct proc
pub const EVFILT_PROC = -5;
/// attached to struct proc
pub const EVFILT_SIGNAL = -6;
/// timers
pub const EVFILT_TIMER = -7;
/// Process descriptors
pub const EVFILT_PROCDESC = -8;
/// Filesystem events
pub const EVFILT_FS = -9;
pub const EVFILT_LIO = -10;
/// User events
pub const EVFILT_USER = -11;
/// Sendfile events
pub const EVFILT_SENDFILE = -12;
pub const EVFILT_EMPTY = -13;
pub const TCGETA = 0x8000;
pub const TCSETA = 0x8001;
pub const TCSETAW = 0x8004;
pub const TCSETAF = 0x8003;
pub const TCSBRK = 08005;
pub const TCXONC = 0x8007;
pub const TCFLSH = 0x8006;
pub const TIOCSCTTY = 0x8017;
pub const TIOCGPGRP = 0x8015;
pub const TIOCSPGRP = 0x8016;
pub const TIOCGWINSZ = 0x8012;
pub const TIOCSWINSZ = 0x8013;
pub const TIOCMGET = 0x8018;
pub const TIOCMBIS = 0x8022;
pub const TIOCMBIC = 0x8023;
pub const TIOCMSET = 0x8019;
pub const FIONREAD = 0xbe000001;
pub const FIONBIO = 0xbe000000;
pub const TIOCSBRK = 0x8020;
pub const TIOCCBRK = 0x8021;
pub const TIOCGSID = 0x8024;
pub fn WEXITSTATUS(s: u32) u8 {
return @intCast(u8, s & 0xff);
}
pub fn WTERMSIG(s: u32) u32 {
return (s >> 8) & 0xff;
}
pub fn WSTOPSIG(s: u32) u32 {
return WEXITSTATUS(s);
}
pub fn WIFEXITED(s: u32) bool {
return WTERMSIG(s) == 0;
}
pub fn WIFSTOPPED(s: u32) bool {
return ((s >> 16) & 0xff) != 0;
}
pub fn WIFSIGNALED(s: u32) bool {
return ((s >> 8) & 0xff) != 0;
}
pub const winsize = extern struct {
ws_row: u16,
ws_col: u16,
ws_xpixel: u16,
ws_ypixel: u16,
};
const NSIG = 32;
pub const SIG_ERR = @intToPtr(fn (i32) callconv(.C) void, maxInt(usize));
pub const SIG_DFL = @intToPtr(fn (i32) callconv(.C) void, 0);
pub const SIG_IGN = @intToPtr(fn (i32) callconv(.C) void, 1);
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
/// signal handler
__sigaction_u: extern union {
__sa_handler: fn (i32) callconv(.C) void,
__sa_sigaction: fn (i32, *__siginfo, usize) callconv(.C) void,
},
/// see signal options
sa_flags: u32,
/// signal mask to apply
sa_mask: sigset_t,
};
pub const _SIG_WORDS = 4;
pub const _SIG_MAXSIG = 128;
pub inline fn _SIG_IDX(sig: usize) usize {
return sig - 1;
}
pub inline fn _SIG_WORD(sig: usize) usize {
return_SIG_IDX(sig) >> 5;
}
pub inline fn _SIG_BIT(sig: usize) usize {
return 1 << (_SIG_IDX(sig) & 31);
}
pub inline fn _SIG_VALID(sig: usize) usize {
return sig <= _SIG_MAXSIG and sig > 0;
}
pub const sigset_t = extern struct {
__bits: [_SIG_WORDS]u32,
};
pub const E = enum(i32) {
/// No error occurred.
SUCCESS = 0,
PERM = -0x7ffffff1, // Operation not permitted
NOENT = -0x7fff9ffd, // No such file or directory
SRCH = -0x7fff8ff3, // No such process
INTR = -0x7ffffff6, // Interrupted system call
IO = -0x7fffffff, // Input/output error
NXIO = -0x7fff8ff5, // Device not configured
@"2BIG" = -0x7fff8fff, // Argument list too long
NOEXEC = -0x7fffecfe, // Exec format error
CHILD = -0x7fff8ffe, // No child processes
DEADLK = -0x7fff8ffd, // Resource deadlock avoided
NOMEM = -0x80000000, // Cannot allocate memory
ACCES = -0x7ffffffe, // Permission denied
FAULT = -0x7fffecff, // Bad address
BUSY = -0x7ffffff2, // Device busy
EXIST = -0x7fff9ffe, // File exists
XDEV = -0x7fff9ff5, // Cross-device link
NODEV = -0x7fff8ff9, // Operation not supported by device
NOTDIR = -0x7fff9ffb, // Not a directory
ISDIR = -0x7fff9ff7, // Is a directory
INVAL = -0x7ffffffb, // Invalid argument
NFILE = -0x7fff8ffa, // Too many open files in system
MFILE = -0x7fff9ff6, // Too many open files
NOTTY = -0x7fff8ff6, // Inappropriate ioctl for device
TXTBSY = -0x7fff8fc5, // Text file busy
FBIG = -0x7fff8ffc, // File too large
NOSPC = -0x7fff9ff9, // No space left on device
SPIPE = -0x7fff8ff4, // Illegal seek
ROFS = -0x7fff9ff8, // Read-only filesystem
MLINK = -0x7fff8ffb, // Too many links
PIPE = -0x7fff9ff3, // Broken pipe
BADF = -0x7fffa000, // Bad file descriptor
// math software
DOM = 33, // Numerical argument out of domain
RANGE = 34, // Result too large
// non-blocking and interrupt i/o
/// Also used for `WOULDBLOCK`.
AGAIN = -0x7ffffff5,
INPROGRESS = -0x7fff8fdc,
ALREADY = -0x7fff8fdb,
// ipc/network software -- argument errors
NOTSOCK = 38, // Socket operation on non-socket
DESTADDRREQ = 39, // Destination address required
MSGSIZE = 40, // Message too long
PROTOTYPE = 41, // Protocol wrong type for socket
NOPROTOOPT = 42, // Protocol not available
PROTONOSUPPORT = 43, // Protocol not supported
SOCKTNOSUPPORT = 44, // Socket type not supported
/// Also used for `NOTSUP`.
OPNOTSUPP = 45, // Operation not supported
PFNOSUPPORT = 46, // Protocol family not supported
AFNOSUPPORT = 47, // Address family not supported by protocol family
ADDRINUSE = 48, // Address already in use
ADDRNOTAVAIL = 49, // Can't assign requested address
// ipc/network software -- operational errors
NETDOWN = 50, // Network is down
NETUNREACH = 51, // Network is unreachable
NETRESET = 52, // Network dropped connection on reset
CONNABORTED = 53, // Software caused connection abort
CONNRESET = 54, // Connection reset by peer
NOBUFS = 55, // No buffer space available
ISCONN = 56, // Socket is already connected
NOTCONN = 57, // Socket is not connected
SHUTDOWN = 58, // Can't send after socket shutdown
TOOMANYREFS = 59, // Too many references: can't splice
TIMEDOUT = 60, // Operation timed out
CONNREFUSED = 61, // Connection refused
LOOP = 62, // Too many levels of symbolic links
NAMETOOLONG = 63, // File name too long
// should be rearranged
HOSTDOWN = 64, // Host is down
HOSTUNREACH = 65, // No route to host
NOTEMPTY = 66, // Directory not empty
// quotas & mush
PROCLIM = 67, // Too many processes
USERS = 68, // Too many users
DQUOT = 69, // Disc quota exceeded
// Network File System
STALE = 70, // Stale NFS file handle
REMOTE = 71, // Too many levels of remote in path
BADRPC = 72, // RPC struct is bad
RPCMISMATCH = 73, // RPC version wrong
PROGUNAVAIL = 74, // RPC prog. not avail
PROGMISMATCH = 75, // Program version wrong
PROCUNAVAIL = 76, // Bad procedure for program
NOLCK = 77, // No locks available
NOSYS = 78, // Function not implemented
FTYPE = 79, // Inappropriate file type or format
AUTH = 80, // Authentication error
NEEDAUTH = 81, // Need authenticator
IDRM = 82, // Identifier removed
NOMSG = 83, // No message of desired type
OVERFLOW = 84, // Value too large to be stored in data type
CANCELED = 85, // Operation canceled
ILSEQ = 86, // Illegal byte sequence
NOATTR = 87, // Attribute not found
DOOFUS = 88, // Programming error
BADMSG = 89, // Bad message
MULTIHOP = 90, // Multihop attempted
NOLINK = 91, // Link has been severed
PROTO = 92, // Protocol error
NOTCAPABLE = 93, // Capabilities insufficient
CAPMODE = 94, // Not permitted in capability mode
NOTRECOVERABLE = 95, // State not recoverable
OWNERDEAD = 96, // Previous owner died
_,
};
pub const MINSIGSTKSZ = switch (builtin.cpu.arch) {
.i386, .x86_64 => 2048,
.arm, .aarch64 => 4096,
else => @compileError("MINSIGSTKSZ not defined for this architecture"),
};
pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
pub const SS_ONSTACK = 1;
pub const SS_DISABLE = 4;
pub const stack_t = extern struct {
ss_sp: [*]u8,
ss_size: isize,
ss_flags: i32,
};
pub const S_IFMT = 0o170000;
pub const S_IFIFO = 0o010000;
pub const S_IFCHR = 0o020000;
pub const S_IFDIR = 0o040000;
pub const S_IFBLK = 0o060000;
pub const S_IFREG = 0o100000;
pub const S_IFLNK = 0o120000;
pub const S_IFSOCK = 0o140000;
pub const S_IFWHT = 0o160000;
pub const S_ISUID = 0o4000;
pub const S_ISGID = 0o2000;
pub const S_ISVTX = 0o1000;
pub const S_IRWXU = 0o700;
pub const S_IRUSR = 0o400;
pub const S_IWUSR = 0o200;
pub const S_IXUSR = 0o100;
pub const S_IRWXG = 0o070;
pub const S_IRGRP = 0o040;
pub const S_IWGRP = 0o020;
pub const S_IXGRP = 0o010;
pub const S_IRWXO = 0o007;
pub const S_IROTH = 0o004;
pub const S_IWOTH = 0o002;
pub const S_IXOTH = 0o001;
pub fn S_ISFIFO(m: u32) bool {
return m & S_IFMT == S_IFIFO;
}
pub fn S_ISCHR(m: u32) bool {
return m & S_IFMT == S_IFCHR;
}
pub fn S_ISDIR(m: u32) bool {
return m & S_IFMT == S_IFDIR;
}
pub fn S_ISBLK(m: u32) bool {
return m & S_IFMT == S_IFBLK;
}
pub fn S_ISREG(m: u32) bool {
return m & S_IFMT == S_IFREG;
}
pub fn S_ISLNK(m: u32) bool {
return m & S_IFMT == S_IFLNK;
}
pub fn S_ISSOCK(m: u32) bool {
return m & S_IFMT == S_IFSOCK;
}
pub fn S_IWHT(m: u32) bool {
return m & S_IFMT == S_IFWHT;
}
pub const HOST_NAME_MAX = 255;
/// Magic value that specify the use of the current working directory
/// to determine the target of relative file paths in the openat() and
/// similar syscalls.
pub const AT_FDCWD = -100;
/// Check access using effective user and group ID
pub const AT_EACCESS = 0x0100;
/// Do not follow symbolic links
pub const AT_SYMLINK_NOFOLLOW = 0x0200;
/// Follow symbolic link
pub const AT_SYMLINK_FOLLOW = 0x0400;
/// Remove directory instead of file
pub const AT_REMOVEDIR = 0x0800;
pub const addrinfo = extern struct {
flags: i32,
family: i32,
socktype: i32,
protocol: i32,
addrlen: socklen_t,
canonname: ?[*:0]u8,
addr: ?*sockaddr,
next: ?*addrinfo,
};
/// Fail if not under dirfd
pub const AT_BENEATH = 0x1000;
/// dummy for IP
pub const IPPROTO_IP = 0;
/// control message protocol
pub const IPPROTO_ICMP = 1;
/// tcp
pub const IPPROTO_TCP = 6;
/// user datagram protocol
pub const IPPROTO_UDP = 17;
/// IP6 header
pub const IPPROTO_IPV6 = 41;
/// raw IP packet
pub const IPPROTO_RAW = 255;
/// IP6 hop-by-hop options
pub const IPPROTO_HOPOPTS = 0;
/// group mgmt protocol
pub const IPPROTO_IGMP = 2;
/// gateway^2 (deprecated)
pub const IPPROTO_GGP = 3;
/// IPv4 encapsulation
pub const IPPROTO_IPV4 = 4;
/// for compatibility
pub const IPPROTO_IPIP = IPPROTO_IPV4;
/// Stream protocol II
pub const IPPROTO_ST = 7;