xfail scan-tree-dump-not throw in g++.dg/pr99966.C on hppa*64*-*-*
[official-gcc.git] / gcc / m2 / gm2-libs / libc.def
blob4a389f5d49f833d9d422c08d3eedda33051a4629
1 (* libc.def provides an interface to the C library functions.
3 Copyright (C) 2001-2024 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
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.
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.
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.
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/>. *)
27 DEFINITION MODULE FOR "C" libc ;
29 FROM SYSTEM IMPORT ADDRESS, CSIZE_T, CSSIZE_T ;
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 ;
50 TYPE
51 time_t = LONGINT ;
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 ;
68 timeb = RECORD
69 time : time_t ;
70 millitm : SHORTCARD ;
71 timezone: SHORTCARD ;
72 dstflag : SHORTCARD ;
73 END ;
75 exitP = PROCEDURE () : INTEGER ;
79 ssize_t write (int d, void *buf, size_t nbytes)
82 PROCEDURE write (d: INTEGER; buf: ADDRESS; nbytes: CSIZE_T) : [ CSSIZE_T ] ;
86 ssize_t read (int d, void *buf, size_t nbytes)
89 PROCEDURE read (d: INTEGER; buf: ADDRESS; nbytes: CSIZE_T) : [ CSSIZE_T ] ;
93 int system(string)
94 char *string;
97 PROCEDURE system (a: ADDRESS) : [ INTEGER ] ;
101 abort - generate a fault
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.
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.
113 PROCEDURE abort <* noreturn *> ;
117 malloc - memory allocator.
119 void *malloc(size_t size);
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.
127 PROCEDURE malloc (size: CSIZE_T) : ADDRESS ;
131 free - memory deallocator.
133 free (void *ptr);
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.
140 PROCEDURE free (ptr: ADDRESS) ;
144 void *realloc (void *ptr, size_t size);
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.
156 PROCEDURE realloc (ptr: ADDRESS; size: CSIZE_T) : ADDRESS ;
160 isatty - does this descriptor refer to a terminal.
163 PROCEDURE isatty (fd: INTEGER) : INTEGER ;
167 exit - returns control to the invoking process. Result, r, is
168 returned.
171 PROCEDURE exit (r: INTEGER) <* noreturn *> ;
175 getenv - returns the C string for the equivalent C environment
176 variable.
179 PROCEDURE getenv (s: ADDRESS) : ADDRESS ;
183 putenv - change or add an environment variable.
186 PROCEDURE putenv (s: ADDRESS) : INTEGER ;
190 getpid - returns the UNIX process identification number.
193 PROCEDURE getpid () : INTEGER ;
197 dup - duplicates the file descriptor, d.
200 PROCEDURE dup (d: INTEGER) : INTEGER ;
204 close - closes the file descriptor, d.
207 PROCEDURE close (d: INTEGER) : [ INTEGER ] ;
211 open - open the file, filename with flag and mode.
214 PROCEDURE open (filename: ADDRESS; oflag: INTEGER; ...) : INTEGER ;
218 creat - creates a new file
221 PROCEDURE creat (filename: ADDRESS; mode: CARDINAL) : INTEGER;
225 lseek - calls unix lseek:
227 off_t lseek(int fildes, off_t offset, int whence);
230 PROCEDURE lseek (fd: INTEGER; offset: LONGINT; whence: INTEGER) : LONGINT ;
234 perror - writes errno and string. (ARRAY OF CHAR is translated onto ADDRESS).
237 PROCEDURE perror (string: ARRAY OF CHAR);
241 readv - reads an io vector of bytes.
244 PROCEDURE readv (fd: INTEGER; v: ADDRESS; n: INTEGER) : [ INTEGER ] ;
248 writev - writes an io vector of bytes.
251 PROCEDURE writev (fd: INTEGER; v: ADDRESS; n: INTEGER) : [ INTEGER ] ;
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.
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.
265 PROCEDURE getcwd (buf: ADDRESS; size: CSIZE_T) : ADDRESS ;
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.
275 If the owner or group is specified as -1, then that ID is
276 not changed.
278 On success, zero is returned. On error, -1 is returned,
279 and errno is set appropriately.
282 PROCEDURE chown (filename: ADDRESS; uid, gid: INTEGER) : [ INTEGER ] ;
286 strlen - returns the length of string, a.
289 PROCEDURE strlen (a: ADDRESS) : CSIZE_T ;
293 strcpy - copies string, src, into, dest.
294 It returns dest.
297 PROCEDURE strcpy (dest, src: ADDRESS) : [ ADDRESS ] ;
301 strncpy - copies string, src, into, dest, copying at most, n, bytes.
302 It returns dest.
305 PROCEDURE strncpy (dest, src: ADDRESS; n: CARDINAL) : [ ADDRESS ] ;
309 unlink - removes file and returns 0 if successful.
312 PROCEDURE unlink (file: ADDRESS) : [ INTEGER ] ;
316 memcpy - copy memory area
318 SYNOPSIS
320 #include <string.h>
322 void *memcpy(void *dest, const void *src, size_t n);
323 It returns dest.
326 PROCEDURE memcpy (dest, src: ADDRESS; size: CSIZE_T) : [ ADDRESS ] ;
330 memset - fill memory with a constant byte
332 SYNOPSIS
334 #include <string.h>
336 void *memset(void *s, int c, size_t n);
337 It returns s.
340 PROCEDURE memset (s: ADDRESS; c: INTEGER; size: CSIZE_T) : [ ADDRESS ] ;
344 memmove - copy memory areas which may overlap
346 SYNOPSIS
348 #include <string.h>
350 void *memmove(void *dest, const void *src, size_t n);
351 It returns dest.
354 PROCEDURE memmove (dest, src: ADDRESS; size: CSIZE_T) : [ ADDRESS ] ;
358 int printf(const char *format, ...);
361 PROCEDURE printf (format: ARRAY OF CHAR; ...) : [ INTEGER ] ;
365 int snprintf(char *str, size_t size, const char *format, ...);
368 PROCEDURE snprintf (dest: ADDRESS; size: CSIZE_T;
369 format: ARRAY OF CHAR; ...) : [ INTEGER ] ;
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.
377 PROCEDURE setenv (name: ADDRESS; value: ADDRESS; overwrite: INTEGER) : [ INTEGER ] ;
381 srand - initialize the random number seed.
384 PROCEDURE srand (seed: INTEGER) ;
388 rand - return a random integer.
391 PROCEDURE rand () : INTEGER ;
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.
400 PROCEDURE time (a: ADDRESS) : time_t ;
404 localtime - returns a pointer to the libc copy of the tm
405 structure.
408 PROCEDURE localtime (VAR t: time_t) : ADDRESS ;
412 ftime - return date and time.
415 PROCEDURE ftime (VAR t: timeb) : [ INTEGER ] ;
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.
425 PROCEDURE shutdown (s: INTEGER; how: INTEGER) : [ INTEGER ] ;
429 rename - change the name or location of a file
432 PROCEDURE rename (oldpath, newpath: ADDRESS) : [ INTEGER ] ;
436 setjmp - returns 0 if returning directly, and non-zero
437 when returning from longjmp using the saved
438 context.
441 PROCEDURE setjmp (env: ADDRESS) : INTEGER ;
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.
453 PROCEDURE longjmp (env: ADDRESS; val: INTEGER) ;
457 atexit - execute, proc, when the function exit is called.
460 PROCEDURE atexit (proc: exitP) : [ INTEGER ] ;
464 ttyname - returns a pointer to a string determining the ttyname.
467 PROCEDURE ttyname (filedes: INTEGER) : ADDRESS ;
471 sleep - calling thread sleeps for seconds.
474 PROCEDURE sleep (seconds: CARDINAL) : [ CARDINAL ] ;
478 execv - execute a file.
481 PROCEDURE execv (pathname: ADDRESS; argv: ADDRESS) : [ INTEGER ] ;
484 END libc.