08993f4d271bb429e30430c076c7497df8788300
1 MODULE LinLibc ["libc.so%%libver%%"];
3 (*
4 %%osname%%
5 %%machine%%
6 *)
8 CONST
9 NULL* = 0H;
10 FALSE* = 0;
11 TRUE* = 1;
13 CLOCKS_PER_SEC* = %%clockspersec%%;
15 MAP_FAILED* = -1;
17 (* MAP_PRIVATE, MAP_ANON (intFlags) *)
18 %%defs-map%%
20 (* PROT_READ, PROT_WRITE, PROT_EXEC (intFlags) *)
21 %%defs-prot%%
23 (* SIG_UNBLOCK, SIG_SETMASK (int) *)
24 %%defs-sigmask%%
26 (* FPE_INTDIV, FPE_INTOVF, FPE_FLTDIV, FPE_FLTOVF, FPE_FLTUND, FPE_FLTRES, FPE_FLTINV, FPE_FLTSUB (int) *)
27 %%defs-fpe%%
29 (* SA_SIGINFO (intFlags) *)
30 %%defs-sa%%
32 (* SIGINT, SIGILL, SIGFPE, SIGSEGV, SIGKILL, SIGSTOP, SIGWINCH, SIGTHR (int) *)
33 %%defs-signo%%
34 _NSIG* = %%nsig%%;
36 (*
37 PAGE_SIZE* = 4096;
38 *)
39 %%defs-sc%%
41 SIGSTKSZ* = %%sigstksz%%;
43 (* ENOENT, EEXIST, EACCES, ENOMEM, EDQUOT, EMFILE, ENOTDIR (int) *)
44 %%defs-errno%%
46 NAME_MAX* = %%namemax%%;
48 SEEK_SET* = 0;
49 SEEK_CUR* = 1;
50 SEEK_END* = 2;
52 STDIN_FILENO* = 0;
53 STDOUT_FILENO* = 1;
54 STDERR_FILENO* = 2;
56 P_tmpdir* = "/tmp";
58 (* O_RDWR, O_NONBLOCK (intFlags) *)
59 %%defs-fcntlo%%
61 %%defs-clockid%%
63 TYPE
64 StrArray* = POINTER TO ARRAY [untagged] OF PtrSTR;
65 PtrSTR* = POINTER TO ARRAY [untagged] OF SHORTCHAR;
67 (* PtrVoid, int, long, size_t, ssize_t, off_t, time_t, clock_t, sigjmp_buf *)
68 (* mode_t, intFlags, sigset_t (set) *)
69 %%defs-basictypes%%
71 tm* = POINTER TO tmDesc;
72 tmDesc* = RECORD [untagged]
73 (* NOTE: check record size *)
74 (* tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday [ , tm_gmtoff ] *)
75 %%fields-tm%%
76 END;
78 Ptrsiginfo_t* = POINTER TO siginfo_t;
79 siginfo_t = RECORD [untagged]
80 (* si_code, fault address *)
81 %%fields-siginfo%%
82 END;
84 Ptrucontext_t* = POINTER TO ucontext_t;
85 ucontext_t = RECORD [untagged]
86 (* IP, SP, FP *)
87 %%fields-ucontext%%
88 END;
90 sigaction_t* = RECORD [untagged]
91 (*
92 sa_sigaction*: PROCEDURE [ccall] (sig: INTEGER; siginfo: Ptrsiginfo_t; context: Ptrucontext_t),
93 sa_flags*: intFlags, sa_mask*: sigset_t
94 *)
95 %%fields-sigaction%%
96 END;
98 stack_t* = RECORD [untagged]
99 (*
100 ss_sp*: PtrVoid, ss_size*: size_t, ss_flags*: intFlags
101 *)
102 %%fields-stack%%
103 END;
105 stat_t* = RECORD [untagged]
106 (*
107 NOTE: check record size
108 st_mode*: mode_t, st_size*: off_t, st_mtime*: time_t
109 *)
110 %%fields-stat%%
111 END;
113 PtrFILE* = PtrVoid;
114 PtrDIR* = PtrVoid;
116 PtrDirent* = POINTER TO Dirent;
117 Dirent = RECORD [untagged]
118 (*
119 d_name*: ARRAY [untagged] NAME_MAX + 1 OF SHORTCHAR
120 *)
121 %%fields-dirent%%
122 END;
124 timespec_t* = RECORD [untagged]
125 %%fields-timespec%%
126 END;
128 (*
129 VAR
130 stdin*: INTEGER;
131 timezone*: INTEGER; (* or tm.tm_gmtoff *)
132 *)
133 (*
134 PROCEDURE [ccall] __errno_location* (): PtrVoid;
135 *)
136 (*
137 (* POSIX.1 *)
138 PROCEDURE [ccall] stat* (path: PtrSTR; VAR sp: stat_t): int;
139 *)
140 %%custom%%
142 (* ANSI C 89 *)
143 PROCEDURE [ccall] clock* (): clock_t;
145 (* POSIX.1 *)
146 PROCEDURE [ccall] clock_gettime* (clock_id: clockid_t; VAR tp: timespec_t): int;
148 PROCEDURE [ccall] mmap* (adr: PtrVoid; len: size_t; prot: intFlags; flags: intFlags; fd: int; offset: off_t): PtrVoid;
149 (* BSD *)
150 PROCEDURE [ccall] munmap* (adr: PtrVoid; len: size_t): int;
151 PROCEDURE [ccall] mprotect* (adr: PtrVoid; len: size_t; prot: intFlags): int;
153 (*
154 PROCEDURE [ccall] calloc* (nmemb: size_t; size: size_t): PtrVoid;
155 (* ANSI C 89 *)
156 PROCEDURE [ccall] malloc* (size: size_t): PtrVoid;
157 *)
158 PROCEDURE [ccall] free* (ptr: PtrVoid);
160 (* AT&T *)
161 PROCEDURE [ccall] time* (VAR [nil] t: time_t): time_t;
162 PROCEDURE [ccall] gmtime* (VAR [nil] t: time_t): tm;
163 PROCEDURE [ccall] localtime* (VAR [nil] t: time_t): tm;
165 (* POSIX.1 *)
166 PROCEDURE [ccall] sigsetjmp* (VAR env: sigjmp_buf; savemask: int): int;
167 PROCEDURE [ccall] siglongjmp* (VAR env: sigjmp_buf; val: int);
169 (* POSIX.1 *)
170 PROCEDURE [ccall] sigemptyset* (VAR set: sigset_t): int;
171 PROCEDURE [ccall] sigfillset* (VAR set: sigset_t): int;
172 PROCEDURE [ccall] sigaddset* (VAR set: sigset_t; signo: int): int;
173 PROCEDURE [ccall] sigprocmask* (how: int; VAR [nil] set: sigset_t; VAR [nil] oset: sigset_t): int;
175 (* POSIX.1 *)
176 PROCEDURE [ccall] sigaction* (sig: int; VAR [nil] act: sigaction_t; VAR [nil] oact: sigaction_t): int;
178 (* BSD *)
179 PROCEDURE [ccall] sigaltstack* (VAR [nil] ss: stack_t; VAR [nil] oss: stack_t): int;
181 (* ANSI C 89 *)
182 PROCEDURE [ccall] getenv* (s: PtrSTR): PtrSTR;
184 (* ANSI C 89 *)
185 PROCEDURE [ccall] fopen* (path, mode: PtrSTR): PtrFILE;
186 PROCEDURE [ccall] fdopen* (fildes: int; mode: PtrSTR): PtrFILE;
187 PROCEDURE [ccall] fclose* (stream: PtrFILE): int;
188 PROCEDURE [ccall] fread* (ptr: PtrVoid; size: size_t; nmemb: size_t; stream: PtrFILE): size_t;
189 PROCEDURE [ccall] fwrite* (ptr: PtrVoid; size: size_t; nmemb: size_t; stream: PtrFILE): size_t;
190 PROCEDURE [ccall] fflush* (s: PtrFILE): int;
191 PROCEDURE [ccall] printf* (s: PtrSTR): int;
192 (* ANSI C 89, XPG4 *)
193 PROCEDURE [ccall] fseek* (stream: PtrFILE; offset: long; whence: int): int;
195 (* POSIX.1 *)
196 PROCEDURE [ccall] rename* (from, to: PtrSTR): int;
197 PROCEDURE [ccall] mkdir* (path: PtrSTR; mode: mode_t): int;
198 PROCEDURE [ccall] opendir* (filename: PtrSTR): PtrDIR;
199 PROCEDURE [ccall] readdir* (dirp: PtrDIR): PtrDirent;
200 PROCEDURE [ccall] closedir* (dirp: PtrDIR): int;
201 (* ANSI C 89, XPG4.2 *)
202 PROCEDURE [ccall] remove* (path: PtrSTR): int;
204 (* POSIX.1 *)
205 PROCEDURE [ccall] getcwd* (buf: PtrSTR; size: size_t): PtrSTR;
207 (* ANSI C 99 *)
208 PROCEDURE [ccall] exit* (status: int);
210 (* ANSI C 89 *)
211 PROCEDURE [ccall] strftime* (buf: PtrSTR; maxsize: size_t; format: PtrSTR; timeptr: tm): size_t;
213 (* XXX: use fread instead *)
214 PROCEDURE [ccall] fgets* (str: PtrSTR; size: int; stream: PtrFILE): PtrSTR;
216 (* POSIX.1 *)
217 PROCEDURE [ccall] open* (path: PtrSTR; flags: intFlags; mode: mode_t): int;
218 PROCEDURE [ccall] write* (d: int; buf: PtrVoid; nbytes: size_t): ssize_t;
219 PROCEDURE [ccall] read* (d: int; buf: PtrVoid; nbytes: size_t): ssize_t;
220 PROCEDURE [ccall] close* (d: int): int;
221 PROCEDURE [ccall] lseek* (d: int; offset: off_t; whence: int): off_t;
223 (* POSIX.1 *)
224 PROCEDURE [ccall] sysconf* (name: int): long;
226 PROCEDURE [ccall] system* (cmd: PtrSTR): INTEGER;
227 PROCEDURE [ccall] popen* (cmd, mode: PtrSTR): INTEGER;
230 END LinLibc.