| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [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 |  */ | 
| Elliott Hughes | 76f8916 | 2015-01-26 13:34:58 -0800 | [diff] [blame] | 28 |  | 
 | 29 | #ifndef _STDLIB_H | 
 | 30 | #define _STDLIB_H | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 31 |  | 
 | 32 | #include <sys/cdefs.h> | 
| Elliott Hughes | 76f8916 | 2015-01-26 13:34:58 -0800 | [diff] [blame] | 33 | #include <xlocale.h> | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 34 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 35 | #include <alloca.h> | 
| Elliott Hughes | 76f8916 | 2015-01-26 13:34:58 -0800 | [diff] [blame] | 36 | #include <malloc.h> | 
 | 37 | #include <stddef.h> | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 38 |  | 
 | 39 | __BEGIN_DECLS | 
 | 40 |  | 
 | 41 | #define EXIT_FAILURE 1 | 
 | 42 | #define EXIT_SUCCESS 0 | 
 | 43 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 44 | __noreturn void abort(void); | 
 | 45 | __noreturn void exit(int); | 
 | 46 | __noreturn void _Exit(int) __INTRODUCED_IN(21); | 
 | 47 | int atexit(void (*)(void)); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 48 |  | 
| Josh Gao | 95fa26e | 2016-06-10 16:33:05 -0700 | [diff] [blame] | 49 | int at_quick_exit(void (*)(void)) __INTRODUCED_IN(21); | 
 | 50 | void quick_exit(int) __noreturn __INTRODUCED_IN(21); | 
| Dan Albert | b8425c5 | 2014-04-29 17:49:06 -0700 | [diff] [blame] | 51 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 52 | char* getenv(const char*); | 
 | 53 | int putenv(char*); | 
 | 54 | int setenv(const char*, const char*, int); | 
 | 55 | int unsetenv(const char*); | 
 | 56 | int clearenv(void); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 57 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 58 | char* mkdtemp(char*); | 
 | 59 | char* mktemp(char*) __attribute__((deprecated("mktemp is unsafe, use mkstemp or tmpfile instead"))); | 
| Elliott Hughes | 31165ed | 2014-09-23 17:34:29 -0700 | [diff] [blame] | 60 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 61 | int mkostemp64(char*, int) __INTRODUCED_IN(23); | 
 | 62 | int mkostemp(char*, int) __INTRODUCED_IN(23); | 
 | 63 | int mkostemps64(char*, int, int) __INTRODUCED_IN(23); | 
 | 64 | int mkostemps(char*, int, int) __INTRODUCED_IN(23); | 
 | 65 | int mkstemp64(char*) __INTRODUCED_IN(21); | 
 | 66 | int mkstemp(char*); | 
 | 67 | int mkstemps64(char*, int) __INTRODUCED_IN(23); | 
 | 68 | int mkstemps(char*, int); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 69 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 70 | long strtol(const char *, char **, int); | 
 | 71 | long long strtoll(const char *, char **, int); | 
 | 72 | unsigned long strtoul(const char *, char **, int); | 
 | 73 | unsigned long long strtoull(const char *, char **, int); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 74 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 75 | int posix_memalign(void** memptr, size_t alignment, size_t size) __INTRODUCED_IN(16); | 
| Ken Sumrall | 85aad90 | 2011-12-14 20:50:01 -0800 | [diff] [blame] | 76 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 77 | double strtod(const char*, char**); | 
 | 78 | long double strtold(const char*, char**) __INTRODUCED_IN(21); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 79 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 80 | long double strtold_l(const char*, char**, locale_t) __INTRODUCED_IN(21); | 
 | 81 | long long strtoll_l(const char*, char**, int, locale_t) __INTRODUCED_IN(21); | 
 | 82 | unsigned long long strtoull_l(const char*, char**, int, locale_t) __INTRODUCED_IN(21); | 
| Dan Albert | dfb5ce4 | 2014-07-09 22:51:34 +0000 | [diff] [blame] | 83 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 84 | int atoi(const char*) __purefunc; | 
 | 85 | long atol(const char*) __purefunc; | 
 | 86 | long long atoll(const char*) __purefunc; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 87 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 88 | char* realpath(const char* path, char* resolved); | 
 | 89 | int system(const char* string); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 90 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 91 | void* bsearch(const void* key, const void* base0, size_t nmemb, size_t size, | 
 | 92 |               int (*compar)(const void*, const void*)); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 93 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 94 | void qsort(void*, size_t, size_t, int (*)(const void*, const void*)); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 95 |  | 
| Yabin Cui | a39f939 | 2014-10-28 12:04:02 -0700 | [diff] [blame] | 96 | uint32_t arc4random(void); | 
 | 97 | uint32_t arc4random_uniform(uint32_t); | 
| Elliott Hughes | 0468feb | 2014-06-20 22:49:20 -0700 | [diff] [blame] | 98 | void arc4random_buf(void*, size_t); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 99 |  | 
 | 100 | #define RAND_MAX 0x7fffffff | 
| Elliott Hughes | a0beeea | 2014-06-12 11:48:04 -0700 | [diff] [blame] | 101 |  | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 102 | int rand_r(unsigned int*) __INTRODUCED_IN(21); | 
| Elliott Hughes | a0beeea | 2014-06-12 11:48:04 -0700 | [diff] [blame] | 103 |  | 
| Elliott Hughes | 274afe8 | 2014-11-06 12:40:08 -0800 | [diff] [blame] | 104 | double drand48(void); | 
 | 105 | double erand48(unsigned short[3]); | 
 | 106 | long jrand48(unsigned short[3]); | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 107 | void lcong48(unsigned short[7]) __INTRODUCED_IN(23); | 
| Elliott Hughes | 274afe8 | 2014-11-06 12:40:08 -0800 | [diff] [blame] | 108 | long lrand48(void); | 
 | 109 | long mrand48(void); | 
 | 110 | long nrand48(unsigned short[3]); | 
 | 111 | unsigned short* seed48(unsigned short[3]); | 
 | 112 | void srand48(long); | 
 | 113 |  | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 114 | char* initstate(unsigned int, char*, size_t) __INTRODUCED_IN(21); | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 115 | char* setstate(char*) __INTRODUCED_IN(21); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 116 |  | 
| Elliott Hughes | 4916706 | 2014-07-25 17:24:00 -0700 | [diff] [blame] | 117 | int getpt(void); | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 118 | int posix_openpt(int) __INTRODUCED_IN(21); | 
| Elliott Hughes | a381fe8 | 2014-12-09 20:30:23 -0800 | [diff] [blame] | 119 | char* ptsname(int); | 
| Elliott Hughes | 4916706 | 2014-07-25 17:24:00 -0700 | [diff] [blame] | 120 | int ptsname_r(int, char*, size_t); | 
 | 121 | int unlockpt(int); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 122 |  | 
| Josh Gao | 34c599a | 2016-04-29 13:45:25 -0700 | [diff] [blame] | 123 | int getsubopt(char**, char* const*, char**) __INTRODUCED_IN_FUTURE; | 
| Elliott Hughes | df143f8 | 2016-04-04 17:34:04 -0700 | [diff] [blame] | 124 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 125 | typedef struct { | 
 | 126 |     int  quot; | 
 | 127 |     int  rem; | 
 | 128 | } div_t; | 
 | 129 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 130 | div_t div(int, int) __pure2; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 131 |  | 
 | 132 | typedef struct { | 
 | 133 |     long int  quot; | 
 | 134 |     long int  rem; | 
 | 135 | } ldiv_t; | 
 | 136 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 137 | ldiv_t ldiv(long, long) __pure2; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 138 |  | 
 | 139 | typedef struct { | 
 | 140 |     long long int  quot; | 
 | 141 |     long long int  rem; | 
 | 142 | } lldiv_t; | 
 | 143 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 144 | lldiv_t lldiv(long long, long long) __pure2; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 145 |  | 
| Elliott Hughes | 692207e | 2014-02-28 16:23:27 -0800 | [diff] [blame] | 146 | /* BSD compatibility. */ | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 147 | const char* getprogname(void) __INTRODUCED_IN(21); | 
 | 148 | void setprogname(const char*) __INTRODUCED_IN(21); | 
| Elliott Hughes | 692207e | 2014-02-28 16:23:27 -0800 | [diff] [blame] | 149 |  | 
| Josh Gao | 34c599a | 2016-04-29 13:45:25 -0700 | [diff] [blame] | 150 | int mblen(const char*, size_t) __INTRODUCED_IN_FUTURE; | 
| Elliott Hughes | 6f6f905 | 2016-04-28 14:54:52 -0700 | [diff] [blame] | 151 | size_t mbstowcs(wchar_t*, const char*, size_t); | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 152 | int mbtowc(wchar_t*, const char*, size_t) __INTRODUCED_IN(21); | 
 | 153 | int wctomb(char*, wchar_t) __INTRODUCED_IN(21); | 
| Elliott Hughes | 6f6f905 | 2016-04-28 14:54:52 -0700 | [diff] [blame] | 154 | size_t wcstombs(char*, const wchar_t*, size_t); | 
| David 'Digit' Turner | bb5581a | 2010-10-09 17:56:55 +0200 | [diff] [blame] | 155 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 156 | size_t __ctype_get_mb_cur_max(void) __INTRODUCED_IN(21); | 
| Dan Albert | 224ff04 | 2014-08-14 13:56:51 -0700 | [diff] [blame] | 157 | #define MB_CUR_MAX __ctype_get_mb_cur_max() | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 158 |  | 
| Daniel Micay | 3244d9f | 2015-04-18 13:04:19 -0400 | [diff] [blame] | 159 | #if defined(__BIONIC_FORTIFY) | 
 | 160 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 161 | char* __realpath_real(const char*, char*) __RENAME(realpath); | 
| Daniel Micay | 3244d9f | 2015-04-18 13:04:19 -0400 | [diff] [blame] | 162 | __errordecl(__realpath_size_error, "realpath output parameter must be NULL or a >= PATH_MAX bytes buffer"); | 
 | 163 |  | 
 | 164 | #if !defined(__clang__) | 
 | 165 | __BIONIC_FORTIFY_INLINE | 
 | 166 | char* realpath(const char* path, char* resolved) { | 
 | 167 |     size_t bos = __bos(resolved); | 
 | 168 |  | 
 | 169 |     /* PATH_MAX is unavailable without polluting the namespace, but it's always 4096 on Linux */ | 
 | 170 |     if (bos != __BIONIC_FORTIFY_UNKNOWN_SIZE && bos < 4096) { | 
 | 171 |         __realpath_size_error(); | 
 | 172 |     } | 
 | 173 |  | 
 | 174 |     return __realpath_real(path, resolved); | 
 | 175 | } | 
 | 176 | #endif | 
 | 177 |  | 
 | 178 | #endif /* defined(__BIONIC_FORTIFY) */ | 
 | 179 |  | 
| Josh Gao | 8778d64 | 2016-07-22 15:26:36 -0700 | [diff] [blame] | 180 | #if __ANDROID_API__ >= 21 | 
| Josh Gao | b6a4a4c | 2016-07-26 16:34:40 -0700 | [diff] [blame] | 181 | float strtof(const char*, char**) __INTRODUCED_IN(21); | 
 | 182 | double atof(const char*) __INTRODUCED_IN(21); | 
 | 183 | int abs(int) __pure2 __INTRODUCED_IN(21); | 
 | 184 | long labs(long) __pure2 __INTRODUCED_IN(21); | 
 | 185 | long long llabs(long long) __pure2 __INTRODUCED_IN(21); | 
 | 186 | int rand(void) __INTRODUCED_IN(21); | 
 | 187 | void srand(unsigned int) __INTRODUCED_IN(21); | 
 | 188 | long random(void) __INTRODUCED_IN(21); | 
 | 189 | void srandom(unsigned int) __INTRODUCED_IN(21); | 
 | 190 | int grantpt(int) __INTRODUCED_IN(21); | 
| Josh Gao | 8778d64 | 2016-07-22 15:26:36 -0700 | [diff] [blame] | 191 | #else | 
 | 192 | // Implemented as static inlines before 21. | 
 | 193 | #endif | 
 | 194 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 195 | __END_DECLS | 
 | 196 |  | 
| Josh Gao | b8e1b705 | 2016-04-13 17:18:20 -0700 | [diff] [blame] | 197 | #include <android/legacy_stdlib_inlines.h> | 
 | 198 |  | 
| Elliott Hughes | 76f8916 | 2015-01-26 13:34:58 -0800 | [diff] [blame] | 199 | #endif /* _STDLIB_H */ |