2 * nonstd.c - A collection of trivial wrappers to allow typical libraries
3 * to work within the yaboot environment.
5 * Copyright 2011 Tony Breeds, IBM Corporation
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.
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.
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.
32 #define __unused __attribute__((unused))
36 FILE *stdout = &_stdout;
37 FILE *stderr = &_stderr;
39 static int fake_errno;
41 int * __errno_location(void)
43 DEBUG_F("Stub function called");
49 DEBUG_F("Stub function called");
55 DEBUG_F("Stub function called");
61 DEBUG_F("Stub function called");
65 /* selected by roll of a six sided dice ... that's random right? */
68 DEBUG_F("Stub function called");
72 void srand(unsigned int seed __unused)
74 DEBUG_F("Stub function called");
79 DEBUG_F("Stub function called");
83 void srandom(unsigned int seed __unused)
85 DEBUG_F("Stub function called");
88 unsigned int sleep(unsigned int seconds)
94 int stat(const char *path __unused, struct stat *buf __unused)
96 DEBUG_F("Stub function called");
100 int stat64(const char *path __unused, struct stat *buf __unused)
102 DEBUG_F("Stub function called");
106 int fstat(int fd __unused, struct stat *buf __unused)
108 DEBUG_F("Stub function called");
112 int fstat64(int fd __unused, struct stat *buf __unused)
114 DEBUG_F("Stub function called");
118 int __xstat64(int vers __unused, const char *name __unused,
119 struct stat64 *buf __unused)
121 DEBUG_F("Stub function called");
125 int __fxstat64(int vers __unused, int fd __unused, struct stat64 *buf __unused)
127 DEBUG_F("Stub function called");
131 int open(const char *pathname, int flags __unused, mode_t mode __unused)
133 return (int) prom_open((char *)pathname);
136 int open64(const char *pathname, int flags __unused, mode_t mode __unused)
138 return (int) prom_open((char *)pathname);
141 int __open64_2(const char *pathname, int flags __unused)
143 return (int) prom_open((char *)pathname);
146 off_t lseek(int fd __unused, off_t offset __unused, int whence __unused)
148 DEBUG_F("Stub function called");
152 off64_t lseek64(int fd __unused, off64_t offset __unused, int whence __unused)
154 DEBUG_F("Stub function called");
158 ssize_t read(int filedes, void *buf, size_t nbyte)
160 return prom_read((void *)filedes, buf, nbyte);
163 int close(int fd __unused)
165 prom_close((void *)fd);
169 int gethostname(char *name __unused, size_t len __unused)
171 DEBUG_F("Stub function called");
175 int gettimeofday(struct timeval *tv __unused, struct timezone *tz __unused)
177 DEBUG_F("Stub function called");
181 int printf(const char *format, ...)
184 va_start (ap, format);
185 prom_vfprintf (prom_stdout, format, ap);
191 int fprintf(FILE *stream __unused, const char *format, ...)
194 va_start (ap, format);
195 prom_vfprintf (prom_stdout, format, ap);
201 int fputs(const char *s, FILE *stream __unused)
203 prom_printf("%s", s);
208 int fflush(FILE *stream __unused)
210 DEBUG_F("Stub function called");
214 char *getenv(const char *name __unused)
216 DEBUG_F("Stub function called");
220 int __printf_chk(int flag __unused, const char *format, ...)
223 va_start (ap, format);
224 prom_vfprintf (prom_stdout, format, ap);
227 DEBUG_F("Stub function called");
231 int __sprintf_chk(char *str __unused, int flag __unused,
232 size_t strlen __unused, const char * format __unused, ...)
234 DEBUG_F("Stub function called");
239 int __fprintf_chk(FILE *stream __unused, int flag __unused,
240 const char *format, ...)
243 va_start (ap, format);
244 prom_vfprintf (prom_stdout, format, ap);
250 void *__memcpy_chk(void *dest, const void *src, size_t n,
251 size_t destlen __unused)
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);
259 void perror(const char *s)
261 DEBUG_F("Stub function called");
265 void exit(int status __unused)
271 int ioctl(int d __unused, int request __unused, ...)
273 DEBUG_F("Stub function called");
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()
280 size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
282 if ((stream == stdout) || (stream == stderr)) {
283 DEBUG_F("Stub function called on known stream");
284 prom_write(prom_stdout, (void *)ptr, size * nmemb);
286 DEBUG_F("Stub function called on unknown stream");
291 long sysconf(int name __unused)
293 DEBUG_F("Stub function called");
297 int getpagesize(void)
299 DEBUG_F("Stub function called");
300 /* I think this is safe to assume */
304 void qsort(void *base __unused, size_t nmemb __unused, size_t size __unused,
305 int(*compar)(const void *, const void *))
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? */
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
315 ssize_t write(int fd, const void *buf, size_t count)
317 DEBUG_F("Stub function called");
321 int fallocate(int fd __unused, int mode __unused, off_t offset __unused,
324 DEBUG_F("Stub function called");
328 unsigned long long int strtoull(const char *nptr, char **endptr, int base)
330 return simple_strtoull(nptr, endptr, base);
333 int fsync(int fd __unused)
335 DEBUG_F("Stub function called");
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
343 int uname(struct utsname *buf __unused)
345 DEBUG_F("Stub function called");
349 int getrlimit(int resource __unused, struct rlimit *rlim __unused)
351 DEBUG_F("Stub function called");
355 int setrlimit(int resource __unused, const struct rlimit *rlim __unused)
357 DEBUG_F("Stub function called");
361 void __stack_chk_fail(void)
363 DEBUG_F("Stub function called");