]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/m2/mc-boot-ch/Glibc.c
Detect errors when dereferencing an undeclared variable.
[thirdparty/gcc.git] / gcc / m2 / mc-boot-ch / Glibc.c
CommitLineData
1eee94d3
GM
1/* Glibc.c provides access to some libc functions.
2
83ffe9cd 3Copyright (C) 2016-2023 Free Software Foundation, Inc.
1eee94d3
GM
4Contributed by Gaius Mulley <gaius@glam.ac.uk>.
5
6This file is part of GNU Modula-2.
7
8GNU Modula-2 is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3, or (at your option)
11any later version.
12
13GNU Modula-2 is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GNU Modula-2; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
21
22#include "config.h"
23#include "system.h"
24
25#if defined(__cplusplus)
26#define EXTERN extern "C"
27#else
28#define EXTERN
29#endif
30
31EXTERN
32int
33libc_read (int fd, void *a, int nbytes)
34{
35 return read (fd, a, nbytes);
36}
37
38EXTERN
39int
40libc_write (int fd, void *a, int nbytes)
41{
42 return write (fd, a, nbytes);
43}
44
45EXTERN
46int
47libc_close (int fd)
48{
49 return close (fd);
50}
51
52EXTERN
53int
54libc_exit (int code)
55{
56 exit (code);
57}
58
59EXTERN
60void
61libc_perror (char *s)
62{
63 perror (s);
64}
65
66EXTERN
67int
68libc_abort ()
69{
70 abort ();
71}
72
73EXTERN
74int
75libc_strlen (char *s)
76{
77 return strlen (s);
78}
79
80EXTERN
81int
82libc_printf (char *_format, unsigned int _format_high, ...)
83{
84 va_list arg;
85 int done;
86 char format[_format_high + 1];
87 unsigned int i = 0;
88 unsigned int j = 0;
89 char *c;
90
91 do
92 {
93 c = index (&_format[i], '\\');
94 if (c == NULL)
95 strcpy (&format[j], &_format[i]);
96 else
97 {
98 memcpy (&format[j], &_format[i], (c - _format) - i);
99 i = c - _format;
100 j += c - _format;
101 if (_format[i + 1] == 'n')
102 format[j] = '\n';
103 else
104 format[j] = _format[i + 1];
105 j++;
106 i += 2;
107 }
108 }
109 while (c != NULL);
110
111 va_start (arg, _format_high);
112 done = vfprintf (stdout, format, arg);
113 va_end (arg);
114
115 return done;
116}
117
118EXTERN
119void *
120libc_malloc (unsigned int size)
121{
122 return malloc (size);
123}
124
125EXTERN
126void
127libc_free (void *p)
128{
129 free (p);
130}
131
132EXTERN
133char *
134libc_strcpy (char *dest, char *src)
135{
136 return strcpy (dest, src);
137}
138
139EXTERN
140char *
141libc_strncpy (char *dest, char *src, int n)
142{
143 return strncpy (dest, src, n);
144}
145
146EXTERN
147int
148libc_unlink (char *p)
149{
150 return unlink (p);
151}
152
153EXTERN
154int
155libc_system (char *command)
156{
157 return system (command);
158}
159
160EXTERN
161void *
162libc_memcpy (void *dest, void *src, int n)
163{
164 return memcpy (dest, src, n);
165}
166
167EXTERN
168char *
169libc_getenv (char *name)
170{
171 return getenv (name);
172}
173
174EXTERN
175int
176libc_putenv (char *name)
177{
178 return putenv (name);
179}
180
181EXTERN
182int
183libc_creat (char *p, mode_t mode)
184{
185 return creat (p, mode);
186}
187
188EXTERN
189int
190libc_open (char *p, int flags, mode_t mode)
191{
192 return open (p, flags, mode);
193}
194
195EXTERN
196off_t
197libc_lseek (int fd, off_t offset, int whence)
198{
199 return lseek (fd, offset, whence);
200}
201
202EXTERN
203void *
204libc_realloc (void *ptr, size_t size)
205{
206 return realloc (ptr, size);
207}
208
209EXTERN
210void *
211libc_memset (void *s, int c, size_t n)
212{
213 return memset (s, c, n);
214}
215
216EXTERN
217void *
218libc_memmove (void *dest, void *src, size_t n)
219{
220 return memmove (dest, src, n);
221}
222
223EXTERN
224int
225libc_getpid (void)
226{
227 return getpid ();
228}
229
230EXTERN
231unsigned int
232libc_sleep (unsigned int s)
233{
234 return sleep (s);
235}
236
237EXTERN
238int
239libc_atexit (void (*function) (void))
240{
241 return atexit (function);
242}