5 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
8 Desc: C99 & POSIX.1-2008 header file stdlib.h
11 #include <aros/system.h>
15 #include <sys/arosc.h>
17 #include <aros/types/size_t.h>
18 #include <aros/types/wchar_t.h>
20 /* Types for div and ldiv */
21 typedef struct div_t {
26 typedef struct ldiv_t {
31 #if defined AROS_HAVE_LONG_LONG
32 typedef struct lldiv_t
{
38 #include <aros/types/null.h>
40 #define EXIT_SUCCESS 0 /* Success exit status */
41 #define EXIT_FAILURE 20 /* Failing exit status */
43 /* Gives the largest size of a multibyte character for the current locale */
44 #define MB_CUR_MAX (__get_arosc_userdata()->acud_mb_cur_max)
46 #define RAND_MAX 2147483647
50 /* Numeric conversion functions */
51 double atof(const char *nptr
);
52 int atoi(const char *nptr
);
53 long int atol(const char *nptr
);
54 #if defined AROS_HAVE_LONG_LONG
55 /* NOTIMPL long long int atoll(const char *nptr); */
58 double strtod(const char * restrict nptr
, char ** restrict endptr
);
59 /* NOTIMPL float strtof(const char * restrict nptr, char ** restrict endptr); */
60 /* NOTIMPL long double strtold(const char * restrict nptr, char ** restrict endptr); */
62 long int strtol(const char * restrict nptr
,
63 char ** restrict endptr
,
65 #if defined AROS_HAVE_LONG_LONG
66 long long int strtoll(const char * restrict nptr
,
67 char ** restrict endptr
,
70 unsigned long int strtoul(const char * restrict nptr
,
71 char ** restrict endptr
,
73 #if defined AROS_HAVE_LONG_LONG
74 unsigned long long int strtoull(const char * restrict nptr
,
75 char ** restrict endptr
,
79 /* Pseudo-random sequence generation functions */
81 void srand (unsigned int seed
);
83 /* Memory management functions */
84 void *calloc(size_t count
, size_t size
);
85 void free(void *memory
);
86 void *malloc(size_t size
);
87 void *realloc(void *oldmem
, size_t newsize
);
89 /* Communication with the environment */
90 void abort (void) __noreturn
;
91 int atexit(void (*func
)(void));
92 void exit(int code
) __noreturn
;
93 /* NOTIMPL void _Exit(int status); */
94 char *getenv(const char *name
);
95 int system(const char *string
);
97 /* Searching and sorting utilities */
98 void *bsearch(const void * key
, const void * base
, size_t count
,
99 size_t size
, int (*comparefunction
)(const void *, const void *));
100 void qsort(void * array
, size_t count
, size_t elementsize
,
101 int (*comparefunction
)(const void * element1
, const void * element2
));
103 /* Integer arithmetic functions */
106 #if defined AROS_HAVE_LONG_LONG
107 long long int llabs(long long int j
);
110 div_t div(int numer
, int denom
);
111 ldiv_t ldiv(long int numer
, long int denom
);
112 #if defined AROS_HAVE_LONG_LONG
113 lldiv_t
lldiv(long long int numer
, long long int denom
);
116 /* Multibyte/wide character conversion functions */
117 int mblen(const char *s
, size_t n
);
118 /* INLINE int mbtowc(wchar_t * restrict pwc, const char * restrict s, size_t n); */
119 /* INLINE int wctomb(char *s, wchar_t wchar); */
121 /* Multibyte/wide string conversion functions */
122 /* INLINE size_t mbstowcs(wchar_t * restrict pwcs, const char * restrict s, size_t n); */
123 /* INLINE size_t wcstombs(char * restrict s, const wchar_t * restrict pwcs, size_t n); */
126 void *realloc_nocopy(void *oldmem
, size_t newsize
); /* AROS specific */
127 int on_exit(void (*func
)(int, void *), void *);
130 /* The multi-byte character functions are implemented inline so that they adapt to the
131 size of wchar_t used by the compiler. This would not be possible if the code would
132 be compiled in the shared library or even the static link library.
135 #if !defined(_STDC_NOINLINE) && !defined(_STDC_NOINLINE_STDLIB)
136 /* This is name space pollution */
140 #if !defined(_STDC_NOINLINE_MBTOWC)
142 int mbtowc(wchar_t * restrict pwc
, const char * restrict s
, size_t n
)
145 /* No state-dependent multi-byte character encoding */
162 #endif /* !_STDC_NOINLINE_MBTOWC */
165 #if !defined(_STDC_NOINLINE_WCTOMB)
167 int wctomb(char *s
, wchar_t wchar
)
170 /* No state dependent encodings */
172 else if (isascii((int)wchar
))
183 #endif /* !_STDC_NOINLINE_WCTOMB */
186 #if !defined(_STDC_NOINLINE_MBSTOWCS)
188 size_t mbstowcs(wchar_t * restrict pwcs
, const char * restrict s
, size_t n
)
192 for(l
= 0; n
> 0; s
++, pwcs
++, n
--)
204 #endif /* !_STDC_NOINLINE_MBSTOWCS */
207 #if !defined(_STDC_NOINLINE_WCSTOMBS)
209 size_t wcstombs(char * restrict s
, const wchar_t * restrict pwcs
, size_t n
)
213 for(l
= 0; n
> 0; s
++, pwcs
++, n
--)
215 if (!isascii((int)*pwcs
))
228 #endif /* !_STDC_NOINLINE_MBTOWC */
231 #endif /* !_STDC_NOINLINE && !_STDC_NOINLINE_STDLIB */
237 /* It seems that also stdlib.h defines alloca() */
242 /* NOTIMPL long a64l(const char *); */
243 double drand48(void);
244 double erand48(unsigned short [3]);
245 /* NOTIMPL int getsubopt(char **, char *const *, char **); */
246 /* NOTIMPL int grantpt(int); */
247 char *initstate(unsigned, char *, int);
248 long int jrand48(unsigned short int [3]);
249 /* NOTIMPL char *l64a(long); */
250 void lcong48(unsigned short int [7]);
251 long int lrand48(void);
252 /* NOTIMPL char *mkdtemp(char *); */
254 long int mrand48(void);
255 long int nrand48(unsigned short int [3]);
256 int posix_memalign(void **memptr
, size_t alignment
, size_t size
);
257 /* NOTIMPL int posix_openpt(int); */
258 /* NOTIMPL char *ptsname(int); */
259 int putenv(const char *);
260 /* NOTIMPL int rand_r(unsigned int *); */
262 /* NOTIMPL char *realpath(const char * restrict , char * restrict); */
263 unsigned short int *seed48(unsigned short int [3]);
264 int setenv(const char *, const char *, int);
265 /* NOTIMPL void setkey(const char *); */
266 char *setstate(char *);
267 void srand48(long int);
268 void srandom(unsigned);
269 /* NOTIMPL int unlockpt(int); */
270 void unsetenv(const char *);
272 /* The following are deprecated POSIX functions */
273 char *mktemp(char *);
276 int getloadavg(double loadavg
[], int n
);
280 #endif /* _STDLIB_H_ */