Optimize arithmetic with pointer to value on stack + constant
[tinycc/daniel.git] / win32 / include / stdlib.h
blob37fae487948407e24772d874aa58ee6ca7f5a72e
1 /*
2 * stdlib.h
4 * Definitions for common types, variables, and functions.
6 * This file is part of the Mingw32 package.
8 * Contributors:
9 * Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
11 * THIS SOFTWARE IS NOT COPYRIGHTED
13 * This source code is offered for use in the public domain. You may
14 * use, modify or distribute it freely.
16 * This code is distributed in the hope that it will be useful but
17 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
18 * DISCLAIMED. This includes but is not limited to warranties of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 * $Revision: 1.2 $
22 * $Author: bellard $
23 * $Date: 2005/04/17 13:14:29 $
27 #ifndef _STDLIB_H_
28 #define _STDLIB_H_
30 /* All the headers include this file. */
31 #include <_mingw.h>
34 #define __need_size_t
35 #define __need_wchar_t
36 #define __need_NULL
37 #ifndef RC_INVOKED
38 #include <stddef.h>
39 #endif /* RC_INVOKED */
42 * RAND_MAX is the maximum value that may be returned by rand.
43 * The minimum is zero.
45 #define RAND_MAX 0x7FFF
48 * These values may be used as exit status codes.
50 #define EXIT_SUCCESS 0
51 #define EXIT_FAILURE 1
54 * Definitions for path name functions.
55 * NOTE: All of these values have simply been chosen to be conservatively high.
56 * Remember that with long file names we can no longer depend on
57 * extensions being short.
59 #ifndef __STRICT_ANSI__
61 #ifndef MAX_PATH
62 #define MAX_PATH (260)
63 #endif
65 #define _MAX_PATH MAX_PATH
66 #define _MAX_DRIVE (3)
67 #define _MAX_DIR 256
68 #define _MAX_FNAME 256
69 #define _MAX_EXT 256
71 #endif /* Not __STRICT_ANSI__ */
74 #ifndef RC_INVOKED
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
81 * This seems like a convenient place to declare these variables, which
82 * give programs using WinMain (or main for that matter) access to main-ish
83 * argc and argv. environ is a pointer to a table of environment variables.
84 * NOTE: Strings in _argv and environ are ANSI strings.
86 extern int _argc;
87 extern char** _argv;
89 /* imports from runtime dll of the above variables */
90 #ifdef __MSVCRT__
92 extern int* __p___argc(void);
93 extern char*** __p___argv(void);
94 extern wchar_t*** __p___wargv(void);
96 #define __argc (*__p___argc())
97 #define __argv (*__p___argv())
98 #define __wargv (*__p___wargv())
100 #else /* !MSVCRT */
102 #ifndef __DECLSPEC_SUPPORTED
104 extern int* __imp___argc_dll;
105 extern char*** __imp___argv_dll;
106 #define __argc (*__imp___argc_dll)
107 #define __argv (*__imp___argv_dll)
109 #else /* __DECLSPEC_SUPPORTED */
111 __MINGW_IMPORT int __argc_dll;
112 __MINGW_IMPORT char** __argv_dll;
113 #define __argc __argc_dll
114 #define __argv __argv_dll
116 #endif /* __DECLSPEC_SUPPORTED */
118 #endif /* __MSVCRT */
121 * Also defined in ctype.h.
124 #ifndef MB_CUR_MAX
125 # ifdef __MSVCRT__
126 # define MB_CUR_MAX __mb_cur_max
127 __MINGW_IMPORT int __mb_cur_max;
128 # else /* not __MSVCRT */
129 # define MB_CUR_MAX __mb_cur_max_dll
130 __MINGW_IMPORT int __mb_cur_max_dll;
131 # endif /* not __MSVCRT */
132 #endif /* MB_CUR_MAX */
135 * MS likes to declare errno in stdlib.h as well.
138 #ifdef _UWIN
139 #undef errno
140 extern int errno;
141 #else
142 int* _errno(void);
143 #define errno (*_errno())
144 #endif
145 int* __doserrno(void);
146 #define _doserrno (*__doserrno())
149 * Use environ from the DLL, not as a global.
152 #ifdef __MSVCRT__
153 extern char *** __p__environ(void);
154 extern wchar_t *** __p__wenviron(void);
155 # define _environ (*__p__environ())
156 # define _wenviron (*__p__wenviron())
157 #else /* ! __MSVCRT__ */
158 # ifndef __DECLSPEC_SUPPORTED
159 extern char *** __imp__environ_dll;
160 # define _environ (*__imp__environ_dll)
161 # else /* __DECLSPEC_SUPPORTED */
162 __MINGW_IMPORT char ** _environ_dll;
163 # define _environ _environ_dll
164 # endif /* __DECLSPEC_SUPPORTED */
165 #endif /* ! __MSVCRT__ */
167 #define environ _environ
169 #ifdef __MSVCRT__
170 /* One of the MSVCRTxx libraries */
172 #ifndef __DECLSPEC_SUPPORTED
173 extern int* __imp__sys_nerr;
174 # define sys_nerr (*__imp__sys_nerr)
175 #else /* __DECLSPEC_SUPPORTED */
176 __MINGW_IMPORT int _sys_nerr;
177 # ifndef _UWIN
178 # define sys_nerr _sys_nerr
179 # endif /* _UWIN */
180 #endif /* __DECLSPEC_SUPPORTED */
182 #else /* ! __MSVCRT__ */
184 /* CRTDLL run time library */
186 #ifndef __DECLSPEC_SUPPORTED
187 extern int* __imp__sys_nerr_dll;
188 # define sys_nerr (*__imp__sys_nerr_dll)
189 #else /* __DECLSPEC_SUPPORTED */
190 __MINGW_IMPORT int _sys_nerr_dll;
191 # define sys_nerr _sys_nerr_dll
192 #endif /* __DECLSPEC_SUPPORTED */
194 #endif /* ! __MSVCRT__ */
196 #ifndef __DECLSPEC_SUPPORTED
197 extern char*** __imp__sys_errlist;
198 #define sys_errlist (*__imp__sys_errlist)
199 #else /* __DECLSPEC_SUPPORTED */
200 __MINGW_IMPORT char* _sys_errlist[];
201 #ifndef _UWIN
202 #define sys_errlist _sys_errlist
203 #endif /* _UWIN */
204 #endif /* __DECLSPEC_SUPPORTED */
207 * OS version and such constants.
209 #ifndef __STRICT_ANSI__
211 #ifdef __MSVCRT__
212 /* msvcrtxx.dll */
214 extern unsigned int* __p__osver(void);
215 extern unsigned int* __p__winver(void);
216 extern unsigned int* __p__winmajor(void);
217 extern unsigned int* __p__winminor(void);
219 #define _osver (*__p__osver())
220 #define _winver (*__p__winver())
221 #define _winmajor (*__p__winmajor())
222 #define _winminor (*__p__winminor())
224 #else
225 /* Not msvcrtxx.dll, thus crtdll.dll */
227 #ifndef __DECLSPEC_SUPPORTED
229 extern unsigned int* _imp___osver_dll;
230 extern unsigned int* _imp___winver_dll;
231 extern unsigned int* _imp___winmajor_dll;
232 extern unsigned int* _imp___winminor_dll;
234 #define _osver (*_imp___osver_dll)
235 #define _winver (*_imp___winver_dll)
236 #define _winmajor (*_imp___winmajor_dll)
237 #define _winminor (*_imp___winminor_dll)
239 #else /* __DECLSPEC_SUPPORTED */
241 __MINGW_IMPORT unsigned int _osver_dll;
242 __MINGW_IMPORT unsigned int _winver_dll;
243 __MINGW_IMPORT unsigned int _winmajor_dll;
244 __MINGW_IMPORT unsigned int _winminor_dll;
246 #define _osver _osver_dll
247 #define _winver _winver_dll
248 #define _winmajor _winmajor_dll
249 #define _winminor _winminor_dll
251 #endif /* __DECLSPEC_SUPPORTED */
253 #endif
255 #if defined __MSVCRT__
256 /* although the _pgmptr is exported as DATA,
257 * be safe and use the access function __p__pgmptr() to get it. */
258 char** __p__pgmptr(void);
259 #define _pgmptr (*__p__pgmptr())
260 wchar_t** __p__wpgmptr(void);
261 #define _wpgmptr (*__p__wpgmptr())
262 #else /* ! __MSVCRT__ */
263 # ifndef __DECLSPEC_SUPPORTED
264 extern char** __imp__pgmptr_dll;
265 # define _pgmptr (*__imp__pgmptr_dll)
266 # else /* __DECLSPEC_SUPPORTED */
267 __MINGW_IMPORT char* _pgmptr_dll;
268 # define _pgmptr _pgmptr_dll
269 # endif /* __DECLSPEC_SUPPORTED */
270 /* no wide version in CRTDLL */
271 #endif /* __MSVCRT__ */
273 #endif /* Not __STRICT_ANSI__ */
275 #ifdef __GNUC__
276 #define _ATTRIB_NORETURN __attribute__ ((noreturn))
277 #else /* Not __GNUC__ */
278 #define _ATTRIB_NORETURN
279 #endif /* __GNUC__ */
281 double atof (const char*);
282 int atoi (const char*);
283 long atol (const char*);
284 int _wtoi (const wchar_t *);
285 long _wtol (const wchar_t *);
287 double strtod (const char*, char**);
288 #if !defined __NO_ISOCEXT /* extern stubs in static libmingwex.a */
289 extern __inline__ float strtof (const char *nptr, char **endptr)
290 { return (strtod (nptr, endptr));}
291 #endif /* __NO_ISOCEXT */
293 long strtol (const char*, char**, int);
294 unsigned long strtoul (const char*, char**, int);
296 #ifndef _WSTDLIB_DEFINED
297 /* also declared in wchar.h */
298 double wcstod (const wchar_t*, wchar_t**);
299 #if !defined __NO_ISOCEXT /* extern stub in static libmingwex.a */
300 extern __inline__ float wcstof( const wchar_t *nptr, wchar_t **endptr)
301 { return (wcstod(nptr, endptr)); }
302 #endif /* __NO_ISOCEXT */
304 long wcstol (const wchar_t*, wchar_t**, int);
305 unsigned long wcstoul (const wchar_t*, wchar_t**, int);
306 #define _WSTDLIB_DEFINED
307 #endif
309 size_t wcstombs (char*, const wchar_t*, size_t);
310 int wctomb (char*, wchar_t);
312 int mblen (const char*, size_t);
313 size_t mbstowcs (wchar_t*, const char*, size_t);
314 int mbtowc (wchar_t*, const char*, size_t);
316 int rand (void);
317 void srand (unsigned int);
319 void* calloc (size_t, size_t);
320 void* malloc (size_t);
321 void* realloc (void*, size_t);
322 void free (void*);
324 void abort (void) _ATTRIB_NORETURN;
325 void exit (int) _ATTRIB_NORETURN;
326 int atexit (void (*)(void));
328 int system (const char*);
329 char* getenv (const char*);
331 void* bsearch (const void*, const void*, size_t, size_t,
332 int (*)(const void*, const void*));
333 void qsort (const void*, size_t, size_t,
334 int (*)(const void*, const void*));
336 int abs (int);
337 long labs (long);
340 * div_t and ldiv_t are structures used to return the results of div and
341 * ldiv.
343 * NOTE: div and ldiv appear not to work correctly unless
344 * -fno-pcc-struct-return is specified. This is included in the
345 * mingw32 specs file.
347 typedef struct { int quot, rem; } div_t;
348 typedef struct { long quot, rem; } ldiv_t;
350 div_t div (int, int);
351 ldiv_t ldiv (long, long);
353 #ifndef __STRICT_ANSI__
356 * NOTE: Officially the three following functions are obsolete. The Win32 API
357 * functions SetErrorMode, Beep and Sleep are their replacements.
359 void _beep (unsigned int, unsigned int);
360 void _seterrormode (int);
361 void _sleep (unsigned long);
363 void _exit (int) _ATTRIB_NORETURN;
364 #if !defined __NO_ISOCEXT /* extern stub in static libmingwex.a */
365 /* C99 function name */
366 void _Exit(int) _ATTRIB_NORETURN; /* Declare to get noreturn attribute. */
367 extern __inline__ void _Exit(int status)
368 { _exit(status); }
369 #endif
370 /* _onexit is MS extension. Use atexit for portability. */
371 typedef int (* _onexit_t)(void);
372 _onexit_t _onexit( _onexit_t );
374 int _putenv (const char*);
375 void _searchenv (const char*, const char*, char*);
378 char* _ecvt (double, int, int*, int*);
379 char* _fcvt (double, int, int*, int*);
380 char* _gcvt (double, int, char*);
382 void _makepath (char*, const char*, const char*, const char*, const char*);
383 void _splitpath (const char*, char*, char*, char*, char*);
384 char* _fullpath (char*, const char*, size_t);
387 char* _itoa (int, char*, int);
388 char* _ltoa (long, char*, int);
389 char* _ultoa(unsigned long, char*, int);
390 wchar_t* _itow (int, wchar_t*, int);
391 wchar_t* _ltow (long, wchar_t*, int);
392 wchar_t* _ultow (unsigned long, wchar_t*, int);
394 #ifdef __MSVCRT__
395 __int64 _atoi64(const char *);
396 char* _i64toa(__int64, char *, int);
397 char* _ui64toa(unsigned __int64, char *, int);
398 __int64 _wtoi64(const wchar_t *);
399 wchar_t* _i64tow(__int64, wchar_t *, int);
400 wchar_t* _ui64tow(unsigned __int64, wchar_t *, int);
402 wchar_t* _wgetenv(const wchar_t*);
403 int _wputenv(const wchar_t*);
404 void _wsearchenv(const wchar_t*, const wchar_t*, wchar_t*);
405 void _wmakepath(wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*);
406 void _wsplitpath (const wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*);
407 wchar_t* _wfullpath (wchar_t*, const wchar_t*, size_t);
408 #endif
410 #ifndef _NO_OLDNAMES
412 int putenv (const char*);
413 void searchenv (const char*, const char*, char*);
415 char* itoa (int, char*, int);
416 char* ltoa (long, char*, int);
418 #ifndef _UWIN
419 char* ecvt (double, int, int*, int*);
420 char* fcvt (double, int, int*, int*);
421 char* gcvt (double, int, char*);
422 #endif /* _UWIN */
423 #endif /* Not _NO_OLDNAMES */
425 #endif /* Not __STRICT_ANSI__ */
427 /* C99 names */
429 #if !defined __NO_ISOCEXT /* externs in static libmingwex.a */
431 typedef struct { long long quot, rem; } lldiv_t;
433 lldiv_t lldiv (long long, long long);
435 extern __inline__ long long llabs(long long _j)
436 {return (_j >= 0 ? _j : -_j);}
438 long long strtoll (const char* __restrict__, char** __restrict, int);
439 unsigned long long strtoull (const char* __restrict__, char** __restrict__, int);
441 #if defined (__MSVCRT__) /* these are stubs for MS _i64 versions */
442 long long atoll (const char *);
444 #if !defined (__STRICT_ANSI__)
445 long long wtoll(const wchar_t *);
446 char* lltoa(long long, char *, int);
447 char* ulltoa(unsigned long long , char *, int);
448 wchar_t* lltow(long long, wchar_t *, int);
449 wchar_t* ulltow(unsigned long long, wchar_t *, int);
451 /* inline using non-ansi functions */
452 extern __inline__ long long atoll (const char * _c)
453 { return _atoi64 (_c); }
454 extern __inline__ char* lltoa(long long _n, char * _c, int _i)
455 { return _i64toa (_n, _c, _i); }
456 extern __inline__ char* ulltoa(unsigned long long _n, char * _c, int _i)
457 { return _ui64toa (_n, _c, _i); }
458 extern __inline__ long long wtoll(const wchar_t * _w)
459 { return _wtoi64 (_w); }
460 extern __inline__ wchar_t* lltow(long long _n, wchar_t * _w, int _i)
461 { return _i64tow (_n, _w, _i); }
462 extern __inline__ wchar_t* ulltow(unsigned long long _n, wchar_t * _w, int _i)
463 { return _ui64tow (_n, _w, _i); }
464 #endif /* (__STRICT_ANSI__) */
466 #endif /* __MSVCRT__ */
468 #endif /* !__NO_ISOCEXT */
471 * Undefine the no return attribute used in some function definitions
473 #undef _ATTRIB_NORETURN
475 #ifdef __cplusplus
477 #endif
479 #endif /* Not RC_INVOKED */
481 #endif /* Not _STDLIB_H_ */