1 #ifndef _STDLIB_H_ 2 #define _STDLIB_H_ 3 /* 4 ** Distributed under the terms of the OpenBeOS License. 5 */ 6 7 #include <sys/types.h> 8 #include <div_t.h> 9 #include <wchar_t.h> 10 #include <stddef.h> 11 #include <limits.h> 12 #include <alloca.h> 13 14 15 #define RAND_MAX 0x7fffffff 16 #define MB_CUR_MAX 1 17 18 #define EXIT_SUCCESS 0 19 #define EXIT_FAILURE 1 20 21 /* random data structures (for thread-safe random numbers) */ 22 struct random_data { 23 int *fptr; 24 int *rptr; 25 int *state; 26 int rand_type; 27 int rand_deg; 28 int rand_sep; 29 int *end_ptr; 30 }; 31 32 struct drand48_data { 33 unsigned short int x[3]; 34 unsigned short int a[3]; 35 unsigned short int c; 36 unsigned short int old_x[3]; 37 int init; 38 }; 39 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 /* memory allocation (see malloc.h for additional defines & prototypes) */ 46 extern void *calloc(size_t nmemb, size_t size); 47 extern void free(void *pointer); 48 extern void *malloc(size_t size); 49 extern void *realloc(void * ptr, size_t size); 50 51 /* process termination */ 52 extern void abort(void); 53 extern int atexit(void (*func)(void)); 54 extern int atfork(void (*func)(void)); 55 extern void exit(int); 56 57 /* misc functions */ 58 extern char *realpath(const char *path, char *resolved); 59 60 extern int daemon(int nochdir, int noclose); 61 extern int system(const char *command); 62 63 extern char *mktemp(char *name); 64 extern int mkstemp(char *templat); 65 66 /* environment variables */ 67 extern char **environ; 68 extern char *getenv(const char *name); 69 extern int putenv(const char *string); 70 extern int setenv(char const *name, char const *value, int rewrite); 71 extern int unsetenv(const char *name); 72 73 /* ASCII string to number conversion */ 74 extern double atof(const char *string); 75 extern int atoi(const char *string); 76 extern long atol(const char *string); 77 extern long long int atoll(const char *string); 78 extern unsigned int atoui(const char *string); 79 extern unsigned long atoul(const char *string); 80 81 extern double strtod(const char *string, char **end); 82 extern long strtol(const char *string, char **end, int base); 83 extern unsigned long strtoul(const char *string, char **end, int base); 84 extern long long strtoll(const char *string, char **end, int base); 85 extern unsigned long long strtoull(const char *string, char **end, int base); 86 87 // ToDo: we will eventually need this 88 //extern int __ctype_get_mb_cur_max(void); 89 90 /* random number generation */ 91 extern void srand(unsigned int seed); 92 extern int rand(void); 93 extern int random(void); 94 extern void srandom(unsigned int seed); 95 extern int rand_r(unsigned int *seed); 96 extern int random_r(struct random_data *data, int *result); 97 extern int srandom_r(unsigned int seed, struct random_data *data); 98 extern char *initstate(unsigned int seed, char *state, size_t size); 99 extern char *setstate(char *state); 100 extern int initstate_r(unsigned int seed, void *stateBuffer, 101 size_t stateLength, struct random_data *data); 102 extern int setstate_r(void *stateBuffer, struct random_data *data); 103 104 extern double drand48(void); 105 extern double erand48(unsigned short int xsubi[3]); 106 extern long lrand48(void); 107 extern long nrand48(unsigned short int xsubi[3]); 108 extern long mrand48(void); 109 extern long jrand48(unsigned short int xsubi[3]); 110 extern void srand48(long int seed); 111 extern unsigned short *seed48(unsigned short int seed16v[3]); 112 extern void lcong48(unsigned short int param[7]); 113 114 extern int drand48_r(struct drand48_data *data, double *result); 115 extern int erand48_r(unsigned short int xsubi[3], 116 struct drand48_data *data, double *result); 117 extern int lrand48_r(struct drand48_data *data, long int *result); 118 extern int nrand48_r(unsigned short int xsubi[3], 119 struct drand48_data *data, long int *result); 120 extern int mrand48_r(struct drand48_data *data, long int *result); 121 extern int jrand48_r(unsigned short int xsubi[3], 122 struct drand48_data *data, long int *result); 123 extern int srand48_r(long int seed, struct drand48_data *data); 124 extern int seed48_r(unsigned short int seed16v[3], 125 struct drand48_data *data); 126 extern int lcong48_r(unsigned short int param[7], 127 struct drand48_data *data); 128 129 /* search and sort functions */ 130 typedef int (*_compare_function)(const void *, const void *); 131 132 extern void *bsearch(const void *key, const void *base, size_t numElements, 133 size_t sizeOfElement, _compare_function); 134 extern int heapsort(void *base, size_t numElements, size_t sizeOfElement, _compare_function); 135 extern int mergesort(void *base, size_t numElements, size_t sizeOfElement, _compare_function); 136 extern void qsort(void *base, size_t numElements, size_t sizeOfElement, _compare_function); 137 extern int radixsort(u_char const **base, int numElements, u_char const *table, u_int endByte); 138 extern int sradixsort(u_char const **base, int numElements, u_char const *table, u_int endByte); 139 140 /* misc math functions */ 141 extern int abs(int number); 142 extern long labs(long number); 143 extern long long llabs(long long number); 144 145 extern div_t div(int numerator, int denominator); 146 extern ldiv_t ldiv(long numerator, long denominator); 147 extern lldiv_t lldiv(long long numerator, long long denominator); 148 149 /* wide & multibyte string functions */ 150 extern int mblen(const char *string, size_t maxSize); 151 extern int mbtowc(wchar_t *pwc, const char *string, size_t maxSize); 152 extern int wctomb(char *string, wchar_t wchar); 153 extern size_t mbstowcs(wchar_t *pwcs, const char *string, size_t maxSize); 154 extern size_t wcstombs(char *string, const wchar_t *pwcs, size_t maxSize); 155 156 #ifdef __cplusplus 157 } /* extern "C" */ 158 #endif 159 160 #endif /* _STDLIB_H_ */ 161