]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/m2/mc-boot-ch/Glibc.c
Update copyright years.
[thirdparty/gcc.git] / gcc / m2 / mc-boot-ch / Glibc.c
CommitLineData
1eee94d3
GM
1/* Glibc.c provides access to some libc functions.
2
a945c346 3Copyright (C) 2016-2024 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
2bf9bbfe
GM
80EXTERN
81time_t
82libc_time (time_t *buf)
83{
84 return time (buf);
85}
86
87EXTERN
88void *
89libc_localtime (time_t *epochtime)
90{
91 return localtime (epochtime);
92}
93
1eee94d3
GM
94EXTERN
95int
96libc_printf (char *_format, unsigned int _format_high, ...)
97{
98 va_list arg;
99 int done;
100 char format[_format_high + 1];
101 unsigned int i = 0;
102 unsigned int j = 0;
103 char *c;
104
105 do
106 {
107 c = index (&_format[i], '\\');
108 if (c == NULL)
109 strcpy (&format[j], &_format[i]);
110 else
111 {
112 memcpy (&format[j], &_format[i], (c - _format) - i);
113 i = c - _format;
114 j += c - _format;
115 if (_format[i + 1] == 'n')
116 format[j] = '\n';
117 else
118 format[j] = _format[i + 1];
119 j++;
120 i += 2;
121 }
122 }
123 while (c != NULL);
124
125 va_start (arg, _format_high);
126 done = vfprintf (stdout, format, arg);
127 va_end (arg);
05652ac4
GM
128 return done;
129}
130
131EXTERN
132int
133libc_snprintf (char *dest, size_t length, char *_format, unsigned int _format_high, ...)
134{
135 va_list arg;
136 int done;
137 char format[_format_high + 1];
138 unsigned int i = 0;
139 unsigned int j = 0;
140 char *c;
141
142 do
143 {
144 c = index (&_format[i], '\\');
145 if (c == NULL)
146 strcpy (&format[j], &_format[i]);
147 else
148 {
149 memcpy (&format[j], &_format[i], (c - _format) - i);
150 i = c - _format;
151 j += c - _format;
152 if (_format[i + 1] == 'n')
153 format[j] = '\n';
154 else
155 format[j] = _format[i + 1];
156 j++;
157 i += 2;
158 }
159 }
160 while (c != NULL);
1eee94d3 161
05652ac4
GM
162 va_start (arg, _format_high);
163 done = vsnprintf (dest, length, format, arg);
164 va_end (arg);
1eee94d3
GM
165 return done;
166}
167
168EXTERN
169void *
170libc_malloc (unsigned int size)
171{
172 return malloc (size);
173}
174
175EXTERN
176void
177libc_free (void *p)
178{
179 free (p);
180}
181
182EXTERN
183char *
184libc_strcpy (char *dest, char *src)
185{
186 return strcpy (dest, src);
187}
188
189EXTERN
190char *
191libc_strncpy (char *dest, char *src, int n)
192{
193 return strncpy (dest, src, n);
194}
195
196EXTERN
197int
198libc_unlink (char *p)
199{
200 return unlink (p);
201}
202
203EXTERN
204int
205libc_system (char *command)
206{
207 return system (command);
208}
209
210EXTERN
211void *
212libc_memcpy (void *dest, void *src, int n)
213{
214 return memcpy (dest, src, n);
215}
216
217EXTERN
218char *
219libc_getenv (char *name)
220{
221 return getenv (name);
222}
223
224EXTERN
225int
226libc_putenv (char *name)
227{
228 return putenv (name);
229}
230
231EXTERN
232int
233libc_creat (char *p, mode_t mode)
234{
235 return creat (p, mode);
236}
237
238EXTERN
239int
240libc_open (char *p, int flags, mode_t mode)
241{
242 return open (p, flags, mode);
243}
244
245EXTERN
246off_t
247libc_lseek (int fd, off_t offset, int whence)
248{
249 return lseek (fd, offset, whence);
250}
251
252EXTERN
253void *
254libc_realloc (void *ptr, size_t size)
255{
256 return realloc (ptr, size);
257}
258
259EXTERN
260void *
261libc_memset (void *s, int c, size_t n)
262{
263 return memset (s, c, n);
264}
265
266EXTERN
267void *
268libc_memmove (void *dest, void *src, size_t n)
269{
270 return memmove (dest, src, n);
271}
272
273EXTERN
274int
275libc_getpid (void)
276{
277 return getpid ();
278}
279
280EXTERN
281unsigned int
282libc_sleep (unsigned int s)
283{
284 return sleep (s);
285}
286
287EXTERN
288int
289libc_atexit (void (*function) (void))
290{
291 return atexit (function);
292}