1  /* do not edit automatically generated by mc from libc.  */
       2  /* libc.def provides an interface to the C library functions.
       3  
       4  Copyright (C) 2001-2023 Free Software Foundation, Inc.
       5  Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
       6  
       7  This file is part of GNU Modula-2.
       8  
       9  GNU Modula-2 is free software; you can redistribute it and/or modify
      10  it under the terms of the GNU General Public License as published by
      11  the Free Software Foundation; either version 3, or (at your option)
      12  any later version.
      13  
      14  GNU Modula-2 is distributed in the hope that it will be useful, but
      15  WITHOUT ANY WARRANTY; without even the implied warranty of
      16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17  General Public License for more details.
      18  
      19  Under Section 7 of GPL version 3, you are granted additional
      20  permissions described in the GCC Runtime Library Exception, version
      21  3.1, as published by the Free Software Foundation.
      22  
      23  You should have received a copy of the GNU General Public License and
      24  a copy of the GCC Runtime Library Exception along with this program;
      25  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
      26  <http://www.gnu.org/licenses/>.  */
      27  
      28  
      29  #if !defined (_libc_H)
      30  #   define _libc_H
      31  
      32  #include "config.h"
      33  #include "system.h"
      34  #   ifdef __cplusplus
      35  extern "C" {
      36  #   endif
      37  #include <stdbool.h>
      38  #   if !defined (PROC_D)
      39  #      define PROC_D
      40         typedef void (*PROC_t) (void);
      41         typedef struct { PROC_t proc; } PROC;
      42  #   endif
      43  
      44  #   include "GSYSTEM.h"
      45  
      46  #   if defined (_libc_C)
      47  #      define EXTERN
      48  #   else
      49  #      define EXTERN extern
      50  #   endif
      51  
      52  typedef long int libc_time_t;
      53  
      54  typedef struct libc_tm_r libc_tm;
      55  
      56  typedef struct libc_timeb_r libc_timeb;
      57  
      58  typedef struct libc_exitP_p libc_exitP;
      59  
      60  typedef libc_tm *libc_ptrToTM;
      61  
      62  struct libc_tm_r {
      63                     int tm_sec;
      64                     int tm_min;
      65                     int tm_hour;
      66                     int tm_mday;
      67                     int tm_mon;
      68                     int tm_year;
      69                     int tm_wday;
      70                     int tm_yday;
      71                     int tm_isdst;
      72                     long int tm_gmtoff;
      73                     void *tm_zone;
      74                   };
      75  
      76  struct libc_timeb_r {
      77                        libc_time_t time_;
      78                        short unsigned int millitm;
      79                        short unsigned int timezone;
      80                        short unsigned int dstflag;
      81                      };
      82  
      83  typedef int (*libc_exitP_t) (void);
      84  typedef libc_exitP_t libc_exitP_C;
      85  
      86  struct libc_exitP_p { libc_exitP_t proc; };
      87  
      88  EXTERN ssize_t libc_write (int d, void * buf, size_t nbytes);
      89  EXTERN ssize_t libc_read (int d, void * buf, size_t nbytes);
      90  EXTERN int libc_system (void * a);
      91  
      92  /*
      93       abort - generate a fault
      94  
      95       abort() first closes all open files if possible, then sends
      96       an IOT signal to the process.  This signal usually results
      97       in termination with a core dump, which may be used for
      98       debugging.
      99  
     100       It is possible for abort() to return control if is caught or
     101       ignored, in which case the value returned is that of the
     102       kill(2V) system call.
     103  */
     104  
     105  EXTERN void libc_abort (void) __attribute__ ((noreturn));
     106  
     107  /*
     108       malloc - memory allocator.
     109  
     110       void *malloc(size_t size);
     111  
     112       malloc() returns a pointer to a block of at least size
     113       bytes, which is appropriately aligned.  If size is zero,
     114       malloc() returns a non-NULL pointer, but this pointer should
     115       not be dereferenced.
     116  */
     117  
     118  EXTERN void * libc_malloc (size_t size);
     119  
     120  /*
     121       free - memory deallocator.
     122  
     123       free (void *ptr);
     124  
     125       free() releases a previously allocated block.  Its argument
     126       is a pointer to a block previously allocated by malloc,
     127       calloc, realloc, malloc, or memalign.
     128  */
     129  
     130  EXTERN void libc_free (void * ptr);
     131  EXTERN void * libc_realloc (void * ptr, size_t size);
     132  
     133  /*
     134     isatty - does this descriptor refer to a terminal.
     135  */
     136  
     137  EXTERN int libc_isatty (int fd);
     138  
     139  /*
     140     exit - returns control to the invoking process. Result, r, is
     141            returned.
     142  */
     143  
     144  EXTERN void libc_exit (int r) __attribute__ ((noreturn));
     145  
     146  /*
     147     getenv - returns the C string for the equivalent C environment
     148              variable.
     149  */
     150  
     151  EXTERN void * libc_getenv (void * s);
     152  
     153  /*
     154     putenv - change or add an environment variable.
     155  */
     156  
     157  EXTERN int libc_putenv (void * s);
     158  
     159  /*
     160     getpid - returns the UNIX process identification number.
     161  */
     162  
     163  EXTERN int libc_getpid (void);
     164  
     165  /*
     166     dup - duplicates the file descriptor, d.
     167  */
     168  
     169  EXTERN int libc_dup (int d);
     170  
     171  /*
     172     close - closes the file descriptor, d.
     173  */
     174  
     175  EXTERN int libc_close (int d);
     176  
     177  /*
     178     open - open the file, filename with flag and mode.
     179  */
     180  
     181  EXTERN int libc_open (void * filename, int oflag, ...);
     182  
     183  /*
     184     creat - creates a new file
     185  */
     186  
     187  EXTERN int libc_creat (void * filename, unsigned int mode);
     188  
     189  /*
     190     lseek - calls unix lseek:
     191  
     192             off_t lseek(int fildes, off_t offset, int whence);
     193  */
     194  
     195  EXTERN long int libc_lseek (int fd, long int offset, int whence);
     196  
     197  /*
     198     perror - writes errno and string. (ARRAY OF CHAR is translated onto ADDRESS).
     199  */
     200  
     201  EXTERN void libc_perror (const char *string_, unsigned int _string_high);
     202  
     203  /*
     204     readv - reads an io vector of bytes.
     205  */
     206  
     207  EXTERN int libc_readv (int fd, void * v, int n);
     208  
     209  /*
     210     writev - writes an io vector of bytes.
     211  */
     212  
     213  EXTERN int libc_writev (int fd, void * v, int n);
     214  
     215  /*
     216     getcwd - copies the absolute pathname of the
     217              current working directory to the array pointed to by buf,
     218              which is of length size.
     219  
     220              If the current absolute path name would require a buffer
     221              longer than size elements, NULL is returned, and errno is
     222              set to ERANGE; an application should check for this error,
     223              and allocate a larger buffer if necessary.
     224  */
     225  
     226  EXTERN void * libc_getcwd (void * buf, size_t size);
     227  
     228  /*
     229     chown - The  owner  of  the  file  specified  by  path or by fd is
     230             changed.  Only the super-user may change the  owner  of  a
     231             file.   The  owner  of  a file may change the group of the
     232             file to any group of which that owner is  a  member.   The
     233             super-user may change the group arbitrarily.
     234  
     235             If  the owner or group is specified as -1, then that ID is
     236             not changed.
     237  
     238             On success, zero is returned.  On error, -1  is  returned,
     239             and errno is set appropriately.
     240  */
     241  
     242  EXTERN int libc_chown (void * filename, int uid, int gid);
     243  
     244  /*
     245     strlen - returns the length of string, a.
     246  */
     247  
     248  EXTERN size_t libc_strlen (void * a);
     249  
     250  /*
     251     strcpy - copies string, src, into, dest.
     252              It returns dest.
     253  */
     254  
     255  EXTERN void * libc_strcpy (void * dest, void * src);
     256  
     257  /*
     258     strncpy - copies string, src, into, dest, copying at most, n, bytes.
     259               It returns dest.
     260  */
     261  
     262  EXTERN void * libc_strncpy (void * dest, void * src, unsigned int n);
     263  
     264  /*
     265     unlink - removes file and returns 0 if successful.
     266  */
     267  
     268  EXTERN int libc_unlink (void * file);
     269  
     270  /*
     271     memcpy - copy memory area
     272  
     273     SYNOPSIS
     274  
     275     #include <string.h>
     276  
     277     void *memcpy(void *dest, const void *src, size_t n);
     278     It returns dest.
     279  */
     280  
     281  EXTERN void * libc_memcpy (void * dest, void * src, size_t size);
     282  
     283  /*
     284     memset - fill memory with a constant byte
     285  
     286     SYNOPSIS
     287  
     288     #include <string.h>
     289  
     290     void *memset(void *s, int c, size_t n);
     291     It returns s.
     292  */
     293  
     294  EXTERN void * libc_memset (void * s, int c, size_t size);
     295  
     296  /*
     297     memmove - copy memory areas which may overlap
     298  
     299     SYNOPSIS
     300  
     301     #include <string.h>
     302  
     303     void *memmove(void *dest, const void *src, size_t n);
     304     It returns dest.
     305  */
     306  
     307  EXTERN void * libc_memmove (void * dest, void * src, size_t size);
     308  EXTERN int libc_printf (const char *format_, unsigned int _format_high, ...);
     309  EXTERN int libc_snprintf (void * dest, size_t size, const char *format_, unsigned int _format_high, ...);
     310  
     311  /*
     312     setenv - sets environment variable, name, to value.
     313              It will overwrite an existing value if, overwrite,
     314              is true.  It returns 0 on success and -1 for an error.
     315  */
     316  
     317  EXTERN int libc_setenv (void * name, void * value, int overwrite);
     318  
     319  /*
     320     srand - initialize the random number seed.
     321  */
     322  
     323  EXTERN void libc_srand (int seed);
     324  
     325  /*
     326     rand - return a random integer.
     327  */
     328  
     329  EXTERN int libc_rand (void);
     330  
     331  /*
     332     time - returns a pointer to the time_t value. If, a,
     333            is not NIL then the libc value is copied into
     334            memory at address, a.
     335  */
     336  
     337  EXTERN libc_time_t libc_time (void * a);
     338  
     339  /*
     340     localtime - returns a pointer to the libc copy of the tm
     341                 structure.
     342  */
     343  
     344  EXTERN void * libc_localtime (libc_time_t *t);
     345  
     346  /*
     347     ftime - return date and time.
     348  */
     349  
     350  EXTERN int libc_ftime (libc_timeb *t);
     351  
     352  /*
     353     shutdown - shutdown a socket, s.
     354                if how = 0, then no more reads are allowed.
     355                if how = 1, then no more writes are allowed.
     356                if how = 2, then mo more reads or writes are allowed.
     357  */
     358  
     359  EXTERN int libc_shutdown (int s, int how);
     360  
     361  /*
     362     rename - change the name or location of a file
     363  */
     364  
     365  EXTERN int libc_rename (void * oldpath, void * newpath);
     366  
     367  /*
     368     setjmp - returns 0 if returning directly, and non-zero
     369              when returning from longjmp using the saved
     370              context.
     371  */
     372  
     373  EXTERN int libc_setjmp (void * env);
     374  
     375  /*
     376     longjmp - restores the environment saved by the last call
     377               of setjmp with the corresponding env argument.
     378               After longjmp is completed, program execution
     379               continues as if the corresponding call of setjmp
     380               had just returned the value val.  The value of
     381               val must not be zero.
     382  */
     383  
     384  EXTERN void libc_longjmp (void * env, int val);
     385  
     386  /*
     387     atexit - execute, proc, when the function exit is called.
     388  */
     389  
     390  EXTERN int libc_atexit (libc_exitP_C proc);
     391  
     392  /*
     393     ttyname - returns a pointer to a string determining the ttyname.
     394  */
     395  
     396  EXTERN void * libc_ttyname (int filedes);
     397  
     398  /*
     399     sleep - calling thread sleeps for seconds.
     400  */
     401  
     402  EXTERN unsigned int libc_sleep (unsigned int seconds);
     403  
     404  /*
     405     execv - execute a file.
     406  */
     407  
     408  EXTERN int libc_execv (void * pathname, void * argv);
     409  #   ifdef __cplusplus
     410  }
     411  #   endif
     412  
     413  #   undef EXTERN
     414  #endif