Home | History | Annotate | Download | only in include
      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  */
     28 
     29 #ifndef _STDLIB_H
     30 #define _STDLIB_H
     31 
     32 #include <alloca.h>
     33 #include <bits/wait.h>
     34 #include <malloc.h>
     35 #include <stddef.h>
     36 #include <sys/cdefs.h>
     37 #include <xlocale.h>
     38 
     39 __BEGIN_DECLS
     40 
     41 #define EXIT_FAILURE 1
     42 #define EXIT_SUCCESS 0
     43 
     44 __noreturn void abort(void);
     45 __noreturn void exit(int __status);
     46 #if __ANDROID_API__ >= __ANDROID_API_L__
     47 __noreturn void _Exit(int __status) __INTRODUCED_IN(21);
     48 #else
     49 __noreturn void _Exit(int) __RENAME(_exit);
     50 #endif
     51 
     52 int atexit(void (*__fn)(void));
     53 
     54 int at_quick_exit(void (*__fn)(void)) __INTRODUCED_IN(21);
     55 void quick_exit(int __status) __noreturn __INTRODUCED_IN(21);
     56 
     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);
     61 int clearenv(void);
     62 
     63 char* mkdtemp(char* __template);
     64 char* mktemp(char* __template) __attribute__((deprecated("mktemp is unsafe, use mkstemp or tmpfile instead")));
     65 
     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);
     74 
     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);
     79 
     80 int posix_memalign(void** __memptr, size_t __alignment, size_t __size) __INTRODUCED_IN(16);
     81 
     82 void* aligned_alloc(size_t __alignment, size_t __size) __INTRODUCED_IN(28);
     83 
     84 double strtod(const char* __s, char** __end_ptr);
     85 long double strtold(const char* __s, char** __end_ptr) __RENAME_LDBL(strtod, 3, 21);
     86 
     87 unsigned long strtoul_l(const char* __s, char** __end_ptr, int __base, locale_t __l) __INTRODUCED_IN(26);
     88 
     89 int atoi(const char* __s) __attribute_pure__;
     90 long atol(const char* __s) __attribute_pure__;
     91 long long atoll(const char* __s) __attribute_pure__;
     92 
     93 char* realpath(const char* __path, char* __resolved);
     94 int system(const char* __command);
     95 
     96 void* bsearch(const void* __key, const void* __base, size_t __nmemb, size_t __size, int (*__comparator)(const void* __lhs, const void* __rhs));
     97 
     98 void qsort(void* __base, size_t __nmemb, size_t __size, int (*__comparator)(const void* __lhs, const void* __rhs));
     99 
    100 uint32_t arc4random(void);
    101 uint32_t arc4random_uniform(uint32_t __upper_bound);
    102 void arc4random_buf(void* __buf, size_t __n);
    103 
    104 #define RAND_MAX 0x7fffffff
    105 
    106 int rand_r(unsigned int* __seed_ptr) __INTRODUCED_IN(21);
    107 
    108 double drand48(void);
    109 double erand48(unsigned short __xsubi[3]);
    110 long jrand48(unsigned short __xsubi[3]);
    111 void lcong48(unsigned short __param[7]) __INTRODUCED_IN(23);
    112 long lrand48(void);
    113 long mrand48(void);
    114 long nrand48(unsigned short __xsubi[3]);
    115 unsigned short* seed48(unsigned short __seed16v[3]);
    116 void srand48(long __seed);
    117 
    118 char* initstate(unsigned int __seed, char* __state, size_t __n) __INTRODUCED_IN(21);
    119 char* setstate(char* __state) __INTRODUCED_IN(21);
    120 
    121 int getpt(void);
    122 int posix_openpt(int __flags) __INTRODUCED_IN(21);
    123 char* ptsname(int __fd);
    124 int ptsname_r(int __fd, char* __buf, size_t __n);
    125 int unlockpt(int __fd);
    126 
    127 int getsubopt(char** __option, char* const* __tokens, char** __value_ptr) __INTRODUCED_IN(26);
    128 
    129 typedef struct {
    130   int quot;
    131   int rem;
    132 } div_t;
    133 
    134 div_t div(int __numerator, int __denominator) __attribute_const__;
    135 
    136 typedef struct {
    137   long int quot;
    138   long int rem;
    139 } ldiv_t;
    140 
    141 ldiv_t ldiv(long __numerator, long __denominator) __attribute_const__;
    142 
    143 typedef struct {
    144   long long int quot;
    145   long long int rem;
    146 } lldiv_t;
    147 
    148 lldiv_t lldiv(long long __numerator, long long __denominator) __attribute_const__;
    149 
    150 /* BSD compatibility. */
    151 const char* getprogname(void) __INTRODUCED_IN(21);
    152 void setprogname(const char* __name) __INTRODUCED_IN(21);
    153 
    154 int mblen(const char* __s, size_t __n) __INTRODUCED_IN(26) __VERSIONER_NO_GUARD;
    155 size_t mbstowcs(wchar_t* __dst, const char* __src, size_t __n);
    156 int mbtowc(wchar_t* __wc_ptr, const char* __s, size_t __n) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
    157 int wctomb(char* __dst, wchar_t __wc) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
    158 
    159 size_t wcstombs(char* __dst, const wchar_t* __src, size_t __n);
    160 
    161 #if __ANDROID_API__ >= __ANDROID_API_L__
    162 size_t __ctype_get_mb_cur_max(void) __INTRODUCED_IN(21);
    163 #define MB_CUR_MAX __ctype_get_mb_cur_max()
    164 #else
    165 /*
    166  * Pre-L we didn't have any locale support and so we were always the POSIX
    167  * locale. POSIX specifies that MB_CUR_MAX for the POSIX locale is 1:
    168  * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdlib.h.html
    169  */
    170 #define MB_CUR_MAX 1
    171 #endif
    172 
    173 #if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
    174 #include <bits/fortify/stdlib.h>
    175 #endif
    176 
    177 #if __ANDROID_API__ >= __ANDROID_API_K__
    178 int abs(int __x) __attribute_const__ __INTRODUCED_IN(19);
    179 long labs(long __x) __attribute_const__ __INTRODUCED_IN(19);
    180 long long llabs(long long __x) __attribute_const__ __INTRODUCED_IN(19);
    181 #else
    182 // Implemented as static inlines before 19.
    183 #endif
    184 
    185 #if __ANDROID_API__ >= __ANDROID_API_L__
    186 float strtof(const char* __s, char** __end_ptr) __INTRODUCED_IN(21);
    187 double atof(const char* __s) __attribute_pure__ __INTRODUCED_IN(21);
    188 int rand(void) __INTRODUCED_IN(21);
    189 void srand(unsigned int __seed) __INTRODUCED_IN(21);
    190 long random(void) __INTRODUCED_IN(21);
    191 void srandom(unsigned int __seed) __INTRODUCED_IN(21);
    192 int grantpt(int __fd) __INTRODUCED_IN(21);
    193 
    194 long long strtoll_l(const char* __s, char** __end_ptr, int __base, locale_t __l) __INTRODUCED_IN(21);
    195 unsigned long long strtoull_l(const char* __s, char** __end_ptr, int __base, locale_t __l) __INTRODUCED_IN(21);
    196 long double strtold_l(const char* __s, char** __end_ptr, locale_t __l) __INTRODUCED_IN(21);
    197 #else
    198 // Implemented as static inlines before 21.
    199 #endif
    200 
    201 #if __ANDROID_API__ >= __ANDROID_API_O__
    202 double strtod_l(const char* __s, char** __end_ptr, locale_t __l) __INTRODUCED_IN(26);
    203 float strtof_l(const char* __s, char** __end_ptr, locale_t __l) __INTRODUCED_IN(26);
    204 long strtol_l(const char* __s, char** __end_ptr, int, locale_t __l) __INTRODUCED_IN(26);
    205 #else
    206 // Implemented as static inlines before 26.
    207 #endif
    208 
    209 __END_DECLS
    210 
    211 #include <android/legacy_stdlib_inlines.h>
    212 
    213 #endif /* _STDLIB_H */
    214