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 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 32 | #include <alloca.h> |
Elliott Hughes | 21b56eb | 2017-10-20 17:57:17 -0700 | [diff] [blame] | 33 | #include <bits/wait.h> |
Elliott Hughes | 76f8916 | 2015-01-26 13:34:58 -0800 | [diff] [blame] | 34 | #include <malloc.h> |
| 35 | #include <stddef.h> |
Elliott Hughes | 21b56eb | 2017-10-20 17:57:17 -0700 | [diff] [blame] | 36 | #include <sys/cdefs.h> |
| 37 | #include <xlocale.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 | 504d048 | 2021-06-07 11:20:28 -0700 | [diff] [blame] | 44 | __noreturn void abort(void) __attribute__((__nomerge__)); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 45 | __noreturn void exit(int __status); |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 46 | __noreturn void _Exit(int __status); |
Elliott Hughes | 2f94a29 | 2017-09-18 14:40:01 -0700 | [diff] [blame] | 47 | |
zijunzhao | 5a918d9 | 2022-11-28 21:05:55 +0000 | [diff] [blame] | 48 | int atexit(void (* _Nonnull __fn)(void)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 49 | |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 50 | int at_quick_exit(void (* _Nonnull __fn)(void)); |
| 51 | void quick_exit(int __status) __noreturn; |
Dan Albert | b8425c5 | 2014-04-29 17:49:06 -0700 | [diff] [blame] | 52 | |
zijunzhao | 5a918d9 | 2022-11-28 21:05:55 +0000 | [diff] [blame] | 53 | char* _Nullable getenv(const char* _Nonnull __name); |
| 54 | int putenv(char* _Nonnull __assignment); |
| 55 | int setenv(const char* _Nonnull __name, const char* _Nonnull __value, int __overwrite); |
| 56 | int unsetenv(const char* _Nonnull __name); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 57 | int clearenv(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 58 | |
zijunzhao | 5a918d9 | 2022-11-28 21:05:55 +0000 | [diff] [blame] | 59 | char* _Nullable mkdtemp(char* _Nonnull __template); |
Elliott Hughes | a1b5ca2 | 2024-04-22 20:10:53 +0000 | [diff] [blame] | 60 | char* _Nullable mktemp(char* _Nonnull __template) __attribute__((__deprecated__("mktemp is unsafe, use mkstemp or tmpfile instead"))); |
Elliott Hughes | 31165ed | 2014-09-23 17:34:29 -0700 | [diff] [blame] | 61 | |
zijunzhao | 5a918d9 | 2022-11-28 21:05:55 +0000 | [diff] [blame] | 62 | int mkostemp64(char* _Nonnull __template, int __flags) __INTRODUCED_IN(23); |
| 63 | int mkostemp(char* _Nonnull __template, int __flags) __INTRODUCED_IN(23); |
| 64 | int mkostemps64(char* _Nonnull __template, int __suffix_length, int __flags) __INTRODUCED_IN(23); |
| 65 | int mkostemps(char* _Nonnull __template, int __suffix_length, int __flags) __INTRODUCED_IN(23); |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 66 | int mkstemp64(char* _Nonnull __template); |
zijunzhao | 5a918d9 | 2022-11-28 21:05:55 +0000 | [diff] [blame] | 67 | int mkstemp(char* _Nonnull __template); |
| 68 | int mkstemps64(char* _Nonnull __template, int __flags) __INTRODUCED_IN(23); |
| 69 | int mkstemps(char* _Nonnull __template, int __flags); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 70 | |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 71 | int posix_memalign(void* _Nullable * _Nullable __memptr, size_t __alignment, size_t __size); |
Ken Sumrall | 85aad90 | 2011-12-14 20:50:01 -0800 | [diff] [blame] | 72 | |
Elliott Hughes | c9f344e | 2024-08-20 15:28:38 +0000 | [diff] [blame] | 73 | /** |
| 74 | * [aligned_alloc(3)](https://man7.org/linux/man-pages/man3/aligned_alloc.3.html) |
| 75 | * allocates the given number of bytes with the given alignment. |
| 76 | * |
| 77 | * Returns a pointer to the allocated memory on success and returns a null |
| 78 | * pointer and sets `errno` on failure. |
| 79 | * |
| 80 | * Available since API level 28. |
| 81 | */ |
Elliott Hughes | b19df89 | 2024-09-06 14:27:41 +0000 | [diff] [blame^] | 82 | __nodiscard void* _Nullable aligned_alloc(size_t __alignment, size_t __size) __INTRODUCED_IN(28); |
Christopher Ferris | cae21a9 | 2018-02-05 18:14:55 -0800 | [diff] [blame] | 83 | |
Elliott Hughes | b19df89 | 2024-09-06 14:27:41 +0000 | [diff] [blame^] | 84 | __nodiscard char* _Nullable realpath(const char* _Nonnull __path, char* _Nullable __resolved); |
Elliott Hughes | cc87eec | 2023-10-26 21:28:12 +0000 | [diff] [blame] | 85 | |
| 86 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 87 | * [system(3)](https://man7.org/linux/man-pages/man3/system.3.html) executes |
Elliott Hughes | cc87eec | 2023-10-26 21:28:12 +0000 | [diff] [blame] | 88 | * the given command in a new shell process. |
| 89 | * |
| 90 | * On Android, the special case of `system(NULL)` always returns 1, |
| 91 | * as specified by POSIX. Passing `NULL` to determine whether or |
| 92 | * not a shell is available is not portable. Callers should just try |
| 93 | * the command they actually want to run, since there are many reasons |
| 94 | * why it might fail, both temporarily (for lack of resources, say) |
| 95 | * or permanently (for lack of permission, say). |
| 96 | * |
| 97 | * Returns -1 and sets errno if process creation fails; returns a |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 98 | * [waitpid(2)](https://man7.org/linux/man-pages/man2/waitpid.2.html) |
Elliott Hughes | cc87eec | 2023-10-26 21:28:12 +0000 | [diff] [blame] | 99 | * status otherwise. |
| 100 | */ |
zijunzhao | 5a918d9 | 2022-11-28 21:05:55 +0000 | [diff] [blame] | 101 | int system(const char* _Nonnull __command); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 102 | |
Elliott Hughes | d4c54b4 | 2024-05-31 17:33:33 +0000 | [diff] [blame] | 103 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 104 | * [bsearch(3)](https://man7.org/linux/man-pages/man3/bsearch.3.html) searches |
Elliott Hughes | d4c54b4 | 2024-05-31 17:33:33 +0000 | [diff] [blame] | 105 | * a sorted array. |
| 106 | * |
| 107 | * Returns a pointer to a matching item on success, |
| 108 | * or NULL if no matching item is found. |
| 109 | */ |
Elliott Hughes | b19df89 | 2024-09-06 14:27:41 +0000 | [diff] [blame^] | 110 | __nodiscard void* _Nullable bsearch(const void* _Nonnull __key, const void* _Nullable __base, size_t __nmemb, size_t __size, int (* _Nonnull __comparator)(const void* _Nonnull __lhs, const void* _Nonnull __rhs)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 111 | |
Elliott Hughes | 5bae572 | 2024-07-30 12:47:33 -0400 | [diff] [blame] | 112 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 113 | * [qsort(3)](https://man7.org/linux/man-pages/man3/qsort.3.html) sorts an array |
Elliott Hughes | 5bae572 | 2024-07-30 12:47:33 -0400 | [diff] [blame] | 114 | * of n elements each of the given size, using the given comparator. |
| 115 | */ |
| 116 | void qsort(void* _Nullable __array, size_t __n, size_t __size, int (* _Nonnull __comparator)(const void* _Nullable __lhs, const void* _Nullable __rhs)); |
| 117 | |
| 118 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 119 | * [qsort_r(3)](https://man7.org/linux/man-pages/man3/qsort_r.3.html) sorts an |
Elliott Hughes | 5bae572 | 2024-07-30 12:47:33 -0400 | [diff] [blame] | 120 | * array of n elements each of the given size, using the given comparator, |
| 121 | * and passing the given context argument to the comparator. |
| 122 | * |
| 123 | * Available since API level 36. |
| 124 | */ |
| 125 | void qsort_r(void* _Nullable __array, size_t __n, size_t __size, int (* _Nonnull __comparator)(const void* _Nullable __lhs, const void* _Nullable __rhs, void* _Nullable __context), void* _Nullable __context) __INTRODUCED_IN(36); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 126 | |
Yabin Cui | a39f939 | 2014-10-28 12:04:02 -0700 | [diff] [blame] | 127 | uint32_t arc4random(void); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 128 | uint32_t arc4random_uniform(uint32_t __upper_bound); |
zijunzhao | 5a918d9 | 2022-11-28 21:05:55 +0000 | [diff] [blame] | 129 | void arc4random_buf(void* _Nonnull __buf, size_t __n); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 130 | |
| 131 | #define RAND_MAX 0x7fffffff |
Elliott Hughes | a0beeea | 2014-06-12 11:48:04 -0700 | [diff] [blame] | 132 | |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 133 | int rand_r(unsigned int* _Nonnull __seed_ptr); |
Elliott Hughes | a0beeea | 2014-06-12 11:48:04 -0700 | [diff] [blame] | 134 | |
Elliott Hughes | 274afe8 | 2014-11-06 12:40:08 -0800 | [diff] [blame] | 135 | double drand48(void); |
zijunzhao | 5a918d9 | 2022-11-28 21:05:55 +0000 | [diff] [blame] | 136 | double erand48(unsigned short __xsubi[_Nonnull 3]); |
| 137 | long jrand48(unsigned short __xsubi[_Nonnull 3]); |
| 138 | void lcong48(unsigned short __param[_Nonnull 7]) __INTRODUCED_IN(23); |
Elliott Hughes | 274afe8 | 2014-11-06 12:40:08 -0800 | [diff] [blame] | 139 | long lrand48(void); |
| 140 | long mrand48(void); |
zijunzhao | 5a918d9 | 2022-11-28 21:05:55 +0000 | [diff] [blame] | 141 | long nrand48(unsigned short __xsubi[_Nonnull 3]); |
| 142 | unsigned short* _Nonnull seed48(unsigned short __seed16v[_Nonnull 3]); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 143 | void srand48(long __seed); |
Elliott Hughes | 274afe8 | 2014-11-06 12:40:08 -0800 | [diff] [blame] | 144 | |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 145 | char* _Nullable initstate(unsigned int __seed, char* _Nonnull __state, size_t __n); |
| 146 | char* _Nullable setstate(char* _Nonnull __state); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 147 | |
Elliott Hughes | 4916706 | 2014-07-25 17:24:00 -0700 | [diff] [blame] | 148 | int getpt(void); |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 149 | int posix_openpt(int __flags); |
zijunzhao | 5a918d9 | 2022-11-28 21:05:55 +0000 | [diff] [blame] | 150 | char* _Nullable ptsname(int __fd); |
| 151 | int ptsname_r(int __fd, char* _Nonnull __buf, size_t __n); |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 152 | int unlockpt(int __fd); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 153 | |
zijunzhao | 5a918d9 | 2022-11-28 21:05:55 +0000 | [diff] [blame] | 154 | int getsubopt(char* _Nonnull * _Nonnull __option, char* _Nonnull const* _Nonnull __tokens, char* _Nullable * _Nonnull __value_ptr) __INTRODUCED_IN(26); |
Elliott Hughes | df143f8 | 2016-04-04 17:34:04 -0700 | [diff] [blame] | 155 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 156 | typedef struct { |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 157 | int quot; |
| 158 | int rem; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 159 | } div_t; |
| 160 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 161 | div_t div(int __numerator, int __denominator) __attribute_const__; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 162 | |
| 163 | typedef struct { |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 164 | long int quot; |
| 165 | long int rem; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 166 | } ldiv_t; |
| 167 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 168 | ldiv_t ldiv(long __numerator, long __denominator) __attribute_const__; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 169 | |
| 170 | typedef struct { |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 171 | long long int quot; |
| 172 | long long int rem; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 173 | } lldiv_t; |
| 174 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 175 | 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] | 176 | |
Elliott Hughes | 2d0b28b | 2018-10-23 11:23:00 -0700 | [diff] [blame] | 177 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 178 | * [getloadavg(3)](https://man7.org/linux/man-pages/man3/getloadavg.3.html) queries the |
Elliott Hughes | 2d0b28b | 2018-10-23 11:23:00 -0700 | [diff] [blame] | 179 | * number of runnable processes averaged over time. The Linux kernel supports averages |
| 180 | * over the last 1, 5, and 15 minutes. |
| 181 | * |
| 182 | * Returns the number of samples written to `__averages` (at most 3), and returns -1 on failure. |
| 183 | */ |
zijunzhao | 5a918d9 | 2022-11-28 21:05:55 +0000 | [diff] [blame] | 184 | int getloadavg(double __averages[_Nonnull], int __n) __INTRODUCED_IN(29); |
Elliott Hughes | 2d0b28b | 2018-10-23 11:23:00 -0700 | [diff] [blame] | 185 | |
Elliott Hughes | 692207e | 2014-02-28 16:23:27 -0800 | [diff] [blame] | 186 | /* BSD compatibility. */ |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 187 | const char* _Nullable getprogname(void); |
| 188 | void setprogname(const char* _Nonnull __name); |
Elliott Hughes | 692207e | 2014-02-28 16:23:27 -0800 | [diff] [blame] | 189 | |
Elliott Hughes | 2f9fe8c | 2024-08-13 13:42:43 +0000 | [diff] [blame] | 190 | int mblen(const char* _Nullable __s, size_t __n) __INTRODUCED_IN(26); |
Elliott Hughes | 2bdeff4 | 2023-06-20 14:32:58 -0700 | [diff] [blame] | 191 | size_t mbstowcs(wchar_t* _Nullable __dst, const char* _Nullable __src, size_t __n); |
| 192 | int mbtowc(wchar_t* _Nullable __wc_ptr, const char* _Nullable __s, size_t __n); |
| 193 | int wctomb(char* _Nullable __dst, wchar_t __wc); |
Dan Albert | cb0b143 | 2016-09-06 16:51:00 -0700 | [diff] [blame] | 194 | |
Elliott Hughes | 2bdeff4 | 2023-06-20 14:32:58 -0700 | [diff] [blame] | 195 | size_t wcstombs(char* _Nullable __dst, const wchar_t* _Nullable __src, size_t __n); |
David 'Digit' Turner | bb5581a | 2010-10-09 17:56:55 +0200 | [diff] [blame] | 196 | |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 197 | size_t __ctype_get_mb_cur_max(void); |
Dan Albert | 224ff04 | 2014-08-14 13:56:51 -0700 | [diff] [blame] | 198 | #define MB_CUR_MAX __ctype_get_mb_cur_max() |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 199 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 200 | #if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS) |
| 201 | #include <bits/fortify/stdlib.h> |
| 202 | #endif |
Daniel Micay | 3244d9f | 2015-04-18 13:04:19 -0400 | [diff] [blame] | 203 | |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 204 | int abs(int __x) __attribute_const__; |
| 205 | long labs(long __x) __attribute_const__; |
| 206 | long long llabs(long long __x) __attribute_const__; |
Ryan Prichard | 51a7fe8 | 2018-01-08 16:18:48 -0800 | [diff] [blame] | 207 | |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 208 | int rand(void); |
| 209 | void srand(unsigned int __seed); |
| 210 | long random(void); |
| 211 | void srandom(unsigned int __seed); |
| 212 | int grantpt(int __fd); |
Josh Gao | 6cd9fb0 | 2016-09-23 14:06:05 -0700 | [diff] [blame] | 213 | |
Elliott Hughes | 14a5588 | 2024-08-23 13:39:13 +0000 | [diff] [blame] | 214 | /** |
| 215 | * [atof(3)](https://man7.org/linux/man-pages/man3/atof.3.html) converts a |
| 216 | * string to a double. |
| 217 | * |
| 218 | * Returns the double; use strtof() or strtod() if you need to detect errors. |
| 219 | */ |
| 220 | double atof(const char* _Nonnull __s) __attribute_pure__; |
| 221 | |
| 222 | /** |
| 223 | * [atoi(3)](https://man7.org/linux/man-pages/man3/atoi.3.html) converts a |
| 224 | * string to an int. |
| 225 | * |
| 226 | * Returns the int or 0 on error; use strtol() if you need to detect errors. |
| 227 | */ |
| 228 | int atoi(const char* _Nonnull __s) __attribute_pure__; |
| 229 | |
| 230 | /** |
| 231 | * [atol(3)](https://man7.org/linux/man-pages/man3/atol.3.html) converts a |
| 232 | * string to a long. |
| 233 | * |
| 234 | * Returns the long or 0 on error; use strtol() if you need to detect errors. |
| 235 | */ |
| 236 | long atol(const char* _Nonnull __s) __attribute_pure__; |
| 237 | |
| 238 | /** |
| 239 | * [atoll(3)](https://man7.org/linux/man-pages/man3/atoll.3.html) converts a |
| 240 | * string to a long long. |
| 241 | * |
| 242 | * Returns the long long or 0 on error; use strtol() if you need to detect errors. |
| 243 | */ |
| 244 | long long atoll(const char* _Nonnull __s) __attribute_pure__; |
| 245 | |
| 246 | /** |
| 247 | * [strtol(3)](https://man7.org/linux/man-pages/man3/strtol.3.html) converts a |
| 248 | * string to a long. |
| 249 | * |
| 250 | * Returns the long. |
| 251 | * `__end_ptr` is set to the last character in `__s` that was converted. |
| 252 | * errno is set to ERANGE if the result overflowed or underflowed. |
| 253 | */ |
| 254 | long strtol(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base); |
| 255 | |
| 256 | /** Equivalent to strtol() on Android. */ |
| 257 | long strtol_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int, locale_t _Nonnull __l) __RENAME(strtol); |
| 258 | |
| 259 | /** |
| 260 | * [strtoll(3)](https://man7.org/linux/man-pages/man3/strtoll.3.html) converts a |
| 261 | * string to a long long. |
| 262 | * |
| 263 | * Returns the long long. |
| 264 | * `__end_ptr` is set to the last character in `__s` that was converted. |
| 265 | * errno is set to ERANGE if the result overflowed or underflowed. |
| 266 | */ |
| 267 | long long strtoll(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base); |
| 268 | |
| 269 | /** Equivalent to strtoll() on Android. */ |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 270 | long long strtoll_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base, locale_t _Nonnull __l); |
Elliott Hughes | 14a5588 | 2024-08-23 13:39:13 +0000 | [diff] [blame] | 271 | |
| 272 | /** |
| 273 | * [strtoul(3)](https://man7.org/linux/man-pages/man3/strtoul.3.html) converts a |
| 274 | * string to an unsigned long. |
| 275 | * |
| 276 | * Returns the unsigned long. |
| 277 | * `__end_ptr` is set to the last character in `__s` that was converted. |
| 278 | * errno is set to ERANGE if the result overflowed or underflowed. |
| 279 | */ |
| 280 | unsigned long strtoul(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base); |
| 281 | |
| 282 | /** Equivalent to strtoul() on Android. */ |
| 283 | unsigned long strtoul_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base, locale_t _Nonnull __l) __RENAME(strtoul); |
| 284 | |
| 285 | /** |
| 286 | * [strtoull(3)](https://man7.org/linux/man-pages/man3/strtoull.3.html) converts a |
| 287 | * string to an unsigned long long. |
| 288 | * |
| 289 | * Returns the unsigned long long. |
| 290 | * `__end_ptr` is set to the last character in `__s` that was converted. |
| 291 | * errno is set to ERANGE if the result overflowed or underflowed. |
| 292 | */ |
| 293 | unsigned long long strtoull(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base); |
| 294 | |
| 295 | /** Equivalent to strtoull() on Android. */ |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 296 | unsigned long long strtoull_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base, locale_t _Nonnull __l); |
Elliott Hughes | 14a5588 | 2024-08-23 13:39:13 +0000 | [diff] [blame] | 297 | |
| 298 | /** |
| 299 | * [strtof(3)](https://man7.org/linux/man-pages/man3/strtof.3.html) converts a |
| 300 | * string to a float. |
| 301 | * |
| 302 | * Returns the float. |
| 303 | * `__end_ptr` is set to the last character in `__s` that was converted. |
| 304 | * errno is set to ERANGE if the result overflowed or underflowed. |
| 305 | */ |
| 306 | float strtof(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr); |
| 307 | |
| 308 | /** |
| 309 | * [strtod(3)](https://man7.org/linux/man-pages/man3/strtod.3.html) converts a |
| 310 | * string to a double. |
| 311 | * |
| 312 | * Returns the double. |
| 313 | * `__end_ptr` is set to the last character in `__s` that was converted. |
| 314 | * errno is set to ERANGE if the result overflowed or underflowed. |
| 315 | */ |
| 316 | double strtod(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr); |
| 317 | |
| 318 | /** |
| 319 | * [strtold(3)](https://man7.org/linux/man-pages/man3/strtold.3.html) converts a |
| 320 | * string to a long double. |
| 321 | * |
| 322 | * Returns the long double. |
| 323 | * `__end_ptr` is set to the last character in `__s` that was converted. |
| 324 | * errno is set to ERANGE if the result overflowed or underflowed. |
| 325 | */ |
| 326 | long double strtold(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr); |
| 327 | |
| 328 | /** Equivalent to strtold() on Android. */ |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 329 | long double strtold_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, locale_t _Nonnull __l); |
Josh Gao | 8778d64 | 2016-07-22 15:26:36 -0700 | [diff] [blame] | 330 | |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 331 | #if __ANDROID_API__ >= 26 |
Elliott Hughes | 14a5588 | 2024-08-23 13:39:13 +0000 | [diff] [blame] | 332 | /** Equivalent to strtod() on Android. */ |
zijunzhao | 5a918d9 | 2022-11-28 21:05:55 +0000 | [diff] [blame] | 333 | double strtod_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, locale_t _Nonnull __l) __INTRODUCED_IN(26); |
Elliott Hughes | 14a5588 | 2024-08-23 13:39:13 +0000 | [diff] [blame] | 334 | /** Equivalent to strtof() on Android. */ |
zijunzhao | 5a918d9 | 2022-11-28 21:05:55 +0000 | [diff] [blame] | 335 | float strtof_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, locale_t _Nonnull __l) __INTRODUCED_IN(26); |
Josh Gao | 6cd9fb0 | 2016-09-23 14:06:05 -0700 | [diff] [blame] | 336 | #else |
Elliott Hughes | 4cae5c3 | 2017-07-10 11:51:00 -0700 | [diff] [blame] | 337 | // Implemented as static inlines before 26. |
Josh Gao | 6cd9fb0 | 2016-09-23 14:06:05 -0700 | [diff] [blame] | 338 | #endif |
| 339 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 340 | __END_DECLS |
| 341 | |
Josh Gao | b8e1b705 | 2016-04-13 17:18:20 -0700 | [diff] [blame] | 342 | #include <android/legacy_stdlib_inlines.h> |
| 343 | |
Elliott Hughes | 76f8916 | 2015-01-26 13:34:58 -0800 | [diff] [blame] | 344 | #endif /* _STDLIB_H */ |