stdlib.h revision a27d2baa0c1a2ec70f47ea9199b1dd6762c8a349
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#ifndef _STDLIB_H_ 29#define _STDLIB_H_ 30 31#include <sys/cdefs.h> 32#include <stddef.h> 33#include <string.h> 34#include <alloca.h> 35#include <strings.h> 36#include <memory.h> 37 38__BEGIN_DECLS 39 40#define EXIT_FAILURE 1 41#define EXIT_SUCCESS 0 42 43extern __noreturn void exit(int); 44extern __noreturn void abort(void); 45extern int atexit(void (*)(void)); 46extern int on_exit(void (*)(int, void *), void *); 47 48extern char *getenv(const char *); 49extern int putenv(const char *); 50extern int setenv(const char *, const char *, int); 51extern int unsetenv(const char *); 52extern int clearenv(void); 53 54extern char *mktemp (char *); 55extern int mkstemp (char *); 56 57extern long strtol(const char *, char **, int); 58extern long long strtoll(const char *, char **, int); 59extern unsigned long strtoul(const char *, char **, int); 60extern unsigned long long strtoull(const char *, char **, int); 61extern double strtod(const char *nptr, char **endptr); 62 63static __inline__ float strtof(const char *nptr, char **endptr) 64{ 65 return (float)strtod(nptr, endptr); 66} 67 68extern int atoi(const char *); 69extern long atol(const char *); 70extern long long atoll(const char *); 71 72static __inline__ double atof(const char *nptr) 73{ 74 return (strtod(nptr, NULL)); 75} 76 77static __inline__ int abs(int __n) { 78 return (__n < 0) ? -__n : __n; 79} 80 81static __inline__ long labs(long __n) { 82 return (__n < 0L) ? -__n : __n; 83} 84 85static __inline__ long long llabs(long long __n) { 86 return (__n < 0LL) ? -__n : __n; 87} 88 89extern char * realpath(const char *path, char *resolved); 90extern int system(const char * string); 91 92extern void * bsearch(const void *key, const void *base0, 93 size_t nmemb, size_t size, 94 int (*compar)(const void *, const void *)); 95 96extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); 97 98extern long jrand48(unsigned short *); 99extern long mrand48(void); 100extern long nrand48(unsigned short *); 101extern long lrand48(void); 102extern unsigned short *seed48(unsigned short*); 103extern void srand48(long); 104extern unsigned int arc4random(void); 105extern void arc4random_stir(void); 106extern void arc4random_addrandom(unsigned char *, int); 107 108#define RAND_MAX 0x7fffffff 109static __inline__ int rand(void) { 110 return (int)lrand48(); 111} 112static __inline__ void srand(unsigned int __s) { 113 srand48(__s); 114} 115static __inline__ long random(void) 116{ 117 return lrand48(); 118} 119static __inline__ void srandom(unsigned int __s) 120{ 121 srand48(__s); 122} 123 124/* Basic PTY functions. These only work if devpts is mounted! */ 125 126extern int unlockpt(int); 127extern char* ptsname(int); 128extern char* ptsname_r(int, char*, size_t); 129extern int getpt(void); 130 131static __inline__ int grantpt(int __fd) 132{ 133 (void)__fd; 134 return 0; /* devpts does this all for us! */ 135} 136 137__END_DECLS 138 139#endif /* _STDLIB_H_ */ 140