blob: 86336a05794b8b8a5db65fc4558954d2cf9a5f1b [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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 Hughes76f89162015-01-26 13:34:58 -080028
29#ifndef _STDLIB_H
30#define _STDLIB_H
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080031
32#include <sys/cdefs.h>
Elliott Hughes76f89162015-01-26 13:34:58 -080033#include <xlocale.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080034
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080035#include <alloca.h>
Elliott Hughes76f89162015-01-26 13:34:58 -080036#include <malloc.h>
37#include <stddef.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080038
39__BEGIN_DECLS
40
41#define EXIT_FAILURE 1
42#define EXIT_SUCCESS 0
43
Elliott Hughes3b2096a2016-07-22 18:57:12 -070044__noreturn void abort(void);
Elliott Hughesfaa74342017-08-11 17:34:44 -070045__noreturn void exit(int __status);
46__noreturn void _Exit(int __status) __INTRODUCED_IN(21);
47int atexit(void (*__fn)(void));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080048
Elliott Hughesfaa74342017-08-11 17:34:44 -070049int at_quick_exit(void (*__fn)(void)) __INTRODUCED_IN(21);
50void quick_exit(int __status) __noreturn __INTRODUCED_IN(21);
Dan Albertb8425c52014-04-29 17:49:06 -070051
Elliott Hughesfaa74342017-08-11 17:34:44 -070052char* getenv(const char* __name);
53int putenv(char* __assignment);
54int setenv(const char* __name, const char* __value, int __overwrite);
55int unsetenv(const char* __name);
Elliott Hughes3b2096a2016-07-22 18:57:12 -070056int clearenv(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080057
Elliott Hughesfaa74342017-08-11 17:34:44 -070058char* mkdtemp(char* __template);
59char* mktemp(char* __template) __attribute__((deprecated("mktemp is unsafe, use mkstemp or tmpfile instead")));
Elliott Hughes31165ed2014-09-23 17:34:29 -070060
Elliott Hughesfaa74342017-08-11 17:34:44 -070061int mkostemp64(char* __template, int __flags) __INTRODUCED_IN(23);
62int mkostemp(char* __template, int __flags) __INTRODUCED_IN(23);
63int mkostemps64(char* __template, int __suffix_length, int __flags) __INTRODUCED_IN(23);
64int mkostemps(char* __template, int __suffix_length, int __flags) __INTRODUCED_IN(23);
65int mkstemp64(char* __template) __INTRODUCED_IN(21);
66int mkstemp(char* __template);
67int mkstemps64(char* __template, int __flags) __INTRODUCED_IN(23);
68int mkstemps(char* __template, int __flags);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080069
Elliott Hughesfaa74342017-08-11 17:34:44 -070070long strtol(const char* __s, char** __end_ptr, int __base);
71long long strtoll(const char* __s, char** __end_ptr, int __base);
72unsigned long strtoul(const char* __s, char** __end_ptr, int __base);
73unsigned long long strtoull(const char* __s, char** __end_ptr, int __base);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080074
Elliott Hughesfaa74342017-08-11 17:34:44 -070075int posix_memalign(void** __memptr, size_t __alignment, size_t __size) __INTRODUCED_IN(16);
Ken Sumrall85aad902011-12-14 20:50:01 -080076
Elliott Hughesfaa74342017-08-11 17:34:44 -070077double strtod(const char* __s, char** __end_ptr);
Elliott Hughes50cda382017-09-14 15:30:08 -070078long double strtold(const char* __s, char** __end_ptr) __RENAME_LDBL(strtod, 3, 21);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080079
Elliott Hughesfaa74342017-08-11 17:34:44 -070080unsigned long strtoul_l(const char* __s, char** __end_ptr, int __base, locale_t __l) __INTRODUCED_IN(26);
Dan Albertdfb5ce42014-07-09 22:51:34 +000081
Elliott Hughesfaa74342017-08-11 17:34:44 -070082int atoi(const char* __s) __attribute_pure__;
83long atol(const char* __s) __attribute_pure__;
84long long atoll(const char* __s) __attribute_pure__;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080085
Elliott Hughesfaa74342017-08-11 17:34:44 -070086char* realpath(const char* __path, char* __resolved);
87int system(const char* __command);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080088
Elliott Hughesfaa74342017-08-11 17:34:44 -070089void* 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 Project1dc9e472009-03-03 19:28:35 -080090
Elliott Hughesfaa74342017-08-11 17:34:44 -070091void qsort(void* __base, size_t __nmemb, size_t __size, int (*__comparator)(const void* __lhs, const void* __rhs));
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080092
Yabin Cuia39f9392014-10-28 12:04:02 -070093uint32_t arc4random(void);
Elliott Hughesfaa74342017-08-11 17:34:44 -070094uint32_t arc4random_uniform(uint32_t __upper_bound);
95void arc4random_buf(void* __buf, size_t __n);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080096
97#define RAND_MAX 0x7fffffff
Elliott Hughesa0beeea2014-06-12 11:48:04 -070098
Elliott Hughesfaa74342017-08-11 17:34:44 -070099int rand_r(unsigned int* __seed_ptr) __INTRODUCED_IN(21);
Elliott Hughesa0beeea2014-06-12 11:48:04 -0700100
Elliott Hughes274afe82014-11-06 12:40:08 -0800101double drand48(void);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700102double erand48(unsigned short __xsubi[3]);
103long jrand48(unsigned short __xsubi[3]);
104void lcong48(unsigned short __param[7]) __INTRODUCED_IN(23);
Elliott Hughes274afe82014-11-06 12:40:08 -0800105long lrand48(void);
106long mrand48(void);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700107long nrand48(unsigned short __xsubi[3]);
108unsigned short* seed48(unsigned short __seed16v[3]);
109void srand48(long __seed);
Elliott Hughes274afe82014-11-06 12:40:08 -0800110
Elliott Hughesfaa74342017-08-11 17:34:44 -0700111char* initstate(unsigned int __seed, char* __state, size_t __n) __INTRODUCED_IN(21);
112char* setstate(char* __state) __INTRODUCED_IN(21);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800113
Elliott Hughes49167062014-07-25 17:24:00 -0700114int getpt(void);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700115int posix_openpt(int __flags) __INTRODUCED_IN(21);
116char* ptsname(int __fd);
117int ptsname_r(int __fd, char* __buf, size_t __n);
118int unlockpt(int __fd);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800119
Elliott Hughesfaa74342017-08-11 17:34:44 -0700120int getsubopt(char** __option, char* const* __tokens, char** __value_ptr) __INTRODUCED_IN(26);
Elliott Hughesdf143f82016-04-04 17:34:04 -0700121
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800122typedef struct {
Elliott Hughesfaa74342017-08-11 17:34:44 -0700123 int quot;
124 int rem;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800125} div_t;
126
Elliott Hughesfaa74342017-08-11 17:34:44 -0700127div_t div(int __numerator, int __denominator) __attribute_const__;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800128
129typedef struct {
Elliott Hughesfaa74342017-08-11 17:34:44 -0700130 long int quot;
131 long int rem;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800132} ldiv_t;
133
Elliott Hughesfaa74342017-08-11 17:34:44 -0700134ldiv_t ldiv(long __numerator, long __denominator) __attribute_const__;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800135
136typedef struct {
Elliott Hughesfaa74342017-08-11 17:34:44 -0700137 long long int quot;
138 long long int rem;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800139} lldiv_t;
140
Elliott Hughesfaa74342017-08-11 17:34:44 -0700141lldiv_t lldiv(long long __numerator, long long __denominator) __attribute_const__;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800142
Elliott Hughes692207e2014-02-28 16:23:27 -0800143/* BSD compatibility. */
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700144const char* getprogname(void) __INTRODUCED_IN(21);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700145void setprogname(const char* __name) __INTRODUCED_IN(21);
Elliott Hughes692207e2014-02-28 16:23:27 -0800146
Elliott Hughesfaa74342017-08-11 17:34:44 -0700147int mblen(const char* __s, size_t __n) __INTRODUCED_IN(26) __VERSIONER_NO_GUARD;
148size_t mbstowcs(wchar_t* __dst, const char* __src, size_t __n);
149int mbtowc(wchar_t* __wc_ptr, const char* __s, size_t __n) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
150int wctomb(char* __dst, wchar_t __wc) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
Dan Albertcb0b1432016-09-06 16:51:00 -0700151
Elliott Hughesfaa74342017-08-11 17:34:44 -0700152size_t wcstombs(char* __dst, const wchar_t* __src, size_t __n);
David 'Digit' Turnerbb5581a2010-10-09 17:56:55 +0200153
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800154#if __ANDROID_API__ >= __ANDROID_API_L__
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700155size_t __ctype_get_mb_cur_max(void) __INTRODUCED_IN(21);
Dan Albert224ff042014-08-14 13:56:51 -0700156#define MB_CUR_MAX __ctype_get_mb_cur_max()
Dan Albertcb0b1432016-09-06 16:51:00 -0700157#else
158/*
Dan Albert5c15b8c2017-02-21 15:54:58 -0800159 * Pre-L we didn't have any locale support and so we were always the POSIX
160 * locale. POSIX specifies that MB_CUR_MAX for the POSIX locale is 1:
161 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdlib.h.html
Dan Albertcb0b1432016-09-06 16:51:00 -0700162 */
Dan Albert5c15b8c2017-02-21 15:54:58 -0800163#define MB_CUR_MAX 1
Dan Albertcb0b1432016-09-06 16:51:00 -0700164#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800165
George Burgess IVb97049c2017-07-24 15:05:05 -0700166#if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
167#include <bits/fortify/stdlib.h>
168#endif
Daniel Micay3244d9f2015-04-18 13:04:19 -0400169
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800170#if __ANDROID_API__ >= __ANDROID_API_L__
Elliott Hughesfaa74342017-08-11 17:34:44 -0700171float strtof(const char* __s, char** __end_ptr) __INTRODUCED_IN(21);
172double atof(const char* __s) __attribute_pure__ __INTRODUCED_IN(21);
173int abs(int __x) __attribute_const__ __INTRODUCED_IN(21);
174long labs(long __x) __attribute_const__ __INTRODUCED_IN(21);
175long long llabs(long long __x) __attribute_const__ __INTRODUCED_IN(21);
Josh Gaob6a4a4c2016-07-26 16:34:40 -0700176int rand(void) __INTRODUCED_IN(21);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700177void srand(unsigned int __seed) __INTRODUCED_IN(21);
Josh Gaob6a4a4c2016-07-26 16:34:40 -0700178long random(void) __INTRODUCED_IN(21);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700179void srandom(unsigned int __seed) __INTRODUCED_IN(21);
180int grantpt(int __fd) __INTRODUCED_IN(21);
Josh Gao6cd9fb02016-09-23 14:06:05 -0700181
Elliott Hughesfaa74342017-08-11 17:34:44 -0700182long long strtoll_l(const char* __s, char** __end_ptr, int __base, locale_t __l) __INTRODUCED_IN(21);
183unsigned long long strtoull_l(const char* __s, char** __end_ptr, int __base, locale_t __l) __INTRODUCED_IN(21);
184long double strtold_l(const char* __s, char** __end_ptr, locale_t __l) __INTRODUCED_IN(21);
Josh Gao8778d642016-07-22 15:26:36 -0700185#else
186// Implemented as static inlines before 21.
187#endif
188
Elliott Hughes4cae5c32017-07-10 11:51:00 -0700189#if __ANDROID_API__ >= __ANDROID_API_O__
Elliott Hughesfaa74342017-08-11 17:34:44 -0700190double strtod_l(const char* __s, char** __end_ptr, locale_t __l) __INTRODUCED_IN(26);
191float strtof_l(const char* __s, char** __end_ptr, locale_t __l) __INTRODUCED_IN(26);
192long strtol_l(const char* __s, char** __end_ptr, int, locale_t __l) __INTRODUCED_IN(26);
Josh Gao6cd9fb02016-09-23 14:06:05 -0700193#else
Elliott Hughes4cae5c32017-07-10 11:51:00 -0700194// Implemented as static inlines before 26.
Josh Gao6cd9fb02016-09-23 14:06:05 -0700195#endif
196
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800197__END_DECLS
198
Josh Gaob8e1b7052016-04-13 17:18:20 -0700199#include <android/legacy_stdlib_inlines.h>
200
Elliott Hughes76f89162015-01-26 13:34:58 -0800201#endif /* _STDLIB_H */