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 | |
Josh Gao | 2e8e5e6 | 2017-04-20 12:58:31 -0700 | [diff] [blame] | 80 | unsigned long strtoul_l(const char*, char**, int, locale_t) __INTRODUCED_IN(26); |
Dan Albert | dfb5ce4 | 2014-07-09 22:51:34 +0000 | [diff] [blame] | 81 | |
Elliott Hughes | 95fa061 | 2016-09-28 12:29:52 -0700 | [diff] [blame] | 82 | int atoi(const char*) __attribute_pure__; |
| 83 | long atol(const char*) __attribute_pure__; |
| 84 | long long atoll(const char*) __attribute_pure__; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 85 | |
George Burgess IV | 54f5d83 | 2017-07-31 21:21:10 -0700 | [diff] [blame] | 86 | char* realpath(const char* path, char* resolved); |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 87 | int system(const char *string); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 88 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 89 | void* bsearch(const void* key, const void* base0, size_t nmemb, size_t size, |
| 90 | int (*compar)(const void*, const void*)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 91 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 92 | 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] | 93 | |
Yabin Cui | a39f939 | 2014-10-28 12:04:02 -0700 | [diff] [blame] | 94 | uint32_t arc4random(void); |
| 95 | uint32_t arc4random_uniform(uint32_t); |
Elliott Hughes | 0468feb | 2014-06-20 22:49:20 -0700 | [diff] [blame] | 96 | void arc4random_buf(void*, size_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 97 | |
| 98 | #define RAND_MAX 0x7fffffff |
Elliott Hughes | a0beeea | 2014-06-12 11:48:04 -0700 | [diff] [blame] | 99 | |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 100 | int rand_r(unsigned int*) __INTRODUCED_IN(21); |
Elliott Hughes | a0beeea | 2014-06-12 11:48:04 -0700 | [diff] [blame] | 101 | |
Elliott Hughes | 274afe8 | 2014-11-06 12:40:08 -0800 | [diff] [blame] | 102 | double drand48(void); |
| 103 | double erand48(unsigned short[3]); |
| 104 | long jrand48(unsigned short[3]); |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 105 | void lcong48(unsigned short[7]) __INTRODUCED_IN(23); |
Elliott Hughes | 274afe8 | 2014-11-06 12:40:08 -0800 | [diff] [blame] | 106 | long lrand48(void); |
| 107 | long mrand48(void); |
| 108 | long nrand48(unsigned short[3]); |
| 109 | unsigned short* seed48(unsigned short[3]); |
| 110 | void srand48(long); |
| 111 | |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 112 | char* initstate(unsigned int, char*, size_t) __INTRODUCED_IN(21); |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 113 | char* setstate(char*) __INTRODUCED_IN(21); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 114 | |
Elliott Hughes | 4916706 | 2014-07-25 17:24:00 -0700 | [diff] [blame] | 115 | int getpt(void); |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 116 | int posix_openpt(int) __INTRODUCED_IN(21); |
Elliott Hughes | a381fe8 | 2014-12-09 20:30:23 -0800 | [diff] [blame] | 117 | char* ptsname(int); |
Elliott Hughes | 4916706 | 2014-07-25 17:24:00 -0700 | [diff] [blame] | 118 | int ptsname_r(int, char*, size_t); |
| 119 | int unlockpt(int); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 120 | |
Josh Gao | 2e8e5e6 | 2017-04-20 12:58:31 -0700 | [diff] [blame] | 121 | int getsubopt(char**, char* const*, char**) __INTRODUCED_IN(26); |
Elliott Hughes | df143f8 | 2016-04-04 17:34:04 -0700 | [diff] [blame] | 122 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 123 | typedef struct { |
| 124 | int quot; |
| 125 | int rem; |
| 126 | } div_t; |
| 127 | |
Elliott Hughes | 95fa061 | 2016-09-28 12:29:52 -0700 | [diff] [blame] | 128 | div_t div(int, int) __attribute_const__; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 129 | |
| 130 | typedef struct { |
| 131 | long int quot; |
| 132 | long int rem; |
| 133 | } ldiv_t; |
| 134 | |
Elliott Hughes | 95fa061 | 2016-09-28 12:29:52 -0700 | [diff] [blame] | 135 | ldiv_t ldiv(long, long) __attribute_const__; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 136 | |
| 137 | typedef struct { |
| 138 | long long int quot; |
| 139 | long long int rem; |
| 140 | } lldiv_t; |
| 141 | |
Elliott Hughes | 95fa061 | 2016-09-28 12:29:52 -0700 | [diff] [blame] | 142 | lldiv_t lldiv(long long, long long) __attribute_const__; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 143 | |
Elliott Hughes | 692207e | 2014-02-28 16:23:27 -0800 | [diff] [blame] | 144 | /* BSD compatibility. */ |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 145 | const char* getprogname(void) __INTRODUCED_IN(21); |
| 146 | void setprogname(const char*) __INTRODUCED_IN(21); |
Elliott Hughes | 692207e | 2014-02-28 16:23:27 -0800 | [diff] [blame] | 147 | |
Josh Gao | 2e8e5e6 | 2017-04-20 12:58:31 -0700 | [diff] [blame] | 148 | int mblen(const char*, size_t) __INTRODUCED_IN(26) __VERSIONER_NO_GUARD; |
Elliott Hughes | 6f6f905 | 2016-04-28 14:54:52 -0700 | [diff] [blame] | 149 | size_t mbstowcs(wchar_t*, const char*, size_t); |
Dan Albert | cb0b143 | 2016-09-06 16:51:00 -0700 | [diff] [blame] | 150 | int mbtowc(wchar_t*, const char*, size_t) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD; |
| 151 | int wctomb(char*, wchar_t) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD; |
| 152 | |
Elliott Hughes | 6f6f905 | 2016-04-28 14:54:52 -0700 | [diff] [blame] | 153 | size_t wcstombs(char*, const wchar_t*, size_t); |
David 'Digit' Turner | bb5581a | 2010-10-09 17:56:55 +0200 | [diff] [blame] | 154 | |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 155 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
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() |
Dan Albert | cb0b143 | 2016-09-06 16:51:00 -0700 | [diff] [blame] | 158 | #else |
| 159 | /* |
Dan Albert | 5c15b8c | 2017-02-21 15:54:58 -0800 | [diff] [blame] | 160 | * Pre-L we didn't have any locale support and so we were always the POSIX |
| 161 | * locale. POSIX specifies that MB_CUR_MAX for the POSIX locale is 1: |
| 162 | * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdlib.h.html |
Dan Albert | cb0b143 | 2016-09-06 16:51:00 -0700 | [diff] [blame] | 163 | */ |
Dan Albert | 5c15b8c | 2017-02-21 15:54:58 -0800 | [diff] [blame] | 164 | #define MB_CUR_MAX 1 |
Dan Albert | cb0b143 | 2016-09-06 16:51:00 -0700 | [diff] [blame] | 165 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 166 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 167 | #if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS) |
| 168 | #include <bits/fortify/stdlib.h> |
| 169 | #endif |
Daniel Micay | 3244d9f | 2015-04-18 13:04:19 -0400 | [diff] [blame] | 170 | |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 171 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
Josh Gao | b6a4a4c | 2016-07-26 16:34:40 -0700 | [diff] [blame] | 172 | float strtof(const char*, char**) __INTRODUCED_IN(21); |
Elliott Hughes | 95fa061 | 2016-09-28 12:29:52 -0700 | [diff] [blame] | 173 | double atof(const char*) __attribute_pure__ __INTRODUCED_IN(21); |
| 174 | int abs(int) __attribute_const__ __INTRODUCED_IN(21); |
| 175 | long labs(long) __attribute_const__ __INTRODUCED_IN(21); |
| 176 | long long llabs(long long) __attribute_const__ __INTRODUCED_IN(21); |
Josh Gao | b6a4a4c | 2016-07-26 16:34:40 -0700 | [diff] [blame] | 177 | int rand(void) __INTRODUCED_IN(21); |
| 178 | void srand(unsigned int) __INTRODUCED_IN(21); |
| 179 | long random(void) __INTRODUCED_IN(21); |
| 180 | void srandom(unsigned int) __INTRODUCED_IN(21); |
| 181 | int grantpt(int) __INTRODUCED_IN(21); |
Josh Gao | 6cd9fb0 | 2016-09-23 14:06:05 -0700 | [diff] [blame] | 182 | |
| 183 | long long strtoll_l(const char*, char**, int, locale_t) __INTRODUCED_IN(21); |
| 184 | unsigned long long strtoull_l(const char*, char**, int, locale_t) __INTRODUCED_IN(21); |
| 185 | long double strtold_l(const char*, char**, locale_t) __INTRODUCED_IN(21); |
Josh Gao | 8778d64 | 2016-07-22 15:26:36 -0700 | [diff] [blame] | 186 | #else |
| 187 | // Implemented as static inlines before 21. |
| 188 | #endif |
| 189 | |
Elliott Hughes | 4cae5c3 | 2017-07-10 11:51:00 -0700 | [diff] [blame] | 190 | #if __ANDROID_API__ >= __ANDROID_API_O__ |
Josh Gao | 2e8e5e6 | 2017-04-20 12:58:31 -0700 | [diff] [blame] | 191 | double strtod_l(const char*, char**, locale_t) __INTRODUCED_IN(26); |
| 192 | float strtof_l(const char*, char**, locale_t) __INTRODUCED_IN(26); |
| 193 | long strtol_l(const char*, char**, int, locale_t) __INTRODUCED_IN(26); |
Josh Gao | 6cd9fb0 | 2016-09-23 14:06:05 -0700 | [diff] [blame] | 194 | #else |
Elliott Hughes | 4cae5c3 | 2017-07-10 11:51:00 -0700 | [diff] [blame] | 195 | // Implemented as static inlines before 26. |
Josh Gao | 6cd9fb0 | 2016-09-23 14:06:05 -0700 | [diff] [blame] | 196 | #endif |
| 197 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 198 | __END_DECLS |
| 199 | |
Josh Gao | b8e1b705 | 2016-04-13 17:18:20 -0700 | [diff] [blame] | 200 | #include <android/legacy_stdlib_inlines.h> |
| 201 | |
Elliott Hughes | 76f8916 | 2015-01-26 13:34:58 -0800 | [diff] [blame] | 202 | #endif /* _STDLIB_H */ |