4 * ANSI/POSIX + Microsoft compatible standard library function prototypes,
5 * associated macros, and manifest constant definitions.
9 * Written by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
10 * Copyright (C) 1997-2009, 2011, 2014-2016, 2018, 2020, MinGW.org Project.
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
20 * The above copyright notice, this permission notice, and the following
21 * disclaimer shall be included in all copies or substantial portions of
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
30 * DEALINGS IN THE SOFTWARE.
34 #pragma GCC system_header
36 /* Some of the content of this header is made selectively accessible,
37 * when indirectly included via <wchar.h>; only when we have established
38 * that this inclusion is NOT via this selective method...
40 #ifndef __WCHAR_H_SOURCED__
41 /* ...do we define the repeat inclusion guard for <stdlib.h> itself.
45 /* All MinGW headers must include <_mingw.h>; if included via <wchar.h>,
46 * we assume that this has been done already, otherwise we must attend to
53 #define __need_wchar_t
56 #endif /* RC_INVOKED */
58 /* RAND_MAX is the maximum value that may be returned by rand.
59 * The minimum is zero.
61 #define RAND_MAX 0x7FFF
63 /* These values may be used as exit status codes.
65 #define EXIT_SUCCESS 0
66 #define EXIT_FAILURE 1
68 /* Definitions for path name functions.
69 * NOTE: All of these values have simply been chosen to be conservatively
70 * high. Remember that with long file names we can no longer depend on
71 * extensions being short.
73 #ifndef __STRICT_ANSI__
76 #define MAX_PATH (260)
79 #define _MAX_PATH MAX_PATH
80 #define _MAX_DRIVE (3)
82 #define _MAX_FNAME 256
85 #endif /* !__STRICT_ANSI__ */
86 #endif /* !__WCHAR_H_SOURCED__ */
93 #if ! defined __STRICT_ANSI__
94 /* This seems like a convenient place to declare these variables, which
95 * give programs using WinMain (or main for that matter) access to main-ish
96 * argc and argv. environ is a pointer to a table of environment variables.
97 * NOTE: Strings in _argv and environ are ANSI strings.
103 /* Imports from the runtime DLL, for the above variables.
105 extern __cdecl __MINGW_NOTHROW int *__p___argc(void);
106 extern __cdecl __MINGW_NOTHROW char ***__p___argv(void);
107 extern __cdecl __MINGW_NOTHROW wchar_t ***__p___wargv(void);
109 #define __argc (*__p___argc())
110 #define __argv (*__p___argv())
111 #define __wargv (*__p___wargv())
113 #else /* ! __MSVCRT__ */
115 #ifndef __DECLSPEC_SUPPORTED
117 extern int *_imp____argc_dll;
118 extern char ***_imp____argv_dll;
120 #define __argc (*_imp____argc_dll)
121 #define __argv (*_imp____argv_dll)
123 #else /* __DECLSPEC_SUPPORTED */
125 __MINGW_IMPORT int __argc_dll;
126 __MINGW_IMPORT char **__argv_dll;
128 #define __argc __argc_dll
129 #define __argv __argv_dll
131 #endif /* __DECLSPEC_SUPPORTED */
133 #endif /* __MSVCRT__ */
134 #endif /* __STRICT_ANSI__ */
137 /* FIXME: also defined in <ctype.h>; should be factored out.
139 #ifdef __DECLSPEC_SUPPORTED
141 # define MB_CUR_MAX __mb_cur_max
142 __MINGW_IMPORT int __mb_cur_max;
143 # else /* ! __MSVCRT__ */
144 # define MB_CUR_MAX __mb_cur_max_dll
145 __MINGW_IMPORT int __mb_cur_max_dll;
146 # endif /* ! __MSVCRT__ */
148 #else /* ! __DECLSPEC_SUPPORTED */
150 extern int* _imp____mb_cur_max;
151 # define MB_CUR_MAX (*_imp____mb_cur_max)
152 # else /* ! __MSVCRT__ */
153 extern int* _imp____mb_cur_max_dll;
154 # define MB_CUR_MAX (*_imp____mb_cur_max_dll)
155 # endif /* ! __MSVCRT__ */
156 #endif /* __DECLSPEC_SUPPORTED */
157 #endif /* MB_CUR_MAX */
159 /* In MSVCR80.DLL, Microsoft introduced the following pair of errno
160 * accessor functions; they subsequently became available in MSVCRT.DLL
161 * from Vista onward. Although they are not required by ISO-C, and they
162 * are more cumbersome to use, than referring to errno directly, the GCC
163 * developers have gratuitously chosen to assume, in GCC-9.x, that they
164 * are always supported on MS-Windows, regardless of Windows version.
165 * Logically, we might expect these to be declared in <errno.h>, but
166 * Microsoft's documentation insists that they are actually declared
167 * here; thus, to satisfy the GCC-9.x requirement, we will declare
168 * them unconditionally here ...
170 __cdecl __MINGW_NOTHROW int _get_errno(int *);
171 __cdecl __MINGW_NOTHROW int _set_errno(int);
173 /* ... then provide in-line implementations, (depending on gratuitous
174 * exposure of EINVAL, which strictly belongs in <errno.h> only, while
175 * also requiring declaring the ISO-C errno feature, which Microsoft
176 * documentation calls for both here, and in <errno.h>; we satisfy
177 * both of these requirements by selective <errno.h> inclusion).
179 #define __STDLIB_H_SOURCED__ 1
182 #if __MSVCRT_VERSION__ < __MSVCR80_DLL && _WIN32_WINNT < _WIN32_WINNT_VISTA
183 /* These in-line implementations will support universal use of this API,
184 * even on legacy Windows versions pre-dating Vista, without requiring use
185 * of non-free MSVCRT80.DLL or later.
187 __CRT_ALIAS __cdecl __MINGW_NOTHROW int _get_errno( int *__val )
188 { return (__val == NULL) ? (errno = EINVAL) : 0 & (*__val = errno); }
190 __CRT_ALIAS __cdecl __MINGW_NOTHROW int _set_errno( int __val )
191 { errno = __val; return 0; }
194 #undef __STDLIB_H_SOURCED__
196 _CRTIMP __cdecl __MINGW_NOTHROW int *__doserrno(void);
197 #define _doserrno (*__doserrno())
199 #if !defined (__STRICT_ANSI__)
200 /* Use environ from the DLL, not as a global.
203 # define _environ (*__p__environ())
204 extern _CRTIMP __cdecl __MINGW_NOTHROW char ***__p__environ(void);
205 # define _wenviron (*__p__wenviron())
206 extern _CRTIMP __cdecl __MINGW_NOTHROW wchar_t ***__p__wenviron(void);
208 #else /* ! __MSVCRT__ */
209 # ifndef __DECLSPEC_SUPPORTED
210 # define _environ (*_imp___environ_dll)
211 extern char ***_imp___environ_dll;
213 # else /* __DECLSPEC_SUPPORTED */
214 # define _environ _environ_dll
215 __MINGW_IMPORT char ** _environ_dll;
216 # endif /* __DECLSPEC_SUPPORTED */
217 #endif /* ! __MSVCRT__ */
219 #define environ _environ
222 /* One of the MSVCRTxx libraries */
224 #ifndef __DECLSPEC_SUPPORTED
225 # define sys_nerr (*_imp___sys_nerr)
226 extern int *_imp___sys_nerr;
228 #else /* __DECLSPEC_SUPPORTED */
229 __MINGW_IMPORT int _sys_nerr;
232 # define sys_nerr _sys_nerr
234 #endif /* __DECLSPEC_SUPPORTED */
236 #else /* ! __MSVCRT__ */
237 /* CRTDLL run time library */
239 #ifndef __DECLSPEC_SUPPORTED
240 extern int* _imp___sys_nerr_dll;
241 # define sys_nerr (*_imp___sys_nerr_dll)
242 #else /* __DECLSPEC_SUPPORTED */
243 __MINGW_IMPORT int _sys_nerr_dll;
244 # define sys_nerr _sys_nerr_dll
245 #endif /* __DECLSPEC_SUPPORTED */
247 #endif /* ! __MSVCRT__ */
249 #ifndef __DECLSPEC_SUPPORTED
250 #define sys_errlist (*_imp___sys_errlist)
251 extern char ***_imp__sys_errlist;
253 #else /* __DECLSPEC_SUPPORTED */
254 __MINGW_IMPORT char *_sys_errlist[];
257 #define sys_errlist _sys_errlist
259 #endif /* __DECLSPEC_SUPPORTED */
261 /* OS version and such constants.
263 #ifdef __MSVCRT__ /* MSVCRT.DLL and MSVCRxx.DLL variants */
265 extern _CRTIMP __cdecl __MINGW_NOTHROW unsigned int *__p__osver(void);
266 extern _CRTIMP __cdecl __MINGW_NOTHROW unsigned int *__p__winver(void);
267 extern _CRTIMP __cdecl __MINGW_NOTHROW unsigned int *__p__winmajor(void);
268 extern _CRTIMP __cdecl __MINGW_NOTHROW unsigned int *__p__winminor(void);
270 #ifndef __DECLSPEC_SUPPORTED
271 # define _osver (*__p__osver())
272 # define _winver (*__p__winver())
273 # define _winmajor (*__p__winmajor())
274 # define _winminor (*__p__winminor())
276 #else /* __DECLSPEC_SUPPORTED */
277 __MINGW_IMPORT unsigned int _osver;
278 __MINGW_IMPORT unsigned int _winver;
279 __MINGW_IMPORT unsigned int _winmajor;
280 __MINGW_IMPORT unsigned int _winminor;
281 #endif /* __DECLSPEC_SUPPORTED */
283 #else /* ! __MSVCRT__; thus CRTDLL */
284 #ifndef __DECLSPEC_SUPPORTED
286 #define _osver (*_imp___osver_dll)
287 #define _winver (*_imp___winver_dll)
288 #define _winmajor (*_imp___winmajor_dll)
289 #define _winminor (*_imp___winminor_dll)
291 extern unsigned int *_imp___osver_dll;
292 extern unsigned int *_imp___winver_dll;
293 extern unsigned int *_imp___winmajor_dll;
294 extern unsigned int *_imp___winminor_dll;
296 #else /* __DECLSPEC_SUPPORTED */
298 #define _osver _osver_dll
299 #define _winver _winver_dll
300 #define _winmajor _winmajor_dll
301 #define _winminor _winminor_dll
303 __MINGW_IMPORT unsigned int _osver_dll;
304 __MINGW_IMPORT unsigned int _winver_dll;
305 __MINGW_IMPORT unsigned int _winmajor_dll;
306 __MINGW_IMPORT unsigned int _winminor_dll;
308 #endif /* __DECLSPEC_SUPPORTED */
311 #if defined __MSVCRT__
312 /* Although _pgmptr is exported as DATA, be safe and use the access
313 * function __p__pgmptr() to get it.
315 #define _pgmptr (*__p__pgmptr())
316 _CRTIMP __cdecl __MINGW_NOTHROW char **__p__pgmptr(void);
318 #define _wpgmptr (*__p__wpgmptr())
319 _CRTIMP __cdecl __MINGW_NOTHROW wchar_t **__p__wpgmptr(void);
321 #else /* ! __MSVCRT__; thus CRTDLL */
323 # ifndef __DECLSPEC_SUPPORTED
324 # define _pgmptr (*_imp___pgmptr_dll)
325 extern char **__imp__pgmptr_dll;
327 # else /* __DECLSPEC_SUPPORTED */
329 # define _pgmptr _pgmptr_dll
330 __MINGW_IMPORT char *_pgmptr_dll;
331 /* no wide version in CRTDLL */
333 # endif /* __DECLSPEC_SUPPORTED */
336 /* This variable determines the default file mode.
337 * TODO: Which flags work?
339 #if !defined (__DECLSPEC_SUPPORTED) || defined (__IN_MINGW_RUNTIME)
342 #define _fmode (*_imp___fmode)
343 extern int *_imp___fmode;
346 #define _fmode (*_imp___fmode_dll)
347 extern int *_imp___fmode_dll;
350 #else /* __DECLSPEC_SUPPORTED */
352 __MINGW_IMPORT int _fmode;
354 #else /* ! __MSVCRT__ */
355 #define _fmode _fmode_dll
356 __MINGW_IMPORT int _fmode_dll;
358 #endif /* !__MSVCRT__ */
359 #endif /* __DECLSPEC_SUPPORTED */
360 #endif /* !__STRICT_ANSI__ */
362 _CRTIMP __cdecl __MINGW_NOTHROW int atoi (const char *);
363 _CRTIMP __cdecl __MINGW_NOTHROW long atol (const char *);
365 _CRTIMP __cdecl __MINGW_NOTHROW double strtod (const char *, char **);
366 _CRTIMP __cdecl __MINGW_NOTHROW double atof (const char *);
368 #if !defined (__STRICT_ANSI__)
369 _CRTIMP __cdecl __MINGW_NOTHROW double _wtof (const wchar_t *);
370 _CRTIMP __cdecl __MINGW_NOTHROW int _wtoi (const wchar_t *);
371 _CRTIMP __cdecl __MINGW_NOTHROW long _wtol (const wchar_t *);
374 #if __USE_MINGW_ANSI_STDIO
375 /* Microsoft's strtod() and atof() implementations, (in MSVCRT.DLL),
376 * mishandle infinities and NaNs; on the basis that this conditional
377 * exposes a more ISO-C conforming printf() I/O family implementaion,
378 * we substitute a similarly more conforming implementation for each
379 * of this pair of (somewhat related) functions.
381 * Note that we provide neither __JMPSTUB__ nor __LIBIMPL__ external
382 * equivalents for either of these two inline functions, because they
383 * would conflict with the runtime DLL implementations; users needing
384 * an address reference for either must provide an equivalent of the
385 * inline implementation, as non-inlined within their own code.
387 extern __cdecl __MINGW_NOTHROW
388 double __strtod (const char *__restrict__, char **__restrict__);
390 __CRT_ALIAS __cdecl __MINGW_NOTHROW
391 double strtod (const char *__restrict__ __nptr, char **__restrict__ __endptr)
392 { return __strtod( __nptr, __endptr ); }
394 __CRT_ALIAS __cdecl __MINGW_NOTHROW
395 double atof (const char *__nptr) { return __strtod( __nptr, NULL ); }
397 #endif /* __USE_MINGW_ANSI_STDIO */
399 #ifdef _ISOC99_SOURCE
400 /* Irrespective of requested standards conformity, where MSVCRT.DLL
401 * falls short, ISO-C99 offers this pair of alternative return type
402 * specific variants of strtod(), which MSVCRT.DLL does not, but we
403 * do, in libmingwex.a:
405 __cdecl __MINGW_NOTHROW
406 float strtof (const char *__restrict__, char **__restrict__);
408 __cdecl __MINGW_NOTHROW
409 long double strtold (const char *__restrict__, char **__restrict__);
410 #endif /* _ISOC99_SOURCE */
412 _CRTIMP __cdecl __MINGW_NOTHROW long strtol (const char *, char **, int);
413 _CRTIMP __cdecl __MINGW_NOTHROW unsigned long strtoul (const char *, char **, int);
415 #endif /* _STDLIB_H only */
416 #if ! (defined _STDLIB_H && defined _WCHAR_H)
417 /* Prototypes which are to be declared both here, in <stdlib.h>,
418 * and also in <wchar.h>; declare them here, such that they may be
419 * selectively included by <wchar.h>.
421 _CRTIMP __cdecl __MINGW_NOTHROW
422 long wcstol (const wchar_t *, wchar_t **, int);
424 _CRTIMP __cdecl __MINGW_NOTHROW
425 unsigned long wcstoul (const wchar_t *, wchar_t **, int);
427 _CRTIMP __cdecl __MINGW_NOTHROW double wcstod (const wchar_t *, wchar_t **);
429 #ifdef _ISOC99_SOURCE
430 /* Variants on wcstod(), specified by ISO-C99; once again, MSVCRT.DLL
431 * doesn't have them, but we offer them in libmingwex.a
433 __cdecl __MINGW_NOTHROW
434 float wcstof (const wchar_t *__restrict__, wchar_t **__restrict__);
436 __cdecl __MINGW_NOTHROW
437 long double wcstold (const wchar_t *__restrict__, wchar_t **__restrict__);
438 #endif /* _ISOC99_SOURCE */
441 #if __MSVCRT_VERSION__ >= __MSVCR70_DLL || _WIN32_WINNT >= _WIN32_WINNT_WINXP
442 /* This pair of wide character equivalents for ISO-C99's strtoll() and
443 * strtoull() require either WinXP (or later), or a non-free MSVC runtime
444 * from MSVCR70.DLL onwards...
446 _CRTIMP __cdecl __MINGW_NOTHROW
447 __int64 _wcstoi64(const wchar_t *, wchar_t **, int);
449 _CRTIMP __cdecl __MINGW_NOTHROW
450 unsigned __int64 _wcstoui64(const wchar_t *, wchar_t **, int);
452 #endif /* WinXP || MSVCR70.DLL || later */
454 #if __MSVCRT_VERSION__ >= __MSVCR80_DLL || _WIN32_WINNT >= _WIN32_WINNT_VISTA
455 /* ...while the following pair require Win-Vista (or later), or non-free
456 * MSVCRT runtime from MSVCR80.DLL onwards; they also require...
458 #ifndef __have_typedef_locale_t
459 /* ...this opaque data type, which we may obtain by selective inclusion
460 * from <locale.h>. (Note that this may render them unusable for users of
461 * MSVCRT.DLL; see the explanation in <locale.h>, regarding the difficulty
462 * in creating, or otherwise acquiring a reference to, a _locale_t object,
463 * notwithstanding the availability of the functions in MSVCRT.DLL, from
464 * the release of Win-Vista onwards).
466 #define __need_locale_t
468 #endif /* !__have_typedef_locale_t */
470 _CRTIMP __cdecl __MINGW_NOTHROW
471 __int64 _wcstoi64_l(const wchar_t *, wchar_t **, int, _locale_t);
473 _CRTIMP __cdecl __MINGW_NOTHROW
474 unsigned __int64 _wcstoui64_l(const wchar_t *, wchar_t **, int, _locale_t);
476 #endif /* Win-Vista || MSVCR80.DLL || later */
478 _CRTIMP __cdecl __MINGW_NOTHROW wchar_t *_wgetenv (const wchar_t *);
479 _CRTIMP __cdecl __MINGW_NOTHROW int _wputenv (const wchar_t *);
481 _CRTIMP __cdecl __MINGW_NOTHROW
482 void _wsearchenv (const wchar_t *, const wchar_t *, wchar_t *);
484 _CRTIMP __cdecl __MINGW_NOTHROW int _wsystem (const wchar_t *);
486 _CRTIMP __cdecl __MINGW_NOTHROW
487 void _wmakepath (wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *,
491 _CRTIMP __cdecl __MINGW_NOTHROW
492 void _wsplitpath (const wchar_t *, wchar_t *, wchar_t *, wchar_t *, wchar_t *);
494 _CRTIMP __cdecl __MINGW_NOTHROW
495 wchar_t *_wfullpath (wchar_t *, const wchar_t *, size_t);
497 #endif /* __MSVCRT__ */
498 #endif /* _STDLIB_H || _WCHAR_H */
500 #ifdef _STDLIB_H /* <stdlib.h> only */
501 _CRTIMP __cdecl __MINGW_NOTHROW size_t wcstombs (char *, const wchar_t *, size_t);
502 _CRTIMP __cdecl __MINGW_NOTHROW int wctomb (char *, wchar_t);
504 _CRTIMP __cdecl __MINGW_NOTHROW int mblen (const char *, size_t);
505 _CRTIMP __cdecl __MINGW_NOTHROW size_t mbstowcs (wchar_t *, const char *, size_t);
506 _CRTIMP __cdecl __MINGW_NOTHROW int mbtowc (wchar_t *, const char *, size_t);
508 _CRTIMP __cdecl __MINGW_NOTHROW int rand (void);
509 _CRTIMP __cdecl __MINGW_NOTHROW void srand (unsigned int);
511 _CRTIMP __cdecl __MINGW_NOTHROW void abort (void) __MINGW_ATTRIB_NORETURN;
512 _CRTIMP __cdecl __MINGW_NOTHROW void exit (int) __MINGW_ATTRIB_NORETURN;
514 /* Note: this is in startup code, not imported directly from the runtime DLL
516 int __cdecl __MINGW_NOTHROW atexit (void (*)(void));
518 _CRTIMP __cdecl __MINGW_NOTHROW int system (const char *);
519 _CRTIMP __cdecl __MINGW_NOTHROW char *getenv (const char *);
521 #ifndef __STRICT_ANSI__
522 /* For GNU compatibility, in addition to the standard memory allocation
523 * functions (declared below), we also include the non-standard alloca()
524 * API declarations here, in accordance with GNU convention.
527 #endif /* !__STRICT_ANSI__ */
529 _CRTIMP __cdecl __MINGW_NOTHROW void *calloc (size_t, size_t) __MINGW_ATTRIB_MALLOC;
530 _CRTIMP __cdecl __MINGW_NOTHROW void *malloc (size_t) __MINGW_ATTRIB_MALLOC;
531 _CRTIMP __cdecl __MINGW_NOTHROW void *realloc (void *, size_t);
532 _CRTIMP __cdecl __MINGW_NOTHROW void free (void *);
534 /* The following pair of MinGW alternatives to realloc() and free() are
535 * always suitable as substitutes for their MSVCRT.DLL counterparts; the
536 * advantage of such substitutions is that these alternatives are able to
537 * operate on heap memory which has been allocated by the MinGW aligned
538 * memory allocation API functions, (but NOT the corresponding Microsoft
539 * functions), in addition to memory allocated by malloc() or calloc().
541 __cdecl __MINGW_NOTHROW void *__mingw_realloc (void *, size_t);
542 __cdecl __MINGW_NOTHROW void __mingw_free (void *);
544 /* bsearch() and qsort() are declared both here, in <stdlib.h>, and in
545 * non-ANSI header <search.h>; we reproduce these declarations in both,
546 * with no attempt to guard them, so the compiler may verify that they
547 * are consistent, if both headers are included.
549 _CRTIMP __cdecl void *bsearch
550 (const void *, const void *, size_t, size_t, int (*)(const void *, const void *));
552 _CRTIMP __cdecl void qsort
553 (void *, size_t, size_t, int (*)(const void *, const void *));
555 _CRTIMP __cdecl __MINGW_NOTHROW int abs (int) __MINGW_ATTRIB_CONST;
556 _CRTIMP __cdecl __MINGW_NOTHROW long labs (long) __MINGW_ATTRIB_CONST;
558 /* div_t and ldiv_t are structures used to return the results of div()
559 * and ldiv() functions.
561 * NOTE: div() and ldiv() appear not to work correctly unless
562 * -fno-pcc-struct-return is specified. This is included in the
563 * mingw32 specs file.
565 typedef struct { int quot, rem; } div_t;
566 typedef struct { long quot, rem; } ldiv_t;
568 _CRTIMP __cdecl __MINGW_NOTHROW div_t div (int, int) __MINGW_ATTRIB_CONST;
569 _CRTIMP __cdecl __MINGW_NOTHROW ldiv_t ldiv (long, long) __MINGW_ATTRIB_CONST;
571 #if !defined __STRICT_ANSI__ || (defined _ISOC99_SOURCE && !defined __NO_INLINE__)
572 /* Although not nominally valid in "__STRICT_ANSI__" mode, when compiling C99
573 * source, we use Microsoft's _exit() function to facilitate our provision of
574 * an inline implementation of ISO-C99's _Exit() function.
576 _CRTIMP __cdecl __MINGW_NOTHROW void _exit (int) __MINGW_ATTRIB_NORETURN;
579 /* Similarly, we use Microsoft's MSVCRT.DLL specific _atoi64() function,
580 * to facilitate an inline implementation of ISO-C99's atoll() function.
582 _CRTIMP __cdecl __MINGW_NOTHROW __int64 _atoi64 (const char *);
584 #endif /* __MSVCRT__ */
585 #endif /* !__STRICT_ANSI__ || (_ISOC99_SOURCE && !__NO_INLINE__) */
587 #if !defined (__STRICT_ANSI__)
588 /* NOTE: Officially the three following functions are obsolete. The Win32 API
589 * functions SetErrorMode, Beep and Sleep are their replacements.
591 _CRTIMP __cdecl __MINGW_NOTHROW void _beep (unsigned int, unsigned int) __MINGW_ATTRIB_DEPRECATED;
592 /* Not to be confused with _set_error_mode (int). */
593 _CRTIMP __cdecl __MINGW_NOTHROW void _seterrormode (int) __MINGW_ATTRIB_DEPRECATED;
594 _CRTIMP __cdecl __MINGW_NOTHROW void _sleep (unsigned long) __MINGW_ATTRIB_DEPRECATED;
596 /* _onexit is a Microsoft extension. Use atexit for portability. */
597 /* Note: This is in startup code, not imported directly from dll */
598 typedef int (* _onexit_t)(void);
599 __cdecl __MINGW_NOTHROW _onexit_t _onexit( _onexit_t );
601 _CRTIMP __cdecl __MINGW_NOTHROW int _putenv (const char *);
602 _CRTIMP __cdecl __MINGW_NOTHROW
603 void _searchenv (const char *, const char *, char *);
605 _CRTIMP __cdecl __MINGW_NOTHROW char *_ecvt (double, int, int *, int *);
606 _CRTIMP __cdecl __MINGW_NOTHROW char *_fcvt (double, int, int *, int *);
607 _CRTIMP __cdecl __MINGW_NOTHROW char *_gcvt (double, int, char *);
609 _CRTIMP __cdecl __MINGW_NOTHROW
610 void _makepath (char *, const char *, const char *, const char *, const char *);
612 _CRTIMP __cdecl __MINGW_NOTHROW
613 void _splitpath (const char *, char *, char *, char *, char *);
615 _CRTIMP __cdecl __MINGW_NOTHROW char *_fullpath (char*, const char*, size_t);
617 _CRTIMP __cdecl __MINGW_NOTHROW char *_itoa (int, char *, int);
618 _CRTIMP __cdecl __MINGW_NOTHROW char *_ltoa (long, char *, int);
619 _CRTIMP __cdecl __MINGW_NOTHROW char *_ultoa(unsigned long, char *, int);
620 _CRTIMP __cdecl __MINGW_NOTHROW wchar_t *_itow (int, wchar_t *, int);
621 _CRTIMP __cdecl __MINGW_NOTHROW wchar_t *_ltow (long, wchar_t *, int);
622 _CRTIMP __cdecl __MINGW_NOTHROW wchar_t *_ultow (unsigned long, wchar_t *, int);
625 _CRTIMP __cdecl __MINGW_NOTHROW char* _i64toa (__int64, char *, int);
626 _CRTIMP __cdecl __MINGW_NOTHROW char* _ui64toa (unsigned __int64, char *, int);
627 _CRTIMP __cdecl __MINGW_NOTHROW __int64 _wtoi64 (const wchar_t *);
628 _CRTIMP __cdecl __MINGW_NOTHROW wchar_t* _i64tow (__int64, wchar_t *, int);
629 _CRTIMP __cdecl __MINGW_NOTHROW wchar_t* _ui64tow (unsigned __int64, wchar_t *, int);
631 _CRTIMP __cdecl __MINGW_NOTHROW unsigned int (_rotl)(unsigned int, int) __MINGW_ATTRIB_CONST;
632 _CRTIMP __cdecl __MINGW_NOTHROW unsigned int (_rotr)(unsigned int, int) __MINGW_ATTRIB_CONST;
633 _CRTIMP __cdecl __MINGW_NOTHROW unsigned long (_lrotl)(unsigned long, int) __MINGW_ATTRIB_CONST;
634 _CRTIMP __cdecl __MINGW_NOTHROW unsigned long (_lrotr)(unsigned long, int) __MINGW_ATTRIB_CONST;
636 _CRTIMP __cdecl __MINGW_NOTHROW int _set_error_mode (int);
638 # define _OUT_TO_DEFAULT 0
639 # define _OUT_TO_STDERR 1
640 # define _OUT_TO_MSGBOX 2
641 # define _REPORT_ERRMODE 3
643 # if __MSVCRT_VERSION__ >= __MSVCR80_DLL
644 # ifndef _UINTPTR_T_DEFINED
645 # define _UINTPTR_T_DEFINED
647 typedef unsigned __int64 uintptr_t;
649 typedef unsigned int uintptr_t;
653 _CRTIMP __cdecl __MINGW_NOTHROW
654 unsigned int _set_abort_behavior (unsigned int, unsigned int);
656 /* These masks work with msvcr80.dll version 8.0.50215.44 (a beta release).
658 # define _WRITE_ABORT_MSG 1
659 # define _CALL_REPORTFAULT 2
662 (* _invalid_parameter_handler) (
668 _invalid_parameter_handler _set_invalid_parameter_handler (_invalid_parameter_handler);
670 # endif /* __MSVCRT_VERSION__ >= __MSVCR80_DLL */
671 #endif /* __MSVCRT__ */
674 _CRTIMP __cdecl __MINGW_NOTHROW int putenv (const char*);
675 _CRTIMP __cdecl __MINGW_NOTHROW void searchenv (const char*, const char*, char*);
677 _CRTIMP __cdecl __MINGW_NOTHROW char* itoa (int, char*, int);
678 _CRTIMP __cdecl __MINGW_NOTHROW char* ltoa (long, char*, int);
681 _CRTIMP __cdecl __MINGW_NOTHROW char* ecvt (double, int, int*, int*);
682 _CRTIMP __cdecl __MINGW_NOTHROW char* fcvt (double, int, int*, int*);
683 _CRTIMP __cdecl __MINGW_NOTHROW char* gcvt (double, int, char*);
686 #endif /* ! _NO_OLDNAMES */
687 #endif /* ! __STRICT_ANSI__ */
689 #ifdef _ISOC99_SOURCE
690 /* Further APIs required to support ISO-C99, but missing from MSVCRT.DLL;
691 * we provide them in libmingwex.a:
693 * ISO-C99 name for _exit()
695 __cdecl __MINGW_NOTHROW void _Exit(int) __MINGW_ATTRIB_NORETURN;
697 #ifndef __NO_INLINE__
698 __CRT_INLINE __JMPSTUB__(( FUNCTION = _Exit, REMAPPED = _exit ))
699 __cdecl __MINGW_NOTHROW void _Exit( int __status ){ _exit (__status); }
702 typedef struct { long long quot, rem; } lldiv_t;
703 __cdecl __MINGW_NOTHROW lldiv_t lldiv (long long, long long) __MINGW_ATTRIB_CONST;
705 __cdecl __MINGW_NOTHROW long long llabs (long long);
707 #ifndef __NO_INLINE__
709 /* No JMPSTUB or LIBIMPL reference here -- we provide a free-standing
710 * implementation, along with imaxabs(), in mingwex/imaxabs.c
712 __cdecl __MINGW_NOTHROW long long llabs( long long __j )
713 { return __j >= 0 ? __j : -__j; }
716 __cdecl __MINGW_NOTHROW
717 long long strtoll (const char *__restrict__, char **__restrict, int);
719 __cdecl __MINGW_NOTHROW
720 unsigned long long strtoull (const char *__restrict__, char **__restrict__, int);
723 /* MSVCRT.DLL does not provide ISO-C99's atoll() function, but it does
724 * provide an analogue, in _atoi64(); map it accordingly.
726 __cdecl __MINGW_NOTHROW long long atoll (const char *);
728 #ifndef __NO_INLINE__
729 __CRT_INLINE __JMPSTUB__(( FUNCTION = atoll, REMAPPED = _atoi64 ))
730 __cdecl __MINGW_NOTHROW long long atoll (const char * _c){ return _atoi64 (_c); }
733 #endif /* __MSVCRT__ */
734 #endif /* _ISOC99_SOURCE */
736 #if defined __MSVCRT__ && ! defined __STRICT_ANSI__
737 #if __MSVCRT_VERSION__ >= __MSVCR70_DLL || _WIN32_WINNT >= _WIN32_WINNT_WINXP
738 /* Microsoft specific alternatives to ISO-C99 strtoll() and strtoull(); the
739 * first pair require WinXP (or later) or non-free MSVCR70.DLL onwards...
741 _CRTIMP __cdecl __MINGW_NOTHROW
742 __int64 _strtoi64(const char*, char **, int);
744 _CRTIMP __cdecl __MINGW_NOTHROW
745 unsigned __int64 _strtoui64(const char*, char **, int);
747 #endif /* WinXP || MSVCR70.DLL || later */
748 #if __MSVCRT_VERSION__ >= __MSVCR80_DLL || _WIN32_WINNT >= _WIN32_WINNT_VISTA
749 /* ...while the following pair require Win-Vista (or later), or non-free
750 * MSVCR80.DLL onwards; (note that, like their wide character counterparts,
751 * they may actually be unusable without MSVCR80.DLL onwards, because of
752 * the difficulty in acquiring a reference to a _locale_t object).
754 _CRTIMP __cdecl __MINGW_NOTHROW
755 __int64 _strtoi64_l(const char *, char **, int, _locale_t);
757 _CRTIMP __cdecl __MINGW_NOTHROW
758 unsigned __int64 _strtoui64_l(const char *, char **, int, _locale_t);
760 #endif /* Win-Vista || MSVCR80.DLL || later */
762 /* Type long long analogues for MSVCRT.DLL specific type long functions;
763 * none are actually provided by any version of MSVCRT.DLL, with names as
764 * specified here, but rather as called by the inline functions used to
765 * implement them, (i.e. the REMAPPED name specified in each__JMPSTUB__
766 * function reference respectively).
768 * FIXME: Not one of these is specified by ISO-C99, nor by POSIX, either;
769 * is there really any justification for us to specify them at all? For
770 * the time being, declare as deprecated; perhaps remove later?
772 __cdecl __MINGW_NOTHROW __MINGW_ATTRIB_DEPRECATED long long wtoll (const wchar_t *);
773 __cdecl __MINGW_NOTHROW __MINGW_ATTRIB_DEPRECATED char *lltoa (long long, char *, int);
774 __cdecl __MINGW_NOTHROW __MINGW_ATTRIB_DEPRECATED char *ulltoa (unsigned long long , char *, int);
775 __cdecl __MINGW_NOTHROW __MINGW_ATTRIB_DEPRECATED wchar_t *lltow (long long, wchar_t *, int);
776 __cdecl __MINGW_NOTHROW __MINGW_ATTRIB_DEPRECATED wchar_t *ulltow (unsigned long long, wchar_t *, int);
778 #ifndef __NO_INLINE__
779 /* None of these functions would exist at all, without either these inline
780 * implementations, or their respective __JMPSTUB__ equivalents.
782 __CRT_INLINE __JMPSTUB__(( FUNCTION = lltoa, REMAPPED = _i64toa ))
783 __cdecl __MINGW_NOTHROW char *lltoa (long long __n, char * __c, int __i)
784 { return _i64toa (__n, __c, __i); }
786 __CRT_INLINE __JMPSTUB__(( FUNCTION = ulltoa, REMAPPED = _ui64toa ))
787 __cdecl __MINGW_NOTHROW char *ulltoa (unsigned long long __n, char * __c, int __i)
788 { return _ui64toa (__n, __c, __i); }
790 __CRT_INLINE __JMPSTUB__(( FUNCTION = wtoll, REMAPPED = _wtoi64 ))
791 __cdecl __MINGW_NOTHROW long long wtoll (const wchar_t * __w){ return _wtoi64 (__w); }
793 __CRT_INLINE __JMPSTUB__(( FUNCTION = lltow, REMAPPED = _i64tow ))
794 __cdecl __MINGW_NOTHROW wchar_t *lltow (long long __n, wchar_t * __w, int __i)
795 { return _i64tow (__n, __w, __i); }
797 __CRT_INLINE __JMPSTUB__(( FUNCTION = ulltow, REMAPPED = _ui64tow ))
798 __cdecl __MINGW_NOTHROW wchar_t *ulltow (unsigned long long __n, wchar_t * __w, int __i)
799 { return _ui64tow (__n, __w, __i); }
801 #endif /* ! __NO_INLINE__ */
802 #endif /* __MSVCRT__ && ! __STRICT_ANSI__ */
804 /* POSIX/BSD extensions in libmingwex.a; these should be exposed only on
805 * the basis of appropriate POSIX or BSD specific feature tests...
807 * mkstemp(3) function support; added per feature request #2003.
808 * POSIX wants _XOPEN_SOURCE >= 500, (implying _POSIX_C_SOURCE >= 200112L).
810 #if _POSIX_C_SOURCE >= 200112L
812 __cdecl __MINGW_NOTHROW int mkstemp (char *);
813 __cdecl __MINGW_NOTHROW int __mingw_mkstemp (int, char *);
815 /* On POSIX platforms, programmers may adopt an idiom such as:
817 * if( mkstemp( template ) >= 0 )
818 * { unlink( template );
822 * to ensure that a temporary file does NOT persist after it is
823 * closed; MS-Windows does not allow such use of unlink(2), while
824 * the file remains open. Thus, MS-Windows programmers must take
825 * extra care, to close and unlink temporary files AFTER use, if
826 * similar behaviour is desired.
828 * To mitigate this MS-Windows limitation, we provide support for
829 * an alternative, MinGW specific idiom:
833 * _MKSTEMP_SETMODE( _O_TEMPORARY );
834 * if( mkstemp( template ) >= 0 )
839 * to achieve a similar effect to that of the above POSIX idiom; the
840 * following macros are a MinGW specific extension, to facilite such
841 * use of _O_TEMPORARY, (in addition to the POSIX required attributes),
842 * when creating the temporary file. Note that they require <fcntl.h>,
843 * which <stdlib.h> should NOT automatically include; we leave it to
844 * the user to explicitly include it, if using _MKSTEMP_SETMODE.
846 #define _MKSTEMP_INVOKE 0
847 #define _MKSTEMP_DEFAULT _O_CREAT | _O_EXCL | _O_RDWR
848 #define _MKSTEMP_SETMODE(M) __mingw_mkstemp( _MKSTEMP_DEFAULT | (M), NULL )
851 #define MKSTEMP_SETMODE(M) __mingw_mkstemp( _MKSTEMP_DEFAULT | (M), NULL )
854 __CRT_ALIAS __LIBIMPL__(( FUNCTION = mkstemp ))
855 __cdecl __MINGW_NOTHROW int mkstemp (char *__filename_template)
856 { return __mingw_mkstemp( _MKSTEMP_INVOKE, __filename_template ); }
858 #endif /* _POSIX_C_SOURCE >= 200112L (for mkstemp()) */
860 /* mkdtemp(3) function support: added as adjunct to feature request #2003.
861 * POSIX wants _XOPEN_SOURCE >= 700, (implying _POSIX_C_SOURCE >= 200809L).
863 #if _POSIX_C_SOURCE >= 200809L
865 __cdecl __MINGW_NOTHROW char *mkdtemp (char *);
866 __cdecl __MINGW_NOTHROW char *__mingw_mkdtemp (char *);
868 __CRT_ALIAS __JMPSTUB__(( FUNCTION = mkdtemp ))
869 __cdecl __MINGW_NOTHROW char *mkdtemp (char *__dirname_template)
870 { return __mingw_mkdtemp( __dirname_template ); }
872 #endif /* _POSIX_C_SOURCE >= 200809L (for mkdtemp()) */
874 #if _POSIX_C_SOURCE >= 200112L
875 /* setenv() and unsetenv() are also available, from POSIX.1-2001 onwards.
877 __cdecl __MINGW_NOTHROW int setenv( const char *, const char *, int );
878 __cdecl __MINGW_NOTHROW int unsetenv( const char * );
880 __cdecl __MINGW_NOTHROW int __mingw_setenv( const char *, const char *, int );
882 __CRT_ALIAS __JMPSTUB__(( FUNCTION = setenv ))
883 __cdecl __MINGW_NOTHROW int setenv( const char *__n, const char *__v, int __f )
884 { return __mingw_setenv( __n, __v, __f ); }
886 __CRT_ALIAS __LIBIMPL__(( FUNCTION = unsetenv ))
887 __cdecl __MINGW_NOTHROW int unsetenv( const char *__name )
888 { return __mingw_setenv( __name, NULL, 1 ); }
890 #endif /* _POSIX_C_SOURCE >= 200112L (for setenv()) */
891 #endif /* _STDLIB_H */
895 #endif /* ! RC_INVOKED */
896 #endif /* ! _STDLIB_H: $RCSfile$: end of file */