3 * This file has no copyright assigned and is placed in the Public Domain.
4 * This file is a part of the mingw-runtime package.
5 * No warranty is given; refer to the file DISCLAIMER within the package.
7 * Definitions for common types, variables, and functions.
14 /* All the headers include this file. */
18 #define __need_wchar_t
22 #endif /* RC_INVOKED */
24 #include <stdint.h> /* For uintptr_t */
27 * RAND_MAX is the maximum value that may be returned by rand.
28 * The minimum is zero.
30 #define RAND_MAX 0x7FFF
33 * These values may be used as exit status codes.
35 #define EXIT_SUCCESS 0
36 #define EXIT_FAILURE 1
39 * Definitions for path name functions.
40 * NOTE: All of these values have simply been chosen to be conservatively high.
41 * Remember that with long file names we can no longer depend on
42 * extensions being short.
44 #ifndef __STRICT_ANSI__
47 #define MAX_PATH (260)
50 #define _MAX_PATH MAX_PATH
51 #define _MAX_DRIVE (3)
53 #define _MAX_FNAME 256
56 #endif /* Not __STRICT_ANSI__ */
65 #if !defined (__STRICT_ANSI__)
68 * This seems like a convenient place to declare these variables, which
69 * give programs using WinMain (or main for that matter) access to main-ish
70 * argc and argv. environ is a pointer to a table of environment variables.
71 * NOTE: Strings in _argv and environ are ANSI strings.
76 /* imports from runtime dll of the above variables */
79 extern int* __cdecl
__p___argc(void);
80 extern char*** __cdecl
__p___argv(void);
81 extern wchar_t*** __cdecl
__p___wargv(void);
83 #define __argc (*__p___argc())
84 #define __argv (*__p___argv())
85 #define __wargv (*__p___wargv())
89 #ifndef __DECLSPEC_SUPPORTED
91 extern int* _imp____argc_dll
;
92 extern char*** _imp____argv_dll
;
93 #define __argc (*_imp____argc_dll)
94 #define __argv (*_imp____argv_dll)
96 #else /* __DECLSPEC_SUPPORTED */
98 __MINGW_IMPORT
int __argc_dll
;
99 __MINGW_IMPORT
char** __argv_dll
;
100 #define __argc __argc_dll
101 #define __argv __argv_dll
103 #endif /* __DECLSPEC_SUPPORTED */
105 #endif /* __MSVCRT */
106 #endif /* __STRICT_ANSI__ */
108 * Also defined in ctype.h.
111 #ifdef __DECLSPEC_SUPPORTED
113 # define MB_CUR_MAX __mb_cur_max
114 __MINGW_IMPORT
int __mb_cur_max
;
115 # else /* not __MSVCRT */
116 # define MB_CUR_MAX __mb_cur_max_dll
117 __MINGW_IMPORT
int __mb_cur_max_dll
;
118 # endif /* not __MSVCRT */
120 #else /* ! __DECLSPEC_SUPPORTED */
122 extern int* _imp____mbcur_max
;
123 # define MB_CUR_MAX (*_imp____mb_cur_max)
124 # else /* not __MSVCRT */
125 extern int* _imp____mbcur_max_dll
;
126 # define MB_CUR_MAX (*_imp____mb_cur_max_dll)
127 # endif /* not __MSVCRT */
128 #endif /* __DECLSPEC_SUPPORTED */
129 #endif /* MB_CUR_MAX */
132 * MS likes to declare errno in stdlib.h as well.
139 _CRTIMP
int* __cdecl
_errno(void);
140 #define errno (*_errno())
142 _CRTIMP
int* __cdecl
__doserrno(void);
143 #define _doserrno (*__doserrno())
145 #if !defined (__STRICT_ANSI__)
147 * Use environ from the DLL, not as a global.
151 extern _CRTIMP
char *** __cdecl
__p__environ(void);
152 extern _CRTIMP
wchar_t *** __cdecl
__p__wenviron(void);
153 # define _environ (*__p__environ())
154 # define _wenviron (*__p__wenviron())
155 #else /* ! __MSVCRT__ */
156 # ifndef __DECLSPEC_SUPPORTED
157 extern char *** _imp___environ_dll
;
158 # define _environ (*_imp___environ_dll)
159 # else /* __DECLSPEC_SUPPORTED */
160 __MINGW_IMPORT
char ** _environ_dll
;
161 # define _environ _environ_dll
162 # endif /* __DECLSPEC_SUPPORTED */
163 #endif /* ! __MSVCRT__ */
165 #define environ _environ
168 /* One of the MSVCRTxx libraries */
170 #ifndef __DECLSPEC_SUPPORTED
171 extern int* _imp___sys_nerr
;
172 # define sys_nerr (*_imp___sys_nerr)
173 #else /* __DECLSPEC_SUPPORTED */
174 __MINGW_IMPORT
int _sys_nerr
;
176 # define sys_nerr _sys_nerr
178 #endif /* __DECLSPEC_SUPPORTED */
180 #else /* ! __MSVCRT__ */
182 /* CRTDLL run time library */
184 #ifndef __DECLSPEC_SUPPORTED
185 extern int* _imp___sys_nerr_dll
;
186 # define sys_nerr (*_imp___sys_nerr_dll)
187 #else /* __DECLSPEC_SUPPORTED */
188 __MINGW_IMPORT
int _sys_nerr_dll
;
189 # define sys_nerr _sys_nerr_dll
190 #endif /* __DECLSPEC_SUPPORTED */
192 #endif /* ! __MSVCRT__ */
194 #ifndef __DECLSPEC_SUPPORTED
195 extern char*** _imp__sys_errlist
;
196 #define sys_errlist (*_imp___sys_errlist)
197 #else /* __DECLSPEC_SUPPORTED */
198 __MINGW_IMPORT
char* _sys_errlist
[];
200 #define sys_errlist _sys_errlist
202 #endif /* __DECLSPEC_SUPPORTED */
205 * OS version and such constants.
211 extern _CRTIMP
unsigned __cdecl
int* __p__osver(void);
212 extern _CRTIMP
unsigned __cdecl
int* __p__winver(void);
213 extern _CRTIMP
unsigned __cdecl
int* __p__winmajor(void);
214 extern _CRTIMP
unsigned __cdecl
int* __p__winminor(void);
216 #ifndef __DECLSPEC_SUPPORTED
217 # define _osver (*__p__osver())
218 # define _winver (*__p__winver())
219 # define _winmajor (*__p__winmajor())
220 # define _winminor (*__p__winminor())
222 __MINGW_IMPORT
unsigned int _osver
;
223 __MINGW_IMPORT
unsigned int _winver
;
224 __MINGW_IMPORT
unsigned int _winmajor
;
225 __MINGW_IMPORT
unsigned int _winminor
;
226 #endif /* __DECLSPEC_SUPPORTED */
229 /* Not msvcrtxx.dll, thus crtdll.dll */
231 #ifndef __DECLSPEC_SUPPORTED
233 extern unsigned int* _imp___osver_dll
;
234 extern unsigned int* _imp___winver_dll
;
235 extern unsigned int* _imp___winmajor_dll
;
236 extern unsigned int* _imp___winminor_dll
;
238 #define _osver (*_imp___osver_dll)
239 #define _winver (*_imp___winver_dll)
240 #define _winmajor (*_imp___winmajor_dll)
241 #define _winminor (*_imp___winminor_dll)
243 #else /* __DECLSPEC_SUPPORTED */
245 __MINGW_IMPORT
unsigned int _osver_dll
;
246 __MINGW_IMPORT
unsigned int _winver_dll
;
247 __MINGW_IMPORT
unsigned int _winmajor_dll
;
248 __MINGW_IMPORT
unsigned int _winminor_dll
;
250 #define _osver _osver_dll
251 #define _winver _winver_dll
252 #define _winmajor _winmajor_dll
253 #define _winminor _winminor_dll
255 #endif /* __DECLSPEC_SUPPORTED */
259 #if defined __MSVCRT__
260 /* although the _pgmptr is exported as DATA,
261 * be safe and use the access function __p__pgmptr() to get it. */
262 _CRTIMP
char** __cdecl
__p__pgmptr(void);
263 #define _pgmptr (*__p__pgmptr())
264 _CRTIMP
wchar_t** __cdecl
__p__wpgmptr(void);
265 #define _wpgmptr (*__p__wpgmptr())
266 #else /* ! __MSVCRT__ */
267 # ifndef __DECLSPEC_SUPPORTED
268 extern char** __imp__pgmptr_dll
;
269 # define _pgmptr (*_imp___pgmptr_dll)
270 # else /* __DECLSPEC_SUPPORTED */
271 __MINGW_IMPORT
char* _pgmptr_dll
;
272 # define _pgmptr _pgmptr_dll
273 # endif /* __DECLSPEC_SUPPORTED */
274 /* no wide version in CRTDLL */
275 #endif /* __MSVCRT__ */
278 * This variable determines the default file mode.
279 * TODO: Which flags work?
281 #if !defined (__DECLSPEC_SUPPORTED) || defined (__IN_MINGW_RUNTIME)
284 extern int* _imp___fmode
;
285 #define _fmode (*_imp___fmode)
288 extern int* _imp___fmode_dll
;
289 #define _fmode (*_imp___fmode_dll)
292 #else /* __DECLSPEC_SUPPORTED */
295 __MINGW_IMPORT
int _fmode
;
296 #else /* ! __MSVCRT__ */
297 __MINGW_IMPORT
int _fmode_dll
;
298 #define _fmode _fmode_dll
299 #endif /* ! __MSVCRT__ */
301 #endif /* __DECLSPEC_SUPPORTED */
303 #endif /* Not __STRICT_ANSI__ */
305 _CRTIMP
double __cdecl
atof (const char*);
306 _CRTIMP
int __cdecl
atoi (const char*);
307 _CRTIMP
long __cdecl
atol (const char*);
308 #if !defined (__STRICT_ANSI__)
309 _CRTIMP
int __cdecl
_wtoi (const wchar_t *);
310 _CRTIMP
long __cdecl
_wtol (const wchar_t *);
312 _CRTIMP
double __cdecl
strtod (const char*, char**);
313 #if !defined __NO_ISOCEXT /* in libmingwex.a */
314 float __cdecl
strtof (const char * __restrict__
, char ** __restrict__
);
315 long double __cdecl
strtold (const char * __restrict__
, char ** __restrict__
);
316 #endif /* __NO_ISOCEXT */
318 _CRTIMP
long __cdecl
strtol (const char*, char**, int);
319 _CRTIMP
unsigned long __cdecl
strtoul (const char*, char**, int);
321 #ifndef _WSTDLIB_DEFINED
322 /* also declared in wchar.h */
323 _CRTIMP
double __cdecl
wcstod (const wchar_t*, wchar_t**);
324 #if !defined __NO_ISOCEXT /* in libmingwex.a */
325 float __cdecl
wcstof( const wchar_t * __restrict__
, wchar_t ** __restrict__
);
326 long double __cdecl
wcstold (const wchar_t * __restrict__
, wchar_t ** __restrict__
);
327 #endif /* __NO_ISOCEXT */
329 _CRTIMP
long __cdecl
wcstol (const wchar_t*, wchar_t**, int);
330 _CRTIMP
unsigned long __cdecl
wcstoul (const wchar_t*, wchar_t**, int);
331 #define _WSTDLIB_DEFINED
334 _CRTIMP
size_t __cdecl
wcstombs (char*, const wchar_t*, size_t);
335 _CRTIMP
int __cdecl
wctomb (char*, wchar_t);
337 _CRTIMP
int __cdecl
mblen (const char*, size_t);
338 _CRTIMP
size_t __cdecl
mbstowcs (wchar_t*, const char*, size_t);
339 _CRTIMP
int __cdecl
mbtowc (wchar_t*, const char*, size_t);
341 _CRTIMP
int __cdecl
rand (void);
342 _CRTIMP
void __cdecl
srand (unsigned int);
344 _CRTIMP
void* __cdecl
calloc (size_t, size_t) __MINGW_ATTRIB_MALLOC
;
345 _CRTIMP
void* __cdecl
malloc (size_t) __MINGW_ATTRIB_MALLOC
;
346 _CRTIMP
void* __cdecl
realloc (void*, size_t);
347 _CRTIMP
void __cdecl
free (void*);
348 _CRTIMP
void __cdecl
abort (void) __MINGW_ATTRIB_NORETURN
;
349 _CRTIMP
void __cdecl
exit (int) __MINGW_ATTRIB_NORETURN
;
351 /* Note: This is in startup code, not imported directly from dll */
352 int __cdecl
atexit (void (*)(void));
354 _CRTIMP
int __cdecl
system (const char*);
355 _CRTIMP
char* __cdecl
getenv (const char*);
357 /* bsearch and qsort are also in non-ANSI header search.h */
358 _CRTIMP
void* __cdecl
bsearch (const void*, const void*, size_t, size_t,
359 int (*)(const void*, const void*));
360 _CRTIMP
void __cdecl
qsort (void*, size_t, size_t,
361 int (*)(const void*, const void*));
363 _CRTIMP
int __cdecl
abs (int) __MINGW_ATTRIB_CONST
;
364 _CRTIMP
long __cdecl
labs (long) __MINGW_ATTRIB_CONST
;
367 * div_t and ldiv_t are structures used to return the results of div and
370 * NOTE: div and ldiv appear not to work correctly unless
371 * -fno-pcc-struct-return is specified. This is included in the
372 * mingw32 specs file.
374 typedef struct { int quot
, rem
; } div_t;
375 typedef struct { long quot
, rem
; } ldiv_t;
377 _CRTIMP
div_t __cdecl
div (int, int) __MINGW_ATTRIB_CONST
;
378 _CRTIMP
ldiv_t __cdecl
ldiv (long, long) __MINGW_ATTRIB_CONST
;
380 #if !defined (__STRICT_ANSI__)
383 * NOTE: Officially the three following functions are obsolete. The Win32 API
384 * functions SetErrorMode, Beep and Sleep are their replacements.
386 _CRTIMP
void __cdecl
_beep (unsigned int, unsigned int) __MINGW_ATTRIB_DEPRECATED
;
387 /* Not to be confused with _set_error_mode (int). */
388 _CRTIMP
void __cdecl
_seterrormode (int) __MINGW_ATTRIB_DEPRECATED
;
389 _CRTIMP
void __cdecl
_sleep (unsigned long) __MINGW_ATTRIB_DEPRECATED
;
391 _CRTIMP
void __cdecl
_exit (int) __MINGW_ATTRIB_NORETURN
;
393 /* _onexit is MS extension. Use atexit for portability. */
394 /* Note: This is in startup code, not imported directly from dll */
395 typedef int (* _onexit_t
)(void);
396 _onexit_t __cdecl
_onexit( _onexit_t
);
398 _CRTIMP
int __cdecl
_putenv (const char*);
399 _CRTIMP
void __cdecl
_searchenv (const char*, const char*, char*);
402 _CRTIMP
char* __cdecl
_ecvt (double, int, int*, int*);
403 _CRTIMP
char* __cdecl
_fcvt (double, int, int*, int*);
404 _CRTIMP
char* __cdecl
_gcvt (double, int, char*);
406 _CRTIMP
void __cdecl
_makepath (char*, const char*, const char*, const char*, const char*);
407 _CRTIMP
void __cdecl
_splitpath (const char*, char*, char*, char*, char*);
408 _CRTIMP
char* __cdecl
_fullpath (char*, const char*, size_t);
410 _CRTIMP
char* __cdecl
_itoa (int, char*, int);
411 _CRTIMP
char* __cdecl
_ltoa (long, char*, int);
412 _CRTIMP
char* __cdecl
_ultoa(unsigned long, char*, int);
413 _CRTIMP
wchar_t* __cdecl
_itow (int, wchar_t*, int);
414 _CRTIMP
wchar_t* __cdecl
_ltow (long, wchar_t*, int);
415 _CRTIMP
wchar_t* __cdecl
_ultow (unsigned long, wchar_t*, int);
418 _CRTIMP __int64 __cdecl
_atoi64(const char *);
419 _CRTIMP
char* __cdecl
_i64toa(__int64
, char *, int);
420 _CRTIMP
char* __cdecl
_ui64toa(unsigned __int64
, char *, int);
421 _CRTIMP __int64 __cdecl
_wtoi64(const wchar_t *);
422 _CRTIMP
wchar_t* __cdecl
_i64tow(__int64
, wchar_t *, int);
423 _CRTIMP
wchar_t* __cdecl
_ui64tow(unsigned __int64
, wchar_t *, int);
425 _CRTIMP
wchar_t* __cdecl
_wgetenv(const wchar_t*);
426 _CRTIMP
int __cdecl
_wputenv(const wchar_t*);
427 _CRTIMP
void __cdecl
_wsearchenv(const wchar_t*, const wchar_t*, wchar_t*);
428 _CRTIMP
void __cdecl
_wmakepath(wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*);
429 _CRTIMP
void __cdecl
_wsplitpath (const wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*);
430 _CRTIMP
wchar_t* __cdecl
_wfullpath (wchar_t*, const wchar_t*, size_t);
432 _CRTIMP
unsigned int __cdecl
_rotl(unsigned int, int) __MINGW_ATTRIB_CONST
;
433 _CRTIMP
unsigned int __cdecl
_rotr(unsigned int, int) __MINGW_ATTRIB_CONST
;
434 _CRTIMP
unsigned long __cdecl
_lrotl(unsigned long, int) __MINGW_ATTRIB_CONST
;
435 _CRTIMP
unsigned long __cdecl
_lrotr(unsigned long, int) __MINGW_ATTRIB_CONST
;
437 _CRTIMP
int __cdecl
_set_error_mode (int);
438 #define _OUT_TO_DEFAULT 0
439 #define _OUT_TO_STDERR 1
440 #define _OUT_TO_MSGBOX 2
441 #define _REPORT_ERRMODE 3
443 #if __MSVCRT_VERSION__ >= 0x800
444 _CRTIMP
unsigned int __cdecl
_set_abort_behavior (unsigned int, unsigned int);
445 /* These masks work with msvcr80.dll version 8.0.50215.44 (a beta release). */
446 #define _WRITE_ABORT_MSG 1
447 #define _CALL_REPORTFAULT 2
449 typedef void (* _invalid_parameter_handler
) (const wchar_t *,
454 _invalid_parameter_handler
_set_invalid_parameter_handler (_invalid_parameter_handler
);
455 #endif /* __MSVCRT_VERSION__ >= 0x800 */
456 #endif /* __MSVCRT__ */
460 _CRTIMP
int __cdecl
putenv (const char*);
461 _CRTIMP
void __cdecl
searchenv (const char*, const char*, char*);
463 _CRTIMP
char* __cdecl
itoa (int, char*, int);
464 _CRTIMP
char* __cdecl
ltoa (long, char*, int);
467 _CRTIMP
char* __cdecl
ecvt (double, int, int*, int*);
468 _CRTIMP
char* __cdecl
fcvt (double, int, int*, int*);
469 _CRTIMP
char* __cdecl
gcvt (double, int, char*);
471 #endif /* Not _NO_OLDNAMES */
473 #endif /* Not __STRICT_ANSI__ */
477 #if !defined __NO_ISOCEXT /* externs in static libmingwex.a */
479 /* C99 name for _exit */
480 void __cdecl
_Exit(int) __MINGW_ATTRIB_NORETURN
;
481 #ifndef __STRICT_ANSI__ /* inline using non-ansi functions */
482 __CRT_INLINE
void __cdecl
_Exit(int __status
)
483 { _exit (__status
); }
486 typedef struct { long long quot
, rem
; } lldiv_t
;
488 lldiv_t __cdecl
lldiv (long long, long long) __MINGW_ATTRIB_CONST
;
490 long long __cdecl
llabs(long long);
491 __CRT_INLINE
long long __cdecl
llabs(long long _j
)
492 {return (_j
>= 0 ? _j
: -_j
);}
494 long long __cdecl
strtoll (const char* __restrict__
, char** __restrict
, int);
495 unsigned long long __cdecl
strtoull (const char* __restrict__
, char** __restrict__
, int);
497 #if defined (__MSVCRT__) /* these are stubs for MS _i64 versions */
498 long long __cdecl
atoll (const char *);
500 #if !defined (__STRICT_ANSI__)
501 long long __cdecl
wtoll (const wchar_t *);
502 char* __cdecl
lltoa (long long, char *, int);
503 char* __cdecl
ulltoa (unsigned long long , char *, int);
504 wchar_t* __cdecl
lltow (long long, wchar_t *, int);
505 wchar_t* __cdecl
ulltow (unsigned long long, wchar_t *, int);
507 /* inline using non-ansi functions */
508 __CRT_INLINE
long long __cdecl
atoll (const char * _c
)
509 { return _atoi64 (_c
); }
510 __CRT_INLINE
char* __cdecl
lltoa (long long _n
, char * _c
, int _i
)
511 { return _i64toa (_n
, _c
, _i
); }
512 __CRT_INLINE
char* __cdecl
ulltoa (unsigned long long _n
, char * _c
, int _i
)
513 { return _ui64toa (_n
, _c
, _i
); }
514 __CRT_INLINE
long long __cdecl
wtoll (const wchar_t * _w
)
515 { return _wtoi64 (_w
); }
516 __CRT_INLINE
wchar_t* __cdecl
lltow (long long _n
, wchar_t * _w
, int _i
)
517 { return _i64tow (_n
, _w
, _i
); }
518 __CRT_INLINE
wchar_t* __cdecl
ulltow (unsigned long long _n
, wchar_t * _w
, int _i
)
519 { return _ui64tow (_n
, _w
, _i
); }
520 #endif /* (__STRICT_ANSI__) */
522 #endif /* __MSVCRT__ */
524 #endif /* !__NO_ISOCEXT */
531 #endif /* Not RC_INVOKED */
533 #endif /* Not _STDLIB_H_ */