Repository navigation
Expand file tree
/
Copy pathLibrarySpec.txt
More file actions
1872 lines (1769 loc) · 77.2 KB
/
Copy pathLibrarySpec.txt
File metadata and controls
1872 lines (1769 loc) · 77.2 KB
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
# LibrarySpec.txt - the declarative C library table (RFC 0030 section 8)
#
# Part of WeaveC, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# CMake embeds this file in the Core library (lib/Core/CMakeLists.txt) and
# core::LibrarySpec parses it on first use. unittests/Core/LibrarySpecTest.cpp
# checks every entry against an independent, hand-written expectation table,
# so an entry changed here must be changed there too.
#
# LEXICAL STRUCTURE
# '#' starts a comment. A line whose last character before any comment is
# '\' continues on the next line. Each logical line holds one directive or
# one entry, ended by ';'. The file is ASCII.
#
# DIRECTIVES
# header NAME; NAME, relative to its include directory ("stdio.h",
# "sys/ioctl.h"), is a C library, POSIX or platform header
# (section 5.2), and the entries that follow are declared in
# it. "DIR/*" names every header under DIR; an entry cannot
# follow a pattern directly.
# builtins; The entries that follow are compiler builtins, declared by
# no header (__builtin_expect, __builtin_object_size).
#
# A system header is a C library, POSIX or platform header when it is
# under the toolchain's resource directory, when it belongs to a Darwin SDK
# (every SDK header counts), or when it is named in a header directive.
# Third-party libraries installed as system headers (sqlite3.h, libcap's
# sys/capability.h, a JSON library's header) are not listed: their
# functions are unknown
# callees (section 5.1).
#
# ENTRIES (section 8.2; '+' marks an extension of the RFC's grammar)
# entry ::= NAME '(' params ')' '->' result { clause } ';'
# params ::= [ param { ',' param } ] [ ',' '...' ]
# param ::= 'int' | 'other' | 'fn' { ':' fflag } | access { ':' pflag }
# fflag ::= callback | 'null-ok'+
# access ::= 'r' | 'w' | 'rw' | 'none'
# pflag ::= 'bytes(' term ')' | 'count(' term ')'+ | 'str' | 'null-ok'
# | 'null-if-zero(' term ')' | 'release(' FAMILY ')'
# | 'range(' term ')'+
# | 'realloc(' FAMILY ')' | 'retain(' STATE ')' | 'escape'
# | 'init(' FAMILY ')'+ | 'fini(' FAMILY ')'+
# | 'out(' value ')'+ | callback+
# callback ::= 'sync(' [ INT { ',' INT } ] ')' | 'entry(' [ INT ] ')'
# | 'at-exit'
# result ::= 'void' | 'int' [ ':value(' term ')' ]+ | 'noreturn' | value
# value ::= rkind { ':' rflag }
# rkind ::= 'fresh(' FAMILY ')' | 'static(' STATE ')' | 'arg(' INT ')'
# | 'interior(' INT ')' | 'interior-state(' STATE ')' | 'ptr'
# rflag ::= 'extent(' term ')' | 'null-on-failure' | 'nonnull'
# | 'null-ok' | 'zero-init' | 'no-zero-init' | 'str'+
# | 'replaces'+ | 'or-fresh(' FAMILY ')'+
# | 'or-static(' STATE ')'+ | 'offset(' term ')'+
# | 'zero-filled'+
# clause ::= 'disjoint(' INT ',' INT ',' term ')'
# | 'copies(' INT ',' INT ',' term ')'+
# | 'fills(' INT ',' term ',' term ')'+
# | 'writes-str(' INT [ ',' term ] ')'+
# | 'invalidates(' STATE ')' | 'reads(' STATE ')' | 'exits'
# | 'returns-twice' | 'wide'+ | 'printf(' INT ',' INT ')'
# | 'scanf(' INT ',' INT ')' | 'chk(' NAME ':' INT { ',' INT } ')'
# | 'wrapper(' NAME ')'+
# term ::= INT | 'a' N | 'strlen(a' N ')' | 'fmtlen(a' N ')' | MACRO+
# | term '*' term | term '+' term | term '-' INT
# | term '/' INT+
# | 'min(' term ',' term ')' | '(' term ')'+
#
# PARAMETERS
# int, other, fn an integer; any other non-pointer (floating, struct,
# va_list); a function pointer.
# r, w, rw, none the call reads, writes, reads and writes, or does not
# access the bytes behind the pointer. Without bytes, count
# or str the pointer needs one element of its pointee type.
# bytes(t) it needs t accessible bytes.
# count(t)+ it needs t accessible elements of its pointee type
# (wchar_t for the wide functions).
# str its pointee holds a string terminated within its object
# (by a zero wchar_t for wide strings); needs r or rw.
# null-ok null is allowed. null-if-zero(t): allowed when t is zero
# (section 8.3). Otherwise null is forbidden.
# release(F) the call releases the pointer, of release family F.
# range(t)+ (with release) the call releases the t bytes from the
# pointer (munmap): the object only when they cover it
# from its start, possibly otherwise, and the pointer may
# point anywhere in it (RFC 0034 section 6.3).
# realloc(F) as realloc: released on a non-null result; on a null
# result kept, or released when the result's extent (the
# requested size) is zero; kept when there is no extent.
# retain(S) the pointer is kept in hidden state slot S; releasing it
# while kept makes the next reads(S) a use after free.
# escape the library keeps the pointer where no entry follows it
# (setvbuf's buffer, pthread_create's argument).
# init(F)+ the object behind the pointer acquires a resource of
# family F (regcomp, glob). fini(F)+: that resource ends.
# The object's own storage is not the resource: it stays
# valid, fini on a local is no invalid release, and init
# after fini is no use after release.
# out(v)+ the pointer points to a pointer slot, and the call stores
# v there (asprintf's buffer, strtol's end pointer). The
# nullability of v describes the stored value; with
# null-on-failure nothing usable is stored when the call
# reports failure.
# sync(i, ...) the function is called zero or more times before the call
# returns, its k-th pointer parameter pointing into call
# argument i_k (qsort: sync(0,0)); sync() when it only
# receives the library's own storage (nftw).
# entry(i) the function becomes an entry point (a thread, a signal
# handler) that receives argument i; entry() when it
# receives nothing from the call (signal).
# at-exit the function runs after the main flow has ended.
# On a pointer parameter, a callback flag describes the
# function pointers stored in the pointee (sigaction).
#
# RESULTS
# void, int no result; any non-pointer result.
# noreturn the call does not return.
# fresh(F) a new resource of family F: 'free' is the heap, 'stack'
# the calling frame (alloca); other families are named
# after their releaser (fclose, closedir, freeaddrinfo).
# static(S) a borrow of hidden state slot S, a global place <S>.
# arg(N) argument N itself.
# interior(N) a pointer into argument N's object. When argument N is
# null, the result points into the object that the entry's
# out(interior(N)) slot held before the call (strtok_r),
# or into static storage when there is no such slot
# (basename(NULL) is ".").
# interior-state(S) a pointer into the value slot S retains (strtok).
# ptr a pointer of unknown provenance.
# extent(t) (fresh, static) the value has t accessible bytes.
# nonnull, null-on-failure, null-ok
# never null (for arg: exactly the argument); null exactly
# when the call fails; possibly null. Defaults: fresh
# null-on-failure; static and arg nonnull; interior,
# interior-state and ptr null-ok.
# zero-init, no-zero-init
# (section 11) whether a fresh value may be lowered to a
# zeroing wrapper; every fresh(free) value carries one. A
# str value without an extent was written up to its
# terminator.
# str+ the value points to a terminated string.
# replaces+ (out values) the slot's previous value is consumed as by
# realloc of the same family before the new one is stored.
# or-fresh(F)+, or-static(S)+
# (arg results) when argument N is null the result is
# fresh(F) (realpath, getcwd) or static(S) (tmpnam).
# value(t)+ (int results) the result equals t (strlen: strlen(a0)).
# offset(t)+ (interior results) the result is t elements past the
# start of argument N (stpcpy: strlen(a1)).
# zero-filled+ (fresh results) the library sets the whole extent to
# zero (calloc), whatever section 11 lowering does.
#
# CLAUSES
# disjoint(a,b,t) the first t bytes behind arguments a and b do not overlap.
# copies(d,s,t)+ the call copies the first t bytes of argument s to
# argument d (memcpy; strncpy copies min(a2,strlen(a1)+1)).
# fills(d,v,t)+ the call sets the first t bytes of argument d to v
# (memset: fills(0,a1,a2); bzero: fills(0,0,a1)).
# writes-str(d[,t])+
# on success argument d holds a string of t characters,
# or of unknown length without t (fgets). Terms use the
# values before the call; a negative t writes nothing
# (snprintf with a zero size).
# invalidates(S) possibly ends every borrow of slot S (section 8.2),
# before the call's own result borrows S (getpwnam reuses
# and may reallocate its static buffer).
# reads(S) the call reads the values slot S retains.
# exits the call ends the process: leaks are not reported there
# (section 8.4). Needs noreturn.
# returns-twice setjmp-like (section 5.4).
# wide+ the row's strings end in a zero wchar_t, and count(t)
# and strlen(aN) count wchar_t elements (wcslen).
# printf(f,v), scanf(f,v)
# argument f is the format; v is the first variadic
# argument, or the va_list parameter of a v- function.
# wrapper(N)+ RFC 0035 section 2.5: weavec-cc replaces the call with
# the runtime's checked __weavec_rt_N, which takes the
# call's arguments and its site (first when the call is
# variadic, last otherwise) and checks what the call reads
# and writes as it runs: bytes no term states before the
# call (a format's output), or fewer than the terms state
# (memchr reads only up to the byte it finds).
# chk(A: i0, i1, ...)
# A is an alias of the entry (a fortified form): its k-th
# argument is the entry's argument i_k, or dropped (-1).
# For a variadic entry, alias arguments after the list
# continue from the last index. Every entry also answers to
# __builtin_NAME. The macOS SDK (secure/_string.h,
# secure/_stdio.h) and glibc (bits/*_fortified.h,
# bits/stdio2.h) spell the same builtins; glibc also calls
# the __NAME_chk functions directly.
#
# TERMS
# aN the value of argument N.
# strlen(aN) the length of argument N's string, in elements. Under
# min(t, e) a strlen(aN) in e is bounded by t, as
# strnlen(aN, t), and needs no terminator within t
# elements: min(a2,strlen(a1)+1) is what strncpy reads.
# fmtlen(aN) the length of the output of the format at argument N; a
# requirement, never a check term (section 8.1).
# MACRO+ the value of that macro in the calling unit (BUFSIZ);
# unknown where it is not defined. No unit defines
# __WEAVEC_UNBOUNDED: a requirement that uses it is never
# proven or checked (gets).
# t / N+ t divided by the positive integer N, rounded down
# (RFC 0033 section 3: select's fd_set words).
# Terms are mathematical integers; '*' and '/' bind tighter than '+' and
# '-'.
#
# PORTABILITY (RFC 0033 section 3)
# A row states what every supported C library (Darwin's libSystem, glibc)
# does with an argument, not what a standard permits it to do: where they
# differ, the row takes the more permissive behaviour. Null is allowed if
# any of them accepts it, and a count of zero allows null if any of them
# then reads nothing. A row that requires more than a library does is a
# false stop. A library accepts null when its manual (or the standard it
# implements, or a nullability annotation in its headers) says what the
# call does with null: an error such as EINVAL, a default, or nothing done.
# An undocumented test in one library for a call that crashes in another
# (glibc's EINVAL for a null printf format) is not acceptance, and neither
# is a system call's EFAULT. An extent is what the call reads or writes,
# or, for a buffer whose size is an argument, that size (the fortified
# forms of both libraries enforce it).
#
# OVERLOADS AND ABSENCES
# A name may have several entries when their signatures (parameter classes,
# arity, variadic, pointer result) differ; the engine uses the one that
# accepts the declaration (glibc and BSD qsort_r, GNU and XSI strerror_r).
# Arguments in '...' positions are borrowed for the call, and read or
# written as the format says for printf and scanf entries.
# Deliberately absent (section 5.2 applies): ioctl (its third argument's
# layout depends on the request) and syscall. The buffers behind iovec and
# msghdr arrays are nested in the argument, where no term can name them.
#============================================================================
# The header list (section 5.2). The entry groups below repeat their header.
# The list is consulted only for system headers under the SDK or sysroot.
#============================================================================
# ISO C (C23)
header assert.h;
header complex.h;
header ctype.h;
header errno.h;
header fenv.h;
header float.h;
header inttypes.h;
header iso646.h;
header limits.h;
header locale.h;
header math.h;
header setjmp.h;
header signal.h;
header stdalign.h;
header stdarg.h;
header stdatomic.h;
header stdbit.h;
header stdbool.h;
header stdckdint.h;
header stddef.h;
header stdint.h;
header stdio.h;
header stdlib.h;
header stdnoreturn.h;
header string.h;
header tgmath.h;
header threads.h;
header time.h;
header uchar.h;
header wchar.h;
header wctype.h;
# POSIX.1-2024 (and headers POSIX.1-2008 had)
header aio.h;
header arpa/inet.h;
header cpio.h;
header devctl.h;
header dirent.h;
header dlfcn.h;
header endian.h;
header fcntl.h;
header fmtmsg.h;
header fnmatch.h;
header ftw.h;
header glob.h;
header grp.h;
header iconv.h;
header langinfo.h;
header libgen.h;
header libintl.h;
header monetary.h;
header mqueue.h;
header ndbm.h;
header net/if.h;
header netdb.h;
header netinet/in.h;
header netinet/tcp.h;
header nl_types.h;
header poll.h;
header pthread.h;
header pwd.h;
header regex.h;
header sched.h;
header search.h;
header semaphore.h;
header spawn.h;
header strings.h;
header stropts.h;
header sys/ipc.h;
header sys/mman.h;
header sys/msg.h;
header sys/resource.h;
header sys/select.h;
header sys/sem.h;
header sys/shm.h;
header sys/socket.h;
header sys/stat.h;
header sys/statvfs.h;
header sys/time.h;
header sys/times.h;
header sys/types.h;
header sys/uio.h;
header sys/un.h;
header sys/utsname.h;
header sys/wait.h;
header syslog.h;
header tar.h;
header termios.h;
header trace.h;
header ulimit.h;
header unistd.h;
header utime.h;
header utmpx.h;
header wordexp.h;
# glibc, musl and BSD headers outside POSIX
header alloca.h;
header argp.h;
header byteswap.h;
header crypt.h;
header elf.h;
header err.h;
header error.h;
header execinfo.h;
header features.h;
header fts.h;
header getopt.h;
header ifaddrs.h;
header lastlog.h;
header link.h;
header malloc.h;
header mntent.h;
header obstack.h;
header paths.h;
header printf.h;
header pty.h;
header resolv.h;
header sgtty.h;
header shadow.h;
header stdc-predef.h;
header sysexits.h;
header ucontext.h;
header utmp.h;
header values.h;
header xlocale.h;
header arpa/ftp.h;
header arpa/nameser.h;
header arpa/nameser_compat.h;
header arpa/telnet.h;
header arpa/tftp.h;
header sys/acct.h;
header sys/auxv.h;
header sys/cdefs.h;
header sys/dir.h;
header sys/epoll.h;
header sys/errno.h;
header sys/event.h;
header sys/eventfd.h;
header sys/fanotify.h;
header sys/fcntl.h;
header sys/file.h;
header sys/filio.h;
header sys/fsuid.h;
header sys/inotify.h;
header sys/io.h;
header sys/ioccom.h;
header sys/ioctl.h;
header sys/kd.h;
header sys/klog.h;
header sys/mount.h;
header sys/mtio.h;
header sys/param.h;
header sys/personality.h;
header sys/pidfd.h;
header sys/poll.h;
header sys/prctl.h;
header sys/procfs.h;
header sys/ptrace.h;
header sys/queue.h;
header sys/quota.h;
header sys/random.h;
header sys/reboot.h;
header sys/rseq.h;
header sys/sendfile.h;
header sys/signal.h;
header sys/signalfd.h;
header sys/single_threaded.h;
header sys/sockio.h;
header sys/statfs.h;
header sys/swap.h;
header sys/syscall.h;
header sys/sysctl.h;
header sys/sysinfo.h;
header sys/syslog.h;
header sys/sysmacros.h;
header sys/timeb.h;
header sys/timerfd.h;
header sys/timex.h;
header sys/ttycom.h;
header sys/ttydefaults.h;
header sys/ucontext.h;
header sys/unistd.h;
header sys/user.h;
header sys/vfs.h;
header sys/vt.h;
header sys/xattr.h;
# Implementation directories: every header under them.
header asm/*;
header asm-generic/*;
header bits/*;
header gnu/*;
header linux/*;
header net/*;
header netinet/*;
header netpacket/*;
header scsi/*;
#============================================================================
# Heap allocation and release
#============================================================================
header stdlib.h;
malloc (int) -> fresh(free):extent(a0):null-on-failure:zero-init;
calloc (int, int) -> \
fresh(free):extent(a0*a1):null-on-failure:zero-init:zero-filled;
realloc (rw:null-ok:realloc(free), int) -> \
fresh(free):extent(a1):null-on-failure:zero-init;
reallocarray (rw:null-ok:realloc(free), int, int) -> \
fresh(free):extent(a1*a2):null-on-failure:zero-init;
# BSD: the argument is freed on failure as well.
reallocf (rw:null-ok:release(free), int) -> \
fresh(free):extent(a1):null-on-failure:no-zero-init;
aligned_alloc (int, int) -> fresh(free):extent(a1):null-on-failure:zero-init;
posix_memalign (w:out(fresh(free):extent(a2):null-on-failure:zero-init), \
int, int) -> int;
valloc (int) -> fresh(free):extent(a0):null-on-failure:zero-init;
free (none:null-ok:release(free)) -> void;
free_sized (none:null-ok:release(free), int) -> void;
free_aligned_sized (none:null-ok:release(free), int, int) -> void;
# glibc: allocates the result of realpath(path, NULL) in one call.
canonicalize_file_name (r:str:null-ok) -> \
fresh(free):null-on-failure:zero-init:str;
realpath (r:str:null-ok, w:null-ok:bytes(PATH_MAX)) -> \
arg(1):null-on-failure:or-fresh(free):zero-init:str \
chk(__realpath_chk: 0,1,-1);
header malloc.h;
memalign (int, int) -> fresh(free):extent(a1):null-on-failure:zero-init;
pvalloc (int) -> fresh(free):extent(a0):null-on-failure:zero-init;
malloc_usable_size (none:null-ok) -> int;
header malloc/malloc.h;
malloc_size (none:null-ok) -> int;
malloc_good_size (int) -> int;
header alloca.h;
alloca (int) -> fresh(stack):extent(a0):nonnull:zero-init;
header string.h;
strdup (r:str) -> \
fresh(free):extent(strlen(a0)+1):null-on-failure:zero-init:str;
strndup (r:bytes(min(a1,strlen(a0)+1)):null-if-zero(a1), int) -> \
fresh(free):extent(min(a1,strlen(a0))+1):null-on-failure:zero-init:str;
header wchar.h;
wcsdup (r:str) -> fresh(free):null-on-failure:zero-init:str wide;
header stdio.h;
asprintf (w:out(fresh(free):extent(fmtlen(a1)+1):null-on-failure:zero-init:str), \
r:str, ...) -> int printf(1,2) chk(__asprintf_chk: 0,-1,1,2);
vasprintf (w:out(fresh(free):extent(fmtlen(a1)+1):null-on-failure:zero-init:str), \
r:str, other) -> int printf(1,2) chk(__vasprintf_chk: 0,-1,1,2);
# The buffer is reallocated in place of the old one, and stays allocated
# after a failed read: it is freed on every path.
getline (rw:null-ok:out(fresh(free):null-ok:zero-init:str:replaces), \
rw:null-ok, rw) -> int;
getdelim (rw:null-ok:out(fresh(free):null-ok:zero-init:str:replaces), \
rw:null-ok, int, rw) -> int;
tempnam (r:str:null-ok, r:str:null-ok) -> \
fresh(free):null-on-failure:zero-init:str reads(environ);
header unistd.h;
# getcwd(NULL, n) allocates (glibc, BSD, macOS).
getcwd (w:null-ok:bytes(a1), int) -> \
arg(0):null-on-failure:or-fresh(free):zero-init:str \
chk(__getcwd_chk: 0,1,-1);
get_current_dir_name () -> fresh(free):null-on-failure:zero-init:str \
reads(environ);
header execinfo.h;
backtrace (w:count(a1), int) -> int;
backtrace_symbols (r:count(a1), int) -> fresh(free):null-on-failure:no-zero-init;
backtrace_symbols_fd (r:count(a1), int, int) -> void;
#============================================================================
# <string.h>, <strings.h>
#============================================================================
header string.h;
memcpy (w:bytes(a2):null-if-zero(a2), r:bytes(a2):null-if-zero(a2), int) \
-> arg(0) disjoint(0,1,a2) copies(0,1,a2) \
chk(__builtin___memcpy_chk: 0,1,2,-1) chk(__memcpy_chk: 0,1,2,-1);
memmove (w:bytes(a2):null-if-zero(a2), r:bytes(a2):null-if-zero(a2), int) \
-> arg(0) copies(0,1,a2) \
chk(__builtin___memmove_chk: 0,1,2,-1) chk(__memmove_chk: 0,1,2,-1);
memset (w:bytes(a2):null-if-zero(a2), int, int) -> arg(0) fills(0,a1,a2) \
chk(__builtin___memset_chk: 0,1,2,-1) chk(__memset_chk: 0,1,2,-1);
memset_explicit (w:bytes(a2):null-if-zero(a2), int, int) -> arg(0) \
fills(0,a1,a2);
memcmp (r:bytes(a2):null-if-zero(a2), r:bytes(a2):null-if-zero(a2), int) \
-> int;
# C11: memchr stops at the first match, so a NUL ends what memchr(s, 0, n)
# reads; a byte other than NUL found earlier is not described.
memchr (r:bytes(min(a2,strlen(a0)+1)):null-if-zero(a2), int, int) -> \
interior(0):null-ok wrapper(memchr);
memrchr (r:bytes(a2):null-if-zero(a2), int, int) -> interior(0):null-ok;
# GNU: searches without a bound for a byte the caller promises is there.
rawmemchr (r:bytes(__WEAVEC_UNBOUNDED), int) -> interior(0):nonnull;
memmem (r:bytes(a1):null-if-zero(a1), int, r:bytes(a3):null-if-zero(a3), int) \
-> interior(0):null-ok;
mempcpy (w:bytes(a2):null-if-zero(a2), r:bytes(a2):null-if-zero(a2), int) \
-> interior(0):offset(a2):nonnull \
disjoint(0,1,a2) copies(0,1,a2) \
chk(__builtin___mempcpy_chk: 0,1,2,-1) chk(__mempcpy_chk: 0,1,2,-1);
# memccpy stops after the byte c; a NUL-terminated source bounds the read for
# the common c == 0 use, and a source without c or NUL is read for n bytes.
memccpy (w:bytes(min(a3,strlen(a1)+1)):null-if-zero(a3), \
r:bytes(min(a3,strlen(a1)+1)):null-if-zero(a3), int, int) -> \
interior(0):null-ok disjoint(0,1,min(a3,strlen(a1)+1)) \
chk(__builtin___memccpy_chk: 0,1,2,3,-1);
strcpy (w:bytes(strlen(a1)+1), r:str) -> arg(0) \
disjoint(0,1,strlen(a1)+1) writes-str(0,strlen(a1)) \
wrapper(strcpy) \
chk(__builtin___strcpy_chk: 0,1,-1) chk(__strcpy_chk: 0,1,-1);
strncpy (w:bytes(a2):null-if-zero(a2), \
r:bytes(min(a2,strlen(a1)+1)):null-if-zero(a2), int) -> arg(0) \
disjoint(0,1,min(a2,strlen(a1)+1)) copies(0,1,min(a2,strlen(a1)+1)) \
chk(__builtin___strncpy_chk: 0,1,2,-1) chk(__strncpy_chk: 0,1,2,-1);
stpcpy (w:bytes(strlen(a1)+1), r:str) -> \
interior(0):offset(strlen(a1)):nonnull \
disjoint(0,1,strlen(a1)+1) writes-str(0,strlen(a1)) \
wrapper(stpcpy) \
chk(__builtin___stpcpy_chk: 0,1,-1) chk(__stpcpy_chk: 0,1,-1);
stpncpy (w:bytes(a2):null-if-zero(a2), \
r:bytes(min(a2,strlen(a1)+1)):null-if-zero(a2), int) \
-> interior(0):offset(min(a2,strlen(a1))):nonnull \
disjoint(0,1,min(a2,strlen(a1)+1)) copies(0,1,min(a2,strlen(a1)+1)) \
chk(__builtin___stpncpy_chk: 0,1,2,-1) chk(__stpncpy_chk: 0,1,2,-1);
strcat (rw:bytes(strlen(a0)+strlen(a1)+1):str, r:str) -> arg(0) \
disjoint(0,1,strlen(a0)+strlen(a1)+1) \
writes-str(0,strlen(a0)+strlen(a1)) wrapper(strcat) \
chk(__builtin___strcat_chk: 0,1,-1) chk(__strcat_chk: 0,1,-1);
strncat (rw:bytes(strlen(a0)+min(a2,strlen(a1))+1):str, \
r:bytes(min(a2,strlen(a1)+1)):null-if-zero(a2), int) -> arg(0) \
disjoint(0,1,strlen(a0)+min(a2,strlen(a1))+1) \
writes-str(0,strlen(a0)+min(a2,strlen(a1))) \
chk(__builtin___strncat_chk: 0,1,2,-1) chk(__strncat_chk: 0,1,2,-1);
# BSD, glibc 2.38: the whole source is read to compute the result.
strlcpy (w:bytes(a2):null-if-zero(a2), r:str, int) -> int:value(strlen(a1)) \
disjoint(0,1,min(a2,strlen(a1)+1)) writes-str(0,min(a2-1,strlen(a1))) \
chk(__builtin___strlcpy_chk: 0,1,2,-1) chk(__strlcpy_chk: 0,1,2,-1);
strlcat (rw:bytes(a2):null-if-zero(a2), r:str, int) -> int \
chk(__builtin___strlcat_chk: 0,1,2,-1) chk(__strlcat_chk: 0,1,2,-1);
strlen (r:str) -> int:value(strlen(a0));
strnlen (r:bytes(min(a1,strlen(a0)+1)):null-if-zero(a1), int) -> int:value(min(a1,strlen(a0)));
strcmp (r:str, r:str) -> int wrapper(strcmp);
strncmp (r:bytes(min(a2,strlen(a0)+1)):null-if-zero(a2), \
r:bytes(min(a2,strlen(a1)+1)):null-if-zero(a2), int) -> int \
wrapper(strncmp);
strcoll (r:str, r:str) -> int;
strcoll_l (r:str, r:str, none:null-ok) -> int;
strxfrm (w:bytes(a2):null-if-zero(a2), r:str, int) -> int;
strxfrm_l (w:bytes(a2):null-if-zero(a2), r:str, int, none:null-ok) -> int;
strverscmp (r:str, r:str) -> int;
strchr (r:str, int) -> interior(0):null-ok wrapper(strchr);
strrchr (r:str, int) -> interior(0):null-ok;
strchrnul (r:str, int) -> interior(0):nonnull;
strstr (r:str, r:str) -> interior(0):null-ok;
strcasestr (r:str, r:str) -> interior(0):null-ok;
strpbrk (r:str, r:str) -> interior(0):null-ok;
strspn (r:str, r:str) -> int;
strcspn (r:str, r:str) -> int;
strtok (rw:str:null-ok:retain(strtok), r:str) -> \
interior-state(strtok):null-ok reads(strtok);
strtok_r (rw:str:null-ok, r:str, rw:out(interior(0):null-ok)) -> \
interior(0):null-ok;
strsep (rw, r:str) -> ptr:null-ok:str;
strerror (int) -> static(strerror):nonnull:str;
strerror_l (int, none) -> static(strerror):nonnull:str;
# GNU: the message is in buf or in static storage. XSI: an int result.
strerror_r (int, w:bytes(a2):null-if-zero(a2), int) -> ptr:nonnull:str;
strerror_r (int, w:bytes(a2):null-if-zero(a2), int) -> int;
strsignal (int) -> static(strsignal):null-ok:str;
explicit_bzero (w:bytes(a1):null-if-zero(a1), int) -> void fills(0,0,a1) \
chk(__explicit_bzero_chk: 0,1,-1);
# macOS: a null s is EINVAL, and min(smax, n) bytes are set.
memset_s (w:bytes(min(a1,a3)):null-ok, int, int, int) -> int \
fills(0,a2,min(a1,a3));
header strings.h;
bzero (w:bytes(a1):null-if-zero(a1), int) -> void fills(0,0,a1);
bcopy (r:bytes(a2):null-if-zero(a2), w:bytes(a2):null-if-zero(a2), int) -> void \
copies(1,0,a2);
bcmp (r:bytes(a2):null-if-zero(a2), r:bytes(a2):null-if-zero(a2), int) -> int;
index (r:str, int) -> interior(0):null-ok;
rindex (r:str, int) -> interior(0):null-ok;
strcasecmp (r:str, r:str) -> int wrapper(strcasecmp);
strncasecmp (r:bytes(min(a2,strlen(a0)+1)):null-if-zero(a2), \
r:bytes(min(a2,strlen(a1)+1)):null-if-zero(a2), int) -> int \
wrapper(strncasecmp);
strcasecmp_l (r:str, r:str, none:null-ok) -> int;
strncasecmp_l (r:bytes(min(a2,strlen(a0)+1)):null-if-zero(a2), \
r:bytes(min(a2,strlen(a1)+1)):null-if-zero(a2), int, none:null-ok) -> int;
ffs (int) -> int;
ffsl (int) -> int;
ffsll (int) -> int;
#============================================================================
# <stdio.h>
#============================================================================
header stdio.h;
fopen (r:str, r:str) -> fresh(fclose):null-on-failure;
fdopen (int, r:str) -> fresh(fclose):null-on-failure;
# On failure the old stream is closed as well; that path is not modelled.
freopen (r:str:null-ok, r:str, rw) -> arg(2):null-on-failure;
tmpfile () -> fresh(fclose):null-on-failure;
fmemopen (w:bytes(a1):null-ok:escape, int, r:str) \
-> fresh(fclose):null-on-failure;
open_memstream ( \
w:null-ok:escape:out(fresh(free):null-on-failure:no-zero-init), \
w:null-ok:escape) -> fresh(fclose):null-on-failure;
fclose (rw:release(fclose)) -> int;
popen (r:str, r:str) -> fresh(pclose):null-on-failure reads(environ);
pclose (rw:release(pclose)) -> int;
fflush (rw:null-ok) -> int;
fpurge (rw) -> int;
setvbuf (rw, w:bytes(a3):null-ok:escape, int, int) -> int;
setbuf (rw, w:bytes(BUFSIZ):null-ok:escape) -> void;
setbuffer (rw, w:bytes(a2):null-ok:escape, int) -> void;
setlinebuf (rw) -> void;
fileno (r) -> int;
fileno_unlocked (r) -> int;
feof (r) -> int;
ferror (r) -> int;
clearerr (rw) -> void;
fseek (rw, int, int) -> int;
fseeko (rw, int, int) -> int;
ftell (r) -> int;
ftello (r) -> int;
rewind (rw) -> void;
fgetpos (rw, w) -> int;
fsetpos (rw, r) -> int;
flockfile (rw) -> void;
funlockfile (rw) -> void;
ftrylockfile (rw) -> int;
fgetc (rw) -> int;
getc (rw) -> int;
getc_unlocked (rw) -> int;
getchar () -> int;
getchar_unlocked () -> int;
ungetc (int, rw) -> int;
fputc (int, rw) -> int;
putc (int, rw) -> int;
putc_unlocked (int, rw) -> int;
putchar (int) -> int;
putchar_unlocked (int) -> int;
fgets (w:bytes(a1):null-if-zero(a1), int, rw) -> arg(0):null-ok writes-str(0) \
chk(__fgets_chk: 0,-1,1,2);
# gets has no bound: no unit defines the macro, so its requirement is never
# proven (C11 removed gets).
gets (w:bytes(__WEAVEC_UNBOUNDED)) -> arg(0):null-ok wrapper(gets) \
chk(__gets_chk: 0,-1);
# BSD: the line is in the stream's buffer, not terminated.
fgetln (rw, w) -> interior(0):null-ok;
fread (w:bytes(a1*a2):null-if-zero(a1*a2), int, int, rw) -> int chk(__fread_chk: 0,-1,1,2,3);
fread_unlocked (w:bytes(a1*a2):null-if-zero(a1*a2), int, int, rw) -> int \
chk(__fread_unlocked_chk: 0,-1,1,2,3);
fwrite (r:bytes(a1*a2):null-if-zero(a1*a2), int, int, rw) -> int;
fwrite_unlocked (r:bytes(a1*a2):null-if-zero(a1*a2), int, int, rw) -> int;
puts (r:str:null-ok) -> int;
fputs (r:str:null-ok, rw) -> int;
perror (r:str:null-ok) -> void;
printf (r:str, ...) -> int printf(0,1) \
chk(__builtin___printf_chk: -1,0,1) chk(__printf_chk: -1,0,1);
fprintf (rw, r:str, ...) -> int printf(1,2) \
chk(__builtin___fprintf_chk: 0,-1,1,2) chk(__fprintf_chk: 0,-1,1,2);
dprintf (int, r:str, ...) -> int printf(1,2) chk(__dprintf_chk: 0,-1,1,2);
sprintf (w:bytes(fmtlen(a1)+1), r:str, ...) -> int:value(fmtlen(a1)) \
writes-str(0,fmtlen(a1)) printf(1,2) wrapper(sprintf) \
chk(__builtin___sprintf_chk: 0,-1,-1,1,2) chk(__sprintf_chk: 0,-1,-1,1,2);
snprintf (w:bytes(a1):null-if-zero(a1), int, r:str, ...) \
-> int:value(fmtlen(a2)) writes-str(0,min(a1-1,fmtlen(a2))) printf(2,3) \
wrapper(snprintf) chk(__builtin___snprintf_chk: 0,1,-1,-1,2,3) \
chk(__snprintf_chk: 0,1,-1,-1,2,3);
vprintf (r:str, other) -> int printf(0,1) \
chk(__builtin___vprintf_chk: -1,0,1) chk(__vprintf_chk: -1,0,1);
vfprintf (rw, r:str, other) -> int printf(1,2) \
chk(__builtin___vfprintf_chk: 0,-1,1,2) chk(__vfprintf_chk: 0,-1,1,2);
vdprintf (int, r:str, other) -> int printf(1,2) chk(__vdprintf_chk: 0,-1,1,2);
vsprintf (w:bytes(fmtlen(a1)+1), r:str, other) -> int:value(fmtlen(a1)) \
writes-str(0,fmtlen(a1)) printf(1,2) wrapper(vsprintf) \
chk(__builtin___vsprintf_chk: 0,-1,-1,1,2) \
chk(__vsprintf_chk: 0,-1,-1,1,2);
vsnprintf (w:bytes(a1):null-if-zero(a1), int, r:str, other) \
-> int:value(fmtlen(a2)) writes-str(0,min(a1-1,fmtlen(a2))) printf(2,3) \
wrapper(vsnprintf) chk(__builtin___vsnprintf_chk: 0,1,-1,-1,2,3) \
chk(__vsnprintf_chk: 0,1,-1,-1,2,3);
# glibc renames the scanf family for C99 and C23 semantics.
scanf (r:str, ...) -> int scanf(0,1) wrapper(scanf) \
chk(__isoc99_scanf: 0,1) chk(__isoc23_scanf: 0,1);
fscanf (rw, r:str, ...) -> int scanf(1,2) wrapper(fscanf) \
chk(__isoc99_fscanf: 0,1,2) chk(__isoc23_fscanf: 0,1,2);
sscanf (r:str, r:str, ...) -> int scanf(1,2) wrapper(sscanf) \
chk(__isoc99_sscanf: 0,1,2) chk(__isoc23_sscanf: 0,1,2);
vscanf (r:str, other) -> int scanf(0,1) wrapper(vscanf) \
chk(__isoc99_vscanf: 0,1) chk(__isoc23_vscanf: 0,1);
vfscanf (rw, r:str, other) -> int scanf(1,2) wrapper(vfscanf) \
chk(__isoc99_vfscanf: 0,1,2) chk(__isoc23_vfscanf: 0,1,2);
vsscanf (r:str, r:str, other) -> int scanf(1,2) wrapper(vsscanf) \
chk(__isoc99_vsscanf: 0,1,2) chk(__isoc23_vsscanf: 0,1,2);
remove (r:str) -> int;
rename (r:str, r:str) -> int;
renameat (int, r:str, int, r:str) -> int;
tmpnam (w:null-ok:bytes(L_tmpnam)) -> \
arg(0):null-on-failure:or-static(tmpnam):str;
ctermid (w:null-ok:bytes(L_ctermid)) -> arg(0):or-static(ctermid):str;
#============================================================================
# <stdlib.h>, <inttypes.h>: conversions, environment, sorting, exit
#============================================================================
header stdlib.h;
atoi (r:str) -> int;
atol (r:str) -> int;
atoll (r:str) -> int;
atof (r:str) -> int;
# The end pointer points into the string; glibc renames the integer forms
# for C23 semantics.
strtol (r:str, w:null-ok:out(interior(0):nonnull), int) -> int \
chk(__isoc23_strtol: 0,1,2);
strtoll (r:str, w:null-ok:out(interior(0):nonnull), int) -> int \
chk(__isoc23_strtoll: 0,1,2);
strtoul (r:str, w:null-ok:out(interior(0):nonnull), int) -> int \
chk(__isoc23_strtoul: 0,1,2);
strtoull (r:str, w:null-ok:out(interior(0):nonnull), int) -> int \
chk(__isoc23_strtoull: 0,1,2);
strtod (r:str, w:null-ok:out(interior(0):nonnull)) -> int;
strtof (r:str, w:null-ok:out(interior(0):nonnull)) -> int;
strtold (r:str, w:null-ok:out(interior(0):nonnull)) -> int;
getenv (r:str:null-ok) -> static(environ):null-ok:str reads(environ);
secure_getenv (r:str) -> static(environ):null-ok:str reads(environ);
setenv (r:str:null-ok, r:str, int) -> int invalidates(environ) reads(environ);
unsetenv (r:str:null-ok) -> int invalidates(environ) reads(environ);
# The string itself becomes part of the environment.
putenv (r:str:null-ok:retain(environ)) -> int invalidates(environ) \
reads(environ);
clearenv () -> int invalidates(environ);
system (r:str:null-ok) -> int reads(environ);
qsort (rw:bytes(a1*a2):null-if-zero(a1*a2), int, int, fn:sync(0,0)) -> void;
# glibc (and C2y): compar(a, b, arg). BSD and macOS: compar(thunk, a, b).
qsort_r (rw:bytes(a1*a2):null-if-zero(a1*a2), int, int, fn:sync(0,0,4), \
none:null-ok) -> void;
qsort_r (rw:bytes(a1*a2):null-if-zero(a1*a2), int, int, none:null-ok, \
fn:sync(3,0,0)) -> void;
bsearch (none:null-ok, r:bytes(a2*a3):null-if-zero(a2*a3), int, int, \
fn:sync(0,1)) -> interior(1):null-ok;
exit (int) -> noreturn exits;
_Exit (int) -> noreturn exits;
quick_exit (int) -> noreturn exits;
abort () -> noreturn exits;
atexit (fn:at-exit) -> int;
at_quick_exit (fn:at-exit) -> int;
on_exit (fn:at-exit, none:null-ok:escape) -> int;
mblen (r:bytes(min(a1,strlen(a0)+1)):null-ok, int) -> int;
mbtowc (w:null-ok, r:bytes(min(a2,strlen(a1)+1)):null-ok, int) -> int;
wctomb (w:bytes(MB_CUR_MAX):null-ok, int) -> int chk(__wctomb_chk: 0,1,-1);
mbstowcs (w:count(a2):null-ok, r:str, int) -> int \
chk(__mbstowcs_chk: 0,1,2,-1);
wcstombs (w:bytes(a2):null-ok, r:str, int) -> int \
chk(__wcstombs_chk: 0,1,2,-1);
mkstemp (rw:str) -> int;
mkostemp (rw:str, int) -> int;
mkstemps (rw:str, int) -> int;
mkdtemp (rw:str) -> arg(0):null-on-failure;
mktemp (rw:str) -> arg(0);
rand () -> int;
srand (int) -> void;
rand_r (rw) -> int;
random () -> int;
srandom (int) -> void;
# The library keeps using the state array after the call.
initstate (int, w:bytes(a2):escape, int) -> ptr:null-ok;
setstate (rw:escape) -> ptr:null-ok;
drand48 () -> int;
erand48 (rw:count(3)) -> int;
lrand48 () -> int;
nrand48 (rw:count(3)) -> int;
mrand48 () -> int;
jrand48 (rw:count(3)) -> int;
srand48 (int) -> void;
seed48 (r:count(3)) -> static(seed48):nonnull;
lcong48 (r:count(7)) -> void;
arc4random () -> int;
arc4random_uniform (int) -> int;
arc4random_buf (w:bytes(a1), int) -> void;
getsubopt (rw, r, w:out(ptr:null-ok)) -> int;
a64l (r:str) -> int;
l64a (int) -> static(l64a):nonnull:str;
# At most three averages are stored.
getloadavg (w:count(min(a1,3)):null-if-zero(a1), int) -> int;
# BSD and macOS: the name set by setprogname is kept, not copied.
getprogname () -> interior-state(progname):nonnull:str reads(progname);
setprogname (r:str:retain(progname)) -> void;
ptsname (int) -> static(ptsname):null-on-failure:str;
ptsname_r (int, w:bytes(a2):null-ok, int) -> int;
posix_openpt (int) -> int;
grantpt (int) -> int;
unlockpt (int) -> int;
header inttypes.h;
strtoimax (r:str, w:null-ok:out(interior(0):nonnull), int) -> int \
chk(__isoc23_strtoimax: 0,1,2);
strtoumax (r:str, w:null-ok:out(interior(0):nonnull), int) -> int \
chk(__isoc23_strtoumax: 0,1,2);
#============================================================================
# <unistd.h>, <fcntl.h>, <sys/stat.h> and file-system relatives
#============================================================================
header unistd.h;
read (int, w:bytes(a2):null-if-zero(a2), int) -> int chk(__read_chk: 0,1,2,-1);
write (int, r:bytes(a2):null-if-zero(a2), int) -> int;
pread (int, w:bytes(a2):null-if-zero(a2), int, int) -> int \
chk(__pread_chk: 0,1,2,3,-1) chk(__pread64_chk: 0,1,2,3,-1);
pwrite (int, r:bytes(a2):null-if-zero(a2), int, int) -> int;
close (int) -> int;
pipe (w:count(2)) -> int;
pipe2 (w:count(2), int) -> int;
dup (int) -> int;
dup2 (int, int) -> int;
dup3 (int, int, int) -> int;
lseek (int, int, int) -> int;
access (r:str, int) -> int;
faccessat (int, r:str, int, int) -> int;
unlink (r:str) -> int;
unlinkat (int, r:str, int) -> int;
rmdir (r:str) -> int;
chdir (r:str) -> int;
fchdir (int) -> int;
getwd (w:bytes(PATH_MAX)) -> arg(0):null-on-failure;
readlink (r:str, w:bytes(a2):null-if-zero(a2), int) -> int \
chk(__readlink_chk: 0,1,2,-1);
readlinkat (int, r:str, w:bytes(a3):null-if-zero(a3), int) -> int \
chk(__readlinkat_chk: 0,1,2,3,-1);
symlink (r:str, r:str) -> int;
symlinkat (r:str, int, r:str) -> int;
link (r:str, r:str) -> int;
linkat (int, r:str, int, r:str, int) -> int;
chown (r:str, int, int) -> int;
fchown (int, int, int) -> int;
lchown (r:str, int, int) -> int;
fchownat (int, r:str, int, int, int) -> int;
truncate (r:str, int) -> int;
ftruncate (int, int) -> int;
fsync (int) -> int;
fdatasync (int) -> int;
sync () -> void;
isatty (int) -> int;
ttyname (int) -> static(ttyname):null-on-failure:str;
ttyname_r (int, w:bytes(a2):null-ok, int) -> int chk(__ttyname_r_chk: 0,1,2,-1);
gethostname (w:bytes(a1), int) -> int chk(__gethostname_chk: 0,1,-1);
sethostname (r:bytes(a1), int) -> int;
getdomainname (w:bytes(a1), int) -> int chk(__getdomainname_chk: 0,1,-1);
getlogin () -> static(getlogin):null-on-failure:str;
getlogin_r (w:bytes(a1), int) -> int chk(__getlogin_r_chk: 0,1,-1);
# GNU getopt permutes argv; optarg points into its strings.
getopt (int, rw:count(a0), r:str) -> int;
execv (r:str, r:null-ok) -> int reads(environ);
execve (r:str, r:null-ok, r:null-ok) -> int;
execvp (r:str, r:null-ok) -> int reads(environ);
execvpe (r:str, r:null-ok, r:null-ok) -> int reads(environ);
execl (r:str, r:str:null-ok, ...) -> int reads(environ);
execlp (r:str, r:str:null-ok, ...) -> int reads(environ);
execle (r:str, r:str:null-ok, ...) -> int;
fexecve (int, r:null-ok, r:null-ok) -> int;
fork () -> int;
vfork () -> int returns-twice;
_exit (int) -> noreturn exits;
alarm (int) -> int;
pause () -> int;
sleep (int) -> int;
usleep (int) -> int;
getpid () -> int;
getppid () -> int;
sysconf (int) -> int;
pathconf (r:str, int) -> int;
fpathconf (int, int) -> int;
confstr (int, w:bytes(a2):null-if-zero(a2), int) -> int \
chk(__confstr_chk: 0,1,2,-1);
chroot (r:str) -> int;
nice (int) -> int;
getentropy (w:bytes(a1):null-if-zero(a1), int) -> int;
getgroups (int, w:count(a0):null-if-zero(a0)) -> int \
chk(__getgroups_chk: 0,1,-1);
swab (r:bytes(a2):null-if-zero(a2), w:bytes(a2):null-if-zero(a2), int) -> void \
disjoint(0,1,a2);
header getopt.h;
getopt_long (int, rw:count(a0), r:str, r:null-ok, w:null-ok) -> int;
getopt_long_only (int, rw:count(a0), r:str, r:null-ok, w:null-ok) -> int;
header fcntl.h;
open (r:str, int, ...) -> int chk(__open_2: 0,1);
openat (int, r:str, int, ...) -> int chk(__openat_2: 0,1,2);
creat (r:str, int) -> int;
fcntl (int, int, ...) -> int;
posix_fadvise (int, int, int, int) -> int;
posix_fallocate (int, int, int) -> int;
header sys/stat.h;
stat (r:str, w) -> int;
fstat (int, w) -> int;
lstat (r:str, w) -> int;
fstatat (int, r:str, w, int) -> int;
chmod (r:str, int) -> int;
fchmod (int, int) -> int;
fchmodat (int, r:str, int, int) -> int;
mkdir (r:str, int) -> int;
mkdirat (int, r:str, int) -> int;
mkfifo (r:str, int) -> int;
mkfifoat (int, r:str, int) -> int;
mknod (r:str, int, int) -> int;
mknodat (int, r:str, int, int) -> int;
umask (int) -> int;
utimensat (int, r:str:null-ok, r:count(2):null-ok, int) -> int;
futimens (int, r:count(2):null-ok) -> int;
header sys/statvfs.h;
statvfs (r:str, w) -> int;
fstatvfs (int, w) -> int;
header sys/statfs.h;
statfs (r:str, w) -> int;
fstatfs (int, w) -> int;
header utime.h;
utime (r:str, r:null-ok) -> int;
header sys/time.h;
utimes (r:str, r:count(2):null-ok) -> int;
futimes (int, r:count(2):null-ok) -> int;
lutimes (r:str, r:count(2):null-ok) -> int;
gettimeofday (w:null-ok, w:null-ok) -> int;
settimeofday (r:null-ok, r:null-ok) -> int;
getitimer (int, w) -> int;
setitimer (int, r:null-ok, w:null-ok) -> int;
#============================================================================
# <dirent.h>, <time.h>, <sys/mman.h>, <dlfcn.h>
#============================================================================
header dirent.h;
opendir (r:str) -> fresh(closedir):null-on-failure;
fdopendir (int) -> fresh(closedir):null-on-failure;
closedir (rw:release(closedir)) -> int;
# The entry lives in the stream: closedir ends it.
readdir (rw) -> interior(0):null-ok;
readdir_r (rw, w, w:out(arg(1):null-ok)) -> int;
rewinddir (rw) -> void;
seekdir (rw, int) -> void;
telldir (r) -> int;
dirfd (r) -> int;
# The array and each entry in it are the caller's to free.
scandir (r:str, w:out(fresh(free):null-on-failure:no-zero-init), \
fn:null-ok:sync(), fn:null-ok:sync()) -> int;
alphasort (r, r) -> int;
versionsort (r, r) -> int;