9 #include "sys/stdtypes.h"
14 #include <sys/stdlib.h>
26 /* declaration prototypes */
28 div_t div(int numer, int denom);
29 ldiv_t ldiv(long int numer, long int denom);
31 void * malloc(size_t n);
32 void * calloc(size_t x, size_t y);
33 void * realloc(void * ptr, size_t n);
35 #if defined(_EiC) && 0
36 #define free(x) (free)(&(x));
39 void (free)(void *ptr);
43 void srand(unsigned int seed);
44 double strtod(const char *str, char **endptr);
45 long strtol(const char *str, char **endptr,int base);
48 unsigned long strtoul(const char *str, char **endptr,int base);
50 #define strtoul(x,y,z) strtol(x,y,z)
53 int system(const char * str);
54 double atof(const char *str);
55 int atoi(const char *s);
56 long atol(const char *s);
58 char *getenv(const char *name);
59 int *putenv(const char *name);
62 int atexit(void f(void));
65 /* these two macros are unsafe */
66 #define abs(x) ((x)>0? (x):-(x))
67 #define labs(x) abs(x)
69 /* non-standard stuff EiC interpreter stuff*/
71 #define itoa(x,y,z) _itoa(x,y,z,1)
72 #define utoa(x,y,z) _itoa(x,y,z,2)
73 #define ltoa(x,y,z) _ltoa(x,y,z,1)
74 #define ultoa(x,y,z) _ltoa(x,y,z,2)
76 char *utoa(unsigned int n, char *s, int radix);
77 char *itoa(int n, char *s, int radix);
78 char *ultoa(unsigned long n, char *s, int radix);
79 char *ltoa(long n, char *s, int radix);
82 #if defined(_SUNOS) && !defined(_EiC)
83 #define realloc(x,z) ((x) ? realloc(x,z) : malloc(z))
86 char * _itoa(int n,char *str, int radix, int mod);
87 char * _ltoa(int n,char *str, int radix, int mod);
92 void (*_exit_FuNcN[32])(void);
93 int _exit_FuNcS_n = 0;
97 int (atexit)(void f(void))
100 if(_exit_FuNcS_n == 32)
102 _exit_FuNcN[_exit_FuNcS_n++] = f;
106 void (exit)(int status)
110 for(i=0;i<_exit_FuNcS_n;++i)
118 /* sort and search functions that can't be builtin.
119 * Functions copied from The Standard C Library
125 void (qsort)(void *_base, size_t _n, size_t _size,
126 int (*_cmp)(const void *, const void *))
130 void *memcpy(void * _dst, const void * _src, size_t _n);
136 char *_qi = (char*)_base;
137 char *_qj = _qi + _size * _j;
141 while(_i < _j && (*_cmp) (_qi, _qp) <= 0)
143 while(_i < _j && (*_cmp)(_qp, _qj) <= 0)
150 for(_ms = _size; 0 < _ms; _ms -= _m, _q1 += _m,
152 _m = _ms < _QS_BS_ ? _ms : _QS_BS_;
153 memcpy(_buf, _q1, _m);
154 memcpy(_q1, _q2, _m);
165 for(_ms = _size; 0 < _ms; _ms -= _m, _q1 += _m,
167 _m = _ms < _QS_BS_ ? _ms : _QS_BS_;
168 memcpy(_buf, _q1, _m);
169 memcpy(_q1, _q2, _m);
174 _j = _n - _i - 1, _qi += _size;
177 qsort(_qi,_j,_size,_cmp);
181 qsort(_base,_i,_size,_cmp);
190 void * (bsearch)(const void * _key, const void * _base,
193 int _cmp(const void * keyval, const void * datum))
195 const char *_p = _base;
197 for(_n=_nelem;_n>0;) {
198 const size_t _pivot = _n >> 1;
199 const char *const _q = _p + _size * _pivot;
200 const int _val = _cmp(_key,_q);
218 #endif /* _STDLIBH */