]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/m2/gm2-libs/libc.def
Update copyright years.
[thirdparty/gcc.git] / gcc / m2 / gm2-libs / libc.def
1 (* libc.def provides an interface to the C library functions.
2
3 Copyright (C) 2001-2024 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
5
6 This file is part of GNU Modula-2.
7
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
21
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. *)
26
27 DEFINITION MODULE FOR "C" libc ;
28
29 FROM SYSTEM IMPORT ADDRESS, CSIZE_T, CSSIZE_T ;
30
31 EXPORT UNQUALIFIED time_t, timeb, tm, ptrToTM,
32 write, read,
33 system, abort,
34 malloc, free,
35 exit, isatty,
36 getenv, putenv, getpid,
37 dup, close, open, lseek,
38 readv, writev,
39 perror, creat,
40 getcwd, chown, strlen, strcpy, strncpy,
41 unlink, setenv,
42 memcpy, memset, memmove, printf, realloc,
43 rand, srand,
44 time, localtime, ftime,
45 shutdown, snprintf,
46 rename, setjmp, longjmp, atexit,
47 ttyname, sleep, execv ;
48
49
50 TYPE
51 time_t = LONGINT ;
52
53 ptrToTM = POINTER TO tm ;
54 tm = RECORD
55 tm_sec: INTEGER ; (* Seconds. [0-60] (1 leap second) *)
56 tm_min: INTEGER ; (* Minutes. [0-59] *)
57 tm_hour: INTEGER ; (* Hours. [0-23] *)
58 tm_mday: INTEGER ; (* Day. [1-31] *)
59 tm_mon: INTEGER ; (* Month. [0-11] *)
60 tm_year: INTEGER ; (* Year - 1900. *)
61 tm_wday: INTEGER ; (* Day of week. [0-6] *)
62 tm_yday: INTEGER ; (* Days in year.[0-365] *)
63 tm_isdst: INTEGER ; (* DST. [-1/0/1] *)
64 tm_gmtoff: LONGINT ; (* Seconds east of UTC. *)
65 tm_zone: ADDRESS ; (* char * zone name *)
66 END ;
67
68 timeb = RECORD
69 time : time_t ;
70 millitm : SHORTCARD ;
71 timezone: SHORTCARD ;
72 dstflag : SHORTCARD ;
73 END ;
74
75 exitP = PROCEDURE () : INTEGER ;
76
77
78 (*
79 ssize_t write (int d, void *buf, size_t nbytes)
80 *)
81
82 PROCEDURE write (d: INTEGER; buf: ADDRESS; nbytes: CSIZE_T) : [ CSSIZE_T ] ;
83
84
85 (*
86 ssize_t read (int d, void *buf, size_t nbytes)
87 *)
88
89 PROCEDURE read (d: INTEGER; buf: ADDRESS; nbytes: CSIZE_T) : [ CSSIZE_T ] ;
90
91
92 (*
93 int system(string)
94 char *string;
95 *)
96
97 PROCEDURE system (a: ADDRESS) : [ INTEGER ] ;
98
99
100 (*
101 abort - generate a fault
102
103 abort() first closes all open files if possible, then sends
104 an IOT signal to the process. This signal usually results
105 in termination with a core dump, which may be used for
106 debugging.
107
108 It is possible for abort() to return control if is caught or
109 ignored, in which case the value returned is that of the
110 kill(2V) system call.
111 *)
112
113 PROCEDURE abort <* noreturn *> ;
114
115
116 (*
117 malloc - memory allocator.
118
119 void *malloc(size_t size);
120
121 malloc() returns a pointer to a block of at least size
122 bytes, which is appropriately aligned. If size is zero,
123 malloc() returns a non-NULL pointer, but this pointer should
124 not be dereferenced.
125 *)
126
127 PROCEDURE malloc (size: CSIZE_T) : ADDRESS ;
128
129
130 (*
131 free - memory deallocator.
132
133 free (void *ptr);
134
135 free() releases a previously allocated block. Its argument
136 is a pointer to a block previously allocated by malloc,
137 calloc, realloc, malloc, or memalign.
138 *)
139
140 PROCEDURE free (ptr: ADDRESS) ;
141
142
143 (*
144 void *realloc (void *ptr, size_t size);
145
146 realloc changes the size of the memory block pointed to
147 by ptr to size bytes. The contents will be unchanged to
148 the minimum of the old and new sizes; newly allocated memory
149 will be uninitialized. If ptr is NIL, the call is
150 equivalent to malloc(size); if size is equal to zero, the
151 call is equivalent to free(ptr). Unless ptr is NIL, it
152 must have been returned by an earlier call to malloc(),
153 realloc.
154 *)
155
156 PROCEDURE realloc (ptr: ADDRESS; size: CSIZE_T) : ADDRESS ;
157
158
159 (*
160 isatty - does this descriptor refer to a terminal.
161 *)
162
163 PROCEDURE isatty (fd: INTEGER) : INTEGER ;
164
165
166 (*
167 exit - returns control to the invoking process. Result, r, is
168 returned.
169 *)
170
171 PROCEDURE exit (r: INTEGER) <* noreturn *> ;
172
173
174 (*
175 getenv - returns the C string for the equivalent C environment
176 variable.
177 *)
178
179 PROCEDURE getenv (s: ADDRESS) : ADDRESS ;
180
181
182 (*
183 putenv - change or add an environment variable.
184 *)
185
186 PROCEDURE putenv (s: ADDRESS) : INTEGER ;
187
188
189 (*
190 getpid - returns the UNIX process identification number.
191 *)
192
193 PROCEDURE getpid () : INTEGER ;
194
195
196 (*
197 dup - duplicates the file descriptor, d.
198 *)
199
200 PROCEDURE dup (d: INTEGER) : INTEGER ;
201
202
203 (*
204 close - closes the file descriptor, d.
205 *)
206
207 PROCEDURE close (d: INTEGER) : [ INTEGER ] ;
208
209
210 (*
211 open - open the file, filename with flag and mode.
212 *)
213
214 PROCEDURE open (filename: ADDRESS; oflag: INTEGER; ...) : INTEGER ;
215
216
217 (*
218 creat - creates a new file
219 *)
220
221 PROCEDURE creat (filename: ADDRESS; mode: CARDINAL) : INTEGER;
222
223
224 (*
225 lseek - calls unix lseek:
226
227 off_t lseek(int fildes, off_t offset, int whence);
228 *)
229
230 PROCEDURE lseek (fd: INTEGER; offset: LONGINT; whence: INTEGER) : LONGINT ;
231
232
233 (*
234 perror - writes errno and string. (ARRAY OF CHAR is translated onto ADDRESS).
235 *)
236
237 PROCEDURE perror (string: ARRAY OF CHAR);
238
239
240 (*
241 readv - reads an io vector of bytes.
242 *)
243
244 PROCEDURE readv (fd: INTEGER; v: ADDRESS; n: INTEGER) : [ INTEGER ] ;
245
246
247 (*
248 writev - writes an io vector of bytes.
249 *)
250
251 PROCEDURE writev (fd: INTEGER; v: ADDRESS; n: INTEGER) : [ INTEGER ] ;
252
253
254 (*
255 getcwd - copies the absolute pathname of the
256 current working directory to the array pointed to by buf,
257 which is of length size.
258
259 If the current absolute path name would require a buffer
260 longer than size elements, NULL is returned, and errno is
261 set to ERANGE; an application should check for this error,
262 and allocate a larger buffer if necessary.
263 *)
264
265 PROCEDURE getcwd (buf: ADDRESS; size: CSIZE_T) : ADDRESS ;
266
267
268 (*
269 chown - The owner of the file specified by path or by fd is
270 changed. Only the super-user may change the owner of a
271 file. The owner of a file may change the group of the
272 file to any group of which that owner is a member. The
273 super-user may change the group arbitrarily.
274
275 If the owner or group is specified as -1, then that ID is
276 not changed.
277
278 On success, zero is returned. On error, -1 is returned,
279 and errno is set appropriately.
280 *)
281
282 PROCEDURE chown (filename: ADDRESS; uid, gid: INTEGER) : [ INTEGER ] ;
283
284
285 (*
286 strlen - returns the length of string, a.
287 *)
288
289 PROCEDURE strlen (a: ADDRESS) : CSIZE_T ;
290
291
292 (*
293 strcpy - copies string, src, into, dest.
294 It returns dest.
295 *)
296
297 PROCEDURE strcpy (dest, src: ADDRESS) : [ ADDRESS ] ;
298
299
300 (*
301 strncpy - copies string, src, into, dest, copying at most, n, bytes.
302 It returns dest.
303 *)
304
305 PROCEDURE strncpy (dest, src: ADDRESS; n: CARDINAL) : [ ADDRESS ] ;
306
307
308 (*
309 unlink - removes file and returns 0 if successful.
310 *)
311
312 PROCEDURE unlink (file: ADDRESS) : [ INTEGER ] ;
313
314
315 (*
316 memcpy - copy memory area
317
318 SYNOPSIS
319
320 #include <string.h>
321
322 void *memcpy(void *dest, const void *src, size_t n);
323 It returns dest.
324 *)
325
326 PROCEDURE memcpy (dest, src: ADDRESS; size: CSIZE_T) : [ ADDRESS ] ;
327
328
329 (*
330 memset - fill memory with a constant byte
331
332 SYNOPSIS
333
334 #include <string.h>
335
336 void *memset(void *s, int c, size_t n);
337 It returns s.
338 *)
339
340 PROCEDURE memset (s: ADDRESS; c: INTEGER; size: CSIZE_T) : [ ADDRESS ] ;
341
342
343 (*
344 memmove - copy memory areas which may overlap
345
346 SYNOPSIS
347
348 #include <string.h>
349
350 void *memmove(void *dest, const void *src, size_t n);
351 It returns dest.
352 *)
353
354 PROCEDURE memmove (dest, src: ADDRESS; size: CSIZE_T) : [ ADDRESS ] ;
355
356
357 (*
358 int printf(const char *format, ...);
359 *)
360
361 PROCEDURE printf (format: ARRAY OF CHAR; ...) : [ INTEGER ] ;
362
363
364 (*
365 int snprintf(char *str, size_t size, const char *format, ...);
366 *)
367
368 PROCEDURE snprintf (dest: ADDRESS; size: CSIZE_T;
369 format: ARRAY OF CHAR; ...) : [ INTEGER ] ;
370
371 (*
372 setenv - sets environment variable, name, to value.
373 It will overwrite an existing value if, overwrite,
374 is true. It returns 0 on success and -1 for an error.
375 *)
376
377 PROCEDURE setenv (name: ADDRESS; value: ADDRESS; overwrite: INTEGER) : [ INTEGER ] ;
378
379
380 (*
381 srand - initialize the random number seed.
382 *)
383
384 PROCEDURE srand (seed: INTEGER) ;
385
386
387 (*
388 rand - return a random integer.
389 *)
390
391 PROCEDURE rand () : INTEGER ;
392
393
394 (*
395 time - returns a pointer to the time_t value. If, a,
396 is not NIL then the libc value is copied into
397 memory at address, a.
398 *)
399
400 PROCEDURE time (a: ADDRESS) : time_t ;
401
402
403 (*
404 localtime - returns a pointer to the libc copy of the tm
405 structure.
406 *)
407
408 PROCEDURE localtime (VAR t: time_t) : ADDRESS ;
409
410
411 (*
412 ftime - return date and time.
413 *)
414
415 PROCEDURE ftime (VAR t: timeb) : [ INTEGER ] ;
416
417
418 (*
419 shutdown - shutdown a socket, s.
420 if how = 0, then no more reads are allowed.
421 if how = 1, then no more writes are allowed.
422 if how = 2, then mo more reads or writes are allowed.
423 *)
424
425 PROCEDURE shutdown (s: INTEGER; how: INTEGER) : [ INTEGER ] ;
426
427
428 (*
429 rename - change the name or location of a file
430 *)
431
432 PROCEDURE rename (oldpath, newpath: ADDRESS) : [ INTEGER ] ;
433
434
435 (*
436 setjmp - returns 0 if returning directly, and non-zero
437 when returning from longjmp using the saved
438 context.
439 *)
440
441 PROCEDURE setjmp (env: ADDRESS) : INTEGER ;
442
443
444 (*
445 longjmp - restores the environment saved by the last call
446 of setjmp with the corresponding env argument.
447 After longjmp is completed, program execution
448 continues as if the corresponding call of setjmp
449 had just returned the value val. The value of
450 val must not be zero.
451 *)
452
453 PROCEDURE longjmp (env: ADDRESS; val: INTEGER) ;
454
455
456 (*
457 atexit - execute, proc, when the function exit is called.
458 *)
459
460 PROCEDURE atexit (proc: exitP) : [ INTEGER ] ;
461
462
463 (*
464 ttyname - returns a pointer to a string determining the ttyname.
465 *)
466
467 PROCEDURE ttyname (filedes: INTEGER) : ADDRESS ;
468
469
470 (*
471 sleep - calling thread sleeps for seconds.
472 *)
473
474 PROCEDURE sleep (seconds: CARDINAL) : [ CARDINAL ] ;
475
476
477 (*
478 execv - execute a file.
479 *)
480
481 PROCEDURE execv (pathname: ADDRESS; argv: ADDRESS) : [ INTEGER ] ;
482
483
484 END libc.