[e16e8f2] | 1 | /* |
---|
| 2 | * stdlib.h |
---|
| 3 | */ |
---|
| 4 | |
---|
| 5 | #ifndef _STDLIB_H |
---|
| 6 | #define _STDLIB_H |
---|
| 7 | |
---|
| 8 | #include <klibc/extern.h> |
---|
| 9 | #include <klibc/compiler.h> |
---|
| 10 | #include <stddef.h> |
---|
| 11 | |
---|
| 12 | #define EXIT_FAILURE 1 |
---|
| 13 | #define EXIT_SUCCESS 0 |
---|
| 14 | |
---|
| 15 | __extern __noreturn abort(void); |
---|
| 16 | static __inline__ int abs(int __n) |
---|
| 17 | { |
---|
| 18 | return (__n < 0) ? -__n : __n; |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | __extern int atexit(void (*)(void)); |
---|
| 22 | __extern int on_exit(void (*)(int, void *), void *); |
---|
| 23 | __extern int atoi(const char *); |
---|
| 24 | __extern long atol(const char *); |
---|
| 25 | __extern long long atoll(const char *); |
---|
| 26 | __extern __noreturn exit(int); |
---|
| 27 | __extern __noreturn _Exit(int); |
---|
| 28 | __extern void free(void *); |
---|
| 29 | static __inline__ long labs(long __n) |
---|
| 30 | { |
---|
| 31 | return (__n < 0L) ? -__n : __n; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | static __inline__ long long llabs(long long __n) |
---|
| 35 | { |
---|
| 36 | return (__n < 0LL) ? -__n : __n; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | __extern __mallocfunc void *malloc(size_t); |
---|
| 40 | __extern __mallocfunc void *zalloc(size_t); |
---|
| 41 | __extern __mallocfunc void *calloc(size_t, size_t); |
---|
| 42 | __extern __mallocfunc void *realloc(void *, size_t); |
---|
| 43 | __extern long strtol(const char *, char **, int); |
---|
| 44 | __extern long long strtoll(const char *, char **, int); |
---|
| 45 | __extern unsigned long strtoul(const char *, char **, int); |
---|
| 46 | __extern unsigned long long strtoull(const char *, char **, int); |
---|
| 47 | |
---|
| 48 | static __inline__ char *getenv(const char *name) |
---|
| 49 | { |
---|
| 50 | (void)name; |
---|
| 51 | return NULL; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | __extern int putenv(const char *); |
---|
| 55 | __extern int setenv(const char *, const char *, int); |
---|
| 56 | __extern int unsetenv(const char *); |
---|
| 57 | |
---|
| 58 | __extern void qsort(void *, size_t, size_t, |
---|
| 59 | int (*)(const void *, const void *)); |
---|
| 60 | |
---|
| 61 | __extern long jrand48(unsigned short *); |
---|
| 62 | __extern long mrand48(void); |
---|
| 63 | __extern long nrand48(unsigned short *); |
---|
| 64 | __extern long lrand48(void); |
---|
| 65 | __extern unsigned short *seed48(const unsigned short *); |
---|
| 66 | __extern void srand48(long); |
---|
| 67 | |
---|
| 68 | #define RAND_MAX 0x7fffffff |
---|
| 69 | static __inline__ int rand(void) |
---|
| 70 | { |
---|
| 71 | return (int)lrand48(); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | static __inline__ void srand(unsigned int __s) |
---|
| 75 | { |
---|
| 76 | srand48(__s); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | static __inline__ long random(void) |
---|
| 80 | { |
---|
| 81 | return lrand48(); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | static __inline__ void srandom(unsigned int __s) |
---|
| 85 | { |
---|
| 86 | srand48(__s); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | /* Basic PTY functions. These only work if devpts is mounted! */ |
---|
| 90 | |
---|
| 91 | __extern int unlockpt(int); |
---|
| 92 | __extern char *ptsname(int); |
---|
| 93 | __extern int getpt(void); |
---|
| 94 | |
---|
| 95 | static __inline__ int grantpt(int __fd) |
---|
| 96 | { |
---|
| 97 | (void)__fd; |
---|
| 98 | return 0; /* devpts does this all for us! */ |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | #endif /* _STDLIB_H */ |
---|