1 |
/* |
2 |
* stdlib.h |
3 |
* |
4 |
* ANSI/POSIX + Microsoft compatible standard library function prototypes, |
5 |
* associated macros, and manifest constant definitions. |
6 |
* |
7 |
* $Id: stdlib.h,v 0e4f78dbc1ba 2016/06/17 14:16:01 keithmarshall $ |
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 |
#if __MSVCRT_VERSION__ >= __MSVCR70_DLL || _WIN32_WINNT >= _WIN32_WINNT_WINXP |
415 |
/* This pair of wide character equivalents for ISO-C99's strtoll() and |
416 |
* strtoull() require either WinXP (or later), or a non-free MSVC runtime |
417 |
* from MSVCR70.DLL onwards... |
418 |
*/ |
419 |
_CRTIMP __cdecl __MINGW_NOTHROW |
420 |
__int64 _wcstoi64(const wchar_t *, wchar_t **, int); |
421 |
|
422 |
_CRTIMP __cdecl __MINGW_NOTHROW |
423 |
unsigned __int64 _wcstoui64(const wchar_t *, wchar_t **, int); |
424 |
|
425 |
#endif /* WinXP || MSVCR70.DLL || later */ |
426 |
|
427 |
#if __MSVCRT_VERSION__ >= __MSVCR80_DLL || _WIN32_WINNT >= _WIN32_WINNT_VISTA |
428 |
/* ...while the following pair require Win-Vista (or later), or non-free |
429 |
* MSVCRT runtime from MSVCR80.DLL onwards; they also require... |
430 |
*/ |
431 |
#ifndef __have_typedef_locale_t |
432 |
/* ...this opaque data type, which we may obtain by selective inclusion |
433 |
* from <locale.h>. (Note that this may render them unusable for users of |
434 |
* MSVCRT.DLL; see the explanation in <locale.h>, regarding the difficulty |
435 |
* in creating, or otherwise acquiring a reference to, a _locale_t object, |
436 |
* notwithstanding the availability of the functions in MSVCRT.DLL, from |
437 |
* the release of Win-Vista onwards). |
438 |
*/ |
439 |
#define __need_locale_t |
440 |
#include <locale.h> |
441 |
#endif /* !__have_typedef_locale_t */ |
442 |
|
443 |
_CRTIMP __cdecl __MINGW_NOTHROW |
444 |
__int64 _wcstoi64_l(const wchar_t *, wchar_t **, int, _locale_t); |
445 |
|
446 |
_CRTIMP __cdecl __MINGW_NOTHROW |
447 |
unsigned __int64 _wcstoui64_l(const wchar_t *, wchar_t **, int, _locale_t); |
448 |
|
449 |
#endif /* Win-Vista || MSVCR80.DLL || later */ |
450 |
|
451 |
_CRTIMP __cdecl __MINGW_NOTHROW wchar_t *_wgetenv (const wchar_t *); |
452 |
_CRTIMP __cdecl __MINGW_NOTHROW int _wputenv (const wchar_t *); |
453 |
|
454 |
_CRTIMP __cdecl __MINGW_NOTHROW |
455 |
void _wsearchenv (const wchar_t *, const wchar_t *, wchar_t *); |
456 |
|
457 |
_CRTIMP __cdecl __MINGW_NOTHROW int _wsystem (const wchar_t *); |
458 |
|
459 |
_CRTIMP __cdecl __MINGW_NOTHROW |
460 |
void _wmakepath (wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *, |
461 |
const wchar_t * |
462 |
); |
463 |
|
464 |
_CRTIMP __cdecl __MINGW_NOTHROW |
465 |
void _wsplitpath (const wchar_t *, wchar_t *, wchar_t *, wchar_t *, wchar_t *); |
466 |
|
467 |
_CRTIMP __cdecl __MINGW_NOTHROW |
468 |
wchar_t *_wfullpath (wchar_t *, const wchar_t *, size_t); |
469 |
|
470 |
#endif /* __MSVCRT__ */ |
471 |
#endif /* _STDLIB_H || _WCHAR_H */ |
472 |
|
473 |
#ifdef _STDLIB_H /* <stdlib.h> only */ |
474 |
_CRTIMP __cdecl __MINGW_NOTHROW size_t wcstombs (char *, const wchar_t *, size_t); |
475 |
_CRTIMP __cdecl __MINGW_NOTHROW int wctomb (char *, wchar_t); |
476 |
|
477 |
_CRTIMP __cdecl __MINGW_NOTHROW int mblen (const char *, size_t); |
478 |
_CRTIMP __cdecl __MINGW_NOTHROW size_t mbstowcs (wchar_t *, const char *, size_t); |
479 |
_CRTIMP __cdecl __MINGW_NOTHROW int mbtowc (wchar_t *, const char *, size_t); |
480 |
|
481 |
_CRTIMP __cdecl __MINGW_NOTHROW int rand (void); |
482 |
_CRTIMP __cdecl __MINGW_NOTHROW void srand (unsigned int); |
483 |
|
484 |
_CRTIMP __cdecl __MINGW_NOTHROW void *calloc (size_t, size_t) __MINGW_ATTRIB_MALLOC; |
485 |
_CRTIMP __cdecl __MINGW_NOTHROW void *malloc (size_t) __MINGW_ATTRIB_MALLOC; |
486 |
_CRTIMP __cdecl __MINGW_NOTHROW void *realloc (void *, size_t); |
487 |
_CRTIMP __cdecl __MINGW_NOTHROW void free (void *); |
488 |
_CRTIMP __cdecl __MINGW_NOTHROW void abort (void) __MINGW_ATTRIB_NORETURN; |
489 |
_CRTIMP __cdecl __MINGW_NOTHROW void exit (int) __MINGW_ATTRIB_NORETURN; |
490 |
|
491 |
/* Note: this is in startup code, not imported directly from the runtime DLL |
492 |
*/ |
493 |
int __cdecl __MINGW_NOTHROW atexit (void (*)(void)); |
494 |
|
495 |
_CRTIMP __cdecl __MINGW_NOTHROW int system (const char *); |
496 |
_CRTIMP __cdecl __MINGW_NOTHROW char *getenv (const char *); |
497 |
|
498 |
/* bsearch() and qsort() are declared both here, in <stdlib.h>, and in |
499 |
* non-ANSI header <search.h>; we reproduce these declarations in both, |
500 |
* with no attempt to guard them, so the compiler may verify that they |
501 |
* are consistent, if both headers are included. |
502 |
*/ |
503 |
_CRTIMP __cdecl void *bsearch |
504 |
(const void *, const void *, size_t, size_t, int (*)(const void *, const void *)); |
505 |
|
506 |
_CRTIMP __cdecl void qsort |
507 |
(void *, size_t, size_t, int (*)(const void *, const void *)); |
508 |
|
509 |
_CRTIMP __cdecl __MINGW_NOTHROW int abs (int) __MINGW_ATTRIB_CONST; |
510 |
_CRTIMP __cdecl __MINGW_NOTHROW long labs (long) __MINGW_ATTRIB_CONST; |
511 |
|
512 |
/* div_t and ldiv_t are structures used to return the results of div() |
513 |
* and ldiv() functions. |
514 |
* |
515 |
* NOTE: div() and ldiv() appear not to work correctly unless |
516 |
* -fno-pcc-struct-return is specified. This is included in the |
517 |
* mingw32 specs file. |
518 |
*/ |
519 |
typedef struct { int quot, rem; } div_t; |
520 |
typedef struct { long quot, rem; } ldiv_t; |
521 |
|
522 |
_CRTIMP __cdecl __MINGW_NOTHROW div_t div (int, int) __MINGW_ATTRIB_CONST; |
523 |
_CRTIMP __cdecl __MINGW_NOTHROW ldiv_t ldiv (long, long) __MINGW_ATTRIB_CONST; |
524 |
|
525 |
#if !defined (__STRICT_ANSI__) |
526 |
/* NOTE: Officially the three following functions are obsolete. The Win32 API |
527 |
* functions SetErrorMode, Beep and Sleep are their replacements. |
528 |
*/ |
529 |
_CRTIMP __cdecl __MINGW_NOTHROW void _beep (unsigned int, unsigned int) __MINGW_ATTRIB_DEPRECATED; |
530 |
/* Not to be confused with _set_error_mode (int). */ |
531 |
_CRTIMP __cdecl __MINGW_NOTHROW void _seterrormode (int) __MINGW_ATTRIB_DEPRECATED; |
532 |
_CRTIMP __cdecl __MINGW_NOTHROW void _sleep (unsigned long) __MINGW_ATTRIB_DEPRECATED; |
533 |
|
534 |
_CRTIMP __cdecl __MINGW_NOTHROW void _exit (int) __MINGW_ATTRIB_NORETURN; |
535 |
|
536 |
/* _onexit is a Microsoft extension. Use atexit for portability. */ |
537 |
/* Note: This is in startup code, not imported directly from dll */ |
538 |
typedef int (* _onexit_t)(void); |
539 |
__cdecl __MINGW_NOTHROW _onexit_t _onexit( _onexit_t ); |
540 |
|
541 |
_CRTIMP __cdecl __MINGW_NOTHROW int _putenv (const char *); |
542 |
_CRTIMP __cdecl __MINGW_NOTHROW |
543 |
void _searchenv (const char *, const char *, char *); |
544 |
|
545 |
_CRTIMP __cdecl __MINGW_NOTHROW char *_ecvt (double, int, int *, int *); |
546 |
_CRTIMP __cdecl __MINGW_NOTHROW char *_fcvt (double, int, int *, int *); |
547 |
_CRTIMP __cdecl __MINGW_NOTHROW char *_gcvt (double, int, char *); |
548 |
|
549 |
_CRTIMP __cdecl __MINGW_NOTHROW |
550 |
void _makepath (char *, const char *, const char *, const char *, const char *); |
551 |
|
552 |
_CRTIMP __cdecl __MINGW_NOTHROW |
553 |
void _splitpath (const char *, char *, char *, char *, char *); |
554 |
|
555 |
_CRTIMP __cdecl __MINGW_NOTHROW char *_fullpath (char*, const char*, size_t); |
556 |
|
557 |
_CRTIMP __cdecl __MINGW_NOTHROW char *_itoa (int, char *, int); |
558 |
_CRTIMP __cdecl __MINGW_NOTHROW char *_ltoa (long, char *, int); |
559 |
_CRTIMP __cdecl __MINGW_NOTHROW char *_ultoa(unsigned long, char *, int); |
560 |
_CRTIMP __cdecl __MINGW_NOTHROW wchar_t *_itow (int, wchar_t *, int); |
561 |
_CRTIMP __cdecl __MINGW_NOTHROW wchar_t *_ltow (long, wchar_t *, int); |
562 |
_CRTIMP __cdecl __MINGW_NOTHROW wchar_t *_ultow (unsigned long, wchar_t *, int); |
563 |
|
564 |
#ifdef __MSVCRT__ |
565 |
_CRTIMP __cdecl __MINGW_NOTHROW __int64 _atoi64 (const char *); |
566 |
_CRTIMP __cdecl __MINGW_NOTHROW char* _i64toa (__int64, char *, int); |
567 |
_CRTIMP __cdecl __MINGW_NOTHROW char* _ui64toa (unsigned __int64, char *, int); |
568 |
_CRTIMP __cdecl __MINGW_NOTHROW __int64 _wtoi64 (const wchar_t *); |
569 |
_CRTIMP __cdecl __MINGW_NOTHROW wchar_t* _i64tow (__int64, wchar_t *, int); |
570 |
_CRTIMP __cdecl __MINGW_NOTHROW wchar_t* _ui64tow (unsigned __int64, wchar_t *, int); |
571 |
|
572 |
_CRTIMP __cdecl __MINGW_NOTHROW unsigned int (_rotl)(unsigned int, int) __MINGW_ATTRIB_CONST; |
573 |
_CRTIMP __cdecl __MINGW_NOTHROW unsigned int (_rotr)(unsigned int, int) __MINGW_ATTRIB_CONST; |
574 |
_CRTIMP __cdecl __MINGW_NOTHROW unsigned long (_lrotl)(unsigned long, int) __MINGW_ATTRIB_CONST; |
575 |
_CRTIMP __cdecl __MINGW_NOTHROW unsigned long (_lrotr)(unsigned long, int) __MINGW_ATTRIB_CONST; |
576 |
|
577 |
_CRTIMP __cdecl __MINGW_NOTHROW int _set_error_mode (int); |
578 |
|
579 |
# define _OUT_TO_DEFAULT 0 |
580 |
# define _OUT_TO_STDERR 1 |
581 |
# define _OUT_TO_MSGBOX 2 |
582 |
# define _REPORT_ERRMODE 3 |
583 |
|
584 |
# if __MSVCRT_VERSION__ >= __MSVCR80_DLL |
585 |
# ifndef _UINTPTR_T_DEFINED |
586 |
# define _UINTPTR_T_DEFINED |
587 |
# ifdef _WIN64 |
588 |
typedef unsigned __int64 uintptr_t; |
589 |
# else |
590 |
typedef unsigned int uintptr_t; |
591 |
# endif |
592 |
# endif |
593 |
|
594 |
_CRTIMP __cdecl __MINGW_NOTHROW |
595 |
unsigned int _set_abort_behavior (unsigned int, unsigned int); |
596 |
|
597 |
/* These masks work with msvcr80.dll version 8.0.50215.44 (a beta release). |
598 |
*/ |
599 |
# define _WRITE_ABORT_MSG 1 |
600 |
# define _CALL_REPORTFAULT 2 |
601 |
|
602 |
typedef void |
603 |
(* _invalid_parameter_handler) ( |
604 |
const wchar_t *, |
605 |
const wchar_t *, |
606 |
const wchar_t *, |
607 |
unsigned int, |
608 |
uintptr_t); |
609 |
_invalid_parameter_handler _set_invalid_parameter_handler (_invalid_parameter_handler); |
610 |
|
611 |
# endif /* __MSVCRT_VERSION__ >= __MSVCR80_DLL */ |
612 |
#endif /* __MSVCRT__ */ |
613 |
|
614 |
#ifndef _NO_OLDNAMES |
615 |
_CRTIMP __cdecl __MINGW_NOTHROW int putenv (const char*); |
616 |
_CRTIMP __cdecl __MINGW_NOTHROW void searchenv (const char*, const char*, char*); |
617 |
|
618 |
_CRTIMP __cdecl __MINGW_NOTHROW char* itoa (int, char*, int); |
619 |
_CRTIMP __cdecl __MINGW_NOTHROW char* ltoa (long, char*, int); |
620 |
|
621 |
#ifndef _UWIN |
622 |
_CRTIMP __cdecl __MINGW_NOTHROW char* ecvt (double, int, int*, int*); |
623 |
_CRTIMP __cdecl __MINGW_NOTHROW char* fcvt (double, int, int*, int*); |
624 |
_CRTIMP __cdecl __MINGW_NOTHROW char* gcvt (double, int, char*); |
625 |
|
626 |
#endif /* ! _UWIN */ |
627 |
#endif /* ! _NO_OLDNAMES */ |
628 |
#endif /* ! __STRICT_ANSI__ */ |
629 |
|
630 |
#ifdef _ISOC99_SOURCE |
631 |
/* Further APIs required to support ISO-C99, but missing from MSVCRT.DLL; |
632 |
* we provide them in libmingwex.a: |
633 |
* |
634 |
* ISO-C99 name for _exit() |
635 |
*/ |
636 |
__cdecl __MINGW_NOTHROW void _Exit(int) __MINGW_ATTRIB_NORETURN; |
637 |
|
638 |
#ifndef __NO_INLINE__ |
639 |
__CRT_INLINE __JMPSTUB__(( FUNCTION = _Exit, REMAPPED = _exit )) |
640 |
__cdecl __MINGW_NOTHROW void _Exit( int __status ){ _exit (__status); } |
641 |
#endif |
642 |
|
643 |
typedef struct { long long quot, rem; } lldiv_t; |
644 |
__cdecl __MINGW_NOTHROW lldiv_t lldiv (long long, long long) __MINGW_ATTRIB_CONST; |
645 |
|
646 |
__cdecl __MINGW_NOTHROW long long llabs (long long); |
647 |
|
648 |
#ifndef __NO_INLINE__ |
649 |
__CRT_INLINE |
650 |
/* No JMPSTUB or LIBIMPL reference here -- we provide a free-standing |
651 |
* implementation, along with imaxabs(), in mingwex/imaxabs.c |
652 |
*/ |
653 |
__cdecl __MINGW_NOTHROW long long llabs( long long __j ) |
654 |
{ return __j >= 0 ? __j : -__j; } |
655 |
#endif |
656 |
|
657 |
__cdecl __MINGW_NOTHROW |
658 |
long long strtoll (const char *__restrict__, char **__restrict, int); |
659 |
|
660 |
__cdecl __MINGW_NOTHROW |
661 |
unsigned long long strtoull (const char *__restrict__, char **__restrict__, int); |
662 |
|
663 |
#ifdef __MSVCRT__ |
664 |
/* MSVCRT.DLL does not provide ISO-C99's atoll() function, but it does |
665 |
* provide an analogue, in _atoi64(); map it accordingly. |
666 |
*/ |
667 |
__cdecl __MINGW_NOTHROW long long atoll (const char *); |
668 |
|
669 |
#ifndef __NO_INLINE__ |
670 |
__CRT_INLINE __JMPSTUB__(( FUNCTION = atoll, REMAPPED = _atoi64 )) |
671 |
__cdecl __MINGW_NOTHROW long long atoll (const char * _c){ return _atoi64 (_c); } |
672 |
#endif |
673 |
|
674 |
#endif /* __MSVCRT__ */ |
675 |
#endif /* _ISOC99_SOURCE */ |
676 |
|
677 |
#if defined __MSVCRT__ && ! defined __STRICT_ANSI__ |
678 |
#if __MSVCRT_VERSION__ >= __MSVCR70_DLL || _WIN32_WINNT >= _WIN32_WINNT_WINXP |
679 |
/* Microsoft specific alternatives to ISO-C99 strtoll() and strtoull(); the |
680 |
* first pair require WinXP (or later) or non-free MSVCR70.DLL onwards... |
681 |
*/ |
682 |
_CRTIMP __cdecl __MINGW_NOTHROW |
683 |
__int64 _strtoi64(const char*, char **, int); |
684 |
|
685 |
_CRTIMP __cdecl __MINGW_NOTHROW |
686 |
unsigned __int64 _strtoui64(const char*, char **, int); |
687 |
|
688 |
#endif /* WinXP || MSVCR70.DLL || later */ |
689 |
#if __MSVCRT_VERSION__ >= __MSVCR80_DLL || _WIN32_WINNT >= _WIN32_WINNT_VISTA |
690 |
/* ...while the following pair require Win-Vista (or later), or non-free |
691 |
* MSVCR80.DLL onwards; (note that, like their wide character counterparts, |
692 |
* they may actually be unusable without MSVCR80.DLL onwards, because of |
693 |
* the difficulty in acquiring a reference to a _locale_t object). |
694 |
*/ |
695 |
_CRTIMP __cdecl __MINGW_NOTHROW |
696 |
__int64 _strtoi64_l(const char *, char **, int, _locale_t); |
697 |
|
698 |
_CRTIMP __cdecl __MINGW_NOTHROW |
699 |
unsigned __int64 _strtoui64_l(const char *, char **, int, _locale_t); |
700 |
|
701 |
#endif /* Win-Vista || MSVCR80.DLL || later */ |
702 |
|
703 |
/* Type long long analogues for MSVCRT.DLL specific type long functions; |
704 |
* none are actually provided by any version of MSVCRT.DLL, with names as |
705 |
* specified here, but rather as called by the inline functions used to |
706 |
* implement them, (i.e. the REMAPPED name specified in each__JMPSTUB__ |
707 |
* function reference respectively). |
708 |
* |
709 |
* FIXME: Not one of these is specified by ISO-C99, nor by POSIX, either; |
710 |
* is there really any justification for us to specify them at all? For |
711 |
* the time being, declare as deprecated; perhaps remove later? |
712 |
*/ |
713 |
__cdecl __MINGW_NOTHROW __MINGW_ATTRIB_DEPRECATED long long wtoll (const wchar_t *); |
714 |
__cdecl __MINGW_NOTHROW __MINGW_ATTRIB_DEPRECATED char *lltoa (long long, char *, int); |
715 |
__cdecl __MINGW_NOTHROW __MINGW_ATTRIB_DEPRECATED char *ulltoa (unsigned long long , char *, int); |
716 |
__cdecl __MINGW_NOTHROW __MINGW_ATTRIB_DEPRECATED wchar_t *lltow (long long, wchar_t *, int); |
717 |
__cdecl __MINGW_NOTHROW __MINGW_ATTRIB_DEPRECATED wchar_t *ulltow (unsigned long long, wchar_t *, int); |
718 |
|
719 |
#ifndef __NO_INLINE__ |
720 |
/* None of these functions would exist at all, without either these inline |
721 |
* implementations, or their respective __JMPSTUB__ equivalents. |
722 |
*/ |
723 |
__CRT_INLINE __JMPSTUB__(( FUNCTION = lltoa, REMAPPED = _i64toa )) |
724 |
__cdecl __MINGW_NOTHROW char *lltoa (long long __n, char * __c, int __i) |
725 |
{ return _i64toa (__n, __c, __i); } |
726 |
|
727 |
__CRT_INLINE __JMPSTUB__(( FUNCTION = ulltoa, REMAPPED = _ui64toa )) |
728 |
__cdecl __MINGW_NOTHROW char *ulltoa (unsigned long long __n, char * __c, int __i) |
729 |
{ return _ui64toa (__n, __c, __i); } |
730 |
|
731 |
__CRT_INLINE __JMPSTUB__(( FUNCTION = wtoll, REMAPPED = _wtoi64 )) |
732 |
__cdecl __MINGW_NOTHROW long long wtoll (const wchar_t * __w){ return _wtoi64 (__w); } |
733 |
|
734 |
__CRT_INLINE __JMPSTUB__(( FUNCTION = lltow, REMAPPED = _i64tow )) |
735 |
__cdecl __MINGW_NOTHROW wchar_t *lltow (long long __n, wchar_t * __w, int __i) |
736 |
{ return _i64tow (__n, __w, __i); } |
737 |
|
738 |
__CRT_INLINE __JMPSTUB__(( FUNCTION = ulltow, REMAPPED = _ui64tow )) |
739 |
__cdecl __MINGW_NOTHROW wchar_t *ulltow (unsigned long long __n, wchar_t * __w, int __i) |
740 |
{ return _ui64tow (__n, __w, __i); } |
741 |
|
742 |
#endif /* ! __NO_INLINE__ */ |
743 |
#endif /* __MSVCRT__ && ! __STRICT_ANSI__ */ |
744 |
|
745 |
/* POSIX/BSD extensions in libmingwex.a; these should be exposed only on |
746 |
* the basis of appropriate POSIX or BSD specific feature tests... |
747 |
* |
748 |
* mkstemp(3) function support; added per feature request #2003. |
749 |
* POSIX wants _XOPEN_SOURCE >= 500, (implying _POSIX_C_SOURCE >= 200112L). |
750 |
*/ |
751 |
#if _POSIX_C_SOURCE >= 200112L |
752 |
|
753 |
__cdecl __MINGW_NOTHROW int mkstemp (char *); |
754 |
__cdecl __MINGW_NOTHROW int __mingw_mkstemp (int, char *); |
755 |
|
756 |
/* On POSIX platforms, programmers may adopt an idiom such as: |
757 |
* |
758 |
* if( mkstemp( template ) >= 0 ) |
759 |
* { unlink( template ); |
760 |
* . . . |
761 |
* } |
762 |
* |
763 |
* to ensure that a temporary file does NOT persist after it is |
764 |
* closed; MS-Windows does not allow such use of unlink(2), while |
765 |
* the file remains open. Thus, MS-Windows programmers must take |
766 |
* extra care, to close and unlink temporary files AFTER use, if |
767 |
* similar behaviour is desired. |
768 |
* |
769 |
* To mitigate this MS-Windows limitation, we provide support for |
770 |
* an alternative, MinGW specific idiom: |
771 |
* |
772 |
* #include <fcntl.h> |
773 |
* |
774 |
* _MKSTEMP_SETMODE( _O_TEMPORARY ); |
775 |
* if( mkstemp( template ) >= 0 ) |
776 |
* { |
777 |
* . . . |
778 |
* } |
779 |
* |
780 |
* to achieve a similar effect to that of the above POSIX idiom; the |
781 |
* following macros are a MinGW specific extension, to facilite such |
782 |
* use of _O_TEMPORARY, (in addition to the POSIX required attributes), |
783 |
* when creating the temporary file. Note that they require <fcntl.h>, |
784 |
* which <stdlib.h> should NOT automatically include; we leave it to |
785 |
* the user to explicitly include it, if using _MKSTEMP_SETMODE. |
786 |
*/ |
787 |
#define _MKSTEMP_INVOKE 0 |
788 |
#define _MKSTEMP_DEFAULT _O_CREAT | _O_EXCL | _O_RDWR |
789 |
#define _MKSTEMP_SETMODE(M) __mingw_mkstemp( _MKSTEMP_DEFAULT | (M), NULL ) |
790 |
|
791 |
#ifndef _NO_OLDNAMES |
792 |
#define MKSTEMP_SETMODE(M) __mingw_mkstemp( _MKSTEMP_DEFAULT | (M), NULL ) |
793 |
#endif |
794 |
|
795 |
__CRT_ALIAS __LIBIMPL__(( FUNCTION = mkstemp )) |
796 |
__cdecl __MINGW_NOTHROW int mkstemp (char *__filename_template) |
797 |
{ return __mingw_mkstemp( _MKSTEMP_INVOKE, __filename_template ); } |
798 |
|
799 |
#endif /* _POSIX_C_SOURCE >= 200112L (for mkstemp()) */ |
800 |
|
801 |
/* mkdtemp(3) function support: added as adjunct to feature request #2003. |
802 |
* POSIX wants _XOPEN_SOURCE >= 700, (implying _POSIX_C_SOURCE >= 200809L). |
803 |
*/ |
804 |
#if _POSIX_C_SOURCE >= 200809L |
805 |
|
806 |
__cdecl __MINGW_NOTHROW char *mkdtemp (char *); |
807 |
__cdecl __MINGW_NOTHROW char *__mingw_mkdtemp (char *); |
808 |
|
809 |
__CRT_ALIAS __JMPSTUB__(( FUNCTION = mkdtemp )) |
810 |
__cdecl __MINGW_NOTHROW char *mkdtemp (char *__dirname_template) |
811 |
{ return __mingw_mkdtemp( __dirname_template ); } |
812 |
|
813 |
#endif /* _POSIX_C_SOURCE >= 200809L (for mkdtemp()) */ |
814 |
#endif /* _STDLIB_H */ |
815 |
|
816 |
_END_C_DECLS |
817 |
|
818 |
#endif /* ! RC_INVOKED */ |
819 |
#endif /* ! _STDLIB_H: $RCSfile: stdlib.h,v $: end of file */ |