stdlib.h revision dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668
11dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 21dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project 31dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * All rights reserved. 41dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 51dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Redistribution and use in source and binary forms, with or without 61dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * modification, are permitted provided that the following conditions 71dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * are met: 81dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * * Redistributions of source code must retain the above copyright 91dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * notice, this list of conditions and the following disclaimer. 101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * * Redistributions in binary form must reproduce the above copyright 111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * notice, this list of conditions and the following disclaimer in 121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * the documentation and/or other materials provided with the 131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * distribution. 141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * SUCH DAMAGE. 271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef _STDLIB_H_ 291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _STDLIB_H_ 301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <sys/cdefs.h> 321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <stddef.h> 341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <string.h> 351dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <alloca.h> 361dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <strings.h> 371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <memory.h> 381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__BEGIN_DECLS 401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 411dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define EXIT_FAILURE 1 421dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define EXIT_SUCCESS 0 431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern __noreturn void abort(void); 459f525644df99cb2f7f81a23ca23840f0a8f82275Elliott Hughesextern __noreturn void exit(int); 469f525644df99cb2f7f81a23ca23840f0a8f82275Elliott Hughesextern __noreturn void _Exit(int); 471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int atexit(void (*)(void)); 481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 49b8425c549a0bfe08b01b5906b95603d8523c1b16Dan Albert#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L 50b8425c549a0bfe08b01b5906b95603d8523c1b16Dan Albertint at_quick_exit(void (*)(void)); 51b8425c549a0bfe08b01b5906b95603d8523c1b16Dan Albertvoid quick_exit(int) __noreturn; 52b8425c549a0bfe08b01b5906b95603d8523c1b16Dan Albert#endif 53b8425c549a0bfe08b01b5906b95603d8523c1b16Dan Albert 5458d9e280d459225aa8dc4533e883182b08215f7dElliott Hughesextern char* getenv(const char*); 5558d9e280d459225aa8dc4533e883182b08215f7dElliott Hughesextern int putenv(char*); 5658d9e280d459225aa8dc4533e883182b08215f7dElliott Hughesextern int setenv(const char*, const char*, int); 5758d9e280d459225aa8dc4533e883182b08215f7dElliott Hughesextern int unsetenv(const char*); 581dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int clearenv(void); 591dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 60c13fb75ceabb47f8292be206db80b93889fccf66Elliott Hughesextern char* mkdtemp(char*); 61c13fb75ceabb47f8292be206db80b93889fccf66Elliott Hughesextern char* mktemp(char*) __warnattr("mktemp possibly used unsafely; consider using mkstemp"); 62c13fb75ceabb47f8292be206db80b93889fccf66Elliott Hughesextern int mkstemp(char*); 63fe317a3775e16d466bb884a8e054fd77f7087bb3Calin Juravleextern int mkstemp64(char*); 641dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 651dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern long strtol(const char *, char **, int); 661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern long long strtoll(const char *, char **, int); 671dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern unsigned long strtoul(const char *, char **, int); 681dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern unsigned long long strtoull(const char *, char **, int); 691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 7085aad909560508410101c18c6ecc6633df39c596Ken Sumrallextern int posix_memalign(void **memptr, size_t alignment, size_t size); 7185aad909560508410101c18c6ecc6633df39c596Ken Sumrall 725a8173860d65182af022be88fed0c5d8d5dcb69dElliott Hughesextern double atof(const char*); 73cce36c187896fb0d4bd36519c4b2e90c502137dcElliott Hughes 74cce36c187896fb0d4bd36519c4b2e90c502137dcElliott Hughesextern double strtod(const char*, char**) __LIBC_ABI_PUBLIC__; 75cce36c187896fb0d4bd36519c4b2e90c502137dcElliott Hughesextern float strtof(const char*, char**) __LIBC_ABI_PUBLIC__; 76cce36c187896fb0d4bd36519c4b2e90c502137dcElliott Hughesextern long double strtold(const char*, char**) __LIBC_ABI_PUBLIC__; 771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 78dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertextern long double strtold_l(const char *, char **, locale_t) __LIBC_ABI_PUBLIC__; 79dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertextern long long strtoll_l(const char *, char **, size_t, locale_t) __LIBC_ABI_PUBLIC__; 80dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertextern unsigned long long strtoull_l(const char *, char **, size_t, locale_t) __LIBC_ABI_PUBLIC__; 81dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albert 825a8173860d65182af022be88fed0c5d8d5dcb69dElliott Hughesextern int atoi(const char*) __purefunc; 835a8173860d65182af022be88fed0c5d8d5dcb69dElliott Hughesextern long atol(const char*) __purefunc; 845a8173860d65182af022be88fed0c5d8d5dcb69dElliott Hughesextern long long atoll(const char*) __purefunc; 851dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 86aec2ffbc5a7b45368ceab3663265fbb659968fe7Elliott Hughesextern int abs(int) __pure2; 87aec2ffbc5a7b45368ceab3663265fbb659968fe7Elliott Hughesextern long labs(long) __pure2; 88aec2ffbc5a7b45368ceab3663265fbb659968fe7Elliott Hughesextern long long llabs(long long) __pure2; 891dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 901dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern char * realpath(const char *path, char *resolved); 911dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int system(const char * string); 921dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 931dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern void * bsearch(const void *key, const void *base0, 941dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project size_t nmemb, size_t size, 951dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project int (*compar)(const void *, const void *)); 961dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 971dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); 981dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 991dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern long jrand48(unsigned short *); 1001dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern long mrand48(void); 1011dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern long nrand48(unsigned short *); 1021dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern long lrand48(void); 1031dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern unsigned short *seed48(unsigned short*); 10450ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turnerextern double erand48(unsigned short xsubi[3]); 10550ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turnerextern double drand48(void); 1061dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern void srand48(long); 1070468feb28696751efcddada8de69a622afffdba8Elliott Hughes 1080468feb28696751efcddada8de69a622afffdba8Elliott Hughesunsigned int arc4random(void); 1090468feb28696751efcddada8de69a622afffdba8Elliott Hughesunsigned int arc4random_uniform(unsigned int); 1100468feb28696751efcddada8de69a622afffdba8Elliott Hughesvoid arc4random_buf(void*, size_t); 1111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define RAND_MAX 0x7fffffff 113a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes 114e61919ad11fc0ca6749ee4d6855bc8b2c316a8f9Elliott Hughes/* Work around x86/x86-64 libvpx build breakage caused by postproc_x86.c. */ 115e61919ad11fc0ca6749ee4d6855bc8b2c316a8f9Elliott Hughes#if (defined(__i386__) || defined(__x86_64__)) && defined(rand) 1163fb5097a7eec40404760c304b36c8b657b374cabElliott Hughes#undef rand 1173fb5097a7eec40404760c304b36c8b657b374cabElliott Hughes#define __rand lrand48 1183fb5097a7eec40404760c304b36c8b657b374cabElliott Hughes#endif 1193fb5097a7eec40404760c304b36c8b657b374cabElliott Hughes 120a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughesint rand(void); 121a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughesint rand_r(unsigned int*); 122a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughesvoid srand(unsigned int); 123a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes 124a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hugheschar* initstate(unsigned int, char*, size_t); 125a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hugheslong random(void); 126a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hugheschar* setstate(char*); 127a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughesvoid srandom(unsigned int); 1281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* Basic PTY functions. These only work if devpts is mounted! */ 1301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int unlockpt(int); 1321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern char* ptsname(int); 1336458c49c96fd2069a82fa6bb48283b4397087a25Colin Crossextern int ptsname_r(int, char*, size_t); 1341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int getpt(void); 1351dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 136506b13d910a1a603b29fbc5a9ba41ba4c533b14cJing Yustatic __inline__ int grantpt(int __fd __attribute((unused))) 1371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project{ 1381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project (void)__fd; 1391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return 0; /* devpts does this all for us! */ 1401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 1411dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1421dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projecttypedef struct { 1431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project int quot; 1441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project int rem; 1451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} div_t; 1461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 147b27a840f4b520bfa095db99b0a2e5205634b0003Elliott Hughesextern div_t div(int, int) __pure2; 1481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projecttypedef struct { 1501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project long int quot; 1511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project long int rem; 1521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} ldiv_t; 1531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 154b27a840f4b520bfa095db99b0a2e5205634b0003Elliott Hughesextern ldiv_t ldiv(long, long) __pure2; 1551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projecttypedef struct { 1571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project long long int quot; 1581dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project long long int rem; 1591dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} lldiv_t; 1601dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 161b27a840f4b520bfa095db99b0a2e5205634b0003Elliott Hughesextern lldiv_t lldiv(long long, long long) __pure2; 1621dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 163692207eb457f9b4bf6cb4301d710d19b6e85c902Elliott Hughes/* BSD compatibility. */ 164692207eb457f9b4bf6cb4301d710d19b6e85c902Elliott Hughesextern const char* getprogname(void); 165692207eb457f9b4bf6cb4301d710d19b6e85c902Elliott Hughesextern void setprogname(const char*); 166692207eb457f9b4bf6cb4301d710d19b6e85c902Elliott Hughes 1671dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* make STLPort happy */ 1681dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int mblen(const char *, size_t); 1691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern size_t mbstowcs(wchar_t *, const char *, size_t); 1701dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int mbtowc(wchar_t *, const char *, size_t); 1711dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1721dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* Likewise, make libstdc++-v3 happy. */ 1731dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int wctomb(char *, wchar_t); 1741dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern size_t wcstombs(char *, const wchar_t *, size_t); 175bb5581ad6eec40041dab4e961149f7a8a3a83497David 'Digit' Turner 17669f05d291d848de654c72e5278de8ca06fbf5d2fElliott Hughes#define MB_CUR_MAX 4U 1771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 178bb5581ad6eec40041dab4e961149f7a8a3a83497David 'Digit' Turner#if 0 /* MISSING FROM BIONIC */ 179bb5581ad6eec40041dab4e961149f7a8a3a83497David 'Digit' Turnerextern int on_exit(void (*)(int, void *), void *); 180bb5581ad6eec40041dab4e961149f7a8a3a83497David 'Digit' Turner#endif /* MISSING */ 181bb5581ad6eec40041dab4e961149f7a8a3a83497David 'Digit' Turner 1821dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__END_DECLS 1831dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1841dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* _STDLIB_H_ */ 185