OSDN Git Service

Merge further W32API updates from Cygwin CVS.
[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, 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 /* FIXME: Nominally in <errno.h>, Microsoft likes to declare errno
160  * in <stdlib.h> as well; we should factor this out.
161  */
162 #ifdef _UWIN
163 # undef errno
164   extern int errno;
165 #else
166 _CRTIMP __cdecl __MINGW_NOTHROW  int *_errno(void);
167 # define errno  (*_errno())
168 #endif
169 _CRTIMP __cdecl __MINGW_NOTHROW  int *__doserrno(void);
170 #define _doserrno  (*__doserrno())
171
172 #if !defined (__STRICT_ANSI__)
173 /* Use environ from the DLL, not as a global.
174  */
175 #ifdef __MSVCRT__
176 # define _environ  (*__p__environ())
177 extern _CRTIMP __cdecl __MINGW_NOTHROW  char ***__p__environ(void);
178 # define _wenviron  (*__p__wenviron())
179 extern _CRTIMP __cdecl __MINGW_NOTHROW  wchar_t ***__p__wenviron(void);
180
181 #else  /* ! __MSVCRT__ */
182 # ifndef __DECLSPEC_SUPPORTED
183 # define _environ (*_imp___environ_dll)
184 extern char ***_imp___environ_dll;
185
186 # else  /* __DECLSPEC_SUPPORTED */
187 # define _environ  _environ_dll
188 __MINGW_IMPORT char ** _environ_dll;
189 # endif  /* __DECLSPEC_SUPPORTED */
190 #endif  /* ! __MSVCRT__ */
191
192 #define environ _environ
193
194 #ifdef  __MSVCRT__
195 /* One of the MSVCRTxx libraries */
196
197 #ifndef __DECLSPEC_SUPPORTED
198 # define sys_nerr  (*_imp___sys_nerr)
199 extern int *_imp___sys_nerr;
200
201 #else /* __DECLSPEC_SUPPORTED */
202 __MINGW_IMPORT int _sys_nerr;
203
204 # ifndef _UWIN
205 # define sys_nerr  _sys_nerr
206 # endif  /* _UWIN */
207 #endif  /* __DECLSPEC_SUPPORTED */
208
209 #else  /* ! __MSVCRT__ */
210 /* CRTDLL run time library */
211
212 #ifndef __DECLSPEC_SUPPORTED
213   extern int*   _imp___sys_nerr_dll;
214 # define sys_nerr       (*_imp___sys_nerr_dll)
215 #else  /* __DECLSPEC_SUPPORTED */
216   __MINGW_IMPORT int    _sys_nerr_dll;
217 # define sys_nerr       _sys_nerr_dll
218 #endif  /* __DECLSPEC_SUPPORTED */
219
220 #endif  /* ! __MSVCRT__ */
221
222 #ifndef __DECLSPEC_SUPPORTED
223 #define sys_errlist  (*_imp___sys_errlist)
224 extern char ***_imp__sys_errlist;
225
226 #else  /* __DECLSPEC_SUPPORTED */
227 __MINGW_IMPORT char *_sys_errlist[];
228
229 #ifndef _UWIN
230 #define sys_errlist  _sys_errlist
231 #endif  /* _UWIN */
232 #endif  /* __DECLSPEC_SUPPORTED */
233
234 /* OS version and such constants.
235  */
236 #ifdef  __MSVCRT__ /* MSVCRT.DLL and MSVCRxx.DLL variants */
237
238 extern _CRTIMP __cdecl __MINGW_NOTHROW  unsigned int *__p__osver(void);
239 extern _CRTIMP __cdecl __MINGW_NOTHROW  unsigned int *__p__winver(void);
240 extern _CRTIMP __cdecl __MINGW_NOTHROW  unsigned int *__p__winmajor(void);
241 extern _CRTIMP __cdecl __MINGW_NOTHROW  unsigned int *__p__winminor(void);
242
243 #ifndef __DECLSPEC_SUPPORTED
244 # define _osver     (*__p__osver())
245 # define _winver    (*__p__winver())
246 # define _winmajor  (*__p__winmajor())
247 # define _winminor  (*__p__winminor())
248
249 #else /* __DECLSPEC_SUPPORTED */
250 __MINGW_IMPORT  unsigned int _osver;
251 __MINGW_IMPORT  unsigned int _winver;
252 __MINGW_IMPORT  unsigned int _winmajor;
253 __MINGW_IMPORT  unsigned int _winminor;
254 #endif  /* __DECLSPEC_SUPPORTED */
255
256 #else  /* ! __MSVCRT__; thus CRTDLL */
257 #ifndef __DECLSPEC_SUPPORTED
258
259 #define _osver      (*_imp___osver_dll)
260 #define _winver    (*_imp___winver_dll)
261 #define _winmajor  (*_imp___winmajor_dll)
262 #define _winminor  (*_imp___winminor_dll)
263
264 extern unsigned int *_imp___osver_dll;
265 extern unsigned int *_imp___winver_dll;
266 extern unsigned int *_imp___winmajor_dll;
267 extern unsigned int *_imp___winminor_dll;
268
269 #else  /* __DECLSPEC_SUPPORTED */
270
271 #define _osver      _osver_dll
272 #define _winver    _winver_dll
273 #define _winmajor  _winmajor_dll
274 #define _winminor  _winminor_dll
275
276 __MINGW_IMPORT unsigned int _osver_dll;
277 __MINGW_IMPORT unsigned int _winver_dll;
278 __MINGW_IMPORT unsigned int _winmajor_dll;
279 __MINGW_IMPORT unsigned int _winminor_dll;
280
281 #endif  /* __DECLSPEC_SUPPORTED */
282 #endif  /* CRTDLL */
283
284 #if defined  __MSVCRT__
285 /* Although _pgmptr is exported as DATA, be safe and use the access
286  * function __p__pgmptr() to get it.
287  */
288 #define _pgmptr  (*__p__pgmptr())
289 _CRTIMP __cdecl __MINGW_NOTHROW  char **__p__pgmptr(void);
290
291 #define _wpgmptr  (*__p__wpgmptr())
292 _CRTIMP __cdecl __MINGW_NOTHROW  wchar_t **__p__wpgmptr(void);
293
294 #else  /* ! __MSVCRT__; thus CRTDLL */
295
296 # ifndef __DECLSPEC_SUPPORTED
297 # define _pgmptr  (*_imp___pgmptr_dll)
298 extern char **__imp__pgmptr_dll;
299
300 # else  /* __DECLSPEC_SUPPORTED */
301
302 # define _pgmptr _pgmptr_dll
303 __MINGW_IMPORT  char *_pgmptr_dll;
304 /* no wide version in CRTDLL */
305
306 # endif /* __DECLSPEC_SUPPORTED */
307 #endif  /* CRTDLL */
308
309 /* This variable determines the default file mode.
310  * TODO: Which flags work?
311  */
312 #if !defined (__DECLSPEC_SUPPORTED) || defined (__IN_MINGW_RUNTIME)
313
314 #ifdef __MSVCRT__
315 #define _fmode  (*_imp___fmode)
316 extern int *_imp___fmode;
317 #else
318 /* CRTDLL */
319 #define _fmode  (*_imp___fmode_dll)
320 extern int *_imp___fmode_dll;
321 #endif
322
323 #else  /* __DECLSPEC_SUPPORTED */
324 #ifdef __MSVCRT__
325 __MINGW_IMPORT  int _fmode;
326
327 #else  /* ! __MSVCRT__ */
328 #define _fmode  _fmode_dll
329 __MINGW_IMPORT  int _fmode_dll;
330
331 #endif  /* !__MSVCRT__ */
332 #endif  /* __DECLSPEC_SUPPORTED */
333 #endif  /* !__STRICT_ANSI__ */
334
335 _CRTIMP __cdecl __MINGW_NOTHROW  int atoi (const char *);
336 _CRTIMP __cdecl __MINGW_NOTHROW  long atol (const char *);
337
338 _CRTIMP __cdecl __MINGW_NOTHROW  double strtod (const char *, char **);
339 _CRTIMP __cdecl __MINGW_NOTHROW  double atof (const char *);
340
341 #if !defined (__STRICT_ANSI__)
342 _CRTIMP __cdecl __MINGW_NOTHROW  double _wtof (const wchar_t *);
343 _CRTIMP __cdecl __MINGW_NOTHROW  int _wtoi (const wchar_t *);
344 _CRTIMP __cdecl __MINGW_NOTHROW  long _wtol (const wchar_t *);
345 #endif
346
347 #if __USE_MINGW_ANSI_STDIO
348 /* Microsoft's strtod() and atof() implementations, (in MSVCRT.DLL),
349  * mishandle infinities and NaNs; on the basis that this conditional
350  * exposes a more ISO-C conforming printf() I/O family implementaion,
351  * we substitute a similarly more conforming implementation for each
352  * of this pair of (somewhat related) functions.
353  *
354  * Note that we provide neither __JMPSTUB__ nor __LIBIMPL__ external
355  * equivalents for either of these two inline functions, because they
356  * would conflict with the runtime DLL implementations; users needing
357  * an address reference for either must provide an equivalent of the
358  * inline implementation, as non-inlined within their own code.
359  */
360 extern __cdecl __MINGW_NOTHROW
361 double __strtod (const char *__restrict__, char **__restrict__);
362
363 __CRT_ALIAS __cdecl __MINGW_NOTHROW
364 double strtod (const char *__restrict__ __nptr, char **__restrict__ __endptr)
365 { return __strtod( __nptr, __endptr ); }
366
367 __CRT_ALIAS __cdecl __MINGW_NOTHROW
368 double atof (const char *__nptr) { return __strtod( __nptr, NULL ); }
369
370 #endif  /* __USE_MINGW_ANSI_STDIO */
371
372 #ifdef _ISOC99_SOURCE
373 /* Irrespective of requested standards conformity, where MSVCRT.DLL
374  * falls short, ISO-C99 offers this pair of alternative return type
375  * specific variants of strtod(), which MSVCRT.DLL does not, but we
376  * do, in libmingwex.a:
377  */
378 __cdecl __MINGW_NOTHROW
379 float strtof (const char *__restrict__, char **__restrict__);
380
381 __cdecl __MINGW_NOTHROW
382 long double strtold (const char *__restrict__, char **__restrict__);
383 #endif  /* _ISOC99_SOURCE */
384
385 _CRTIMP __cdecl __MINGW_NOTHROW  long strtol (const char *, char **, int);
386 _CRTIMP __cdecl __MINGW_NOTHROW  unsigned long strtoul (const char *, char **, int);
387
388 #endif  /* _STDLIB_H only */
389 #if ! (defined _STDLIB_H && defined _WCHAR_H)
390 /* Prototypes which are to be declared both here, in <stdlib.h>,
391  * and also in <wchar.h>; declare them here, such that they may be
392  * selectively included by <wchar.h>.
393  */
394 _CRTIMP __cdecl __MINGW_NOTHROW
395 long wcstol (const wchar_t *, wchar_t **, int);
396
397 _CRTIMP __cdecl __MINGW_NOTHROW
398 unsigned long wcstoul (const wchar_t *, wchar_t **, int);
399
400 _CRTIMP __cdecl __MINGW_NOTHROW  double wcstod (const wchar_t *, wchar_t **);
401
402 #ifdef _ISOC99_SOURCE
403 /* Variants on wcstod(), specified by ISO-C99; once again, MSVCRT.DLL
404  * doesn't have them, but we offer them in libmingwex.a
405  */
406 __cdecl __MINGW_NOTHROW
407 float wcstof (const wchar_t *__restrict__, wchar_t **__restrict__);
408
409 __cdecl __MINGW_NOTHROW
410 long double wcstold (const wchar_t *__restrict__, wchar_t **__restrict__);
411 #endif  /* _ISOC99_SOURCE */
412
413 #ifdef __MSVCRT__
414 _CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *_wgetenv (const wchar_t *);
415 _CRTIMP __cdecl __MINGW_NOTHROW  int _wputenv (const wchar_t *);
416
417 _CRTIMP __cdecl __MINGW_NOTHROW
418 void _wsearchenv (const wchar_t *, const wchar_t *, wchar_t *);
419
420 _CRTIMP __cdecl __MINGW_NOTHROW  int _wsystem (const wchar_t *);
421
422 _CRTIMP __cdecl __MINGW_NOTHROW
423 void _wmakepath (wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *,
424     const wchar_t *
425   );
426
427 _CRTIMP __cdecl __MINGW_NOTHROW
428 void _wsplitpath (const wchar_t *, wchar_t *, wchar_t *, wchar_t *, wchar_t *);
429
430 _CRTIMP __cdecl __MINGW_NOTHROW
431 wchar_t *_wfullpath (wchar_t *, const wchar_t *, size_t);
432
433 #endif  /* __MSVCRT__ */
434 #endif  /* _STDLIB_H || _WCHAR_H */
435
436 #ifdef _STDLIB_H  /* <stdlib.h> only */
437 _CRTIMP __cdecl __MINGW_NOTHROW  size_t wcstombs (char *, const wchar_t *, size_t);
438 _CRTIMP __cdecl __MINGW_NOTHROW  int wctomb (char *, wchar_t);
439
440 _CRTIMP __cdecl __MINGW_NOTHROW  int mblen (const char *, size_t);
441 _CRTIMP __cdecl __MINGW_NOTHROW  size_t mbstowcs (wchar_t *, const char *, size_t);
442 _CRTIMP __cdecl __MINGW_NOTHROW  int mbtowc (wchar_t *, const char *, size_t);
443
444 _CRTIMP __cdecl __MINGW_NOTHROW  int rand (void);
445 _CRTIMP __cdecl __MINGW_NOTHROW  void srand (unsigned int);
446
447 _CRTIMP __cdecl __MINGW_NOTHROW  void *calloc (size_t, size_t) __MINGW_ATTRIB_MALLOC;
448 _CRTIMP __cdecl __MINGW_NOTHROW  void *malloc (size_t) __MINGW_ATTRIB_MALLOC;
449 _CRTIMP __cdecl __MINGW_NOTHROW  void *realloc (void *, size_t);
450 _CRTIMP __cdecl __MINGW_NOTHROW  void free (void *);
451 _CRTIMP __cdecl __MINGW_NOTHROW  void abort (void) __MINGW_ATTRIB_NORETURN;
452 _CRTIMP __cdecl __MINGW_NOTHROW  void exit (int) __MINGW_ATTRIB_NORETURN;
453
454 /* Note: this is in startup code, not imported directly from the runtime DLL
455  */
456 int __cdecl __MINGW_NOTHROW atexit (void (*)(void));
457
458 _CRTIMP __cdecl __MINGW_NOTHROW  int system (const char *);
459 _CRTIMP __cdecl __MINGW_NOTHROW  char *getenv (const char *);
460
461 /* bsearch() and qsort() are declared both here, in <stdlib.h>, and in
462  * non-ANSI header <search.h>; we reproduce these declarations in both,
463  * with no attempt to guard them, so the compiler may verify that they
464  * are consistent, if both headers are included.
465  */
466 _CRTIMP __cdecl  void *bsearch
467 (const void *, const void *, size_t, size_t, int (*)(const void *, const void *));
468
469 _CRTIMP __cdecl  void qsort
470 (void *, size_t, size_t, int (*)(const void *, const void *));
471
472 _CRTIMP __cdecl __MINGW_NOTHROW  int abs (int) __MINGW_ATTRIB_CONST;
473 _CRTIMP __cdecl __MINGW_NOTHROW  long labs (long) __MINGW_ATTRIB_CONST;
474
475 /* div_t and ldiv_t are structures used to return the results of div()
476  * and ldiv() functions.
477  *
478  * NOTE: div() and ldiv() appear not to work correctly unless
479  *       -fno-pcc-struct-return is specified. This is included in the
480  *       mingw32 specs file.
481  */
482 typedef struct { int quot, rem; } div_t;
483 typedef struct { long quot, rem; } ldiv_t;
484
485 _CRTIMP __cdecl __MINGW_NOTHROW  div_t div (int, int) __MINGW_ATTRIB_CONST;
486 _CRTIMP __cdecl __MINGW_NOTHROW  ldiv_t ldiv (long, long) __MINGW_ATTRIB_CONST;
487
488 #if !defined (__STRICT_ANSI__)
489 /* NOTE: Officially the three following functions are obsolete. The Win32 API
490  *       functions SetErrorMode, Beep and Sleep are their replacements.
491  */
492 _CRTIMP __cdecl __MINGW_NOTHROW  void _beep (unsigned int, unsigned int) __MINGW_ATTRIB_DEPRECATED;
493 /* Not to be confused with  _set_error_mode (int).  */
494 _CRTIMP __cdecl __MINGW_NOTHROW  void _seterrormode (int) __MINGW_ATTRIB_DEPRECATED;
495 _CRTIMP __cdecl __MINGW_NOTHROW  void _sleep (unsigned long) __MINGW_ATTRIB_DEPRECATED;
496
497 _CRTIMP __cdecl __MINGW_NOTHROW  void _exit (int) __MINGW_ATTRIB_NORETURN;
498
499 /* _onexit is a Microsoft extension. Use atexit for portability. */
500 /* Note: This is in startup code, not imported directly from dll */
501 typedef  int (* _onexit_t)(void);
502 __cdecl __MINGW_NOTHROW  _onexit_t _onexit( _onexit_t );
503
504 _CRTIMP __cdecl __MINGW_NOTHROW  int _putenv (const char *);
505 _CRTIMP __cdecl __MINGW_NOTHROW
506 void _searchenv (const char *, const char *, char *);
507
508 _CRTIMP __cdecl __MINGW_NOTHROW  char *_ecvt (double, int, int *, int *);
509 _CRTIMP __cdecl __MINGW_NOTHROW  char *_fcvt (double, int, int *, int *);
510 _CRTIMP __cdecl __MINGW_NOTHROW  char *_gcvt (double, int, char *);
511
512 _CRTIMP __cdecl __MINGW_NOTHROW
513 void _makepath (char *, const char *, const char *, const char *, const char *);
514
515 _CRTIMP __cdecl __MINGW_NOTHROW
516 void _splitpath (const char *, char *, char *, char *, char *);
517
518 _CRTIMP __cdecl __MINGW_NOTHROW  char *_fullpath (char*, const char*, size_t);
519
520 _CRTIMP __cdecl __MINGW_NOTHROW  char *_itoa (int, char *, int);
521 _CRTIMP __cdecl __MINGW_NOTHROW  char *_ltoa (long, char *, int);
522 _CRTIMP __cdecl __MINGW_NOTHROW  char *_ultoa(unsigned long, char *, int);
523 _CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *_itow (int, wchar_t *, int);
524 _CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *_ltow (long, wchar_t *, int);
525 _CRTIMP __cdecl __MINGW_NOTHROW  wchar_t *_ultow (unsigned long, wchar_t *, int);
526
527 #ifdef __MSVCRT__
528 _CRTIMP __cdecl __MINGW_NOTHROW  __int64 _atoi64 (const char *);
529 _CRTIMP __cdecl __MINGW_NOTHROW  char* _i64toa (__int64, char *, int);
530 _CRTIMP __cdecl __MINGW_NOTHROW  char* _ui64toa (unsigned __int64, char *, int);
531 _CRTIMP __cdecl __MINGW_NOTHROW  __int64 _wtoi64 (const wchar_t *);
532 _CRTIMP __cdecl __MINGW_NOTHROW  wchar_t* _i64tow (__int64, wchar_t *, int);
533 _CRTIMP __cdecl __MINGW_NOTHROW  wchar_t* _ui64tow (unsigned __int64, wchar_t *, int);
534
535 _CRTIMP __cdecl __MINGW_NOTHROW  unsigned int (_rotl)(unsigned int, int) __MINGW_ATTRIB_CONST;
536 _CRTIMP __cdecl __MINGW_NOTHROW  unsigned int (_rotr)(unsigned int, int) __MINGW_ATTRIB_CONST;
537 _CRTIMP __cdecl __MINGW_NOTHROW  unsigned long (_lrotl)(unsigned long, int) __MINGW_ATTRIB_CONST;
538 _CRTIMP __cdecl __MINGW_NOTHROW  unsigned long (_lrotr)(unsigned long, int) __MINGW_ATTRIB_CONST;
539
540 _CRTIMP __cdecl __MINGW_NOTHROW  int _set_error_mode (int);
541
542 # define _OUT_TO_DEFAULT        0
543 # define _OUT_TO_STDERR         1
544 # define _OUT_TO_MSGBOX         2
545 # define _REPORT_ERRMODE        3
546
547 # if __MSVCRT_VERSION__ >= __MSVCR80_DLL
548 #  ifndef _UINTPTR_T_DEFINED
549 #   define _UINTPTR_T_DEFINED
550 #   ifdef _WIN64
551       typedef unsigned __int64 uintptr_t;
552 #   else
553       typedef unsigned int uintptr_t;
554 #   endif
555 #  endif
556
557 _CRTIMP __cdecl __MINGW_NOTHROW
558 unsigned int _set_abort_behavior (unsigned int, unsigned int);
559
560 /* These masks work with msvcr80.dll version 8.0.50215.44 (a beta release).
561  */
562 #  define _WRITE_ABORT_MSG      1
563 #  define _CALL_REPORTFAULT     2
564
565 typedef void
566 (* _invalid_parameter_handler) (
567     const wchar_t *,
568     const wchar_t *,
569     const wchar_t *,
570     unsigned int,
571     uintptr_t);
572 _invalid_parameter_handler _set_invalid_parameter_handler (_invalid_parameter_handler);
573
574 # endif /* __MSVCRT_VERSION__ >= __MSVCR80_DLL */
575 #endif  /* __MSVCRT__ */
576
577 #ifndef _NO_OLDNAMES
578 _CRTIMP __cdecl __MINGW_NOTHROW  int putenv (const char*);
579 _CRTIMP __cdecl __MINGW_NOTHROW  void searchenv (const char*, const char*, char*);
580
581 _CRTIMP __cdecl __MINGW_NOTHROW  char* itoa (int, char*, int);
582 _CRTIMP __cdecl __MINGW_NOTHROW  char* ltoa (long, char*, int);
583
584 #ifndef _UWIN
585 _CRTIMP __cdecl __MINGW_NOTHROW  char* ecvt (double, int, int*, int*);
586 _CRTIMP __cdecl __MINGW_NOTHROW  char* fcvt (double, int, int*, int*);
587 _CRTIMP __cdecl __MINGW_NOTHROW  char* gcvt (double, int, char*);
588
589 #endif  /* ! _UWIN */
590 #endif  /* ! _NO_OLDNAMES */
591 #endif  /* ! __STRICT_ANSI__ */
592
593 #ifdef _ISOC99_SOURCE
594 /* Further APIs required to support ISO-C99, but missing from MSVCRT.DLL;
595  * we provide them in libmingwex.a:
596  *
597  * ISO-C99 name for _exit()
598  */
599 __cdecl __MINGW_NOTHROW  void _Exit(int) __MINGW_ATTRIB_NORETURN;
600
601 #ifndef __NO_INLINE__
602 __CRT_INLINE __JMPSTUB__(( FUNCTION = _Exit, REMAPPED = _exit ))
603 __cdecl __MINGW_NOTHROW  void _Exit( int __status ){ _exit (__status); }
604 #endif
605
606 typedef struct { long long quot, rem; } lldiv_t;
607 __cdecl __MINGW_NOTHROW  lldiv_t lldiv (long long, long long) __MINGW_ATTRIB_CONST;
608
609 __cdecl __MINGW_NOTHROW  long long llabs (long long);
610
611 #ifndef __NO_INLINE__
612 __CRT_INLINE
613 /* No JMPSTUB or LIBIMPL reference here -- we provide a free-standing
614  * implementation, along with imaxabs(), in mingwex/imaxabs.c
615  */
616 __cdecl __MINGW_NOTHROW  long long llabs( long long __j )
617 { return __j >= 0 ? __j : -__j; }
618 #endif
619
620 __cdecl __MINGW_NOTHROW
621 long long strtoll (const char *__restrict__, char **__restrict, int);
622
623 __cdecl __MINGW_NOTHROW
624 unsigned long long strtoull (const char *__restrict__, char **__restrict__, int);
625
626 #ifdef __MSVCRT__
627 /* MSVCRT.DLL does not provide ISO-C99's atoll() function, but it does
628  * provide an analogue, in _atoi64(); map it accordingly.
629  */
630 __cdecl __MINGW_NOTHROW  long long atoll (const char *);
631
632 #ifndef __NO_INLINE__
633 __CRT_INLINE __JMPSTUB__(( FUNCTION = atoll, REMAPPED = _atoi64 ))
634 __cdecl __MINGW_NOTHROW  long long atoll (const char * _c){ return _atoi64 (_c); }
635 #endif
636
637 #endif  /* __MSVCRT__ */
638 #endif  /* _ISOC99_SOURCE */
639
640 #if defined __MSVCRT__ && ! defined __STRICT_ANSI__
641 /* Type long long analogues for MSVCRT.DLL specific type long functions;
642  * none are actually provided by any version of MSVCRT.DLL, with names as
643  * specified here, but rather as called by the inline functions used to
644  * implement them, (i.e. the REMAPPED name specified in each__JMPSTUB__
645  * function reference respectively).
646  *
647  * FIXME: Not one of these is specified by ISO-C99, nor by POSIX, either;
648  * is there really any justification for us to specify them at all?  For
649  * the time being, declare as deprecated; perhaps remove later?
650  */
651 __cdecl __MINGW_NOTHROW __MINGW_ATTRIB_DEPRECATED  long long wtoll (const wchar_t *);
652 __cdecl __MINGW_NOTHROW __MINGW_ATTRIB_DEPRECATED  char *lltoa (long long, char *, int);
653 __cdecl __MINGW_NOTHROW __MINGW_ATTRIB_DEPRECATED  char *ulltoa (unsigned long long , char *, int);
654 __cdecl __MINGW_NOTHROW __MINGW_ATTRIB_DEPRECATED  wchar_t *lltow (long long, wchar_t *, int);
655 __cdecl __MINGW_NOTHROW __MINGW_ATTRIB_DEPRECATED  wchar_t *ulltow (unsigned long long, wchar_t *, int);
656
657 #ifndef __NO_INLINE__
658 /* None of these functions would exist at all, without either these inline
659  * implementations, or their respective __JMPSTUB__ equivalents.
660  */
661 __CRT_INLINE __JMPSTUB__(( FUNCTION = lltoa, REMAPPED = _i64toa ))
662 __cdecl __MINGW_NOTHROW  char *lltoa (long long __n, char * __c, int __i)
663 { return _i64toa (__n, __c, __i); }
664
665 __CRT_INLINE __JMPSTUB__(( FUNCTION = ulltoa, REMAPPED = _ui64toa ))
666 __cdecl __MINGW_NOTHROW  char *ulltoa (unsigned long long __n, char * __c, int __i)
667 { return _ui64toa (__n, __c, __i); }
668
669 __CRT_INLINE __JMPSTUB__(( FUNCTION = wtoll, REMAPPED = _wtoi64 ))
670 __cdecl __MINGW_NOTHROW  long long wtoll (const wchar_t * __w){ return _wtoi64 (__w); }
671
672 __CRT_INLINE __JMPSTUB__(( FUNCTION = lltow, REMAPPED = _i64tow ))
673 __cdecl __MINGW_NOTHROW  wchar_t *lltow (long long __n, wchar_t * __w, int __i)
674 { return _i64tow (__n, __w, __i); }
675
676 __CRT_INLINE __JMPSTUB__(( FUNCTION = ulltow, REMAPPED = _ui64tow ))
677 __cdecl __MINGW_NOTHROW  wchar_t *ulltow (unsigned long long __n, wchar_t * __w, int __i)
678 { return _ui64tow (__n, __w, __i); }
679
680 #endif  /* ! __NO_INLINE__ */
681 #endif  /* __MSVCRT__ && ! __STRICT_ANSI__ */
682
683 /* POSIX/BSD extensions in libmingwex.a; these should be exposed only on
684  * the basis of appropriate POSIX or BSD specific feature tests...
685  *
686  * mkstemp(3) function support; added per feature request #2003.
687  * POSIX wants _XOPEN_SOURCE >= 500, (implying _POSIX_C_SOURCE >= 200112L).
688  */
689 #if _POSIX_C_SOURCE >= 200112L
690
691 __cdecl __MINGW_NOTHROW  int mkstemp (char *);
692 __cdecl __MINGW_NOTHROW  int __mingw_mkstemp (int, char *);
693
694 /* On POSIX platforms, programmers may adopt an idiom such as:
695  *
696  *   if( mkstemp( template ) >= 0 )
697  *   { unlink( template );
698  *     . . .
699  *   }
700  *
701  * to ensure that a temporary file does NOT persist after it is
702  * closed; MS-Windows does not allow such use of unlink(2), while
703  * the file remains open.  Thus, MS-Windows programmers must take
704  * extra care, to close and unlink temporary files AFTER use, if
705  * similar behaviour is desired.
706  *
707  * To mitigate this MS-Windows limitation, we provide support for
708  * an alternative, MinGW specific idiom:
709  *
710  *   #include <fcntl.h>
711  *
712  *   _MKSTEMP_SETMODE( _O_TEMPORARY );
713  *   if( mkstemp( template ) >= 0 )
714  *   {
715  *     . . .
716  *   }
717  *
718  * to achieve a similar effect to that of the above POSIX idiom; the
719  * following macros are a MinGW specific extension, to facilite such
720  * use of _O_TEMPORARY, (in addition to the POSIX required attributes),
721  * when creating the temporary file.  Note that they require <fcntl.h>,
722  * which <stdlib.h> should NOT automatically include; we leave it to
723  * the user to explicitly include it, if using _MKSTEMP_SETMODE.
724  */
725 #define _MKSTEMP_INVOKE       0
726 #define _MKSTEMP_DEFAULT     _O_CREAT | _O_EXCL | _O_RDWR
727 #define _MKSTEMP_SETMODE(M) __mingw_mkstemp( _MKSTEMP_DEFAULT | (M), NULL )
728
729 #ifndef _NO_OLDNAMES
730 #define MKSTEMP_SETMODE(M)  __mingw_mkstemp( _MKSTEMP_DEFAULT | (M), NULL )
731 #endif
732
733 __CRT_ALIAS __LIBIMPL__(( FUNCTION = mkstemp ))
734 __cdecl __MINGW_NOTHROW  int mkstemp (char *__filename_template)
735 { return __mingw_mkstemp( _MKSTEMP_INVOKE, __filename_template ); }
736
737 #endif  /* _POSIX_C_SOURCE >= 200112L (for mkstemp()) */
738
739 /* mkdtemp(3) function support: added as adjunct to feature request #2003.
740  * POSIX wants _XOPEN_SOURCE >= 700, (implying _POSIX_C_SOURCE >= 200809L).
741  */
742 #if _POSIX_C_SOURCE >= 200809L
743
744 __cdecl __MINGW_NOTHROW  char *mkdtemp (char *);
745 __cdecl __MINGW_NOTHROW  char *__mingw_mkdtemp (char *);
746
747 __CRT_ALIAS __JMPSTUB__(( FUNCTION = mkdtemp ))
748 __cdecl __MINGW_NOTHROW  char *mkdtemp (char *__dirname_template)
749 { return __mingw_mkdtemp( __dirname_template ); }
750
751 #endif  /* _POSIX_C_SOURCE >= 200809L (for mkdtemp()) */
752 #endif  /* _STDLIB_H */
753
754 _END_C_DECLS
755
756 #endif  /* ! RC_INVOKED */
757 #endif  /* ! _STDLIB_H: $RCSfile$: end of file */