The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | #ifndef _STDLIB_H_ |
| 29 | #define _STDLIB_H_ |
| 30 | |
| 31 | #include <sys/cdefs.h> |
| 32 | #include <stddef.h> |
| 33 | #include <string.h> |
| 34 | #include <alloca.h> |
| 35 | #include <strings.h> |
| 36 | #include <memory.h> |
| 37 | |
| 38 | __BEGIN_DECLS |
| 39 | |
| 40 | #define EXIT_FAILURE 1 |
| 41 | #define EXIT_SUCCESS 0 |
| 42 | |
| 43 | extern __noreturn void exit(int); |
| 44 | extern __noreturn void abort(void); |
| 45 | extern int atexit(void (*)(void)); |
| 46 | extern int on_exit(void (*)(int, void *), void *); |
| 47 | |
| 48 | extern char *getenv(const char *); |
| 49 | extern int putenv(const char *); |
| 50 | extern int setenv(const char *, const char *, int); |
| 51 | extern int unsetenv(const char *); |
| 52 | extern int clearenv(void); |
| 53 | |
| 54 | extern char *mktemp (char *); |
| 55 | extern int mkstemp (char *); |
| 56 | |
| 57 | extern long strtol(const char *, char **, int); |
| 58 | extern long long strtoll(const char *, char **, int); |
| 59 | extern unsigned long strtoul(const char *, char **, int); |
| 60 | extern unsigned long long strtoull(const char *, char **, int); |
| 61 | extern double strtod(const char *nptr, char **endptr); |
| 62 | |
| 63 | static __inline__ float strtof(const char *nptr, char **endptr) |
| 64 | { |
| 65 | return (float)strtod(nptr, endptr); |
| 66 | } |
| 67 | |
| 68 | extern int atoi(const char *); |
| 69 | extern long atol(const char *); |
| 70 | extern long long atoll(const char *); |
| 71 | |
| 72 | static __inline__ double atof(const char *nptr) |
| 73 | { |
| 74 | return (strtod(nptr, NULL)); |
| 75 | } |
| 76 | |
| 77 | static __inline__ int abs(int __n) { |
| 78 | return (__n < 0) ? -__n : __n; |
| 79 | } |
| 80 | |
| 81 | static __inline__ long labs(long __n) { |
| 82 | return (__n < 0L) ? -__n : __n; |
| 83 | } |
| 84 | |
| 85 | static __inline__ long long llabs(long long __n) { |
| 86 | return (__n < 0LL) ? -__n : __n; |
| 87 | } |
| 88 | |
| 89 | extern char * realpath(const char *path, char *resolved); |
| 90 | extern int system(const char * string); |
| 91 | |
| 92 | extern void * bsearch(const void *key, const void *base0, |
| 93 | size_t nmemb, size_t size, |
| 94 | int (*compar)(const void *, const void *)); |
| 95 | |
| 96 | extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); |
| 97 | |
| 98 | extern long jrand48(unsigned short *); |
| 99 | extern long mrand48(void); |
| 100 | extern long nrand48(unsigned short *); |
| 101 | extern long lrand48(void); |
| 102 | extern unsigned short *seed48(unsigned short*); |
| 103 | extern void srand48(long); |
| 104 | extern unsigned int arc4random(void); |
| 105 | extern void arc4random_stir(void); |
| 106 | extern void arc4random_addrandom(unsigned char *, int); |
| 107 | |
| 108 | #define RAND_MAX 0x7fffffff |
| 109 | static __inline__ int rand(void) { |
| 110 | return (int)lrand48(); |
| 111 | } |
| 112 | static __inline__ void srand(unsigned int __s) { |
| 113 | srand48(__s); |
| 114 | } |
| 115 | static __inline__ long random(void) |
| 116 | { |
| 117 | return lrand48(); |
| 118 | } |
| 119 | static __inline__ void srandom(unsigned int __s) |
| 120 | { |
| 121 | srand48(__s); |
| 122 | } |
| 123 | |
| 124 | /* Basic PTY functions. These only work if devpts is mounted! */ |
| 125 | |
| 126 | extern int unlockpt(int); |
| 127 | extern char* ptsname(int); |
| 128 | extern char* ptsname_r(int, char*, size_t); |
| 129 | extern int getpt(void); |
| 130 | |
| 131 | static __inline__ int grantpt(int __fd) |
| 132 | { |
| 133 | (void)__fd; |
| 134 | return 0; /* devpts does this all for us! */ |
| 135 | } |
| 136 | |
| 137 | __END_DECLS |
| 138 | |
| 139 | #endif /* _STDLIB_H_ */ |