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); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 45 | __noreturn void exit(int __status); |
Elliott Hughes | 2f94a29 | 2017-09-18 14:40:01 -0700 | [diff] [blame] | 46 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 47 | __noreturn void _Exit(int __status) __INTRODUCED_IN(21); |
Elliott Hughes | 2f94a29 | 2017-09-18 14:40:01 -0700 | [diff] [blame] | 48 | #else |
| 49 | __noreturn void _Exit(int) __RENAME(_exit); |
| 50 | #endif |
| 51 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 52 | int atexit(void (*__fn)(void)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 53 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 54 | int at_quick_exit(void (*__fn)(void)) __INTRODUCED_IN(21); |
| 55 | void quick_exit(int __status) __noreturn __INTRODUCED_IN(21); |
Dan Albert | b8425c5 | 2014-04-29 17:49:06 -0700 | [diff] [blame] | 56 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 57 | char* getenv(const char* __name); |
| 58 | int putenv(char* __assignment); |
| 59 | int setenv(const char* __name, const char* __value, int __overwrite); |
| 60 | int unsetenv(const char* __name); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 61 | int clearenv(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 62 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 63 | char* mkdtemp(char* __template); |
| 64 | char* mktemp(char* __template) __attribute__((deprecated("mktemp is unsafe, use mkstemp or tmpfile instead"))); |
Elliott Hughes | 31165ed | 2014-09-23 17:34:29 -0700 | [diff] [blame] | 65 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 66 | int mkostemp64(char* __template, int __flags) __INTRODUCED_IN(23); |
| 67 | int mkostemp(char* __template, int __flags) __INTRODUCED_IN(23); |
| 68 | int mkostemps64(char* __template, int __suffix_length, int __flags) __INTRODUCED_IN(23); |
| 69 | int mkostemps(char* __template, int __suffix_length, int __flags) __INTRODUCED_IN(23); |
| 70 | int mkstemp64(char* __template) __INTRODUCED_IN(21); |
| 71 | int mkstemp(char* __template); |
| 72 | int mkstemps64(char* __template, int __flags) __INTRODUCED_IN(23); |
| 73 | int mkstemps(char* __template, int __flags); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 74 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 75 | long strtol(const char* __s, char** __end_ptr, int __base); |
| 76 | long long strtoll(const char* __s, char** __end_ptr, int __base); |
| 77 | unsigned long strtoul(const char* __s, char** __end_ptr, int __base); |
| 78 | unsigned long long strtoull(const char* __s, char** __end_ptr, int __base); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 79 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 80 | 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] | 81 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 82 | double strtod(const char* __s, char** __end_ptr); |
Elliott Hughes | 50cda38 | 2017-09-14 15:30:08 -0700 | [diff] [blame] | 83 | long double strtold(const char* __s, char** __end_ptr) __RENAME_LDBL(strtod, 3, 21); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 84 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 85 | unsigned long strtoul_l(const char* __s, char** __end_ptr, int __base, locale_t __l) __INTRODUCED_IN(26); |
Dan Albert | dfb5ce4 | 2014-07-09 22:51:34 +0000 | [diff] [blame] | 86 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 87 | int atoi(const char* __s) __attribute_pure__; |
| 88 | long atol(const char* __s) __attribute_pure__; |
| 89 | long long atoll(const char* __s) __attribute_pure__; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 90 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 91 | char* realpath(const char* __path, char* __resolved); |
| 92 | int system(const char* __command); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 93 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 94 | void* bsearch(const void* __key, const void* __base, size_t __nmemb, size_t __size, int (*__comparator)(const void* __lhs, const void* __rhs)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 95 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 96 | void qsort(void* __base, size_t __nmemb, size_t __size, int (*__comparator)(const void* __lhs, const void* __rhs)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 97 | |
Yabin Cui | a39f939 | 2014-10-28 12:04:02 -0700 | [diff] [blame] | 98 | uint32_t arc4random(void); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 99 | uint32_t arc4random_uniform(uint32_t __upper_bound); |
| 100 | void arc4random_buf(void* __buf, size_t __n); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 101 | |
| 102 | #define RAND_MAX 0x7fffffff |
Elliott Hughes | a0beeea | 2014-06-12 11:48:04 -0700 | [diff] [blame] | 103 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 104 | int rand_r(unsigned int* __seed_ptr) __INTRODUCED_IN(21); |
Elliott Hughes | a0beeea | 2014-06-12 11:48:04 -0700 | [diff] [blame] | 105 | |
Elliott Hughes | 274afe8 | 2014-11-06 12:40:08 -0800 | [diff] [blame] | 106 | double drand48(void); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 107 | double erand48(unsigned short __xsubi[3]); |
| 108 | long jrand48(unsigned short __xsubi[3]); |
| 109 | void lcong48(unsigned short __param[7]) __INTRODUCED_IN(23); |
Elliott Hughes | 274afe8 | 2014-11-06 12:40:08 -0800 | [diff] [blame] | 110 | long lrand48(void); |
| 111 | long mrand48(void); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 112 | long nrand48(unsigned short __xsubi[3]); |
| 113 | unsigned short* seed48(unsigned short __seed16v[3]); |
| 114 | void srand48(long __seed); |
Elliott Hughes | 274afe8 | 2014-11-06 12:40:08 -0800 | [diff] [blame] | 115 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 116 | char* initstate(unsigned int __seed, char* __state, size_t __n) __INTRODUCED_IN(21); |
| 117 | char* setstate(char* __state) __INTRODUCED_IN(21); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 118 | |
Elliott Hughes | 4916706 | 2014-07-25 17:24:00 -0700 | [diff] [blame] | 119 | int getpt(void); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 120 | int posix_openpt(int __flags) __INTRODUCED_IN(21); |
| 121 | char* ptsname(int __fd); |
| 122 | int ptsname_r(int __fd, char* __buf, size_t __n); |
| 123 | int unlockpt(int __fd); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 124 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 125 | int getsubopt(char** __option, char* const* __tokens, char** __value_ptr) __INTRODUCED_IN(26); |
Elliott Hughes | df143f8 | 2016-04-04 17:34:04 -0700 | [diff] [blame] | 126 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 127 | typedef struct { |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 128 | int quot; |
| 129 | int rem; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 130 | } div_t; |
| 131 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 132 | div_t div(int __numerator, int __denominator) __attribute_const__; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 133 | |
| 134 | typedef struct { |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 135 | long int quot; |
| 136 | long int rem; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 137 | } ldiv_t; |
| 138 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 139 | ldiv_t ldiv(long __numerator, long __denominator) __attribute_const__; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 140 | |
| 141 | typedef struct { |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 142 | long long int quot; |
| 143 | long long int rem; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 144 | } lldiv_t; |
| 145 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 146 | lldiv_t lldiv(long long __numerator, long long __denominator) __attribute_const__; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 147 | |
Elliott Hughes | 692207e | 2014-02-28 16:23:27 -0800 | [diff] [blame] | 148 | /* BSD compatibility. */ |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 149 | const char* getprogname(void) __INTRODUCED_IN(21); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 150 | void setprogname(const char* __name) __INTRODUCED_IN(21); |
Elliott Hughes | 692207e | 2014-02-28 16:23:27 -0800 | [diff] [blame] | 151 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 152 | int mblen(const char* __s, size_t __n) __INTRODUCED_IN(26) __VERSIONER_NO_GUARD; |
| 153 | size_t mbstowcs(wchar_t* __dst, const char* __src, size_t __n); |
| 154 | int mbtowc(wchar_t* __wc_ptr, const char* __s, size_t __n) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD; |
| 155 | int wctomb(char* __dst, wchar_t __wc) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD; |
Dan Albert | cb0b143 | 2016-09-06 16:51:00 -0700 | [diff] [blame] | 156 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 157 | size_t wcstombs(char* __dst, const wchar_t* __src, size_t __n); |
David 'Digit' Turner | bb5581a | 2010-10-09 17:56:55 +0200 | [diff] [blame] | 158 | |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 159 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 160 | size_t __ctype_get_mb_cur_max(void) __INTRODUCED_IN(21); |
Dan Albert | 224ff04 | 2014-08-14 13:56:51 -0700 | [diff] [blame] | 161 | #define MB_CUR_MAX __ctype_get_mb_cur_max() |
Dan Albert | cb0b143 | 2016-09-06 16:51:00 -0700 | [diff] [blame] | 162 | #else |
| 163 | /* |
Dan Albert | 5c15b8c | 2017-02-21 15:54:58 -0800 | [diff] [blame] | 164 | * Pre-L we didn't have any locale support and so we were always the POSIX |
| 165 | * locale. POSIX specifies that MB_CUR_MAX for the POSIX locale is 1: |
| 166 | * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdlib.h.html |
Dan Albert | cb0b143 | 2016-09-06 16:51:00 -0700 | [diff] [blame] | 167 | */ |
Dan Albert | 5c15b8c | 2017-02-21 15:54:58 -0800 | [diff] [blame] | 168 | #define MB_CUR_MAX 1 |
Dan Albert | cb0b143 | 2016-09-06 16:51:00 -0700 | [diff] [blame] | 169 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 170 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 171 | #if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS) |
| 172 | #include <bits/fortify/stdlib.h> |
| 173 | #endif |
Daniel Micay | 3244d9f | 2015-04-18 13:04:19 -0400 | [diff] [blame] | 174 | |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 175 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 176 | float strtof(const char* __s, char** __end_ptr) __INTRODUCED_IN(21); |
| 177 | double atof(const char* __s) __attribute_pure__ __INTRODUCED_IN(21); |
| 178 | int abs(int __x) __attribute_const__ __INTRODUCED_IN(21); |
| 179 | long labs(long __x) __attribute_const__ __INTRODUCED_IN(21); |
| 180 | long long llabs(long long __x) __attribute_const__ __INTRODUCED_IN(21); |
Josh Gao | b6a4a4c | 2016-07-26 16:34:40 -0700 | [diff] [blame] | 181 | int rand(void) __INTRODUCED_IN(21); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 182 | void srand(unsigned int __seed) __INTRODUCED_IN(21); |
Josh Gao | b6a4a4c | 2016-07-26 16:34:40 -0700 | [diff] [blame] | 183 | long random(void) __INTRODUCED_IN(21); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 184 | void srandom(unsigned int __seed) __INTRODUCED_IN(21); |
| 185 | int grantpt(int __fd) __INTRODUCED_IN(21); |
Josh Gao | 6cd9fb0 | 2016-09-23 14:06:05 -0700 | [diff] [blame] | 186 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 187 | long long strtoll_l(const char* __s, char** __end_ptr, int __base, locale_t __l) __INTRODUCED_IN(21); |
| 188 | unsigned long long strtoull_l(const char* __s, char** __end_ptr, int __base, locale_t __l) __INTRODUCED_IN(21); |
| 189 | long double strtold_l(const char* __s, char** __end_ptr, locale_t __l) __INTRODUCED_IN(21); |
Josh Gao | 8778d64 | 2016-07-22 15:26:36 -0700 | [diff] [blame] | 190 | #else |
| 191 | // Implemented as static inlines before 21. |
| 192 | #endif |
| 193 | |
Elliott Hughes | 4cae5c3 | 2017-07-10 11:51:00 -0700 | [diff] [blame] | 194 | #if __ANDROID_API__ >= __ANDROID_API_O__ |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 195 | double strtod_l(const char* __s, char** __end_ptr, locale_t __l) __INTRODUCED_IN(26); |
| 196 | float strtof_l(const char* __s, char** __end_ptr, locale_t __l) __INTRODUCED_IN(26); |
| 197 | long strtol_l(const char* __s, char** __end_ptr, int, locale_t __l) __INTRODUCED_IN(26); |
Josh Gao | 6cd9fb0 | 2016-09-23 14:06:05 -0700 | [diff] [blame] | 198 | #else |
Elliott Hughes | 4cae5c3 | 2017-07-10 11:51:00 -0700 | [diff] [blame] | 199 | // Implemented as static inlines before 26. |
Josh Gao | 6cd9fb0 | 2016-09-23 14:06:05 -0700 | [diff] [blame] | 200 | #endif |
| 201 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 202 | __END_DECLS |
| 203 | |
Josh Gao | b8e1b705 | 2016-04-13 17:18:20 -0700 | [diff] [blame] | 204 | #include <android/legacy_stdlib_inlines.h> |
| 205 | |
Elliott Hughes | 76f8916 | 2015-01-26 13:34:58 -0800 | [diff] [blame] | 206 | #endif /* _STDLIB_H */ |