OSDN Git Service

Implement <wspiapi.h> sockets fall-back API.
[mingw/mingw-org-wsl.git] / mingwrt / include / stdlib.h
1 /*
2  * stdlib.h
3  *
4  * ANSI/POSIX + Microsoft compatible standard library function prototypes,
5  * associated macros, and manifest constant definitions.
6  *
7  * $Id$
8  *
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.
11  *
12  *
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:
19  *
20  * The above copyright notice, this permission notice, and the following
21  * disclaimer shall be included in all copies or substantial portions of
22  * the Software.
23  *
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.
31  *
32  */
33 #ifndef _STDLIB_H
34 #pragma GCC system_header
35
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...
39  */
40 #ifndef __WCHAR_H_SOURCED__
41  /* ...do we define the repeat inclusion guard for <stdlib.h> itself.
42   */
43 #define _STDLIB_H
44
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
47  * it for <stdlib.h>.
48  */
49 #include <_mingw.h>
50
51 #ifndef RC_INVOKED
52 #define __need_size_t
53 #define __need_wchar_t
54 #define __need_NULL
55 #include <stddef.h>
56 #endif /* RC_INVOKED */
57
58 /* RAND_MAX is the maximum value that may be returned by rand.
59  * The minimum is zero.
60  */
61 #define RAND_MAX        0x7FFF
62
63 /* These values may be used as exit status codes.
64  */
65 #define EXIT_SUCCESS    0
66 #define EXIT_FAILURE    1
67
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.
72  */
73 #ifndef __STRICT_ANSI__
74
75 #ifndef MAX_PATH
76 #define MAX_PATH        (260)
77 #endif
78
79 #define _MAX_PATH       MAX_PATH
80 #define _MAX_DRIVE      (3)
81 #define _MAX_DIR        256
82 #define _MAX_FNAME      256
83 #define _MAX_EXT        256
84
85 #endif  /* !__STRICT_ANSI__ */
86 #endif  /* !__WCHAR_H_SOURCED__ */
87
88 #ifndef RC_INVOKED
89
90 _BEGIN_C_DECLS
91
92 #ifdef _STDLIB_H
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.
98  */
99 extern int     _argc;
100 extern char  **_argv;
101
102 #ifdef __MSVCRT__
103 /* Imports from the runtime DLL, for the above variables.
104  */
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);
108
109 #define __argc (*__p___argc())
110 #define __argv (*__p___argv())
111 #define __wargv (*__p___wargv())
112
113 #else  /* ! __MSVCRT__ */
114
115 #ifndef __DECLSPEC_SUPPORTED
116
117 extern int    *_imp____argc_dll;
118 extern char ***_imp____argv_dll;
119
120 #define __argc (*_imp____argc_dll)
121 #define __argv (*_imp____argv_dll)
122
123 #else  /* __DECLSPEC_SUPPORTED */
124
125 __MINGW_IMPORT int    __argc_dll;
126 __MINGW_IMPORT char **__argv_dll;
127
128 #define __argc __argc_dll
129 #define __argv __argv_dll
130
131 #endif  /* __DECLSPEC_SUPPORTED */
132
133 #endif  /* __MSVCRT__ */
134 #endif  /* __STRICT_ANSI__ */
135
136 #ifndef MB_CUR_MAX
137 /* FIXME: also defined in <ctype.h>; should be factored out.
138  */
139 #ifdef __DECLSPEC_SUPPORTED
140 # ifdef __MSVCRT__
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__ */
147
148 #else  /* ! __DECLSPEC_SUPPORTED */
149 # ifdef __MSVCRT__
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 */
158
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 ...
169  */
170 __cdecl __MINGW_NOTHROW  int _get_errno(int *);
171 __cdecl __MINGW_NOTHROW  int _set_errno(int);
172
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).
178  */
179 #define __STDLIB_H_SOURCED__ 1
180 #include "errno.h"
181
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.
186  */
187 __CRT_ALIAS __cdecl __MINGW_NOTHROW  int _get_errno( int *__val )
188 { return (__val == NULL) ? (errno = EINVAL) : 0 & (*__val = errno); }
189
190 __CRT_ALIAS __cdecl __MINGW_NOTHROW  int _set_errno( int __val )
191 { errno = __val; return 0; }
192
193 #endif
194 #undef __STDLIB_H_SOURCED__
195
196 _CRTIMP __cdecl __MINGW_NOTHROW  int *__doserrno(void);
197 #define _doserrno  (*__doserrno())
198
199 #if !defined (__STRICT_ANSI__)
200 /* Use environ from the DLL, not as a global.
201  */
202 #ifdef __MSVCRT__
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);
207
208 #else  /* ! __MSVCRT__ */
209 # ifndef __DECLSPEC_SUPPORTED
210 # define _environ (*_imp___environ_dll)
211 extern char ***_imp___environ_dll;
212
213 # else  /* __DECLSPEC_SUPPORTED */
214 # define _environ  _environ_dll
215 __MINGW_IMPORT char ** _environ_dll;
216 # endif  /* __DECLSPEC_SUPPORTED */
217 #endif  /* ! __MSVCRT__ */
218
219 #define environ _environ
220
221 #ifdef  __MSVCRT__
222 /* One of the MSVCRTxx libraries */
223
224 #ifndef __DECLSPEC_SUPPORTED
225 # define sys_nerr  (*_imp___sys_nerr)
226 extern int *_imp___sys_nerr;
227
228 #else /* __DECLSPEC_SUPPORTED */
229 __MINGW_IMPORT int _sys_nerr;
230
231 # ifndef _UWIN
232 # define sys_nerr  _sys_nerr
233 # endif  /* _UWIN */
234 #endif  /* __DECLSPEC_SUPPORTED */
235
236 #else  /* ! __MSVCRT__ */
237 /* CRTDLL run time library */
238
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 */
246
247 #endif  /* ! __MSVCRT__ */
248
249 #ifndef __DECLSPEC_SUPPORTED
250 #define sys_errlist  (*_imp___sys_errlist)
251 extern char ***_imp__sys_errlist;
252
253 #else  /* __DECLSPEC_SUPPORTED */
254 __MINGW_IMPORT char *_sys_errlist[];
255
256 #ifndef _UWIN
257 #define sys_errlist  _sys_errlist
258 #endif  /* _UWIN */
259 #endif  /* __DECLSPEC_SUPPORTED */
260
261 /* OS version and such constants.
262  */
263 #ifdef  __MSVCRT__ /* MSVCRT.DLL and MSVCRxx.DLL variants */
264
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);
269
270 #ifndef __DECLSPEC_SUPPORTED
271 # define _osver     (*__p__osver())
272 # define _winver    (*__p__winver())
273 # define _winmajor  (*__p__winmajor())
274 # define _winminor  (*__p__winminor())
275
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 */
282
283 #else  /* ! __MSVCRT__; thus CRTDLL */
284 #ifndef __DECLSPEC_SUPPORTED
285
286 #define _osver      (*_imp___osver_dll)
287 #define _winver    (*_imp___winver_dll)
288 #define _winmajor  (*_imp___winmajor_dll)
289 #define _winminor  (*_imp___winminor_dll)
290
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;
295
296 #else  /* __DECLSPEC_SUPPORTED */
297
298 #define _osver      _osver_dll
299 #define _winver    _winver_dll
300 #define _winmajor  _winmajor_dll
301 #define _winminor  _winminor_dll
302
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;
307
308 #endif  /* __DECLSPEC_SUPPORTED */
309 #endif  /* CRTDLL */
310
311 #if defined  __MSVCRT__
312 /* Although _pgmptr is exported as DATA, be safe and use the access
313  * function __p__pgmptr() to get it.
314  */
315 #define _pgmptr  (*__p__pgmptr())
316 _CRTIMP __cdecl __MINGW_NOTHROW  char **__p__pgmptr(void);
317
318 #define _wpgmptr  (*__p__wpgmptr())
319 _CRTIMP __cdecl __MINGW_NOTHROW  wchar_t **__p__wpgmptr(void);
320
321 #else  /* ! __MSVCRT__; thus CRTDLL */
322
323 # ifndef __DECLSPEC_SUPPORTED
324 # define _pgmptr  (*_imp___pgmptr_dll)
325 extern char **__imp__pgmptr_dll;
326
327 # else  /* __DECLSPEC_SUPPORTED */
328
329 # define _pgmptr _pgmptr_dll
330 __MINGW_IMPORT  char *_pgmptr_dll;
331 /* no wide version in CRTDLL */
332
333 # endif /* __DECLSPEC_SUPPORTED */
334 #endif  /* CRTDLL */
335
336 /* This variable determines the default file mode.
337  * TODO: Which flags work?
338  */
339 #if !defined (__DECLSPEC_SUPPORTED) || defined (__IN_MINGW_RUNTIME)
340
341 #ifdef __MSVCRT__
342 #define _fmode  (*_imp___fmode)
343 extern int *_imp___fmode;
344 #else
345 /* CRTDLL */
346 #define _fmode  (*_imp___fmode_dll)
347 extern int *_imp___fmode_dll;
348 #endif
349
350 #else  /* __DECLSPEC_SUPPORTED */
351 #ifdef __MSVCRT__
352 __MINGW_IMPORT  int _fmode;
353
354 #else  /* ! __MSVCRT__ */
355 #define _fmode  _fmode_dll
356 __MINGW_IMPORT  int _fmode_dll;
357
358 #endif  /* !__MSVCRT__ */
359 #endif  /* __DECLSPEC_SUPPORTED */
360 #endif  /* !__STRICT_ANSI__ */
361
362 _CRTIMP __cdecl __MINGW_NOTHROW  int atoi (const char *);
363 _CRTIMP __cdecl __MINGW_NOTHROW  long atol (const char *);
364
365 _CRTIMP __cdecl __MINGW_NOTHROW  double strtod (const char *, char **);
366 _CRTIMP __cdecl __MINGW_NOTHROW  double atof (const char *);
367
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 *);
372 #endif
373
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.
380  *
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.
386  */
387 extern __cdecl __MINGW_NOTHROW
388 double __strtod (const char *__restrict__, char **__restrict__);
389
390 __CRT_ALIAS __cdecl __MINGW_NOTHROW
391 double strtod (const char *__restrict__ __nptr, char **__restrict__ __endptr)
392 { return __strtod( __nptr, __endptr ); }
393
394 __CRT_ALIAS __cdecl __MINGW_NOTHROW
395 double atof (const char *__nptr) { return __strtod( __nptr, NULL ); }
396
397 #endif  /* __USE_MINGW_ANSI_STDIO */
398
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:
404  */
405 __cdecl __MINGW_NOTHROW
406 float strtof (const char *__restrict__, char **__restrict__);
407
408 __cdecl __MINGW_NOTHROW
409 long double strtold (const char *__restrict__, char **__restrict__);
410 #endif  /* _ISOC99_SOURCE */
411
412 _CRTIMP __cdecl __MINGW_NOTHROW  long strtol (const char *, char **, int);
413 _CRTIMP __cdecl __MINGW_NOTHROW  unsigned long strtoul (const char *, char **, int);
414
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>.
420  */
421 _CRTIMP __cdecl __MINGW_NOTHROW
422 long wcstol (const wchar_t *, wchar_t **, int);
423
424 _CRTIMP __cdecl __MINGW_NOTHROW
425 unsigned long wcstoul (const wchar_t *, wchar_t **, int);
426
427 _CRTIMP __cdecl __MINGW_NOTHROW  double wcstod (const wchar_t *, wchar_t **);
428
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
432  */
433 __cdecl __MINGW_NOTHROW
434 float wcstof (const wchar_t *__restrict__, wchar_t **__restrict__);
435
436 __cdecl __MINGW_NOTHROW
437 long double wcstold (const wchar_t *__restrict__, wchar_t **__restrict__);
438 #endif  /* _ISOC99_SOURCE */
439
440 #ifdef __MSVCRT__
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...
445  */
446 _CRTIMP __cdecl __MINGW_NOTHROW
447 __int64 _wcstoi64(const wchar_t *, wchar_t **, int);
448
449 _CRTIMP __cdecl __MINGW_NOTHROW
450 unsigned __int64 _wcstoui64(const wchar_t *, wchar_t **, int);
451
452 #endif  /* WinXP || MSVCR70.DLL || later */
453
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...
457  */
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).
465  */
466 #define __need_locale_t
467 #include <locale.h>
468 #endif  /* !__have_typedef_locale_t */
469
470 _CRTIMP __cdecl __MINGW_NOTHROW
471 __int64 _wcstoi64_l(const wchar_t *, wchar_t **, int, _locale_t);
472
473 _CRTIMP __cdecl __MINGW_NOTHROW
474 unsigned __int64 _wcstoui64_l(const wchar_t *, wchar_t **, int, _locale_t);
475
476 #endif  /* Win-Vista || MSVCR80.DLL || later */
477
478 _CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *_wgetenv (const wchar_t *);
479 _CRTIMP __cdecl __MINGW_NOTHROW  int _wputenv (const wchar_t *);
480
481 _CRTIMP __cdecl __MINGW_NOTHROW
482 void _wsearchenv (const wchar_t *, const wchar_t *, wchar_t *);
483
484 _CRTIMP __cdecl __MINGW_NOTHROW  int _wsystem (const wchar_t *);
485
486 _CRTIMP __cdecl __MINGW_NOTHROW
487 void _wmakepath (wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *,
488     const wchar_t *
489   );
490
491 _CRTIMP __cdecl __MINGW_NOTHROW
492 void _wsplitpath (const wchar_t *, wchar_t *, wchar_t *, wchar_t *, wchar_t *);
493
494 _CRTIMP __cdecl __MINGW_NOTHROW
495 wchar_t *_wfullpath (wchar_t *, const wchar_t *, size_t);
496
497 #endif  /* __MSVCRT__ */
498 #endif  /* _STDLIB_H || _WCHAR_H */
499
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);
503
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);
507
508 _CRTIMP __cdecl __MINGW_NOTHROW  int rand (void);
509 _CRTIMP __cdecl __MINGW_NOTHROW  void srand (unsigned int);
510
511 _CRTIMP __cdecl __MINGW_NOTHROW  void abort (void) __MINGW_ATTRIB_NORETURN;
512 _CRTIMP __cdecl __MINGW_NOTHROW  void exit (int) __MINGW_ATTRIB_NORETURN;
513
514 /* Note: this is in startup code, not imported directly from the runtime DLL
515  */
516 int __cdecl __MINGW_NOTHROW atexit (void (*)(void));
517
518 _CRTIMP __cdecl __MINGW_NOTHROW  int system (const char *);
519 _CRTIMP __cdecl __MINGW_NOTHROW  char *getenv (const char *);
520
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.
525  */
526 # include "alloca.h"
527 #endif  /* !__STRICT_ANSI__ */
528
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 *);
533
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().
540  */
541 __cdecl __MINGW_NOTHROW  void *__mingw_realloc (void *, size_t);
542 __cdecl __MINGW_NOTHROW  void __mingw_free (void *);
543
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.
548  */
549 _CRTIMP __cdecl  void *bsearch
550 (const void *, const void *, size_t, size_t, int (*)(const void *, const void *));
551
552 _CRTIMP __cdecl  void qsort
553 (void *, size_t, size_t, int (*)(const void *, const void *));
554
555 _CRTIMP __cdecl __MINGW_NOTHROW  int abs (int) __MINGW_ATTRIB_CONST;
556 _CRTIMP __cdecl __MINGW_NOTHROW  long labs (long) __MINGW_ATTRIB_CONST;
557
558 /* div_t and ldiv_t are structures used to return the results of div()
559  * and ldiv() functions.
560  *
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.
564  */
565 typedef struct { int quot, rem; } div_t;
566 typedef struct { long quot, rem; } ldiv_t;
567
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;
570
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.
575  */
576 _CRTIMP __cdecl __MINGW_NOTHROW  void _exit (int) __MINGW_ATTRIB_NORETURN;
577
578 #ifdef __MSVCRT__
579 /* Similarly, we use Microsoft's MSVCRT.DLL specific _atoi64() function,
580  * to facilitate an inline implementation of ISO-C99's atoll() function.
581  */
582 _CRTIMP __cdecl __MINGW_NOTHROW  __int64 _atoi64 (const char *);
583
584 #endif  /* __MSVCRT__ */
585 #endif  /* !__STRICT_ANSI__ || (_ISOC99_SOURCE && !__NO_INLINE__) */
586
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.
590  */
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;
595
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 );
600
601 _CRTIMP __cdecl __MINGW_NOTHROW  int _putenv (const char *);
602 _CRTIMP __cdecl __MINGW_NOTHROW
603 void _searchenv (const char *, const char *, char *);
604
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 *);
608
609 _CRTIMP __cdecl __MINGW_NOTHROW
610 void _makepath (char *, const char *, const char *, const char *, const char *);
611
612 _CRTIMP __cdecl __MINGW_NOTHROW
613 void _splitpath (const char *, char *, char *, char *, char *);
614
615 _CRTIMP __cdecl __MINGW_NOTHROW  char *_fullpath (char*, const char*, size_t);
616
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);
623
624 #ifdef __MSVCRT__
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);
630
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;
635
636 _CRTIMP __cdecl __MINGW_NOTHROW  int _set_error_mode (int);
637
638 # define _OUT_TO_DEFAULT        0
639 # define _OUT_TO_STDERR         1
640 # define _OUT_TO_MSGBOX         2
641 # define _REPORT_ERRMODE        3
642
643 # if __MSVCRT_VERSION__ >= __MSVCR80_DLL
644 #  ifndef _UINTPTR_T_DEFINED
645 #   define _UINTPTR_T_DEFINED
646 #   ifdef _WIN64
647       typedef unsigned __int64 uintptr_t;
648 #   else
649       typedef unsigned int uintptr_t;
650 #   endif
651 #  endif
652
653 _CRTIMP __cdecl __MINGW_NOTHROW
654 unsigned int _set_abort_behavior (unsigned int, unsigned int);
655
656 /* These masks work with msvcr80.dll version 8.0.50215.44 (a beta release).
657  */
658 #  define _WRITE_ABORT_MSG      1
659 #  define _CALL_REPORTFAULT     2
660
661 typedef void
662 (* _invalid_parameter_handler) (
663     const wchar_t *,
664     const wchar_t *,
665     const wchar_t *,
666     unsigned int,
667     uintptr_t);
668 _invalid_parameter_handler _set_invalid_parameter_handler (_invalid_parameter_handler);
669
670 # endif /* __MSVCRT_VERSION__ >= __MSVCR80_DLL */
671 #endif  /* __MSVCRT__ */
672
673 #ifndef _NO_OLDNAMES
674 _CRTIMP __cdecl __MINGW_NOTHROW  int putenv (const char*);
675 _CRTIMP __cdecl __MINGW_NOTHROW  void searchenv (const char*, const char*, char*);
676
677 _CRTIMP __cdecl __MINGW_NOTHROW  char* itoa (int, char*, int);
678 _CRTIMP __cdecl __MINGW_NOTHROW  char* ltoa (long, char*, int);
679
680 #ifndef _UWIN
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*);
684
685 #endif  /* ! _UWIN */
686 #endif  /* ! _NO_OLDNAMES */
687 #endif  /* ! __STRICT_ANSI__ */
688
689 #ifdef _ISOC99_SOURCE
690 /* Further APIs required to support ISO-C99, but missing from MSVCRT.DLL;
691  * we provide them in libmingwex.a:
692  *
693  * ISO-C99 name for _exit()
694  */
695 __cdecl __MINGW_NOTHROW  void _Exit(int) __MINGW_ATTRIB_NORETURN;
696
697 #ifndef __NO_INLINE__
698 __CRT_INLINE __JMPSTUB__(( FUNCTION = _Exit, REMAPPED = _exit ))
699 __cdecl __MINGW_NOTHROW  void _Exit( int __status ){ _exit (__status); }
700 #endif
701
702 typedef struct { long long quot, rem; } lldiv_t;
703 __cdecl __MINGW_NOTHROW  lldiv_t lldiv (long long, long long) __MINGW_ATTRIB_CONST;
704
705 __cdecl __MINGW_NOTHROW  long long llabs (long long);
706
707 #ifndef __NO_INLINE__
708 __CRT_INLINE
709 /* No JMPSTUB or LIBIMPL reference here -- we provide a free-standing
710  * implementation, along with imaxabs(), in mingwex/imaxabs.c
711  */
712 __cdecl __MINGW_NOTHROW  long long llabs( long long __j )
713 { return __j >= 0 ? __j : -__j; }
714 #endif
715
716 __cdecl __MINGW_NOTHROW
717 long long strtoll (const char *__restrict__, char **__restrict, int);
718
719 __cdecl __MINGW_NOTHROW
720 unsigned long long strtoull (const char *__restrict__, char **__restrict__, int);
721
722 #ifdef __MSVCRT__
723 /* MSVCRT.DLL does not provide ISO-C99's atoll() function, but it does
724  * provide an analogue, in _atoi64(); map it accordingly.
725  */
726 __cdecl __MINGW_NOTHROW  long long atoll (const char *);
727
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); }
731 #endif
732
733 #endif  /* __MSVCRT__ */
734 #endif  /* _ISOC99_SOURCE */
735
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...
740  */
741 _CRTIMP __cdecl __MINGW_NOTHROW
742 __int64 _strtoi64(const char*, char **, int);
743
744 _CRTIMP __cdecl __MINGW_NOTHROW
745 unsigned __int64 _strtoui64(const char*, char **, int);
746
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).
753  */
754 _CRTIMP __cdecl __MINGW_NOTHROW
755 __int64 _strtoi64_l(const char *, char **, int, _locale_t);
756
757 _CRTIMP __cdecl __MINGW_NOTHROW
758 unsigned __int64 _strtoui64_l(const char *, char **, int, _locale_t);
759
760 #endif  /* Win-Vista || MSVCR80.DLL || later */
761
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).
767  *
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?
771  */
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);
777
778 #ifndef __NO_INLINE__
779 /* None of these functions would exist at all, without either these inline
780  * implementations, or their respective __JMPSTUB__ equivalents.
781  */
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); }
785
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); }
789
790 __CRT_INLINE __JMPSTUB__(( FUNCTION = wtoll, REMAPPED = _wtoi64 ))
791 __cdecl __MINGW_NOTHROW  long long wtoll (const wchar_t * __w){ return _wtoi64 (__w); }
792
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); }
796
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); }
800
801 #endif  /* ! __NO_INLINE__ */
802 #endif  /* __MSVCRT__ && ! __STRICT_ANSI__ */
803
804 /* POSIX/BSD extensions in libmingwex.a; these should be exposed only on
805  * the basis of appropriate POSIX or BSD specific feature tests...
806  *
807  * mkstemp(3) function support; added per feature request #2003.
808  * POSIX wants _XOPEN_SOURCE >= 500, (implying _POSIX_C_SOURCE >= 200112L).
809  */
810 #if _POSIX_C_SOURCE >= 200112L
811
812 __cdecl __MINGW_NOTHROW  int mkstemp (char *);
813 __cdecl __MINGW_NOTHROW  int __mingw_mkstemp (int, char *);
814
815 /* On POSIX platforms, programmers may adopt an idiom such as:
816  *
817  *   if( mkstemp( template ) >= 0 )
818  *   { unlink( template );
819  *     . . .
820  *   }
821  *
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.
827  *
828  * To mitigate this MS-Windows limitation, we provide support for
829  * an alternative, MinGW specific idiom:
830  *
831  *   #include <fcntl.h>
832  *
833  *   _MKSTEMP_SETMODE( _O_TEMPORARY );
834  *   if( mkstemp( template ) >= 0 )
835  *   {
836  *     . . .
837  *   }
838  *
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.
845  */
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 )
849
850 #ifndef _NO_OLDNAMES
851 #define MKSTEMP_SETMODE(M)  __mingw_mkstemp( _MKSTEMP_DEFAULT | (M), NULL )
852 #endif
853
854 __CRT_ALIAS __LIBIMPL__(( FUNCTION = mkstemp ))
855 __cdecl __MINGW_NOTHROW  int mkstemp (char *__filename_template)
856 { return __mingw_mkstemp( _MKSTEMP_INVOKE, __filename_template ); }
857
858 #endif  /* _POSIX_C_SOURCE >= 200112L (for mkstemp()) */
859
860 /* mkdtemp(3) function support: added as adjunct to feature request #2003.
861  * POSIX wants _XOPEN_SOURCE >= 700, (implying _POSIX_C_SOURCE >= 200809L).
862  */
863 #if _POSIX_C_SOURCE >= 200809L
864
865 __cdecl __MINGW_NOTHROW  char *mkdtemp (char *);
866 __cdecl __MINGW_NOTHROW  char *__mingw_mkdtemp (char *);
867
868 __CRT_ALIAS __JMPSTUB__(( FUNCTION = mkdtemp ))
869 __cdecl __MINGW_NOTHROW  char *mkdtemp (char *__dirname_template)
870 { return __mingw_mkdtemp( __dirname_template ); }
871
872 #endif  /* _POSIX_C_SOURCE >= 200809L (for mkdtemp()) */
873
874 #if _POSIX_C_SOURCE >= 200112L
875 /* setenv() and unsetenv() are also available, from POSIX.1-2001 onwards.
876  */
877 __cdecl __MINGW_NOTHROW  int setenv( const char *, const char *, int );
878 __cdecl __MINGW_NOTHROW  int unsetenv( const char * );
879
880 __cdecl __MINGW_NOTHROW  int __mingw_setenv( const char *, const char *, int );
881
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 ); }
885
886 __CRT_ALIAS __LIBIMPL__(( FUNCTION = unsetenv ))
887 __cdecl __MINGW_NOTHROW  int unsetenv( const char *__name )
888 { return __mingw_setenv( __name, NULL, 1 ); }
889
890 #endif  /* _POSIX_C_SOURCE >= 200112L (for setenv()) */
891 #endif  /* _STDLIB_H */
892
893 _END_C_DECLS
894
895 #endif  /* ! RC_INVOKED */
896 #endif  /* ! _STDLIB_H: $RCSfile$: end of file */