stdlib.h revision 1dc9e472e19acfe6dc7f41e429236e7eef7ceda1
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/* wchar_t is required in stdlib.h according to POSIX.
341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * note that defining __need_wchar_t prevents stddef.h
351dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * to define all other symbols it does normally */
361dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __need_wchar_t
371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <stddef.h>
381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <stddef.h>
401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <string.h>
411dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <alloca.h>
421dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <strings.h>
431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <memory.h>
441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__BEGIN_DECLS
461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define EXIT_FAILURE 1
481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define EXIT_SUCCESS 0
491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern __noreturn void exit(int);
511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern __noreturn void abort(void);
521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int atexit(void (*)(void));
531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int on_exit(void (*)(int, void *), void *);
541dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern char *getenv(const char *);
561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int putenv(const char *);
571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int setenv(const char *, const char *, int);
581dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int unsetenv(const char *);
591dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int clearenv(void);
601dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
611dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern char *mktemp (char *);
621dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int mkstemp (char *);
631dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
641dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern long strtol(const char *, char **, int);
651dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern long long strtoll(const char *, char **, int);
661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern unsigned long strtoul(const char *, char **, int);
671dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern unsigned long long strtoull(const char *, char **, int);
681dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern double strtod(const char *nptr, char **endptr);
691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
701dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectstatic __inline__ float strtof(const char *nptr, char **endptr)
711dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project{
721dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    return (float)strtod(nptr, endptr);
731dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project}
741dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
751dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int atoi(const char *);
761dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern long atol(const char *);
771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern long long atoll(const char *);
781dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
791dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectstatic __inline__ double atof(const char *nptr)
801dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project{
811dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    return (strtod(nptr, NULL));
821dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project}
831dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
841dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectstatic __inline__ int abs(int __n) {
851dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    return (__n < 0) ? -__n : __n;
861dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project}
871dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
881dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectstatic __inline__ long labs(long __n) {
891dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    return (__n < 0L) ? -__n : __n;
901dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project}
911dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
921dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectstatic __inline__ long long llabs(long long __n) {
931dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    return (__n < 0LL) ? -__n : __n;
941dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project}
951dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
961dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern char * realpath(const char *path, char *resolved);
971dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int system(const char * string);
981dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
991dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern void * bsearch(const void *key, const void *base0,
1001dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	size_t nmemb, size_t size,
1011dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	int (*compar)(const void *, const void *));
1021dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1031dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1041dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1051dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern long jrand48(unsigned short *);
1061dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern long mrand48(void);
1071dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern long nrand48(unsigned short *);
1081dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern long lrand48(void);
1091dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern unsigned short *seed48(unsigned short*);
1101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern void srand48(long);
1111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern unsigned int arc4random(void);
1121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern void arc4random_stir(void);
1131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern void arc4random_addrandom(unsigned char *, int);
1141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define RAND_MAX 0x7fffffff
1161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectstatic __inline__ int rand(void) {
1171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    return (int)lrand48();
1181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project}
1191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectstatic __inline__ void srand(unsigned int __s) {
1201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    srand48(__s);
1211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project}
1221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectstatic __inline__ long random(void)
1231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project{
1241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    return lrand48();
1251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project}
1261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectstatic __inline__ void srandom(unsigned int __s)
1271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project{
1281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    srand48(__s);
1291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project}
1301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* Basic PTY functions.  These only work if devpts is mounted! */
1321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int    unlockpt(int);
1341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern char*  ptsname(int);
1351dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern char*  ptsname_r(int, char*, size_t);
1361dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int    getpt(void);
1371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectstatic __inline__ int grantpt(int __fd)
1391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project{
1401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project  (void)__fd;
1411dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project  return 0;     /* devpts does this all for us! */
1421dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project}
1431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projecttypedef struct {
1451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    int  quot;
1461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    int  rem;
1471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} div_t;
1481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern div_t   div(int, int);
1501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projecttypedef struct {
1521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    long int  quot;
1531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    long int  rem;
1541dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} ldiv_t;
1551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern ldiv_t   ldiv(long, long);
1571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1581dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projecttypedef struct {
1591dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    long long int  quot;
1601dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    long long int  rem;
1611dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} lldiv_t;
1621dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1631dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern lldiv_t   lldiv(long long, long long);
1641dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1651dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* make STLPort happy */
1661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int      mblen(const char *, size_t);
1671dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern size_t   mbstowcs(wchar_t *, const char *, size_t);
1681dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int      mbtowc(wchar_t *, const char *, size_t);
1691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1701dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* Likewise, make libstdc++-v3 happy.  */
1711dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern int	wctomb(char *, wchar_t);
1721dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern size_t	wcstombs(char *, const wchar_t *, size_t);
1731dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define MB_CUR_MAX 1
1741dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1751dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__END_DECLS
1761dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* _STDLIB_H_ */
178