1 /***
2 *stdlib.h - declarations/definitions for commonly used library functions
3 *
4 *           Copyright (c) Microsoft Corporation. All rights reserved.
5 *
6 *Purpose:
7 *           This include file contains the function declarations for commonly
8 *           used library functions which either don't fit somewhere else, or,
9 *           cannot be declared in the normal place for other reasons.
10 *           [ANSI]
11 *
12 *           [Public]
13 *
14 ****/
15
16 #if        _MSC_VER > 1000
17 #pragma once
18 #endif
19
20 #ifndef _INC_STDLIB
21 #define _INC_STDLIB
22
23 #include <crtdefs.h>
24 #include <limits.h>
25
26 #ifdef  _MSC_VER
27 /*
28  * Currently, all MS C compilers for Win32 platforms default to 8 byte
29  * alignment.
30  */
31 #pragma pack(push,_CRT_PACKING)
32 #endif  /* _MSC_VER */
33
34 #ifdef  __cplusplus
35 extern "C" {
36 #endif
37
38 /* Define NULL pointer value */
39 #ifndef NULL
40 #ifdef __cplusplus
41 #define NULL      0
42 #else
43 #define NULL      ((void *)0)
44 #endif
45 #endif
46
47 /* Definition of the argument values for the exit() function */
48
49 #define EXIT_SUCCESS      0
50 #define EXIT_FAILURE      1
51
52
53 #ifndef _ONEXIT_T_DEFINED
54
55 #if !defined (_M_CEE_PURE)
56 typedef int (__cdecl * _onexit_t)(void);
57 #else
58 typedef int (__clrcall * _onexit_t)(void);
59 typedef _onexit_t _onexit_m_t;
60 #endif
61
62 #if defined (_M_CEE_MIXED)
63 typedef int (__clrcall * _onexit_m_t)(void);
64 #endif
65
66 #if        !__STDC__
67 /* Non-ANSI name for compatibility */
68 #define onexit_t _onexit_t
69 #endif
70
71 #define _ONEXIT_T_DEFINED
72 #endif
73
74
75 /* Data structure definitions for div and ldiv runtimes. */
76
77 #ifndef _DIV_T_DEFINED
78
79 typedef struct _div_t {
80              int quot;
81              int rem;
82 } div_t;
83
84 typedef struct _ldiv_t {
85              long quot;
86              long rem;
87 } ldiv_t;
88
89 #define _DIV_T_DEFINED
90 #endif
91
92 /*
93  * structs used to fool the compiler into not generating floating point
Lines 94 ... 799 are skipped.
800 #if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
801 #pragma push_macro("_wfullpath")
802 #undef _wfullpath
803 #endif
804
805 _Check_return_ _CRTIMP wchar_t * __cdecl _wfullpath(_Out_opt_z_cap_(_SizeInWords) wchar_t * _FullPath, _In_z_ const wchar_t * _Path, _In_ size_t _SizeInWords);
806
807 #if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
808 #pragma pop_macro("_wfullpath")
809 #endif
810
811 _Check_return_wat_ _CRTIMP_ALTERNATIVE errno_t __cdecl _wmakepath_s(_Out_z_cap_(_SIZE) wchar_t * _PathResult, _In_ size_t _SIZE, _In_opt_z_ const wchar_t * _Drive, _In_opt_z_ const wchar_t * _Dir, _In_opt_z_ const wchar_t * _Filename,
812              _In_opt_z_ const wchar_t * _Ext);             
813 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_4(errno_t, _wmakepath_s, wchar_t, _ResultPath, _In_opt_z_ const wchar_t *, _Drive, _In_opt_z_ const wchar_t *, _Dir, _In_opt_z_ const wchar_t *, _Filename, _In_opt_z_ const wchar_t *, _Ext)
814 __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_4(void, __RETURN_POLICY_VOID, _CRTIMP, _wmakepath, _Pre_notnull_ _Post_z_, wchar_t, _ResultPath, _In_opt_z_ const wchar_t *, _Drive, _In_opt_z_ const wchar_t *, _Dir, _In_opt_z_ const wchar_t *, _Filename, _In_opt_z_ const wchar_t *, _Ext)
815 #ifndef _CRT_WPERROR_DEFINED
816 #define _CRT_WPERROR_DEFINED
817 _CRTIMP void __cdecl _wperror(_In_opt_z_ const wchar_t * _ErrMsg);
818 #endif 
819 _Check_return_ _CRTIMP int      __cdecl _wputenv(_In_z_ const wchar_t * _EnvString);
820 _Check_return_wat_ _CRTIMP errno_t __cdecl _wputenv_s(_In_z_ const wchar_t * _Name, _In_z_ const wchar_t * _Value);
821 _CRTIMP errno_t __cdecl _wsearchenv_s(_In_z_ const wchar_t * _Filename, _In_z_ const wchar_t * _EnvVar, _Out_z_cap_(_SizeInWords) wchar_t * _ResultPath, _In_ size_t _SizeInWords);
822 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_2_0(errno_t, _wsearchenv_s, _In_z_ const wchar_t *, _Filename, _In_z_ const wchar_t *, _EnvVar, wchar_t, _ResultPath)
823 __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_2_0(void, __RETURN_POLICY_VOID, _CRTIMP, _wsearchenv, _In_z_ const wchar_t *, _Filename, _In_z_ const wchar_t *, _EnvVar, _Pre_notnull_ _Post_z_, wchar_t, _ResultPath)
824 _CRT_INSECURE_DEPRECATE(_wsplitpath_s) _CRTIMP void     __cdecl _wsplitpath(_In_z_ const wchar_t * _FullPath, _Pre_maybenull_ _Post_z_ wchar_t * _Drive, _Pre_maybenull_ _Post_z_ wchar_t * _Dir, _Pre_maybenull_ _Post_z_ wchar_t * _Filename, _Pre_maybenull_ _Post_z_ wchar_t * _Ext);
825 _CRTIMP_ALTERNATIVE errno_t __cdecl _wsplitpath_s(_In_z_ const wchar_t * _FullPath, 
826         _Out_opt_z_cap_(_DriveSize) wchar_t * _Drive, _In_ size_t _DriveSize, 
827         _Out_opt_z_cap_(_DirSize) wchar_t * _Dir, _In_ size_t _DirSize, 
828         _Out_opt_z_cap_(_FilenameSize) wchar_t * _Filename, _In_ size_t _FilenameSize, 
829         _Out_opt_z_cap_(_ExtSize) wchar_t * _Ext, _In_ size_t _ExtSize);
830 __DEFINE_CPP_OVERLOAD_SECURE_FUNC_SPLITPATH(errno_t, _wsplitpath_s, wchar_t, _Path)
831
832 #define _WSTDLIBP_DEFINED
833 #endif
834
835 /* The Win32 API SetErrorMode, Beep and Sleep should be used instead. */
836 _CRT_OBSOLETE(SetErrorMode) _CRTIMP void __cdecl _seterrormode(_In_ int _Mode);
837 _CRT_OBSOLETE(Beep) _CRTIMP void __cdecl _beep(_In_ unsigned _Frequency, _In_ unsigned _Duration);
838 _CRT_OBSOLETE(Sleep) _CRTIMP void __cdecl _sleep(_In_ unsigned long _Duration);
839
840 #endif  /* _POSIX_ */
841
842 #if        !__STDC__
843
844 #ifndef _POSIX_
845
846 /* Non-ANSI names for compatibility */
847
848 #ifndef __cplusplus
849 #define max(a,b)      (((a) > (b)) ? (a) : (b))
850 #define min(a,b)      (((a) < (b)) ? (a) : (b))
851 #endif
852
853 #define sys_errlist _sys_errlist
854 #define sys_nerr      _sys_nerr
855 #define environ        _environ
856
857 #pragma warning(push)
858 #pragma warning(disable: 4141) /* Using deprecated twice */ 
859 _Check_return_ _CRT_NONSTDC_DEPRECATE(_ecvt) _CRT_INSECURE_DEPRECATE(_ecvt_s) _CRTIMP char * __cdecl ecvt(_In_ double _Val, _In_ int _NumOfDigits, _Out_ int * _PtDec, _Out_ int * _PtSign);
860 _Check_return_ _CRT_NONSTDC_DEPRECATE(_fcvt) _CRT_INSECURE_DEPRECATE(_fcvt_s) _CRTIMP char * __cdecl fcvt(_In_ double _Val, _In_ int _NumOfDec, _Out_ int * _PtDec, _Out_ int * _PtSign);
861 _CRT_NONSTDC_DEPRECATE(_gcvt) _CRT_INSECURE_DEPRECATE(_fcvt_s)        _CRTIMP char * __cdecl gcvt(_In_ double _Val, _In_ int _NumOfDigits, _Pre_notnull_ _Post_z_ char * _DstBuf);
862 _CRT_NONSTDC_DEPRECATE(_itoa) _CRT_INSECURE_DEPRECATE(_itoa_s)        _CRTIMP char * __cdecl itoa(_In_ int _Val, _Pre_notnull_ _Post_z_ char * _DstBuf, _In_ int _Radix);
863 _CRT_NONSTDC_DEPRECATE(_ltoa) _CRT_INSECURE_DEPRECATE(_ltoa_s)        _CRTIMP char * __cdecl ltoa(_In_ long _Val, _Pre_notnull_ _Post_z_ char * _DstBuf, _In_ int _Radix);
864 _Check_return_ _CRT_NONSTDC_DEPRECATE(_putenv) _CRTIMP int      __cdecl putenv(_In_z_ const char * _EnvString);
865 _CRT_NONSTDC_DEPRECATE(_swab)                                        _CRTIMP void     __cdecl swab(_Inout_z_bytecap_(_SizeInBytes) char * _Buf1,_Inout_z_bytecap_(_SizeInBytes) char * _Buf2, _In_ int _SizeInBytes);
866 _CRT_NONSTDC_DEPRECATE(_ultoa) _CRT_INSECURE_DEPRECATE(_ultoa_s)    _CRTIMP char * __cdecl ultoa(_In_ unsigned long _Val, _Pre_notnull_ _Post_z_ char * _Dstbuf, _In_ int _Radix);
867 #pragma warning(pop)
868 onexit_t __cdecl onexit(_In_opt_ onexit_t _Func);
869
870 #endif  /* _POSIX_ */
871
872 #endif  /* __STDC__ */
873
874 #ifdef  __cplusplus
875 }
876
877 #endif
878
879 #ifdef  _MSC_VER
880 #pragma pack(pop)
881 #endif  /* _MSC_VER */
882
883 #endif  /* _INC_STDLIB */
884