arosc.library: Use __inline__ instead of inline (needed for '-ansi' compilation)
[AROS.git] / compiler / clib / include / stdlib.h
blob74e567eb760f30051a6ce773cd51ecc71267ec77
1 #ifndef _STDLIB_H_
2 #define _STDLIB_H_
4 /*
5 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
6 $Id$
8 Desc: C99 & POSIX.1-2008 header file stdlib.h
9 */
11 #include <aros/system.h>
14 /* C99 */
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 {
22 int quot;
23 int rem;
24 } div_t;
26 typedef struct ldiv_t {
27 long int quot;
28 long int rem;
29 } ldiv_t;
31 #if defined AROS_HAVE_LONG_LONG
32 typedef struct lldiv_t {
33 long long int quot;
34 long long int rem;
35 } lldiv_t;
36 #endif
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
48 __BEGIN_DECLS
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); */
56 #endif
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,
64 int base);
65 #if defined AROS_HAVE_LONG_LONG
66 long long int strtoll(const char * restrict nptr,
67 char ** restrict endptr,
68 int base);
69 #endif
70 unsigned long int strtoul(const char * restrict nptr,
71 char ** restrict endptr,
72 int base);
73 #if defined AROS_HAVE_LONG_LONG
74 unsigned long long int strtoull(const char * restrict nptr,
75 char ** restrict endptr,
76 int base);
77 #endif
79 /* Pseudo-random sequence generation functions */
80 int rand (void);
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 */
104 int abs (int j);
105 long labs (long j);
106 #if defined AROS_HAVE_LONG_LONG
107 long long int llabs(long long int j);
108 #endif
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);
114 #endif
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); */
125 /* AROS extra */
126 void *realloc_nocopy(void *oldmem, size_t newsize); /* AROS specific */
127 int on_exit(void (*func)(int, void *), void *);
129 /* inline code */
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 */
137 #include <ctype.h>
140 #if !defined(_STDC_NOINLINE_MBTOWC)
141 static __inline__
142 int mbtowc(wchar_t * restrict pwc, const char * restrict s, size_t n)
144 if (s == NULL)
145 /* No state-dependent multi-byte character encoding */
146 return 0;
147 else
149 if (isascii(*s))
151 if (pwc)
152 *pwc = (wchar_t)*s;
153 if (*s == 0)
154 return 0;
155 else
156 return 1;
158 else
159 return -1;
162 #endif /* !_STDC_NOINLINE_MBTOWC */
165 #if !defined(_STDC_NOINLINE_WCTOMB)
166 static __inline__
167 int wctomb(char *s, wchar_t wchar)
169 if (s == NULL)
170 /* No state dependent encodings */
171 return 0;
172 else if (isascii((int)wchar))
174 *s = (char)wchar;
175 if (wchar == 0)
176 return 0;
177 else
178 return 1;
180 else
181 return -1;
183 #endif /* !_STDC_NOINLINE_WCTOMB */
186 #if !defined(_STDC_NOINLINE_MBSTOWCS)
187 static __inline__
188 size_t mbstowcs(wchar_t * restrict pwcs, const char * restrict s, size_t n)
190 size_t l;
192 for(l = 0; n > 0; s++, pwcs++, n--)
194 *pwcs = (wchar_t)*s;
196 if (*s == '\0')
197 break;
199 l++;
202 return l;
204 #endif /* !_STDC_NOINLINE_MBSTOWCS */
207 #if !defined(_STDC_NOINLINE_WCSTOMBS)
208 static __inline__
209 size_t wcstombs(char * restrict s, const wchar_t * restrict pwcs, size_t n)
211 size_t l;
213 for(l = 0; n > 0; s++, pwcs++, n--)
215 if (!isascii((int)*pwcs))
216 return (size_t)-1;
218 *s = (char)*pwcs;
220 if (*s == '\0')
221 break;
223 l++;
226 return l;
228 #endif /* !_STDC_NOINLINE_MBTOWC */
231 #endif /* !_STDC_NOINLINE && !_STDC_NOINLINE_STDLIB */
233 __END_DECLS
236 /* POSIX.1-2008 */
237 /* It seems that also stdlib.h defines alloca() */
238 #include <alloca.h>
240 __BEGIN_DECLS
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 *); */
253 int mkstemp(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 *); */
261 long random(void);
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 *);
275 /* BSD */
276 int getloadavg(double loadavg[], int n);
278 __END_DECLS
280 #endif /* _STDLIB_H_ */