raz / lib / C.raz

113 lines · 5.1 KiB · raw · history · last change e0d008cd

1(* The C library: what raz's own library calls in it, and what most
2 programs reach for. A program that imports C uses C, and so is
3 linked dynamically and starts through the C library. *)
4module C;
5import SYSTEM;
6
7extern proc write*(fd: I32; buf: ^U8; n: UINT): INT;
8extern proc read*(fd: I32; buf: ^U8; n: UINT): INT;
9extern proc open*(path: ^U8; flags: I32; ...): I32;
10extern proc creat*(path: ^U8; mode: U32): I32;
11extern proc close*(fd: I32): I32;
12extern proc mmap*(addr: ^U8; n: UINT; prot, flags, fd: I32; off: I64): ^U8;
13extern proc munmap*(addr: ^U8; n: UINT): I32;
14extern proc mprotect*(addr: ^U8; n: UINT; prot: I32): I32;
15extern proc isatty*(fd: I32): I32;
16extern proc exit*(status: I32);
17extern proc _exit*(status: I32);
18extern proc __errno_location*: ^I32; (* errno, this thread's *)
19extern proc sched_yield*: I32;
20extern proc pthread_create*(t: ^UINT; attr: ^U8;
21 start: proc(arg: ^U8): ^U8; arg: ^U8): I32;
22extern proc pthread_join*(t: UINT; result: ^^U8): I32;
23extern proc rename*(old, new: ^U8): I32;
24extern proc unlink*(path: ^U8): I32;
25extern proc mkdir*(path: ^U8; mode: U32): I32;
26extern proc rmdir*(path: ^U8): I32;
27extern proc chmod*(path: ^U8; mode: U32): I32;
28extern proc chown*(path: ^U8; uid, gid: U32): I32;
29extern proc mkfifo*(path: ^U8; mode: U32): I32;
30extern proc utimensat*(dir: I32; path, times: ^U8; flags: I32): I32;
31extern proc readlink*(path, buf: ^U8; n: UINT): INT;
32extern proc lseek*(fd: I32; off: I64; whence: I32): I64;
33extern proc opendir*(path: ^U8): ^U8; (* DIR * *)
34extern proc readdir*(d: ^U8): ^U8; (* struct dirent * *)
35extern proc closedir*(d: ^U8): I32;
36extern proc tcgetattr*(fd: I32; t: ^U8): I32;
37extern proc tcsetattr*(fd: I32; when: I32; t: ^U8): I32;
38extern proc cfmakeraw*(t: ^U8);
39extern proc ioctl*(fd: I32; request: UINT; ...): I32;
40extern proc poll*(fds: ^U8; n: UINT; ms: I32): I32;
41extern proc fcntl*(fd, cmd: I32; ...): I32;
42extern proc socket*(domain, kind, protocol: I32): I32;
43extern proc connect*(fd: I32; addr: ^U8; len: U32): I32;
44extern proc send*(fd: I32; buf: ^U8; n: UINT; flags: I32): INT;
45extern proc bind*(fd: I32; addr: ^U8; len: U32): I32;
46extern proc listen*(fd, backlog: I32): I32;
47extern proc accept*(fd: I32; addr: ^U8; len: ^U32): I32;
48extern proc accept4*(fd: I32; addr: ^U8; len: ^U32; flags: I32): I32;
49extern proc setsockopt*(fd, level, name: I32; value: ^U8; len: U32): I32;
50extern proc getsockopt*(fd, level, name: I32; value: ^U8; len: ^U32): I32;
51extern proc getpeername*(fd: I32; addr: ^U8; len: ^U32): I32;
52extern proc shutdown*(fd, how: I32): I32;
53extern proc socketpair*(domain, kind, protocol: I32; fds: ^I32): I32;
54extern proc getsockname*(fd: I32; addr: ^U8; len: ^U32): I32;
55extern proc recvfrom*(fd: I32; buf: ^U8; n: UINT; flags: I32; addr: ^U8; len: ^U32): INT;
56extern proc sendto*(fd: I32; buf: ^U8; n: UINT; flags: I32; addr: ^U8; len: U32): INT;
57extern proc sendmsg*(fd: I32; msg: ^U8; flags: I32): INT;
58extern proc recvmsg*(fd: I32; msg: ^U8; flags: I32): INT;
59extern proc memfd_create*(name: ^U8; flags: U32): I32;
60extern proc ftruncate*(fd: I32; size: I64): I32;
61extern proc inet_pton*(family: I32; src, dst: ^U8): I32;
62extern proc clock_gettime*(clock: I32; t: ^U8): I32;
63extern proc clock_nanosleep*(clock, flags: I32; t, left: ^U8): I32;
64extern proc getrandom*(buf: ^U8; n: UINT; flags: U32): INT;
65extern proc getenv*(name: ^U8): ^U8;
66extern proc setenv*(name, value: ^U8; overwrite: I32): I32;
67extern proc strerror*(err: I32): ^U8;
68extern proc getcwd*(buf: ^U8; n: UINT): ^U8;
69extern proc chdir*(path: ^U8): I32;
70extern proc stat*(path, st: ^U8): I32;
71extern proc fstat*(fd: I32; st: ^U8): I32;
72extern proc fsync*(fd: I32): I32;
73extern proc sync*;
74extern proc flock*(fd, how: I32): I32;
75extern proc lstat*(path, st: ^U8): I32;
76extern proc statvfs*(path, st: ^U8): I32;
77extern proc symlink*(target, path: ^U8): I32;
78extern proc posix_openpt*(flags: I32): I32;
79extern proc grantpt*(fd: I32): I32;
80extern proc unlockpt*(fd: I32): I32;
81extern proc ptsname*(fd: I32): ^U8;
82extern proc fork*: I32;
83extern proc setsid*: I32;
84extern proc dup2*(fd, fd2: I32): I32;
85extern proc dup*(fd: I32): I32;
86extern proc close_range*(first, last: U32; flags: I32): I32;
87extern proc execve*(path: ^U8; argv, envp: ^^U8): I32;
88extern proc waitpid*(pid: I32; status: ^I32; options: I32): I32;
89extern proc kill*(pid, signal: I32): I32;
90extern proc getpid*: I32;
91extern proc getuid*: U32;
92extern proc geteuid*: U32;
93extern proc gethostname*(name: ^U8; n: UINT): I32;
94extern proc access*(path: ^U8; how: I32): I32;
95extern proc umask*(mask: U32): U32;
96extern proc sched_getaffinity*(pid: I32; size: UINT; mask: ^U8): I32;
97extern proc getrusage*(who: I32; usage: ^U8): I32;
98extern proc getrlimit*(which: I32; limit: ^U8): I32;
99extern proc setrlimit*(which: I32; limit: ^U8): I32;
100extern proc getpgrp*: I32;
101extern proc setpgid*(pid, group: I32): I32;
102extern proc tcsetpgrp*(fd, group: I32): I32;
103extern proc tcgetpgrp*(fd: I32): I32;
104extern proc pipe2*(fds: ^I32; flags: I32): I32;
105extern proc sigaction*(sig: I32; act, old: ^U8): I32;
106extern proc sigprocmask*(how: I32; mask, old: ^U8): I32;
107extern proc printf*(format: ^U8; ...): I32;
108extern proc fflush*(f: ^U8): I32;
109extern var environ*: ^^U8;
110extern var stdout*: ^U8; (* FILE * *)
111extern var stderr*: ^U8;
112
113end C.