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);
57 char *getenv(const char *name);
60 int atexit(void f(void));
63 /* these two macros are unsafe */
64 #define abs(x) ((x)>0? (x):-(x))
65 #define labs(x) abs(x)
67 /* non-standard stuff EiC interpreter stuff*/
69 #define itoa(x,y,z) _itoa(x,y,z,1)
70 #define utoa(x,y,z) _itoa(x,y,z,2)
71 #define ltoa(x,y,z) _ltoa(x,y,z,1)
72 #define ultoa(x,y,z) _ltoa(x,y,z,2)
74 char *utoa(unsigned int n, char *s, int radix);
75 char *itoa(int n, char *s, int radix);
76 char *ultoa(unsigned long n, char *s, int radix);
77 char *ltoa(long n, char *s, int radix);
80 #if defined(_SUNOS) && !defined(_EiC)
81 #define realloc(x,z) ((x) ? realloc(x,z) : malloc(z))
84 char * _itoa(int n,char *str, int radix, int mod);
85 char * _ltoa(int n,char *str, int radix, int mod);
90 void (*_exit_FuNcN[32])(void);
91 int _exit_FuNcS_n = 0;
95 int (atexit)(void f(void))
98 if(_exit_FuNcS_n == 32)
100 _exit_FuNcN[_exit_FuNcS_n++] = f;
104 void (exit)(int status)
108 for(i=0;i<_exit_FuNcS_n;++i)
116 /* sort and search functions that can't be builtin.
117 * Functions copied from The Standard C Library
123 void (qsort)(void *_base, size_t _n, size_t _size,
124 int (*_cmp)(const void *, const void *))
128 void *memcpy(void * _dst, const void * _src, size_t _n);
134 char *_qi = (char*)_base;
135 char *_qj = _qi + _size * _j;
139 while(_i < _j && (*_cmp) (_qi, _qp) <= 0)
141 while(_i < _j && (*_cmp)(_qp, _qj) <= 0)
148 for(_ms = _size; 0 < _ms; _ms -= _m, _q1 += _m,
150 _m = _ms < _QS_BS_ ? _ms : _QS_BS_;
151 memcpy(_buf, _q1, _m);
152 memcpy(_q1, _q2, _m);
163 for(_ms = _size; 0 < _ms; _ms -= _m, _q1 += _m,
165 _m = _ms < _QS_BS_ ? _ms : _QS_BS_;
166 memcpy(_buf, _q1, _m);
167 memcpy(_q1, _q2, _m);
172 _j = _n - _i - 1, _qi += _size;
175 qsort(_qi,_j,_size,_cmp);
179 qsort(_base,_i,_size,_cmp);
188 void * (bsearch)(const void * _key, const void * _base,
191 int _cmp(const void * keyval, const void * datum))
193 const char *_p = _base;
195 for(_n=_nelem;_n>0;) {
196 const size_t _pivot = _n >> 1;
197 const char *const _q = _p + _size * _pivot;
198 const int _val = _cmp(_key,_q);
216 #endif /* _STDLIBH */