]> granicus.if.org Git - esp-idf/blob - components/newlib/include/stdlib.h
Initial public version
[esp-idf] / components / newlib / include / stdlib.h
1 /*
2  * stdlib.h
3  *
4  * Definitions for common types, variables, and functions.
5  */
6
7 #ifndef _STDLIB_H_
8 #define _STDLIB_H_
9
10 #include <machine/ieeefp.h>
11 #include "_ansi.h"
12
13 #define __need_size_t
14 #define __need_wchar_t
15 #define __need_NULL
16 #include <stddef.h>
17
18 #include <sys/reent.h>
19 #include <sys/cdefs.h>
20 #include <machine/stdlib.h>
21 #ifndef __STRICT_ANSI__
22 #include <alloca.h>
23 #endif
24
25 #ifdef __CYGWIN__
26 #include <cygwin/stdlib.h>
27 #endif
28
29 _BEGIN_STD_C
30
31 typedef struct 
32 {
33   int quot; /* quotient */
34   int rem; /* remainder */
35 } div_t;
36
37 typedef struct 
38 {
39   long quot; /* quotient */
40   long rem; /* remainder */
41 } ldiv_t;
42
43 #if !defined(__STRICT_ANSI__) || \
44   (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
45   (defined(__cplusplus) && __cplusplus >= 201103L)
46 typedef struct
47 {
48   long long int quot; /* quotient */
49   long long int rem; /* remainder */
50 } lldiv_t;
51 #endif
52
53 #ifndef __compar_fn_t_defined
54 #define __compar_fn_t_defined
55 typedef int (*__compar_fn_t) (const _PTR, const _PTR);
56 #endif
57
58 #ifndef NULL
59 #define NULL 0
60 #endif
61
62 #define EXIT_FAILURE 1
63 #define EXIT_SUCCESS 0
64
65 #define RAND_MAX __RAND_MAX
66
67 int     _EXFUN(__locale_mb_cur_max,(_VOID));
68
69 #define MB_CUR_MAX __locale_mb_cur_max()
70
71 _VOID   _EXFUN(abort,(_VOID) _ATTRIBUTE ((__noreturn__)));
72 int     _EXFUN(abs,(int));
73 int     _EXFUN(atexit,(_VOID (*__func)(_VOID)));
74 double  _EXFUN(atof,(const char *__nptr));
75 #ifndef __STRICT_ANSI__
76 float   _EXFUN(atoff,(const char *__nptr));
77 #endif
78 int     _EXFUN(atoi,(const char *__nptr));
79 int     _EXFUN(_atoi_r,(struct _reent *, const char *__nptr));
80 long    _EXFUN(atol,(const char *__nptr));
81 long    _EXFUN(_atol_r,(struct _reent *, const char *__nptr));
82 _PTR    _EXFUN(bsearch,(const _PTR __key,
83                        const _PTR __base,
84                        size_t __nmemb,
85                        size_t __size,
86                        __compar_fn_t _compar));
87 _PTR    _EXFUN_NOTHROW(calloc,(size_t __nmemb, size_t __size));
88 div_t   _EXFUN(div,(int __numer, int __denom));
89 _VOID   _EXFUN(exit,(int __status) _ATTRIBUTE ((__noreturn__)));
90 _VOID   _EXFUN_NOTHROW(free,(_PTR));
91 char *  _EXFUN(getenv,(const char *__string));
92 char *  _EXFUN(_getenv_r,(struct _reent *, const char *__string));
93 char *  _EXFUN(_findenv,(_CONST char *, int *));
94 char *  _EXFUN(_findenv_r,(struct _reent *, _CONST char *, int *));
95 #ifndef __STRICT_ANSI__
96 extern char *suboptarg;                 /* getsubopt(3) external variable */
97 int     _EXFUN(getsubopt,(char **, char * const *, char **));
98 #endif
99 long    _EXFUN(labs,(long));
100 ldiv_t  _EXFUN(ldiv,(long __numer, long __denom));
101 _PTR    _EXFUN_NOTHROW(malloc,(size_t __size));
102 int     _EXFUN(mblen,(const char *, size_t));
103 int     _EXFUN(_mblen_r,(struct _reent *, const char *, size_t, _mbstate_t *));
104 int     _EXFUN(mbtowc,(wchar_t *__restrict, const char *__restrict, size_t));
105 int     _EXFUN(_mbtowc_r,(struct _reent *, wchar_t *__restrict, const char *__restrict, size_t, _mbstate_t *));
106 int     _EXFUN(wctomb,(char *, wchar_t));
107 int     _EXFUN(_wctomb_r,(struct _reent *, char *, wchar_t, _mbstate_t *));
108 size_t  _EXFUN(mbstowcs,(wchar_t *__restrict, const char *__restrict, size_t));
109 size_t  _EXFUN(_mbstowcs_r,(struct _reent *, wchar_t *__restrict, const char *__restrict, size_t, _mbstate_t *));
110 size_t  _EXFUN(wcstombs,(char *__restrict, const wchar_t *__restrict, size_t));
111 size_t  _EXFUN(_wcstombs_r,(struct _reent *, char *__restrict, const wchar_t *__restrict, size_t, _mbstate_t *));
112 #ifndef __STRICT_ANSI__
113 #ifndef _REENT_ONLY
114 char *  _EXFUN(mkdtemp,(char *));
115 int     _EXFUN(mkostemp,(char *, int));
116 int     _EXFUN(mkostemps,(char *, int, int));
117 int     _EXFUN(mkstemp,(char *));
118 int     _EXFUN(mkstemps,(char *, int));
119 #if (__GNUC__ < 4) || defined(__XTENSA__)
120 char *  _EXFUN(mktemp,(char *));
121 #else
122 char *  _EXFUN(mktemp,(char *) _ATTRIBUTE ((__warning__ ("the use of `mktemp' is dangerous; use `mkstemp' instead"))));
123 #endif
124 #endif
125 char *  _EXFUN(_mkdtemp_r, (struct _reent *, char *));
126 int     _EXFUN(_mkostemp_r, (struct _reent *, char *, int));
127 int     _EXFUN(_mkostemps_r, (struct _reent *, char *, int, int));
128 int     _EXFUN(_mkstemp_r, (struct _reent *, char *));
129 int     _EXFUN(_mkstemps_r, (struct _reent *, char *, int));
130 #if (__GNUC__ < 4) || defined(__XTENSA__)
131 char *  _EXFUN(_mktemp_r, (struct _reent *, char *)); 
132 #else
133 char *  _EXFUN(_mktemp_r, (struct _reent *, char *) _ATTRIBUTE ((__warning__ ("the use of `mktemp' is dangerous; use `mkstemp' instead"))));
134 #endif
135 #endif
136 _VOID   _EXFUN(qsort,(_PTR __base, size_t __nmemb, size_t __size, __compar_fn_t _compar));
137 int     _EXFUN(rand,(_VOID));
138 _PTR    _EXFUN_NOTHROW(realloc,(_PTR __r, size_t __size));
139 #ifndef __STRICT_ANSI__
140 _PTR    _EXFUN(reallocf,(_PTR __r, size_t __size));
141 char *  _EXFUN(realpath, (const char *__restrict path, char *__restrict resolved_path));
142 #endif
143 _VOID   _EXFUN(srand,(unsigned __seed));
144 double  _EXFUN(strtod,(const char *__restrict __n, char **__restrict __end_PTR));
145 double  _EXFUN(_strtod_r,(struct _reent *,const char *__restrict __n, char **__restrict __end_PTR));
146 #if !defined(__STRICT_ANSI__) || \
147   (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
148   (defined(__cplusplus) && __cplusplus >= 201103L)
149 float   _EXFUN(strtof,(const char *__restrict __n, char **__restrict __end_PTR));
150 #endif
151 #ifndef __STRICT_ANSI__
152 /* the following strtodf interface is deprecated...use strtof instead */
153 # ifndef strtodf 
154 #  define strtodf strtof
155 # endif
156 #endif
157 long    _EXFUN(strtol,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
158 long    _EXFUN(_strtol_r,(struct _reent *,const char *__restrict __n, char **__restrict __end_PTR, int __base));
159 unsigned long _EXFUN(strtoul,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
160 unsigned long _EXFUN(_strtoul_r,(struct _reent *,const char *__restrict __n, char **__restrict __end_PTR, int __base));
161
162 int     _EXFUN(system,(const char *__string));
163
164 #ifndef __STRICT_ANSI__
165 long    _EXFUN(a64l,(const char *__input));
166 char *  _EXFUN(l64a,(long __input));
167 char *  _EXFUN(_l64a_r,(struct _reent *,long __input));
168 int     _EXFUN(on_exit,(_VOID (*__func)(int, _PTR),_PTR __arg));
169 #endif /* ! __STRICT_ANSI__ */
170 #if !defined(__STRICT_ANSI__) || \
171   (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
172   (defined(__cplusplus) && __cplusplus >= 201103L)
173 _VOID   _EXFUN(_Exit,(int __status) _ATTRIBUTE ((__noreturn__)));
174 #endif
175 #ifndef __STRICT_ANSI__
176 int     _EXFUN(putenv,(char *__string));
177 int     _EXFUN(_putenv_r,(struct _reent *, char *__string));
178 _PTR    _EXFUN(_reallocf_r,(struct _reent *, _PTR, size_t));
179 int     _EXFUN(setenv,(const char *__string, const char *__value, int __overwrite));
180 int     _EXFUN(_setenv_r,(struct _reent *, const char *__string, const char *__value, int __overwrite));
181
182 char *  _EXFUN(gcvt,(double,int,char *));
183 char *  _EXFUN(gcvtf,(float,int,char *));
184 char *  _EXFUN(fcvt,(double,int,int *,int *));
185 char *  _EXFUN(fcvtf,(float,int,int *,int *));
186 char *  _EXFUN(ecvt,(double,int,int *,int *));
187 char *  _EXFUN(ecvtbuf,(double, int, int*, int*, char *));
188 char *  _EXFUN(fcvtbuf,(double, int, int*, int*, char *));
189 char *  _EXFUN(ecvtf,(float,int,int *,int *));
190 char *  _EXFUN(dtoa,(double, int, int, int *, int*, char**));
191 #endif
192 char *  _EXFUN(__itoa,(int, char *, int));
193 char *  _EXFUN(__utoa,(unsigned, char *, int));
194 #ifndef __STRICT_ANSI__
195 char *  _EXFUN(itoa,(int, char *, int));
196 char *  _EXFUN(utoa,(unsigned, char *, int));
197 int     _EXFUN(rand_r,(unsigned *__seed));
198
199 double _EXFUN(drand48,(_VOID));
200 double _EXFUN(_drand48_r,(struct _reent *));
201 double _EXFUN(erand48,(unsigned short [3]));
202 double _EXFUN(_erand48_r,(struct _reent *, unsigned short [3]));
203 long   _EXFUN(jrand48,(unsigned short [3]));
204 long   _EXFUN(_jrand48_r,(struct _reent *, unsigned short [3]));
205 _VOID  _EXFUN(lcong48,(unsigned short [7]));
206 _VOID  _EXFUN(_lcong48_r,(struct _reent *, unsigned short [7]));
207 long   _EXFUN(lrand48,(_VOID));
208 long   _EXFUN(_lrand48_r,(struct _reent *));
209 long   _EXFUN(mrand48,(_VOID));
210 long   _EXFUN(_mrand48_r,(struct _reent *));
211 long   _EXFUN(nrand48,(unsigned short [3]));
212 long   _EXFUN(_nrand48_r,(struct _reent *, unsigned short [3]));
213 unsigned short *
214        _EXFUN(seed48,(unsigned short [3]));
215 unsigned short *
216        _EXFUN(_seed48_r,(struct _reent *, unsigned short [3]));
217 _VOID  _EXFUN(srand48,(long));
218 _VOID  _EXFUN(_srand48_r,(struct _reent *, long));
219 #endif /* ! __STRICT_ANSI__ */
220 #if !defined(__STRICT_ANSI__) || \
221   (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
222   (defined(__cplusplus) && __cplusplus >= 201103L)
223 long long _EXFUN(atoll,(const char *__nptr));
224 #endif
225 #ifndef __STRICT_ANSI__
226 long long _EXFUN(_atoll_r,(struct _reent *, const char *__nptr));
227 #endif /* ! __STRICT_ANSI__ */
228 #if !defined(__STRICT_ANSI__) || \
229   (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
230   (defined(__cplusplus) && __cplusplus >= 201103L)
231 long long _EXFUN(llabs,(long long));
232 lldiv_t _EXFUN(lldiv,(long long __numer, long long __denom));
233 long long _EXFUN(strtoll,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
234 #endif
235 #ifndef __STRICT_ANSI__
236 long long _EXFUN(_strtoll_r,(struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base));
237 #endif /* ! __STRICT_ANSI__ */
238 #if !defined(__STRICT_ANSI__) || \
239   (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
240   (defined(__cplusplus) && __cplusplus >= 201103L)
241 unsigned long long _EXFUN(strtoull,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
242 #endif
243 #ifndef __STRICT_ANSI__
244 unsigned long long _EXFUN(_strtoull_r,(struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base));
245
246 #ifndef __CYGWIN__
247 _VOID   _EXFUN(cfree,(_PTR));
248 int     _EXFUN(unsetenv,(const char *__string));
249 int     _EXFUN(_unsetenv_r,(struct _reent *, const char *__string));
250 #endif
251
252 #ifdef __rtems__
253 int _EXFUN(posix_memalign,(void **, size_t, size_t));
254 #endif
255
256 #endif /* ! __STRICT_ANSI__ */
257
258 char *  _EXFUN(_dtoa_r,(struct _reent *, double, int, int, int *, int*, char**));
259 #ifndef __CYGWIN__
260 _PTR    _EXFUN_NOTHROW(_malloc_r,(struct _reent *, size_t));
261 _PTR    _EXFUN_NOTHROW(_calloc_r,(struct _reent *, size_t, size_t));
262 _VOID   _EXFUN_NOTHROW(_free_r,(struct _reent *, _PTR));
263 _PTR    _EXFUN_NOTHROW(_realloc_r,(struct _reent *, _PTR, size_t));
264 _VOID   _EXFUN(_mstats_r,(struct _reent *, char *));
265 #endif
266 int     _EXFUN(_system_r,(struct _reent *, const char *));
267
268 _VOID   _EXFUN(__eprintf,(const char *, const char *, unsigned int, const char *));
269
270 /* There are two common qsort_r variants.  If you request
271    _BSD_SOURCE, you get the BSD version; otherwise you get the GNU
272    version.  We want that #undef qsort_r will still let you
273    invoke the underlying function, but that requires gcc support. */
274 #ifdef _BSD_SOURCE
275 # ifdef __GNUC__
276 _VOID   _EXFUN(qsort_r,(_PTR __base, size_t __nmemb, size_t __size, _PTR __thunk, int (*_compar)(_PTR, const _PTR, const _PTR)))
277              __asm__ (__ASMNAME ("__bsd_qsort_r"));
278 # else
279 _VOID   _EXFUN(__bsd_qsort_r,(_PTR __base, size_t __nmemb, size_t __size, _PTR __thunk, int (*_compar)(_PTR, const _PTR, const _PTR)));
280 #  define qsort_r __bsd_qsort_r
281 # endif
282 #elif __GNU_VISIBLE
283 _VOID   _EXFUN(qsort_r,(_PTR __base, size_t __nmemb, size_t __size, int (*_compar)(const _PTR, const _PTR, _PTR), _PTR __thunk));
284 #endif
285
286 /* On platforms where long double equals double.  */
287 #ifdef _HAVE_LONG_DOUBLE
288 #if !defined(__STRICT_ANSI__) || \
289   (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
290   (defined(__cplusplus) && __cplusplus >= 201103L)
291 extern long double strtold (const char *__restrict, char **__restrict);
292 #endif
293 #endif /* _HAVE_LONG_DOUBLE */
294
295 _END_STD_C
296
297 #endif /* _STDLIB_H_ */