-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathc.zig
10320 lines (9851 loc) · 312 KB
/
c.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");
const builtin = @import("builtin");
const c = @This();
const maxInt = std.math.maxInt;
const assert = std.debug.assert;
const page_size = std.heap.page_size_min;
const native_abi = builtin.abi;
const native_arch = builtin.cpu.arch;
const native_os = builtin.os.tag;
const linux = std.os.linux;
const emscripten = std.os.emscripten;
const wasi = std.os.wasi;
const windows = std.os.windows;
const ws2_32 = std.os.windows.ws2_32;
const darwin = @import("c/darwin.zig");
const freebsd = @import("c/freebsd.zig");
const solaris = @import("c/solaris.zig");
const netbsd = @import("c/netbsd.zig");
const dragonfly = @import("c/dragonfly.zig");
const haiku = @import("c/haiku.zig");
const openbsd = @import("c/openbsd.zig");
// These constants are shared among all operating systems even when not linking
// libc.
pub const iovec = std.posix.iovec;
pub const iovec_const = std.posix.iovec_const;
pub const LOCK = std.posix.LOCK;
pub const winsize = std.posix.winsize;
/// The value of the link editor defined symbol _MH_EXECUTE_SYM is the address
/// of the mach header in a Mach-O executable file type. It does not appear in
/// any file type other than a MH_EXECUTE file type. The type of the symbol is
/// absolute as the header is not part of any section.
/// This symbol is populated when linking the system's libc, which is guaranteed
/// on this operating system. However when building object files or libraries,
/// the system libc won't be linked until the final executable. So we
/// export a weak symbol here, to be overridden by the real one.
pub extern var _mh_execute_header: mach_hdr;
var dummy_execute_header: mach_hdr = undefined;
comptime {
if (native_os.isDarwin()) {
@export(&dummy_execute_header, .{ .name = "_mh_execute_header", .linkage = .weak });
}
}
/// * If not linking libc, returns `false`.
/// * If linking musl libc, returns `true`.
/// * If linking GNU libc (glibc), returns `true` if the target version is greater than or equal to
/// `version`.
/// * If linking Android libc (bionic), returns `true` if the target API level is greater than or
/// equal to `version.major`, ignoring other components.
/// * If linking a libc other than these, returns `false`.
pub inline fn versionCheck(comptime version: std.SemanticVersion) bool {
return comptime blk: {
if (!builtin.link_libc) break :blk false;
if (native_abi.isMusl()) break :blk true;
if (builtin.target.isGnuLibC()) {
const ver = builtin.os.versionRange().gnuLibCVersion().?;
break :blk switch (ver.order(version)) {
.gt, .eq => true,
.lt => false,
};
} else if (builtin.abi.isAndroid()) {
break :blk builtin.os.version_range.linux.android >= version.major;
} else {
break :blk false;
}
};
}
pub const ino_t = switch (native_os) {
.linux => linux.ino_t,
.emscripten => emscripten.ino_t,
.wasi => wasi.inode_t,
.windows => windows.LARGE_INTEGER,
.haiku => i64,
else => u64,
};
pub const off_t = switch (native_os) {
.linux => linux.off_t,
.emscripten => emscripten.off_t,
else => i64,
};
pub const timespec = switch (native_os) {
.linux => linux.timespec,
.emscripten => emscripten.timespec,
.wasi => extern struct {
sec: time_t,
nsec: isize,
pub fn fromTimestamp(tm: wasi.timestamp_t) timespec {
const sec: wasi.timestamp_t = tm / 1_000_000_000;
const nsec = tm - sec * 1_000_000_000;
return .{
.sec = @as(time_t, @intCast(sec)),
.nsec = @as(isize, @intCast(nsec)),
};
}
pub fn toTimestamp(ts: timespec) wasi.timestamp_t {
return @as(wasi.timestamp_t, @intCast(ts.sec * 1_000_000_000)) +
@as(wasi.timestamp_t, @intCast(ts.nsec));
}
},
.windows => extern struct {
sec: time_t,
nsec: c_long,
},
.dragonfly, .freebsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
sec: isize,
nsec: isize,
},
.netbsd, .solaris, .illumos => extern struct {
sec: i64,
nsec: isize,
},
.openbsd, .haiku => extern struct {
sec: time_t,
nsec: isize,
},
else => void,
};
pub const dev_t = switch (native_os) {
.linux => linux.dev_t,
.emscripten => emscripten.dev_t,
.wasi => wasi.device_t,
.openbsd, .haiku, .solaris, .illumos, .macos, .ios, .tvos, .watchos, .visionos => i32,
.netbsd, .freebsd => u64,
else => void,
};
pub const mode_t = switch (native_os) {
.linux => linux.mode_t,
.emscripten => emscripten.mode_t,
.openbsd, .haiku, .netbsd, .solaris, .illumos, .wasi, .windows => u32,
.freebsd, .macos, .ios, .tvos, .watchos, .visionos, .dragonfly => u16,
else => u0,
};
pub const nlink_t = switch (native_os) {
.linux => linux.nlink_t,
.emscripten => emscripten.nlink_t,
.wasi => c_ulonglong,
.freebsd => u64,
.openbsd, .netbsd, .solaris, .illumos => u32,
.haiku => i32,
else => void,
};
pub const uid_t = switch (native_os) {
.linux => linux.uid_t,
.emscripten => emscripten.uid_t,
else => u32,
};
pub const gid_t = switch (native_os) {
.linux => linux.gid_t,
.emscripten => emscripten.gid_t,
else => u32,
};
pub const blksize_t = switch (native_os) {
.linux => linux.blksize_t,
.emscripten => emscripten.blksize_t,
.wasi => c_long,
else => i32,
};
pub const passwd = switch (native_os) {
.linux => extern struct {
name: ?[*:0]const u8, // username
passwd: ?[*:0]const u8, // user password
uid: uid_t, // user ID
gid: gid_t, // group ID
gecos: ?[*:0]const u8, // user information
dir: ?[*:0]const u8, // home directory
shell: ?[*:0]const u8, // shell program
},
.netbsd, .openbsd, .macos => extern struct {
name: ?[*:0]const u8, // user name
passwd: ?[*:0]const u8, // encrypted password
uid: uid_t, // user uid
gid: gid_t, // user gid
change: time_t, // password change time
class: ?[*:0]const u8, // user access class
gecos: ?[*:0]const u8, // Honeywell login info
dir: ?[*:0]const u8, // home directory
shell: ?[*:0]const u8, // default shell
expire: time_t, // account expiration
},
else => void,
};
pub const blkcnt_t = switch (native_os) {
.linux => linux.blkcnt_t,
.emscripten => emscripten.blkcnt_t,
.wasi => c_longlong,
else => i64,
};
pub const fd_t = switch (native_os) {
.linux => linux.fd_t,
.wasi => wasi.fd_t,
.windows => windows.HANDLE,
else => i32,
};
pub const ARCH = switch (native_os) {
.linux => linux.ARCH,
else => void,
};
// For use with posix.timerfd_create()
// Actually, the parameter for the timerfd_create() function is an integer,
// which means that the developer has to figure out which value is appropriate.
// To make this easier and, above all, safer, because an incorrect value leads
// to a panic, an enum is introduced which only allows the values
// that actually work.
pub const TIMERFD_CLOCK = timerfd_clockid_t;
pub const timerfd_clockid_t = switch (native_os) {
.freebsd => enum(u32) {
REALTIME = 0,
MONOTONIC = 4,
_,
},
.linux => linux.timerfd_clockid_t,
else => clockid_t,
};
pub const CLOCK = clockid_t;
pub const clockid_t = switch (native_os) {
.linux, .emscripten => linux.clockid_t,
.wasi => wasi.clockid_t,
.macos, .ios, .tvos, .watchos, .visionos => enum(u32) {
REALTIME = 0,
MONOTONIC = 6,
MONOTONIC_RAW = 4,
MONOTONIC_RAW_APPROX = 5,
UPTIME_RAW = 8,
UPTIME_RAW_APPROX = 9,
PROCESS_CPUTIME_ID = 12,
THREAD_CPUTIME_ID = 16,
_,
},
.haiku => enum(i32) {
/// system-wide monotonic clock (aka system time)
MONOTONIC = 0,
/// system-wide real time clock
REALTIME = -1,
/// clock measuring the used CPU time of the current process
PROCESS_CPUTIME_ID = -2,
/// clock measuring the used CPU time of the current thread
THREAD_CPUTIME_ID = -3,
},
.freebsd => enum(u32) {
REALTIME = 0,
VIRTUAL = 1,
PROF = 2,
MONOTONIC = 4,
UPTIME = 5,
UPTIME_PRECISE = 7,
UPTIME_FAST = 8,
REALTIME_PRECISE = 9,
REALTIME_FAST = 10,
MONOTONIC_PRECISE = 11,
MONOTONIC_FAST = 12,
SECOND = 13,
THREAD_CPUTIME_ID = 14,
PROCESS_CPUTIME_ID = 15,
},
.solaris, .illumos => enum(u32) {
VIRTUAL = 1,
THREAD_CPUTIME_ID = 2,
REALTIME = 3,
MONOTONIC = 4,
PROCESS_CPUTIME_ID = 5,
},
.netbsd => enum(u32) {
REALTIME = 0,
VIRTUAL = 1,
PROF = 2,
MONOTONIC = 3,
THREAD_CPUTIME_ID = 0x20000000,
PROCESS_CPUTIME_ID = 0x40000000,
},
.dragonfly => enum(u32) {
REALTIME = 0,
VIRTUAL = 1,
PROF = 2,
MONOTONIC = 4,
UPTIME = 5,
UPTIME_PRECISE = 7,
UPTIME_FAST = 8,
REALTIME_PRECISE = 9,
REALTIME_FAST = 10,
MONOTONIC_PRECISE = 11,
MONOTONIC_FAST = 12,
SECOND = 13,
THREAD_CPUTIME_ID = 14,
PROCESS_CPUTIME_ID = 15,
},
.openbsd => enum(u32) {
REALTIME = 0,
PROCESS_CPUTIME_ID = 2,
MONOTONIC = 3,
THREAD_CPUTIME_ID = 4,
},
else => void,
};
pub const CPU_COUNT = switch (native_os) {
.linux => linux.CPU_COUNT,
.emscripten => emscripten.CPU_COUNT,
else => void,
};
pub const E = switch (native_os) {
.linux => linux.E,
.emscripten => emscripten.E,
.wasi => wasi.errno_t,
.windows => enum(u16) {
/// No error occurred.
SUCCESS = 0,
PERM = 1,
NOENT = 2,
SRCH = 3,
INTR = 4,
IO = 5,
NXIO = 6,
@"2BIG" = 7,
NOEXEC = 8,
BADF = 9,
CHILD = 10,
AGAIN = 11,
NOMEM = 12,
ACCES = 13,
FAULT = 14,
BUSY = 16,
EXIST = 17,
XDEV = 18,
NODEV = 19,
NOTDIR = 20,
ISDIR = 21,
NFILE = 23,
MFILE = 24,
NOTTY = 25,
FBIG = 27,
NOSPC = 28,
SPIPE = 29,
ROFS = 30,
MLINK = 31,
PIPE = 32,
DOM = 33,
/// Also means `DEADLOCK`.
DEADLK = 36,
NAMETOOLONG = 38,
NOLCK = 39,
NOSYS = 40,
NOTEMPTY = 41,
INVAL = 22,
RANGE = 34,
ILSEQ = 42,
// POSIX Supplement
ADDRINUSE = 100,
ADDRNOTAVAIL = 101,
AFNOSUPPORT = 102,
ALREADY = 103,
BADMSG = 104,
CANCELED = 105,
CONNABORTED = 106,
CONNREFUSED = 107,
CONNRESET = 108,
DESTADDRREQ = 109,
HOSTUNREACH = 110,
IDRM = 111,
INPROGRESS = 112,
ISCONN = 113,
LOOP = 114,
MSGSIZE = 115,
NETDOWN = 116,
NETRESET = 117,
NETUNREACH = 118,
NOBUFS = 119,
NODATA = 120,
NOLINK = 121,
NOMSG = 122,
NOPROTOOPT = 123,
NOSR = 124,
NOSTR = 125,
NOTCONN = 126,
NOTRECOVERABLE = 127,
NOTSOCK = 128,
NOTSUP = 129,
OPNOTSUPP = 130,
OTHER = 131,
OVERFLOW = 132,
OWNERDEAD = 133,
PROTO = 134,
PROTONOSUPPORT = 135,
PROTOTYPE = 136,
TIME = 137,
TIMEDOUT = 138,
TXTBSY = 139,
WOULDBLOCK = 140,
DQUOT = 10069,
_,
},
.macos, .ios, .tvos, .watchos, .visionos => darwin.E,
.freebsd => freebsd.E,
.solaris, .illumos => enum(u16) {
/// No error occurred.
SUCCESS = 0,
/// Not super-user
PERM = 1,
/// No such file or directory
NOENT = 2,
/// No such process
SRCH = 3,
/// interrupted system call
INTR = 4,
/// I/O error
IO = 5,
/// No such device or address
NXIO = 6,
/// Arg list too long
@"2BIG" = 7,
/// Exec format error
NOEXEC = 8,
/// Bad file number
BADF = 9,
/// No children
CHILD = 10,
/// Resource temporarily unavailable.
/// also: WOULDBLOCK: Operation would block.
AGAIN = 11,
/// Not enough core
NOMEM = 12,
/// Permission denied
ACCES = 13,
/// Bad address
FAULT = 14,
/// Block device required
NOTBLK = 15,
/// Mount device busy
BUSY = 16,
/// File exists
EXIST = 17,
/// Cross-device link
XDEV = 18,
/// No such device
NODEV = 19,
/// Not a directory
NOTDIR = 20,
/// Is a directory
ISDIR = 21,
/// Invalid argument
INVAL = 22,
/// File table overflow
NFILE = 23,
/// Too many open files
MFILE = 24,
/// Inappropriate ioctl for device
NOTTY = 25,
/// Text file busy
TXTBSY = 26,
/// File too large
FBIG = 27,
/// No space left on device
NOSPC = 28,
/// Illegal seek
SPIPE = 29,
/// Read only file system
ROFS = 30,
/// Too many links
MLINK = 31,
/// Broken pipe
PIPE = 32,
/// Math arg out of domain of func
DOM = 33,
/// Math result not representable
RANGE = 34,
/// No message of desired type
NOMSG = 35,
/// Identifier removed
IDRM = 36,
/// Channel number out of range
CHRNG = 37,
/// Level 2 not synchronized
L2NSYNC = 38,
/// Level 3 halted
L3HLT = 39,
/// Level 3 reset
L3RST = 40,
/// Link number out of range
LNRNG = 41,
/// Protocol driver not attached
UNATCH = 42,
/// No CSI structure available
NOCSI = 43,
/// Level 2 halted
L2HLT = 44,
/// Deadlock condition.
DEADLK = 45,
/// No record locks available.
NOLCK = 46,
/// Operation canceled
CANCELED = 47,
/// Operation not supported
NOTSUP = 48,
// Filesystem Quotas
/// Disc quota exceeded
DQUOT = 49,
// Convergent Error Returns
/// invalid exchange
BADE = 50,
/// invalid request descriptor
BADR = 51,
/// exchange full
XFULL = 52,
/// no anode
NOANO = 53,
/// invalid request code
BADRQC = 54,
/// invalid slot
BADSLT = 55,
/// file locking deadlock error
DEADLOCK = 56,
/// bad font file fmt
BFONT = 57,
// Interprocess Robust Locks
/// process died with the lock
OWNERDEAD = 58,
/// lock is not recoverable
NOTRECOVERABLE = 59,
/// locked lock was unmapped
LOCKUNMAPPED = 72,
/// Facility is not active
NOTACTIVE = 73,
/// multihop attempted
MULTIHOP = 74,
/// trying to read unreadable message
BADMSG = 77,
/// path name is too long
NAMETOOLONG = 78,
/// value too large to be stored in data type
OVERFLOW = 79,
/// given log. name not unique
NOTUNIQ = 80,
/// f.d. invalid for this operation
BADFD = 81,
/// Remote address changed
REMCHG = 82,
// Stream Problems
/// Device not a stream
NOSTR = 60,
/// no data (for no delay io)
NODATA = 61,
/// timer expired
TIME = 62,
/// out of streams resources
NOSR = 63,
/// Machine is not on the network
NONET = 64,
/// Package not installed
NOPKG = 65,
/// The object is remote
REMOTE = 66,
/// the link has been severed
NOLINK = 67,
/// advertise error
ADV = 68,
/// srmount error
SRMNT = 69,
/// Communication error on send
COMM = 70,
/// Protocol error
PROTO = 71,
// Shared Library Problems
/// Can't access a needed shared lib.
LIBACC = 83,
/// Accessing a corrupted shared lib.
LIBBAD = 84,
/// .lib section in a.out corrupted.
LIBSCN = 85,
/// Attempting to link in too many libs.
LIBMAX = 86,
/// Attempting to exec a shared library.
LIBEXEC = 87,
/// Illegal byte sequence.
ILSEQ = 88,
/// Unsupported file system operation
NOSYS = 89,
/// Symbolic link loop
LOOP = 90,
/// Restartable system call
RESTART = 91,
/// if pipe/FIFO, don't sleep in stream head
STRPIPE = 92,
/// directory not empty
NOTEMPTY = 93,
/// Too many users (for UFS)
USERS = 94,
// BSD Networking Software
// Argument Errors
/// Socket operation on non-socket
NOTSOCK = 95,
/// Destination address required
DESTADDRREQ = 96,
/// Message too long
MSGSIZE = 97,
/// Protocol wrong type for socket
PROTOTYPE = 98,
/// Protocol not available
NOPROTOOPT = 99,
/// Protocol not supported
PROTONOSUPPORT = 120,
/// Socket type not supported
SOCKTNOSUPPORT = 121,
/// Operation not supported on socket
OPNOTSUPP = 122,
/// Protocol family not supported
PFNOSUPPORT = 123,
/// Address family not supported by
AFNOSUPPORT = 124,
/// Address already in use
ADDRINUSE = 125,
/// Can't assign requested address
ADDRNOTAVAIL = 126,
// Operational Errors
/// Network is down
NETDOWN = 127,
/// Network is unreachable
NETUNREACH = 128,
/// Network dropped connection because
NETRESET = 129,
/// Software caused connection abort
CONNABORTED = 130,
/// Connection reset by peer
CONNRESET = 131,
/// No buffer space available
NOBUFS = 132,
/// Socket is already connected
ISCONN = 133,
/// Socket is not connected
NOTCONN = 134,
/// Can't send after socket shutdown
SHUTDOWN = 143,
/// Too many references: can't splice
TOOMANYREFS = 144,
/// Connection timed out
TIMEDOUT = 145,
/// Connection refused
CONNREFUSED = 146,
/// Host is down
HOSTDOWN = 147,
/// No route to host
HOSTUNREACH = 148,
/// operation already in progress
ALREADY = 149,
/// operation now in progress
INPROGRESS = 150,
// SUN Network File System
/// Stale NFS file handle
STALE = 151,
_,
},
.netbsd => netbsd.E,
.dragonfly => dragonfly.E,
.haiku => haiku.E,
.openbsd => openbsd.E,
else => void,
};
pub const Elf_Symndx = switch (native_os) {
.linux => linux.Elf_Symndx,
else => void,
};
/// Command flags for fcntl(2).
pub const F = switch (native_os) {
.linux => linux.F,
.emscripten => emscripten.F,
.wasi => struct {
// Match `F_*` constants from lib/libc/include/wasm-wasi-musl/__header_fcntl.h
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
},
.macos, .ios, .tvos, .watchos, .visionos => struct {
/// duplicate file descriptor
pub const DUPFD = 0;
/// get file descriptor flags
pub const GETFD = 1;
/// set file descriptor flags
pub const SETFD = 2;
/// get file status flags
pub const GETFL = 3;
/// set file status flags
pub const SETFL = 4;
/// get SIGIO/SIGURG proc/pgrp
pub const GETOWN = 5;
/// set SIGIO/SIGURG proc/pgrp
pub const SETOWN = 6;
/// get record locking information
pub const GETLK = 7;
/// set record locking information
pub const SETLK = 8;
/// F.SETLK; wait if blocked
pub const SETLKW = 9;
/// F.SETLK; wait if blocked, return on timeout
pub const SETLKWTIMEOUT = 10;
pub const FLUSH_DATA = 40;
/// Used for regression test
pub const CHKCLEAN = 41;
/// Preallocate storage
pub const PREALLOCATE = 42;
/// Truncate a file without zeroing space
pub const SETSIZE = 43;
/// Issue an advisory read async with no copy to user
pub const RDADVISE = 44;
/// turn read ahead off/on for this fd
pub const RDAHEAD = 45;
/// turn data caching off/on for this fd
pub const NOCACHE = 48;
/// file offset to device offset
pub const LOG2PHYS = 49;
/// return the full path of the fd
pub const GETPATH = 50;
/// fsync + ask the drive to flush to the media
pub const FULLFSYNC = 51;
/// find which component (if any) is a package
pub const PATHPKG_CHECK = 52;
/// "freeze" all fs operations
pub const FREEZE_FS = 53;
/// "thaw" all fs operations
pub const THAW_FS = 54;
/// turn data caching off/on (globally) for this file
pub const GLOBAL_NOCACHE = 55;
/// add detached signatures
pub const ADDSIGS = 59;
/// add signature from same file (used by dyld for shared libs)
pub const ADDFILESIGS = 61;
/// used in conjunction with F.NOCACHE to indicate that DIRECT, synchronous writes
/// should not be used (i.e. its ok to temporarily create cached pages)
pub const NODIRECT = 62;
/// Get the protection class of a file from the EA, returns int
pub const GETPROTECTIONCLASS = 63;
/// Set the protection class of a file for the EA, requires int
pub const SETPROTECTIONCLASS = 64;
/// file offset to device offset, extended
pub const LOG2PHYS_EXT = 65;
/// get record locking information, per-process
pub const GETLKPID = 66;
/// Mark the file as being the backing store for another filesystem
pub const SETBACKINGSTORE = 70;
/// return the full path of the FD, but error in specific mtmd circumstances
pub const GETPATH_MTMINFO = 71;
/// Returns the code directory, with associated hashes, to the caller
pub const GETCODEDIR = 72;
/// No SIGPIPE generated on EPIPE
pub const SETNOSIGPIPE = 73;
/// Status of SIGPIPE for this fd
pub const GETNOSIGPIPE = 74;
/// For some cases, we need to rewrap the key for AKS/MKB
pub const TRANSCODEKEY = 75;
/// file being written to a by single writer... if throttling enabled, writes
/// may be broken into smaller chunks with throttling in between
pub const SINGLE_WRITER = 76;
/// Get the protection version number for this filesystem
pub const GETPROTECTIONLEVEL = 77;
/// Add detached code signatures (used by dyld for shared libs)
pub const FINDSIGS = 78;
/// Add signature from same file, only if it is signed by Apple (used by dyld for simulator)
pub const ADDFILESIGS_FOR_DYLD_SIM = 83;
/// fsync + issue barrier to drive
pub const BARRIERFSYNC = 85;
/// Add signature from same file, return end offset in structure on success
pub const ADDFILESIGS_RETURN = 97;
/// Check if Library Validation allows this Mach-O file to be mapped into the calling process
pub const CHECK_LV = 98;
/// Deallocate a range of the file
pub const PUNCHHOLE = 99;
/// Trim an active file
pub const TRIM_ACTIVE_FILE = 100;
/// mark the dup with FD_CLOEXEC
pub const DUPFD_CLOEXEC = 67;
/// shared or read lock
pub const RDLCK = 1;
/// unlock
pub const UNLCK = 2;
/// exclusive or write lock
pub const WRLCK = 3;
},
.freebsd => struct {
/// Duplicate file descriptor.
pub const DUPFD = 0;
/// Get file descriptor flags.
pub const GETFD = 1;
/// Set file descriptor flags.
pub const SETFD = 2;
/// Get file status flags.
pub const GETFL = 3;
/// Set file status flags.
pub const SETFL = 4;
/// Get SIGIO/SIGURG proc/pgrrp.
pub const GETOWN = 5;
/// Set SIGIO/SIGURG proc/pgrrp.
pub const SETOWN = 6;
/// Get record locking information.
pub const GETLK = 11;
/// Set record locking information.
pub const SETLK = 12;
/// Set record locking information and wait if blocked.
pub const SETLKW = 13;
/// Debugging support for remote locks.
pub const SETLK_REMOTE = 14;
/// Read ahead.
pub const READAHEAD = 15;
/// DUPFD with FD_CLOEXEC set.
pub const DUPFD_CLOEXEC = 17;
/// DUP2FD with FD_CLOEXEC set.
pub const DUP2FD_CLOEXEC = 18;
pub const ADD_SEALS = 19;
pub const GET_SEALS = 20;
/// Return `kinfo_file` for a file descriptor.
pub const KINFO = 22;
// Seals (ADD_SEALS, GET_SEALS)
/// Prevent adding sealings.
pub const SEAL_SEAL = 0x0001;
/// May not shrink
pub const SEAL_SHRINK = 0x0002;
/// May not grow.
pub const SEAL_GROW = 0x0004;
/// May not write.
pub const SEAL_WRITE = 0x0008;
// Record locking flags (GETLK, SETLK, SETLKW).
/// Shared or read lock.
pub const RDLCK = 1;
/// Unlock.
pub const UNLCK = 2;
/// Exclusive or write lock.
pub const WRLCK = 3;
/// Purge locks for a given system ID.
pub const UNLCKSYS = 4;
/// Cancel an async lock request.
pub const CANCEL = 5;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
},
.solaris, .illumos => struct {
/// Unlock a previously locked region
pub const ULOCK = 0;
/// Lock a region for exclusive use
pub const LOCK = 1;
/// Test and lock a region for exclusive use
pub const TLOCK = 2;
/// Test a region for other processes locks
pub const TEST = 3;
/// Duplicate fildes
pub const DUPFD = 0;
/// Get fildes flags
pub const GETFD = 1;
/// Set fildes flags
pub const SETFD = 2;
/// Get file flags
pub const GETFL = 3;
/// Get file flags including open-only flags
pub const GETXFL = 45;
/// Set file flags
pub const SETFL = 4;
/// Unused
pub const CHKFL = 8;
/// Duplicate fildes at third arg
pub const DUP2FD = 9;
/// Like DUP2FD with O_CLOEXEC set EINVAL is fildes matches arg1
pub const DUP2FD_CLOEXEC = 36;
/// Like DUPFD with O_CLOEXEC set
pub const DUPFD_CLOEXEC = 37;
/// Is the file desc. a stream ?
pub const ISSTREAM = 13;
/// Turn on private access to file
pub const PRIV = 15;
/// Turn off private access to file
pub const NPRIV = 16;
/// UFS quota call
pub const QUOTACTL = 17;
/// Get number of BLKSIZE blocks allocated
pub const BLOCKS = 18;
/// Get optimal I/O block size
pub const BLKSIZE = 19;
/// Get owner (socket emulation)
pub const GETOWN = 23;
/// Set owner (socket emulation)
pub const SETOWN = 24;
/// Object reuse revoke access to file desc.
pub const REVOKE = 25;
/// Does vp have NFS locks private to lock manager
pub const HASREMOTELOCKS = 26;
/// Set file lock
pub const SETLK = 6;
/// Set file lock and wait
pub const SETLKW = 7;
/// Allocate file space
pub const ALLOCSP = 10;
/// Free file space
pub const FREESP = 11;
/// Get file lock
pub const GETLK = 14;
/// Get file lock owned by file
pub const OFD_GETLK = 47;
/// Set file lock owned by file
pub const OFD_SETLK = 48;
/// Set file lock owned by file and wait
pub const OFD_SETLKW = 49;
/// Set a file share reservation
pub const SHARE = 40;
/// Remove a file share reservation
pub const UNSHARE = 41;
/// Create Poison FD
pub const BADFD = 46;
/// Read lock
pub const RDLCK = 1;
/// Write lock
pub const WRLCK = 2;
/// Remove lock(s)
pub const UNLCK = 3;
/// remove remote locks for a given system
pub const UNLKSYS = 4;
// f_access values
/// Read-only share access
pub const RDACC = 0x1;
/// Write-only share access
pub const WRACC = 0x2;
/// Read-Write share access
pub const RWACC = 0x3;
// f_deny values
/// Don't deny others access
pub const NODNY = 0x0;
/// Deny others read share access
pub const RDDNY = 0x1;
/// Deny others write share access
pub const WRDNY = 0x2;
/// Deny others read or write share access
pub const RWDNY = 0x3;
/// private flag: Deny delete share access
pub const RMDNY = 0x4;
},
.netbsd => 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 CLOSEM = 10;
pub const MAXFD = 11;
pub const DUPFD_CLOEXEC = 12;
pub const GETNOSIGPIPE = 13;
pub const SETNOSIGPIPE = 14;
pub const GETPATH = 15;
pub const RDLCK = 1;
pub const WRLCK = 3;
pub const UNLCK = 2;
},
.dragonfly => struct {
pub const ULOCK = 0;