File Index Symbol Index

//
// stdlib.h
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The C Standard Library <stdlib.h> header.
//
#pragma once
#ifndef _INC_STDLIB // include guard for 3rd party interop
#define _INC_STDLIB
#include <corecrt.h> #include <corecrt_malloc.h> #include <corecrt_search.h> #include <corecrt_wstdlib.h> #include <limits.h>
#ifndef _countof
#define _countof __crt_countof #endif
// Minimum and maximum macros
#define __max(a,b) (((a) > (b)) ? (a) : (b))
#define __min(a,b) (((a) < (b)) ? (a) : (b))
);
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
// Exit and Abort
//
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Argument values for exit()
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
#if _CRT_FUNCTIONS_REQUIRED
// Argument values for _set_abort_behavior().
#define _WRITE_ABORT_MSG 0x1 // debug only, has no effect in release
#define _CALL_REPORTFAULT 0x2
);
#ifndef _CRT_ONEXIT_T_DEFINED
#define _CRT_ONEXIT_T_DEFINED
#ifdef _M_CEE
typedef int (__clrcall* _onexit_m_t)(void);
#endif #endif
#if _CRT_INTERNAL_NONSTDC_NAMES
// Non-ANSI name for compatibility
#define onexit_t _onexit_t #endif
#ifdef _M_CEE
#pragma warning (push)
#pragma warning (disable: 4985)
_Check_return_ int __clrcall _atexit_m_appdomain(_In_opt_ void (__clrcall* _Function)(void));
_onexit_m_t __clrcall _onexit_m_appdomain(_onexit_m_t _Function);
#ifdef _M_CEE_MIXED
#ifdef __cplusplus
[System::Security::SecurityCritical]
#endif
_Check_return_ int __clrcall _atexit_m(_In_opt_ void (__clrcall* _Function)(void));
_onexit_m_t __clrcall _onexit_m(_onexit_m_t _Function);
#else
#ifdef __cplusplus
[System::Security::SecurityCritical]
#endif
_Check_return_ inline int __clrcall _atexit_m(_In_opt_ void (__clrcall* _Function)(void))
{
return _atexit_m_appdomain(_Function);
}
inline _onexit_m_t __clrcall _onexit_m(_onexit_t _Function)
{
return _onexit_m_appdomain(_Function);
}
#endif
#pragma warning (pop)
#endif
#ifdef _M_CEE_PURE
// In pure mode, atexit is the same as atexit_m_appdomain
extern "C++"
{
#ifdef __cplusplus
[System::Security::SecurityCritical]
#endif
inline int __clrcall atexit(void (__clrcall* _Function)(void))
{
return _atexit_m_appdomain(_Function);
}
inline _onexit_t __clrcall _onexit(_onexit_t _Function)
{
return _onexit_m_appdomain(_Function);
}
} // extern "C++"
#else
int
__cdecl
atexit
(
void
(
__cdecl
*)(
void
));
int
__cdecl
at_quick_exit
(
void
(
__cdecl
*)(
void
));
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
// Global State (errno, global handlers, etc.)
//
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#ifndef _M_CEE_PURE
// a purecall handler procedure. Never returns normally
typedef
void
(
__cdecl
*
_purecall_handler
)(
void
);
// Invalid parameter handler function pointer type
typedef
void
(
__cdecl
*
_invalid_parameter_handler
)(
wchar_t
const
*,
wchar_t
const
*,
wchar_t
const
*,
unsigned
int
,
uintptr_t
);
// Establishes a purecall handler
);
// Establishes an invalid parameter handler
); );
#if defined __cplusplus && defined _M_CEE_PURE
extern "C++"
{
typedef void (__clrcall* _purecall_handler)(void);
typedef _purecall_handler _purecall_handler_m;
_MRTIMP _purecall_handler __cdecl _set_purecall_handler(
_In_opt_ _purecall_handler _Handler
);
} // extern "C++" #endif
// Argument values for _set_error_mode().
#define _OUT_TO_DEFAULT 0
#define _OUT_TO_STDERR 1
#define _OUT_TO_MSGBOX 2
#define _REPORT_ERRMODE 3
#if _CRT_FUNCTIONS_REQUIRED
#define errno (*_errno())
#define _doserrno (*__doserrno())
// This is non-const for backwards compatibility; do not modify it.
#define _sys_errlist (__sys_errlist())
#define _sys_nerr (*__sys_nerr())
// These point to the executable module name.
#ifdef _CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY
_CRT_INSECURE_DEPRECATE_GLOBALS(_get_pgmptr ) extern char* _pgmptr;
_CRT_INSECURE_DEPRECATE_GLOBALS(_get_wpgmptr) extern wchar_t* _wpgmptr;
#ifndef _CORECRT_BUILD
_CRT_INSECURE_DEPRECATE_GLOBALS(_get_fmode ) extern int _fmode;
#endif
#else
#define _pgmptr (*__p__pgmptr ())
#define _wpgmptr (*__p__wpgmptr())
#define _fmode (*__p__fmode ()) #endif
_Success_(return == 0)
_Success_(return == 0)
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
// Math
//
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
typedef
struct
_div_t
{
int
quot
;
int
rem
; }
div_t
;
typedef
struct
_ldiv_t
{
long
quot
;
long
rem
; }
ldiv_t
;
typedef
struct
_lldiv_t
{
long
long
quot
;
long
long
rem
; }
lldiv_t
;
// These functions have declspecs in their declarations in the Windows headers,
// which cause PREfast to fire 6540.
#pragma warning (push) #pragma warning (disable:
6540
)
unsigned
int
__cdecl
_rotl
( );
_Check_return_
unsigned
long
__cdecl
_lrotl
( );
unsigned
__int64
__cdecl
_rotl64
( );
unsigned
int
__cdecl
_rotr
( );
_Check_return_
unsigned
long
__cdecl
_lrotr
( );
unsigned
__int64
__cdecl
_rotr64
( ); #pragma warning (pop)
// Maximum value that can be returned by the rand function:
#define RAND_MAX 0x7fff
#if defined _CRT_RAND_S || defined _CRTBLD
_ACRTIMP errno_t __cdecl rand_s(_Out_ unsigned int* _RandomValue); #endif
#ifdef __cplusplus
extern
"C++"
{
inline
long
abs
(
long
const
_X
)
throw
() {
return
labs
(
_X
); }
inline
long
long
abs
(
long
long
const
_X
)
throw
() {
return
llabs
(
_X
); }
inline
ldiv_t
div
(
long
const
_A1
,
long
const
_A2
)
throw
() {
return
ldiv
(
_A1
,
_A2
); }
inline
lldiv_t
div
(
long
long
const
_A1
,
long
long
const
_A2
)
throw
() {
return
lldiv
(
_A1
,
_A2
); } }
#endif // __cplusplus
// Structs used to fool the compiler into not generating floating point
// instructions when copying and pushing [long] double values
#define _CRT_DOUBLE_DEC
#ifndef _LDSUPPORT
typedef
struct
{
unsigned
char
ld
[
10
]; }
_LDOUBLE
;
#define _PTR_LD(x) ((unsigned char*)(&(x)->ld))
#else // _LDSUPPORT
// push and pop long, which is #defined as __int64 by a spec2k test
#pragma push_macro("long")
#undef long
typedef long double _LDOUBLE;
#pragma pop_macro("long")
#define _PTR_LD(x) ((unsigned char *)(x))
#endif // _LDSUPPORT
typedef
struct
{
double
x
; }
_CRT_DOUBLE
;
typedef
struct
{
float
f
; }
_CRT_FLOAT
;
// push and pop long, which is #defined as __int64 by a spec2k test
#pragma push_macro("long")
#undef long
typedef
struct
{
long
double
x
; }
_LONGDOUBLE
;
#pragma pop_macro("long")
#pragma pack(push,
4
)
typedef
struct
{
unsigned
char
ld12
[
12
]; }
_LDBL12
; #pragma pack(pop)
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
// Narrow String to Number Conversions
//
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
_Check_return_
);
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
// Number to Narrow String Conversions
//
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
_Success_(return == 0)
_Check_return_opt_
); #pragma warning(push) #pragma warning(pop)
_Success_(return == 0)
_Check_return_opt_
);
_Success_(return == 0)
_Check_return_opt_
); #pragma warning(push) #pragma warning(pop)
_Success_(return == 0)
_Check_return_opt_
);
_Success_(return == 0)
);
_Success_(return == 0)
_Check_return_opt_
); );
// _CVTBUFSIZE is the maximum size for the per-thread conversion buffer. It
// should be at least as long as the number of digits in the largest double
// precision value (?.?e308 in IEEE arithmetic). We will use the same size
// buffer as is used in the printf support routines.
//
// (This value actually allows 40 additional decimal places; even though there
// are only 16 digits of accuracy in a double precision IEEE number, the user may
// ask for more to effect zero padding.)
#define _CVTBUFSIZE (309 + 40) // # of digits in max. dp value + slop
_Success_(return == 0)
_Check_return_wat_
); );
_Success_(return == 0)
_Check_return_wat_
);
_Success_(return == 0)
);
_Success_(return == 0)
); );
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
// Multibyte String Operations and Conversions
//
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Maximum number of bytes in multi-byte character in the current locale
// (also defined in ctype.h).
#ifndef MB_CUR_MAX
#if defined _CRT_DISABLE_PERFCRIT_LOCKS && !defined _DLL
#define MB_CUR_MAX __mb_cur_max #else
#define MB_CUR_MAX ___mb_cur_max_func() #endif
#ifdef _CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY
extern int __mb_cur_max;
#else
#define __mb_cur_max (___mb_cur_max_func()) #endif
_Post_satisfies_(return > 0 && return < MB_LEN_MAX)
_Post_satisfies_(return > 0 && return < MB_LEN_MAX)
_Check_return_
);
_Check_return_
);
_Check_return_
_Post_satisfies_(return <= _String_length_(_String))
);
_Check_return_
_Post_satisfies_(return <= _String_length_(_String) || return == (size_t)-1)
);
_Check_return_
_Post_satisfies_((return <= _String_length_(_String) && return <= _MaxCount) || return == (size_t)-1)
);
_Post_satisfies_((return <= _String_length_(_String) && return <= _MaxCount) || return == (size_t)-1)
_Check_return_
);
_Success_(return != -1)
);
_Success_(return != -1)
);
_Check_return_opt_
);
_Check_return_opt_
); ); );
#if __STDC_WANT_SECURE_LIB__
_Check_return_wat_
);
#endif // __STDC_WANT_SECURE_LIB__
_Check_return_wat_
_Check_return_wat_
);
_Check_return_wat_
);
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
// Path Manipulation
//
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Sizes for buffers used by the _makepath() and _splitpath() functions.
// note that the sizes include space for 0-terminator
#define _MAX_PATH 260 // max. length of full pathname
#define _MAX_DRIVE 3 // max. length of drive component
#define _MAX_DIR 256 // max. length of path component
#define _MAX_FNAME 256 // max. length of file name component
#define _MAX_EXT 256 // max. length of extension component
#pragma push_macro("_fullpath")
#undef _fullpath
_Success_(return != 0)
_Check_return_
);
#pragma pop_macro("_fullpath")
_Check_return_wat_
); #pragma warning(push) #pragma warning(pop) );
_Check_return_wat_
);
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_
_Success_(return == 0)
);
#endif // __STDC_WANT_SECURE_LIB__
#ifdef _CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY
extern int __argc;
extern char** __argv;
extern wchar_t** __wargv;
#else
#define __argc (*__p___argc()) // Pointer to number of command line arguments
#define __argv (*__p___argv()) // Pointer to table of narrow command line arguments
#define __wargv (*__p___wargv()) // Pointer to table of wide command line arguments #endif
#ifndef _CRT_BEST_PRACTICES_USAGE
#define _CRT_V12_LEGACY_FUNCTIONALITY #endif
#ifndef _CRT_V12_LEGACY_FUNCTIONALITY
// Deprecated symbol: Do not expose environment global pointers unless
// legacy access is specifically requested
#define _environ crt_usage_error__do_not_reference_global_pointer_directly__environ
#define _wenviron crt_usage_error__do_not_reference_global_pointer_directly__wenviron
#else
#define _environ (*__p__environ()) // Pointer to narrow environment table
#define _wenviron (*__p__wenviron()) // Pointer to wide environment table #endif
// Sizes for buffers used by the getenv/putenv family of functions.
#define _MAX_ENV 32767
#if _CRT_FUNCTIONS_REQUIRED
);
#if defined (_DEBUG) && defined (_CRTDBG_MAP_ALLOC)
#pragma push_macro("_dupenv_s")
#undef _dupenv_s #endif
_Check_return_opt_
);
#if defined (_DEBUG) && defined (_CRTDBG_MAP_ALLOC)
#pragma pop_macro("_dupenv_s") #endif
);
// The functions below have declspecs in their declarations in the Windows
// headers, causing PREfast to fire 6540 here
_Check_return_
);
_Check_return_wat_
); );
// The Win32 API SetErrorMode, Beep and Sleep should be used instead.
); ); );
#endif // _CRT_FUNCTIONS_REQUIRED
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
// Non-ANSI Names for Compatibility
//
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#if _CRT_INTERNAL_NONSTDC_NAMES
#ifndef __cplusplus
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#define sys_errlist _sys_errlist
#define sys_nerr _sys_nerr
); ); ); ); ); ); );
#define environ _environ
);
#endif // _CRT_INTERNAL_NONSTDC_NAMES