]> git.ozlabs.org Git - yaboot.git/blob - lib/nonstd.c
fs_of: Increase the LOAD_BUFFER_SIZE to 32MB
[yaboot.git] / lib / nonstd.c
1 /*
2  *  nonstd.c - A collection of trivial wrappers to allow typical libraries
3  *             to work within the yaboot environment.
4  *
5  *  Copyright 2011 Tony Breeds, IBM Corporation
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20  */
21
22 #include "ctype.h"
23 #include "types.h"
24 #include "stddef.h"
25 #include "stdlib.h"
26 #include "string.h"
27 #include "ctype.h"
28 #include "prom.h"
29 #include "nonstd.h"
30 #include "debug.h"
31
32 #define __unused        __attribute__((unused))
33
34 static FILE _stdout;
35 static FILE _stderr;
36 FILE *stdout = &_stdout;
37 FILE *stderr = &_stderr;
38
39 static int fake_errno;
40
41 int * __errno_location(void)
42 {
43         DEBUG_F("Stub function called");
44         return &fake_errno;
45 }
46
47 uid_t geteuid(void)
48 {
49         DEBUG_F("Stub function called");
50         return 0;
51 }
52
53 uid_t getuid(void)
54 {
55         DEBUG_F("Stub function called");
56         return 0;
57 }
58
59 pid_t getpid(void)
60 {
61         DEBUG_F("Stub function called");
62         return 1;
63 }
64
65 /* selected by roll of a six sided dice ... that's random right? */
66 int rand(void)
67 {
68         DEBUG_F("Stub function called");
69         return 4;
70 }
71
72 void srand(unsigned int seed __unused)
73 {
74         DEBUG_F("Stub function called");
75 }
76
77 long int random(void)
78 {
79         DEBUG_F("Stub function called");
80         return 4;
81 }
82
83 void srandom(unsigned int seed __unused)
84 {
85         DEBUG_F("Stub function called");
86 }
87
88 unsigned int sleep(unsigned int seconds)
89 {
90         prom_sleep(seconds);
91         return 0;
92 }
93
94 int stat(const char *path __unused, struct stat *buf __unused)
95 {
96         DEBUG_F("Stub function called");
97         return EACCES;
98 }
99
100 int stat64(const char *path __unused, struct stat *buf __unused)
101 {
102         DEBUG_F("Stub function called");
103         return EACCES;
104 }
105
106 int fstat(int fd __unused, struct stat *buf __unused)
107 {
108         DEBUG_F("Stub function called");
109         return EBADF;
110 }
111
112 int fstat64(int fd __unused, struct stat *buf __unused)
113 {
114         DEBUG_F("Stub function called");
115         return EBADF;
116 }
117
118 int __xstat64(int vers __unused, const char *name __unused,
119               struct stat64 *buf __unused)
120 {
121         DEBUG_F("Stub function called");
122         return EBADF;
123 }
124
125 int __fxstat64(int vers __unused, int fd __unused, struct stat64 *buf __unused)
126 {
127         DEBUG_F("Stub function called");
128         return EBADF;
129 }
130
131 int open(const char *pathname, int flags __unused, mode_t mode __unused)
132 {
133         return (int) prom_open((char *)pathname);
134 }
135
136 int open64(const char *pathname, int flags __unused, mode_t mode __unused)
137 {
138         return (int) prom_open((char *)pathname);
139 }
140
141 int __open64_2(const char *pathname, int flags __unused)
142 {
143         return (int) prom_open((char *)pathname);
144 }
145
146 off_t lseek(int fd __unused, off_t offset __unused, int whence __unused)
147 {
148         DEBUG_F("Stub function called");
149         return EBADF;
150 }
151
152 off64_t lseek64(int fd __unused, off64_t offset __unused, int whence __unused)
153 {
154         DEBUG_F("Stub function called");
155         return EBADF;
156 }
157
158 ssize_t read(int filedes, void *buf, size_t nbyte)
159 {
160         return prom_read((void *)filedes, buf, nbyte);
161 }
162
163 int close(int fd __unused)
164 {
165         prom_close((void *)fd);
166         return 0;
167 }
168
169 int gethostname(char *name __unused, size_t len __unused)
170 {
171         DEBUG_F("Stub function called");
172         return EPERM;
173 }
174
175 int gettimeofday(struct timeval *tv __unused, struct timezone *tz __unused)
176 {
177         DEBUG_F("Stub function called");
178         return EPERM;
179 }
180
181 int printf(const char *format, ...)
182 {
183         va_list ap;
184         va_start (ap, format);
185         prom_vfprintf (prom_stdout, format, ap);
186         va_end (ap);
187
188         return 0;
189 }
190
191 int fprintf(FILE *stream __unused, const char *format, ...)
192 {
193         va_list ap;
194         va_start (ap, format);
195         prom_vfprintf (prom_stdout, format, ap);
196         va_end (ap);
197
198         return 0;
199 }
200
201 int fputs(const char *s, FILE *stream __unused)
202 {
203         prom_printf("%s", s);
204
205         return 0;
206 }
207
208 int fflush(FILE *stream __unused)
209 {
210         DEBUG_F("Stub function called");
211         return 0;
212 }
213
214 char *getenv(const char *name __unused)
215 {
216         DEBUG_F("Stub function called");
217         return NULL;
218 }
219
220 int __printf_chk(int flag __unused, const char *format, ...)
221 {
222         va_list ap;
223         va_start (ap, format);
224         prom_vfprintf (prom_stdout, format, ap);
225         va_end (ap);
226
227         DEBUG_F("Stub function called");
228         return 0;
229 }
230
231 int __sprintf_chk(char *str __unused, int flag __unused,
232                   size_t strlen __unused, const char * format __unused, ...)
233 {
234         DEBUG_F("Stub function called");
235         return 0;
236
237 }
238
239 int __fprintf_chk(FILE *stream __unused, int flag __unused,
240                   const char *format, ...)
241 {
242         va_list ap;
243         va_start (ap, format);
244         prom_vfprintf (prom_stdout, format, ap);
245         va_end (ap);
246
247         return 0;
248 }
249
250 void *__memcpy_chk(void *dest, const void *src, size_t n,
251                    size_t destlen __unused)
252 {
253         DEBUG_F("Stub function called");
254         /* FIXME: We really could check that dest+destlen < src, to ensure
255          * we're not overwriting the src */
256         return memcpy(dest, src, n);
257 }
258
259 void perror(const char *s)
260 {
261         DEBUG_F("Stub function called");
262         prom_printf(s);
263 }
264
265 void exit(int status __unused)
266 {
267         prom_exit();
268         for(;;);
269 }
270
271 int ioctl(int d __unused, int request __unused, ...)
272 {
273         DEBUG_F("Stub function called");
274         return 0;
275 }
276
277 /* As we do not implement fopen() I think we're only going to get called
278  * with stdout and stderr.  If that's the case we degenerate to prom_write()
279  * on stdout */
280 size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
281 {
282         if ((stream == stdout) || (stream == stderr)) {
283                 DEBUG_F("Stub function called on known stream");
284                 prom_write(prom_stdout, (void *)ptr, size * nmemb);
285         } else {
286                 DEBUG_F("Stub function called on unknown stream");
287         }
288         return nmemb;
289 }
290
291 long sysconf(int name __unused)
292 {
293         DEBUG_F("Stub function called");
294         return -1;
295 }
296
297 int getpagesize(void)
298 {
299         DEBUG_F("Stub function called");
300         /* I think this is safe to assume */
301         return 4096;
302 }
303
304 void qsort(void *base __unused, size_t nmemb __unused, size_t size __unused,
305            int(*compar)(const void *, const void *))
306 {
307         DEBUG_F("Stub function called");
308         /* I'm quite nervous about not implementing this.  Could we end up with
309          * disk corruption.  Couldn't we? */
310 }
311
312 /* FIXME: I'd like to call prom_write here, but we can't ber certain that
313  *        we'll have "text" so just move along nothing to see here
314  */
315 ssize_t write(int fd, const void *buf, size_t count)
316 {
317         DEBUG_F("Stub function called");
318         return 0;
319 }
320
321 int fallocate(int fd __unused, int mode __unused, off_t offset __unused,
322               off_t len __unused)
323 {
324         DEBUG_F("Stub function called");
325         return 0;
326 }
327
328 unsigned long long int strtoull(const char *nptr, char **endptr, int base)
329 {
330         return simple_strtoull(nptr, endptr, base);
331 }
332
333 int fsync(int fd __unused)
334 {
335         DEBUG_F("Stub function called");
336         return 0;
337 }
338
339 /* Return EFAULT here as it's too hard in yaboot to know the size of struct
340  * utsname.  If we don't touch it and return 0 bad things might happen.
341  * Lets hope the caller handles failure
342  */
343 int uname(struct utsname *buf __unused)
344 {
345         DEBUG_F("Stub function called");
346         return EFAULT;
347 }
348
349 int getrlimit(int resource __unused, struct rlimit *rlim __unused)
350 {
351         DEBUG_F("Stub function called");
352         return 0;
353 }
354
355 int setrlimit(int resource __unused, const struct rlimit *rlim __unused)
356 {
357         DEBUG_F("Stub function called");
358         return 0;
359 }
360
361 void __stack_chk_fail(void)
362 {
363         DEBUG_F("Stub function called");
364 }