-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
openbsd.zig
1634 lines (1446 loc) · 47.1 KB
/
openbsd.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;
const builtin = @import("builtin");
const iovec = std.os.iovec;
const iovec_const = std.os.iovec_const;
extern "c" fn __errno() *c_int;
pub const _errno = __errno;
pub const dl_iterate_phdr_callback = switch (builtin.zig_backend) {
.stage1 => fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int,
else => *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int,
};
pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*anyopaque) c_int;
pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
pub extern "c" fn getthrid() pid_t;
pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;
pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
pub const pthread_mutex_t = extern struct {
inner: ?*anyopaque = null,
};
pub const pthread_cond_t = extern struct {
inner: ?*anyopaque = null,
};
pub const pthread_rwlock_t = extern struct {
ptr: ?*anyopaque = null,
};
pub const pthread_spinlock_t = extern struct {
inner: ?*anyopaque = null,
};
pub const pthread_attr_t = extern struct {
inner: ?*anyopaque = null,
};
pub const pthread_key_t = c_int;
pub const sem_t = ?*opaque {};
pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
pub extern "c" fn pledge(promises: ?[*:0]const u8, execpromises: ?[*:0]const u8) c_int;
pub extern "c" fn unveil(path: ?[*:0]const u8, permissions: ?[*:0]const u8) c_int;
pub extern "c" fn pthread_set_name_np(thread: std.c.pthread_t, name: [*:0]const u8) void;
pub extern "c" fn pthread_get_name_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) void;
// https://github.com/openbsd/src/blob/2207c4325726fdc5c4bcd0011af0fdf7d3dab137/sys/sys/futex.h
pub const FUTEX_WAIT = 1;
pub const FUTEX_WAKE = 2;
pub const FUTEX_REQUEUE = 3;
pub const FUTEX_PRIVATE_FLAG = 128;
pub extern "c" fn futex(uaddr: ?*const volatile u32, op: c_int, val: c_int, timeout: ?*const timespec, uaddr2: ?*const volatile u32) c_int;
pub const login_cap_t = extern struct {
lc_class: ?[*:0]const u8,
lc_cap: ?[*:0]const u8,
lc_style: ?[*:0]const u8,
};
pub extern "c" fn login_getclass(class: ?[*:0]const u8) ?*login_cap_t;
pub extern "c" fn login_getstyle(lc: *login_cap_t, style: ?[*:0]const u8, atype: ?[*:0]const u8) ?[*:0]const u8;
pub extern "c" fn login_getcapbool(lc: *login_cap_t, cap: [*:0]const u8, def: c_int) c_int;
pub extern "c" fn login_getcapnum(lc: *login_cap_t, cap: [*:0]const u8, def: i64, err: i64) i64;
pub extern "c" fn login_getcapsize(lc: *login_cap_t, cap: [*:0]const u8, def: i64, err: i64) i64;
pub extern "c" fn login_getcapstr(lc: *login_cap_t, cap: [*:0]const u8, def: [*:0]const u8, err: [*:0]const u8) [*:0]const u8;
pub extern "c" fn login_getcaptime(lc: *login_cap_t, cap: [*:0]const u8, def: i64, err: i64) i64;
pub extern "c" fn login_close(lc: *login_cap_t) void;
pub extern "c" fn setclasscontext(class: [*:0]const u8, flags: c_uint) c_int;
pub extern "c" fn setusercontext(lc: *login_cap_t, pwd: *passwd, uid: uid_t, flags: c_uint) c_int;
pub const auth_session_t = opaque {};
pub extern "c" fn auth_userokay(name: [*:0]const u8, style: ?[*:0]const u8, arg_type: ?[*:0]const u8, password: ?[*:0]const u8) c_int;
pub extern "c" fn auth_approval(as: ?*auth_session_t, ?*login_cap_t, name: ?[*:0]const u8, type: ?[*:0]const u8) c_int;
pub extern "c" fn auth_userchallenge(name: [*:0]const u8, style: ?[*:0]const u8, arg_type: ?[*:0]const u8, chappengep: *?[*:0]const u8) ?*auth_session_t;
pub extern "c" fn auth_userresponse(as: *auth_session_t, response: [*:0]const u8, more: c_int) c_int;
pub extern "c" fn auth_usercheck(name: [*:0]const u8, style: ?[*:0]const u8, arg_type: ?[*:0]const u8, password: ?[*:0]const u8) ?*auth_session_t;
pub extern "c" fn auth_open() ?*auth_session_t;
pub extern "c" fn auth_close(as: *auth_session_t) c_int;
pub extern "c" fn auth_setdata(as: *auth_session_t, ptr: *anyopaque, len: usize) c_int;
pub extern "c" fn auth_setitem(as: *auth_session_t, item: auth_item_t, value: [*:0]const u8) c_int;
pub extern "c" fn auth_getitem(as: *auth_session_t, item: auth_item_t) ?[*:0]const u8;
pub extern "c" fn auth_setoption(as: *auth_session_t, n: [*:0]const u8, v: [*:0]const u8) c_int;
pub extern "c" fn auth_setstate(as: *auth_session_t, s: c_int) void;
pub extern "c" fn auth_getstate(as: *auth_session_t) c_int;
pub extern "c" fn auth_clean(as: *auth_session_t) void;
pub extern "c" fn auth_clrenv(as: *auth_session_t) void;
pub extern "c" fn auth_clroption(as: *auth_session_t, option: [*:0]const u8) void;
pub extern "c" fn auth_clroptions(as: *auth_session_t) void;
pub extern "c" fn auth_setenv(as: *auth_session_t) void;
pub extern "c" fn auth_getvalue(as: *auth_session_t, what: [*:0]const u8) ?[*:0]const u8;
pub extern "c" fn auth_verify(as: ?*auth_session_t, style: ?[*:0]const u8, name: ?[*:0]const u8, ...) ?*auth_session_t;
pub extern "c" fn auth_call(as: *auth_session_t, path: [*:0]const u8, ...) c_int;
pub extern "c" fn auth_challenge(as: *auth_session_t) [*:0]const u8;
pub extern "c" fn auth_check_expire(as: *auth_session_t) i64;
pub extern "c" fn auth_check_change(as: *auth_session_t) i64;
pub extern "c" fn auth_getpwd(as: *auth_session_t) ?*passwd;
pub extern "c" fn auth_setpwd(as: *auth_session_t, pwd: *passwd) c_int;
pub extern "c" fn auth_mkvalue(value: [*:0]const u8) ?[*:0]const u8;
pub extern "c" fn auth_cat(file: [*:0]const u8) c_int;
pub extern "c" fn auth_checknologin(lc: *login_cap_t) void;
// TODO: auth_set_va_list requires zig support for va_list type (#515)
pub const passwd = extern struct {
pw_name: ?[*:0]const u8, // user name
pw_passwd: ?[*:0]const u8, // encrypted password
pw_uid: uid_t, // user uid
pw_gid: gid_t, // user gid
pw_change: time_t, // password change time
pw_class: ?[*:0]const u8, // user access class
pw_gecos: ?[*:0]const u8, // Honeywell login info
pw_dir: ?[*:0]const u8, // home directory
pw_shell: ?[*:0]const u8, // default shell
pw_expire: time_t, // account expiration
};
pub extern "c" fn getpwuid(uid: uid_t) ?*passwd;
pub extern "c" fn getpwnam(name: [*:0]const u8) ?*passwd;
pub extern "c" fn getpwuid_shadow(uid: uid_t) ?*passwd;
pub extern "c" fn getpwnam_shadow(name: [*:0]const u8) ?*passwd;
pub extern "c" fn getpwnam_r(name: [*:0]const u8, pw: *passwd, buf: [*]u8, buflen: usize, pwretp: *?*passwd) c_int;
pub extern "c" fn getpwuid_r(uid: uid_t, pw: *passwd, buf: [*]u8, buflen: usize, pwretp: *?*passwd) c_int;
pub extern "c" fn getpwent() ?*passwd;
pub extern "c" fn setpwent() void;
pub extern "c" fn endpwent() void;
pub extern "c" fn setpassent(stayopen: c_int) c_int;
pub extern "c" fn uid_from_user(name: [*:0]const u8, uid: *uid_t) c_int;
pub extern "c" fn user_from_uid(uid: uid_t, noname: c_int) ?[*:0]const u8;
pub extern "c" fn bcrypt_gensalt(log_rounds: u8) [*:0]const u8;
pub extern "c" fn bcrypt(pass: [*:0]const u8, salt: [*:0]const u8) ?[*:0]const u8;
pub extern "c" fn bcrypt_newhash(pass: [*:0]const u8, log_rounds: c_int, hash: [*]u8, hashlen: usize) c_int;
pub extern "c" fn bcrypt_checkpass(pass: [*:0]const u8, goodhash: [*:0]const u8) c_int;
pub extern "c" fn pw_dup(pw: *const passwd) ?*passwd;
pub const blkcnt_t = i64;
pub const blksize_t = i32;
pub const clock_t = i64;
pub const dev_t = i32;
pub const fd_t = c_int;
pub const gid_t = u32;
pub const ino_t = u64;
pub const mode_t = u32;
pub const nlink_t = u32;
pub const off_t = i64;
pub const pid_t = i32;
pub const socklen_t = u32;
pub const time_t = i64;
pub const uid_t = u32;
/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
pub const Kevent = extern struct {
ident: usize,
filter: c_short,
flags: u16,
fflags: c_uint,
data: i64,
udata: usize,
};
// Modes and flags for dlopen()
// include/dlfcn.h
pub const RTLD = struct {
/// Bind function calls lazily.
pub const LAZY = 1;
/// Bind function calls immediately.
pub const NOW = 2;
/// Make symbols globally available.
pub const GLOBAL = 0x100;
/// Opposite of GLOBAL, and the default.
pub const LOCAL = 0x000;
/// Trace loaded objects and exit.
pub const TRACE = 0x200;
};
pub const dl_phdr_info = extern struct {
dlpi_addr: std.elf.Addr,
dlpi_name: ?[*:0]const u8,
dlpi_phdr: [*]std.elf.Phdr,
dlpi_phnum: std.elf.Half,
};
pub const Flock = extern struct {
start: off_t,
len: off_t,
pid: pid_t,
type: c_short,
whence: c_short,
};
pub const addrinfo = extern struct {
flags: c_int,
family: c_int,
socktype: c_int,
protocol: c_int,
addrlen: socklen_t,
addr: ?*sockaddr,
canonname: ?[*:0]u8,
next: ?*addrinfo,
};
pub const EAI = enum(c_int) {
/// address family for hostname not supported
ADDRFAMILY = -9,
/// name could not be resolved at this time
AGAIN = -3,
/// flags parameter had an invalid value
BADFLAGS = -1,
/// non-recoverable failure in name resolution
FAIL = -4,
/// address family not recognized
FAMILY = -6,
/// memory allocation failure
MEMORY = -10,
/// no address associated with hostname
NODATA = -5,
/// name does not resolve
NONAME = -2,
/// service not recognized for socket type
SERVICE = -8,
/// intended socket type was not recognized
SOCKTYPE = -7,
/// system error returned in errno
SYSTEM = -11,
/// invalid value for hints
BADHINTS = -12,
/// resolved protocol is unknown
PROTOCOL = -13,
/// argument buffer overflow
OVERFLOW = -14,
_,
};
pub const EAI_MAX = 15;
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: c_uint,
/// ancillary data
msg_control: ?*anyopaque,
/// ancillary data buffer len
msg_controllen: socklen_t,
/// flags on received message
msg_flags: c_int,
};
pub const msghdr_const = extern struct {
/// optional address
msg_name: ?*const sockaddr,
/// size of address
msg_namelen: socklen_t,
/// scatter/gather array
msg_iov: [*]const iovec_const,
/// # elements in msg_iov
msg_iovlen: c_uint,
/// ancillary data
msg_control: ?*const anyopaque,
/// ancillary data buffer len
msg_controllen: socklen_t,
/// flags on received message
msg_flags: c_int,
};
pub const Stat = extern struct {
mode: mode_t,
dev: dev_t,
ino: ino_t,
nlink: nlink_t,
uid: uid_t,
gid: gid_t,
rdev: dev_t,
atim: timespec,
mtim: timespec,
ctim: timespec,
size: off_t,
blocks: blkcnt_t,
blksize: blksize_t,
flags: u32,
gen: u32,
birthtim: timespec,
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 birthtime(self: @This()) timespec {
return self.birthtim;
}
};
pub const timespec = extern struct {
tv_sec: time_t,
tv_nsec: c_long,
};
pub const timeval = extern struct {
tv_sec: time_t,
tv_usec: c_long,
};
pub const timezone = extern struct {
tz_minuteswest: c_int,
tz_dsttime: c_int,
};
pub const MAXNAMLEN = 255;
pub const dirent = extern struct {
d_fileno: ino_t,
d_off: off_t,
d_reclen: u16,
d_type: u8,
d_namlen: u8,
__d_padding: [4]u8,
d_name: [MAXNAMLEN + 1]u8,
pub fn reclen(self: dirent) u16 {
return self.d_reclen;
}
};
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 SS_MAXSIZE = 256;
pub const storage = std.x.os.Socket.Address.Native.Storage;
pub const in = extern struct {
len: u8 = @sizeOf(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 in6 = extern struct {
len: u8 = @sizeOf(in6),
family: sa_family_t = AF.INET6,
port: in_port_t,
flowinfo: u32,
addr: [16]u8,
scope_id: u32,
};
/// Definitions for UNIX IPC domain.
pub const un = extern struct {
/// total sockaddr length
len: u8 = @sizeOf(un),
family: sa_family_t = AF.LOCAL,
/// path name
path: [104]u8,
};
};
pub const AI = struct {
/// get address to use bind()
pub const PASSIVE = 1;
/// fill ai_canonname
pub const CANONNAME = 2;
/// prevent host name resolution
pub const NUMERICHOST = 4;
/// prevent service name resolution
pub const NUMERICSERV = 16;
/// only if any address is assigned
pub const ADDRCONFIG = 64;
};
pub const PATH_MAX = 1024;
pub const IOV_MAX = 1024;
pub const STDIN_FILENO = 0;
pub const STDOUT_FILENO = 1;
pub const STDERR_FILENO = 2;
pub const PROT = struct {
pub const NONE = 0;
pub const READ = 1;
pub const WRITE = 2;
pub const EXEC = 4;
};
pub const CLOCK = struct {
pub const REALTIME = 0;
pub const PROCESS_CPUTIME_ID = 2;
pub const MONOTONIC = 3;
pub const THREAD_CPUTIME_ID = 4;
};
pub const MAP = struct {
pub const FAILED = @intToPtr(*anyopaque, maxInt(usize));
pub const SHARED = 0x0001;
pub const PRIVATE = 0x0002;
pub const FIXED = 0x0010;
pub const RENAME = 0;
pub const NORESERVE = 0;
pub const INHERIT = 0;
pub const HASSEMAPHORE = 0;
pub const TRYFIXED = 0;
pub const FILE = 0;
pub const ANON = 0x1000;
pub const ANONYMOUS = ANON;
pub const STACK = 0x4000;
pub const CONCEAL = 0x8000;
};
pub const MSF = struct {
pub const ASYNC = 1;
pub const INVALIDATE = 2;
pub const SYNC = 4;
};
pub const W = struct {
pub const NOHANG = 1;
pub const UNTRACED = 2;
pub const CONTINUED = 8;
pub fn EXITSTATUS(s: u32) u8 {
return @intCast(u8, (s >> 8) & 0xff);
}
pub fn TERMSIG(s: u32) u32 {
return (s & 0x7f);
}
pub fn STOPSIG(s: u32) u32 {
return EXITSTATUS(s);
}
pub fn IFEXITED(s: u32) bool {
return TERMSIG(s) == 0;
}
pub fn IFCONTINUED(s: u32) bool {
return ((s & 0o177777) == 0o177777);
}
pub fn IFSTOPPED(s: u32) bool {
return (s & 0xff == 0o177);
}
pub fn IFSIGNALED(s: u32) bool {
return (((s) & 0o177) != 0o177) and (((s) & 0o177) != 0);
}
};
pub const SA = struct {
pub const ONSTACK = 0x0001;
pub const RESTART = 0x0002;
pub const RESETHAND = 0x0004;
pub const NOCLDSTOP = 0x0008;
pub const NODEFER = 0x0010;
pub const NOCLDWAIT = 0x0020;
pub const SIGINFO = 0x0040;
};
// 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 = struct {
/// open for reading only
pub const RDONLY = 0x00000000;
/// open for writing only
pub const WRONLY = 0x00000001;
/// open for reading and writing
pub const RDWR = 0x00000002;
/// mask for above modes
pub const ACCMODE = 0x00000003;
/// no delay
pub const NONBLOCK = 0x00000004;
/// set append mode
pub const APPEND = 0x00000008;
/// open with shared file lock
pub const SHLOCK = 0x00000010;
/// open with exclusive file lock
pub const EXLOCK = 0x00000020;
/// signal pgrp when data ready
pub const ASYNC = 0x00000040;
/// synchronous writes
pub const SYNC = 0x00000080;
/// don't follow symlinks on the last
pub const NOFOLLOW = 0x00000100;
/// create if nonexistent
pub const CREAT = 0x00000200;
/// truncate to zero length
pub const TRUNC = 0x00000400;
/// error if already exists
pub const EXCL = 0x00000800;
/// don't assign controlling terminal
pub const NOCTTY = 0x00008000;
/// write: I/O data completion
pub const DSYNC = SYNC;
/// read: I/O completion as for write
pub const RSYNC = SYNC;
/// fail if not a directory
pub const DIRECTORY = 0x20000;
/// set close on exec
pub const CLOEXEC = 0x10000;
};
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const GETOWN = 5;
pub const SETOWN = 6;
pub const GETLK = 7;
pub const SETLK = 8;
pub const SETLKW = 9;
pub const RDLCK = 1;
pub const UNLCK = 2;
pub const WRLCK = 3;
};
pub const LOCK = struct {
pub const SH = 0x01;
pub const EX = 0x02;
pub const NB = 0x04;
pub const UN = 0x08;
};
pub const FD_CLOEXEC = 1;
pub const SEEK = struct {
pub const SET = 0;
pub const CUR = 1;
pub const END = 2;
};
pub const SOCK = struct {
pub const STREAM = 1;
pub const DGRAM = 2;
pub const RAW = 3;
pub const RDM = 4;
pub const SEQPACKET = 5;
pub const CLOEXEC = 0x8000;
pub const NONBLOCK = 0x4000;
};
pub const SO = struct {
pub const DEBUG = 0x0001;
pub const ACCEPTCONN = 0x0002;
pub const REUSEADDR = 0x0004;
pub const KEEPALIVE = 0x0008;
pub const DONTROUTE = 0x0010;
pub const BROADCAST = 0x0020;
pub const USELOOPBACK = 0x0040;
pub const LINGER = 0x0080;
pub const OOBINLINE = 0x0100;
pub const REUSEPORT = 0x0200;
pub const TIMESTAMP = 0x0800;
pub const BINDANY = 0x1000;
pub const ZEROIZE = 0x2000;
pub const SNDBUF = 0x1001;
pub const RCVBUF = 0x1002;
pub const SNDLOWAT = 0x1003;
pub const RCVLOWAT = 0x1004;
pub const SNDTIMEO = 0x1005;
pub const RCVTIMEO = 0x1006;
pub const ERROR = 0x1007;
pub const TYPE = 0x1008;
pub const NETPROC = 0x1020;
pub const RTABLE = 0x1021;
pub const PEERCRED = 0x1022;
pub const SPLICE = 0x1023;
pub const DOMAIN = 0x1024;
pub const PROTOCOL = 0x1025;
};
pub const SOL = struct {
pub const SOCKET = 0xffff;
};
pub const PF = struct {
pub const UNSPEC = AF.UNSPEC;
pub const LOCAL = AF.LOCAL;
pub const UNIX = AF.UNIX;
pub const INET = AF.INET;
pub const APPLETALK = AF.APPLETALK;
pub const INET6 = AF.INET6;
pub const DECnet = AF.DECnet;
pub const KEY = AF.KEY;
pub const ROUTE = AF.ROUTE;
pub const SNA = AF.SNA;
pub const MPLS = AF.MPLS;
pub const BLUETOOTH = AF.BLUETOOTH;
pub const ISDN = AF.ISDN;
pub const MAX = AF.MAX;
};
pub const AF = struct {
pub const UNSPEC = 0;
pub const UNIX = 1;
pub const LOCAL = UNIX;
pub const INET = 2;
pub const APPLETALK = 16;
pub const INET6 = 24;
pub const KEY = 30;
pub const ROUTE = 17;
pub const SNA = 11;
pub const MPLS = 33;
pub const BLUETOOTH = 32;
pub const ISDN = 26;
pub const MAX = 36;
};
pub const DT = struct {
pub const UNKNOWN = 0;
pub const FIFO = 1;
pub const CHR = 2;
pub const DIR = 4;
pub const BLK = 6;
pub const REG = 8;
pub const LNK = 10;
pub const SOCK = 12;
pub const WHT = 14; // XXX
};
pub const EV_ADD = 0x0001;
pub const EV_DELETE = 0x0002;
pub const EV_ENABLE = 0x0004;
pub const EV_DISABLE = 0x0008;
pub const EV_ONESHOT = 0x0010;
pub const EV_CLEAR = 0x0020;
pub const EV_RECEIPT = 0x0040;
pub const EV_DISPATCH = 0x0080;
pub const EV_FLAG1 = 0x2000;
pub const EV_ERROR = 0x4000;
pub const EV_EOF = 0x8000;
pub const EVFILT_READ = -1;
pub const EVFILT_WRITE = -2;
pub const EVFILT_AIO = -3;
pub const EVFILT_VNODE = -4;
pub const EVFILT_PROC = -5;
pub const EVFILT_SIGNAL = -6;
pub const EVFILT_TIMER = -7;
pub const EVFILT_EXCEPT = -9;
// data/hint flags for EVFILT_{READ|WRITE}
pub const NOTE_LOWAT = 0x0001;
pub const NOTE_EOF = 0x0002;
// data/hint flags for EVFILT_EXCEPT and EVFILT_{READ|WRITE}
pub const NOTE_OOB = 0x0004;
// data/hint flags for EVFILT_VNODE
pub const NOTE_DELETE = 0x0001;
pub const NOTE_WRITE = 0x0002;
pub const NOTE_EXTEND = 0x0004;
pub const NOTE_ATTRIB = 0x0008;
pub const NOTE_LINK = 0x0010;
pub const NOTE_RENAME = 0x0020;
pub const NOTE_REVOKE = 0x0040;
pub const NOTE_TRUNCATE = 0x0080;
// data/hint flags for EVFILT_PROC
pub const NOTE_EXIT = 0x80000000;
pub const NOTE_FORK = 0x40000000;
pub const NOTE_EXEC = 0x20000000;
pub const NOTE_PDATAMASK = 0x000fffff;
pub const NOTE_PCTRLMASK = 0xf0000000;
pub const NOTE_TRACK = 0x00000001;
pub const NOTE_TRACKERR = 0x00000002;
pub const NOTE_CHILD = 0x00000004;
// data/hint flags for EVFILT_DEVICE
pub const NOTE_CHANGE = 0x00000001;
pub const T = struct {
pub const IOCCBRK = 0x2000747a;
pub const IOCCDTR = 0x20007478;
pub const IOCCONS = 0x80047462;
pub const IOCDCDTIMESTAMP = 0x40107458;
pub const IOCDRAIN = 0x2000745e;
pub const IOCEXCL = 0x2000740d;
pub const IOCEXT = 0x80047460;
pub const IOCFLAG_CDTRCTS = 0x10;
pub const IOCFLAG_CLOCAL = 0x2;
pub const IOCFLAG_CRTSCTS = 0x4;
pub const IOCFLAG_MDMBUF = 0x8;
pub const IOCFLAG_SOFTCAR = 0x1;
pub const IOCFLUSH = 0x80047410;
pub const IOCGETA = 0x402c7413;
pub const IOCGETD = 0x4004741a;
pub const IOCGFLAGS = 0x4004745d;
pub const IOCGLINED = 0x40207442;
pub const IOCGPGRP = 0x40047477;
pub const IOCGQSIZE = 0x40047481;
pub const IOCGRANTPT = 0x20007447;
pub const IOCGSID = 0x40047463;
pub const IOCGSIZE = 0x40087468;
pub const IOCGWINSZ = 0x40087468;
pub const IOCMBIC = 0x8004746b;
pub const IOCMBIS = 0x8004746c;
pub const IOCMGET = 0x4004746a;
pub const IOCMSET = 0x8004746d;
pub const IOCM_CAR = 0x40;
pub const IOCM_CD = 0x40;
pub const IOCM_CTS = 0x20;
pub const IOCM_DSR = 0x100;
pub const IOCM_DTR = 0x2;
pub const IOCM_LE = 0x1;
pub const IOCM_RI = 0x80;
pub const IOCM_RNG = 0x80;
pub const IOCM_RTS = 0x4;
pub const IOCM_SR = 0x10;
pub const IOCM_ST = 0x8;
pub const IOCNOTTY = 0x20007471;
pub const IOCNXCL = 0x2000740e;
pub const IOCOUTQ = 0x40047473;
pub const IOCPKT = 0x80047470;
pub const IOCPKT_DATA = 0x0;
pub const IOCPKT_DOSTOP = 0x20;
pub const IOCPKT_FLUSHREAD = 0x1;
pub const IOCPKT_FLUSHWRITE = 0x2;
pub const IOCPKT_IOCTL = 0x40;
pub const IOCPKT_NOSTOP = 0x10;
pub const IOCPKT_START = 0x8;
pub const IOCPKT_STOP = 0x4;
pub const IOCPTMGET = 0x40287446;
pub const IOCPTSNAME = 0x40287448;
pub const IOCRCVFRAME = 0x80087445;
pub const IOCREMOTE = 0x80047469;
pub const IOCSBRK = 0x2000747b;
pub const IOCSCTTY = 0x20007461;
pub const IOCSDTR = 0x20007479;
pub const IOCSETA = 0x802c7414;
pub const IOCSETAF = 0x802c7416;
pub const IOCSETAW = 0x802c7415;
pub const IOCSETD = 0x8004741b;
pub const IOCSFLAGS = 0x8004745c;
pub const IOCSIG = 0x2000745f;
pub const IOCSLINED = 0x80207443;
pub const IOCSPGRP = 0x80047476;
pub const IOCSQSIZE = 0x80047480;
pub const IOCSSIZE = 0x80087467;
pub const IOCSTART = 0x2000746e;
pub const IOCSTAT = 0x80047465;
pub const IOCSTI = 0x80017472;
pub const IOCSTOP = 0x2000746f;
pub const IOCSWINSZ = 0x80087467;
pub const IOCUCNTL = 0x80047466;
pub const IOCXMTFRAME = 0x80087444;
};
// BSD Authentication
pub const auth_item_t = c_int;
pub const AUTHV = struct {
pub const ALL: auth_item_t = 0;
pub const CHALLENGE: auth_item_t = 1;
pub const CLASS: auth_item_t = 2;
pub const NAME: auth_item_t = 3;
pub const SERVICE: auth_item_t = 4;
pub const STYLE: auth_item_t = 5;
pub const INTERACTIVE: auth_item_t = 6;
};
pub const BI = struct {
pub const AUTH = "authorize"; // Accepted authentication
pub const REJECT = "reject"; // Rejected authentication
pub const CHALLENGE = "reject challenge"; // Reject with a challenge
pub const SILENT = "reject silent"; // Reject silently
pub const REMOVE = "remove"; // remove file on error
pub const ROOTOKAY = "authorize root"; // root authenticated
pub const SECURE = "authorize secure"; // okay on non-secure line
pub const SETENV = "setenv"; // set environment variable
pub const UNSETENV = "unsetenv"; // unset environment variable
pub const VALUE = "value"; // set local variable
pub const EXPIRED = "reject expired"; // account expired
pub const PWEXPIRED = "reject pwexpired"; // password expired
pub const FDPASS = "fd"; // child is passing an fd
};
pub const AUTH = struct {
pub const OKAY: c_int = 0x01; // user authenticated
pub const ROOTOKAY: c_int = 0x02; // authenticated as root
pub const SECURE: c_int = 0x04; // secure login
pub const SILENT: c_int = 0x08; // silent rejection
pub const CHALLENGE: c_int = 0x10; // a challenge was given
pub const EXPIRED: c_int = 0x20; // account expired
pub const PWEXPIRED: c_int = 0x40; // password expired
pub const ALLOW: c_int = (OKAY | ROOTOKAY | SECURE);
};
// Term
pub const V = struct {
pub const EOF = 0; // ICANON
pub const EOL = 1; // ICANON
pub const EOL2 = 2; // ICANON
pub const ERASE = 3; // ICANON
pub const WERASE = 4; // ICANON
pub const KILL = 5; // ICANON
pub const REPRINT = 6; // ICANON
// 7 spare 1
pub const INTR = 8; // ISIG
pub const QUIT = 9; // ISIG
pub const SUSP = 10; // ISIG
pub const DSUSP = 11; // ISIG
pub const START = 12; // IXON, IXOFF
pub const STOP = 13; // IXON, IXOFF
pub const LNEXT = 14; // IEXTEN
pub const DISCARD = 15; // IEXTEN
pub const MIN = 16; // !ICANON
pub const TIME = 17; // !ICANON
pub const STATUS = 18; // ICANON
// 19 spare 2
};
pub const tcflag_t = c_uint;
pub const speed_t = c_uint;
pub const cc_t = u8;
pub const NCCS = 20;
// Input flags - software input processing
pub const IGNBRK: tcflag_t = 0x00000001; // ignore BREAK condition
pub const BRKINT: tcflag_t = 0x00000002; // map BREAK to SIGINT
pub const IGNPAR: tcflag_t = 0x00000004; // ignore (discard) parity errors
pub const PARMRK: tcflag_t = 0x00000008; // mark parity and framing errors
pub const INPCK: tcflag_t = 0x00000010; // enable checking of parity errors
pub const ISTRIP: tcflag_t = 0x00000020; // strip 8th bit off chars
pub const INLCR: tcflag_t = 0x00000040; // map NL into CR
pub const IGNCR: tcflag_t = 0x00000080; // ignore CR
pub const ICRNL: tcflag_t = 0x00000100; // map CR to NL (ala CRMOD)
pub const IXON: tcflag_t = 0x00000200; // enable output flow control
pub const IXOFF: tcflag_t = 0x00000400; // enable input flow control
pub const IXANY: tcflag_t = 0x00000800; // any char will restart after stop
pub const IUCLC: tcflag_t = 0x00001000; // translate upper to lower case
pub const IMAXBEL: tcflag_t = 0x00002000; // ring bell on input queue full
// Output flags - software output processing
pub const OPOST: tcflag_t = 0x00000001; // enable following output processing
pub const ONLCR: tcflag_t = 0x00000002; // map NL to CR-NL (ala CRMOD)
pub const OXTABS: tcflag_t = 0x00000004; // expand tabs to spaces
pub const ONOEOT: tcflag_t = 0x00000008; // discard EOT's (^D) on output
pub const OCRNL: tcflag_t = 0x00000010; // map CR to NL
pub const OLCUC: tcflag_t = 0x00000020; // translate lower case to upper case
pub const ONOCR: tcflag_t = 0x00000040; // No CR output at column 0
pub const ONLRET: tcflag_t = 0x00000080; // NL performs the CR function
// Control flags - hardware control of terminal
pub const CIGNORE: tcflag_t = 0x00000001; // ignore control flags
pub const CSIZE: tcflag_t = 0x00000300; // character size mask
pub const CS5: tcflag_t = 0x00000000; // 5 bits (pseudo)
pub const CS6: tcflag_t = 0x00000100; // 6 bits
pub const CS7: tcflag_t = 0x00000200; // 7 bits
pub const CS8: tcflag_t = 0x00000300; // 8 bits
pub const CSTOPB: tcflag_t = 0x00000400; // send 2 stop bits
pub const CREAD: tcflag_t = 0x00000800; // enable receiver
pub const PARENB: tcflag_t = 0x00001000; // parity enable
pub const PARODD: tcflag_t = 0x00002000; // odd parity, else even
pub const HUPCL: tcflag_t = 0x00004000; // hang up on last close
pub const CLOCAL: tcflag_t = 0x00008000; // ignore modem status lines
pub const CRTSCTS: tcflag_t = 0x00010000; // RTS/CTS full-duplex flow control
pub const CRTS_IFLOW: tcflag_t = CRTSCTS; // XXX compat
pub const CCTS_OFLOW: tcflag_t = CRTSCTS; // XXX compat
pub const MDMBUF: tcflag_t = 0x00100000; // DTR/DCD hardware flow control
pub const CHWFLOW: tcflag_t = (MDMBUF | CRTSCTS); // all types of hw flow control
pub const termios = extern struct {
iflag: tcflag_t, // input flags
oflag: tcflag_t, // output flags
cflag: tcflag_t, // control flags
lflag: tcflag_t, // local flags
cc: [NCCS]cc_t, // control chars
ispeed: c_int, // input speed
ospeed: c_int, // output speed
};
// Commands passed to tcsetattr() for setting the termios structure.
pub const TCSA = struct {
pub const NOW = 0; // make change immediate
pub const DRAIN = 1; // drain output, then change
pub const FLUSH = 2; // drain output, flush input
pub const SOFT = 0x10; // flag - don't alter h.w. state
};
// Standard speeds
pub const B0 = 0;
pub const B50 = 50;
pub const B75 = 75;
pub const B110 = 110;
pub const B134 = 134;
pub const B150 = 150;
pub const B200 = 200;
pub const B300 = 300;
pub const B600 = 600;
pub const B1200 = 1200;
pub const B1800 = 1800;
pub const B2400 = 2400;
pub const B4800 = 4800;
pub const B9600 = 9600;
pub const B19200 = 19200;
pub const B38400 = 38400;
pub const B7200 = 7200;
pub const B14400 = 14400;
pub const B28800 = 28800;
pub const B57600 = 57600;
pub const B76800 = 76800;
pub const B115200 = 115200;
pub const B230400 = 230400;
pub const EXTA = 19200;
pub const EXTB = 38400;
pub const TCIFLUSH = 1;
pub const TCOFLUSH = 2;
pub const TCIOFLUSH = 3;
pub const TCOOFF = 1;
pub const TCOON = 2;
pub const TCIOFF = 3;
pub const TCION = 4;
pub const winsize = extern struct {
ws_row: c_ushort,
ws_col: c_ushort,
ws_xpixel: c_ushort,
ws_ypixel: c_ushort,
};
const NSIG = 33;
pub const SIG = struct {
pub const DFL = @intToPtr(?Sigaction.handler_fn, 0);
pub const IGN = @intToPtr(?Sigaction.handler_fn, 1);
pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize));
pub const CATCH = @intToPtr(?Sigaction.handler_fn, 2);
pub const HOLD = @intToPtr(?Sigaction.handler_fn, 3);
pub const HUP = 1;
pub const INT = 2;
pub const QUIT = 3;
pub const ILL = 4;
pub const TRAP = 5;
pub const ABRT = 6;
pub const IOT = ABRT;
pub const EMT = 7;
pub const FPE = 8;
pub const KILL = 9;