Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

434 lines
13 KiB

  1. /***
  2. *stdlib.h - declarations/definitions for commonly used library functions
  3. *
  4. * Copyright (c) 1985-2001, 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. #if _MSC_VER > 1000
  16. #pragma once
  17. #endif
  18. #ifndef _INC_STDLIB
  19. #define _INC_STDLIB
  20. #if !defined(_WIN32)
  21. #error ERROR: Only Win32 target supported!
  22. #endif
  23. #ifdef _MSC_VER
  24. /*
  25. * Currently, all MS C compilers for Win32 platforms default to 8 byte
  26. * alignment.
  27. */
  28. #pragma pack(push,8)
  29. #endif /* _MSC_VER */
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. #if !defined(_W64)
  34. #if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
  35. #define _W64 __w64
  36. #else
  37. #define _W64
  38. #endif
  39. #endif
  40. /* Define _CRTIMP */
  41. #ifndef _CRTIMP
  42. #ifdef _DLL
  43. #define _CRTIMP __declspec(dllimport)
  44. #else /* ndef _DLL */
  45. #define _CRTIMP
  46. #endif /* _DLL */
  47. #endif /* _CRTIMP */
  48. /* Define _CRTNOALIAS, _CRTRESTRICT */
  49. #if _MSC_FULL_VER >= 14002050
  50. #ifndef _CRTNOALIAS
  51. #define _CRTNOALIAS __declspec(noalias)
  52. #endif /* _CRTNOALIAS */
  53. #ifndef _CRTRESTRICT
  54. #define _CRTRESTRICT __declspec(restrict)
  55. #endif /* _CRTRESTRICT */
  56. #else
  57. #ifndef _CRTNOALIAS
  58. #define _CRTNOALIAS
  59. #endif /* _CRTNOALIAS */
  60. #ifndef _CRTRESTRICT
  61. #define _CRTRESTRICT
  62. #endif /* _CRTRESTRICT */
  63. #endif
  64. /* Define __cdecl for non-Microsoft compilers */
  65. #if ( !defined(_MSC_VER) && !defined(__cdecl) )
  66. #define __cdecl
  67. #endif
  68. #ifndef _SIZE_T_DEFINED
  69. #ifdef _WIN64
  70. typedef unsigned __int64 size_t;
  71. #else
  72. typedef _W64 unsigned int size_t;
  73. #endif
  74. #define _SIZE_T_DEFINED
  75. #endif
  76. #if !defined(_WCHAR_T_DEFINED) && !defined(_NATIVE_WCHAR_T_DEFINED)
  77. typedef unsigned short wchar_t;
  78. #define _WCHAR_T_DEFINED
  79. #endif
  80. /* Define NULL pointer value */
  81. #ifndef NULL
  82. #ifdef __cplusplus
  83. #define NULL 0
  84. #else
  85. #define NULL ((void *)0)
  86. #endif
  87. #endif
  88. /* Definition of the argument values for the exit() function */
  89. #define EXIT_SUCCESS 0
  90. #define EXIT_FAILURE 1
  91. #ifndef _ONEXIT_T_DEFINED
  92. typedef int (__cdecl * _onexit_t)(void);
  93. #if !__STDC__
  94. /* Non-ANSI name for compatibility */
  95. #define onexit_t _onexit_t
  96. #endif
  97. #define _ONEXIT_T_DEFINED
  98. #endif
  99. /* Data structure definitions for div and ldiv runtimes. */
  100. #ifndef _DIV_T_DEFINED
  101. typedef struct _div_t {
  102. int quot;
  103. int rem;
  104. } div_t;
  105. typedef struct _ldiv_t {
  106. long quot;
  107. long rem;
  108. } ldiv_t;
  109. #define _DIV_T_DEFINED
  110. #endif
  111. /* Maximum value that can be returned by the rand function. */
  112. #define RAND_MAX 0x7fff
  113. /*
  114. * Maximum number of bytes in multi-byte character in the current locale
  115. * (also defined in ctype.h).
  116. */
  117. #ifndef MB_CUR_MAX
  118. #ifdef _MT
  119. #define MB_CUR_MAX ___mb_cur_max_func()
  120. #else
  121. #define MB_CUR_MAX __mb_cur_max
  122. #endif
  123. _CRTIMP extern int __mb_cur_max;
  124. _CRTIMP int __cdecl ___mb_cur_max_func(void);
  125. #endif /* MB_CUR_MAX */
  126. /* Minimum and maximum macros */
  127. #define __max(a,b) (((a) > (b)) ? (a) : (b))
  128. #define __min(a,b) (((a) < (b)) ? (a) : (b))
  129. /*
  130. * Sizes for buffers used by the _makepath() and _splitpath() functions.
  131. * note that the sizes include space for 0-terminator
  132. */
  133. #define _MAX_PATH 260 /* max. length of full pathname */
  134. #define _MAX_DRIVE 3 /* max. length of drive component */
  135. #define _MAX_DIR 256 /* max. length of path component */
  136. #define _MAX_FNAME 256 /* max. length of file name component */
  137. #define _MAX_EXT 256 /* max. length of extension component */
  138. /*
  139. * Argument values for _set_error_mode().
  140. */
  141. #define _OUT_TO_DEFAULT 0
  142. #define _OUT_TO_STDERR 1
  143. #define _OUT_TO_MSGBOX 2
  144. #define _REPORT_ERRMODE 3
  145. #if defined(_M_IX86)
  146. /*
  147. * Typedefs and argument values for _set_security_error_handler()
  148. */
  149. #define _SECERR_BUFFER_OVERRUN 1 /* void* arg ignored */
  150. typedef void (__cdecl * _secerr_handler_func)(int, void *);
  151. #endif
  152. /* External variable declarations */
  153. #if defined(_MT) || defined(_DLL)
  154. _CRTIMP int * __cdecl _errno(void);
  155. _CRTIMP unsigned long * __cdecl __doserrno(void);
  156. #define errno (*_errno())
  157. #define _doserrno (*__doserrno())
  158. #else /* ndef _MT && ndef _DLL */
  159. _CRTIMP extern int errno; /* XENIX style error number */
  160. _CRTIMP extern unsigned long _doserrno; /* OS system error value */
  161. #endif /* _MT || _DLL */
  162. _CRTIMP extern char * _sys_errlist[]; /* perror error message table */
  163. _CRTIMP extern int _sys_nerr; /* # of entries in sys_errlist table */
  164. _CRTIMP extern int __argc; /* count of cmd line args */
  165. _CRTIMP extern char ** __argv; /* pointer to table of cmd line args */
  166. _CRTIMP extern wchar_t ** __wargv; /* pointer to table of wide cmd line args */
  167. #ifdef _POSIX_
  168. extern char ** environ; /* pointer to environment table */
  169. #else
  170. _CRTIMP extern char ** _environ; /* pointer to environment table */
  171. _CRTIMP extern wchar_t ** _wenviron; /* pointer to wide environment table */
  172. #endif /* _POSIX_ */
  173. _CRTIMP extern char * _pgmptr; /* points to the module (EXE) name */
  174. _CRTIMP extern wchar_t * _wpgmptr; /* points to the module (EXE) wide name */
  175. _CRTIMP extern int _fmode; /* default file translation mode */
  176. _CRTIMP extern int _fileinfo; /* open file info mode (for spawn) */
  177. /* Windows major/minor and O.S. version numbers */
  178. _CRTIMP extern unsigned int _osplatform;
  179. _CRTIMP extern unsigned int _osver;
  180. _CRTIMP extern unsigned int _winver;
  181. _CRTIMP extern unsigned int _winmajor;
  182. _CRTIMP extern unsigned int _winminor;
  183. /* function prototypes */
  184. #if _MSC_VER >= 1200
  185. _CRTIMP __declspec(noreturn) void __cdecl abort(void);
  186. _CRTIMP __declspec(noreturn) void __cdecl exit(int);
  187. #else
  188. _CRTIMP void __cdecl abort(void);
  189. _CRTIMP void __cdecl exit(int);
  190. #endif
  191. int __cdecl abs(int);
  192. __int64 __cdecl _abs64(__int64);
  193. int __cdecl atexit(void (__cdecl *)(void));
  194. _CRTIMP double __cdecl atof(const char *);
  195. _CRTIMP int __cdecl atoi(const char *);
  196. _CRTIMP long __cdecl atol(const char *);
  197. _CRTIMP void * __cdecl bsearch(const void *, const void *, size_t, size_t,
  198. int (__cdecl *)(const void *, const void *));
  199. unsigned short __cdecl _byteswap_ushort(unsigned short);
  200. unsigned long __cdecl _byteswap_ulong (unsigned long);
  201. unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64);
  202. _CRTIMP _CRTNOALIAS _CRTRESTRICT void * __cdecl calloc(size_t, size_t);
  203. _CRTIMP div_t __cdecl div(int, int);
  204. _CRTIMP _CRTNOALIAS void __cdecl free(void *);
  205. _CRTIMP char * __cdecl getenv(const char *);
  206. _CRTIMP char * __cdecl _itoa(int, char *, int);
  207. #if _INTEGRAL_MAX_BITS >= 64
  208. _CRTIMP char * __cdecl _i64toa(__int64, char *, int);
  209. _CRTIMP char * __cdecl _ui64toa(unsigned __int64, char *, int);
  210. _CRTIMP __int64 __cdecl _atoi64(const char *);
  211. _CRTIMP __int64 __cdecl _strtoi64(const char *, char **, int);
  212. _CRTIMP unsigned __int64 __cdecl _strtoui64(const char *, char **, int);
  213. #endif
  214. long __cdecl labs(long);
  215. _CRTIMP ldiv_t __cdecl ldiv(long, long);
  216. _CRTIMP char * __cdecl _ltoa(long, char *, int);
  217. _CRTIMP _CRTNOALIAS _CRTRESTRICT void * __cdecl malloc(size_t);
  218. _CRTIMP int __cdecl mblen(const char *, size_t);
  219. _CRTIMP size_t __cdecl _mbstrlen(const char *s);
  220. _CRTIMP int __cdecl mbtowc(wchar_t *, const char *, size_t);
  221. _CRTIMP size_t __cdecl mbstowcs(wchar_t *, const char *, size_t);
  222. _CRTIMP void __cdecl qsort(void *, size_t, size_t, int (__cdecl *)
  223. (const void *, const void *));
  224. _CRTIMP int __cdecl rand(void);
  225. _CRTIMP _CRTNOALIAS _CRTRESTRICT void * __cdecl realloc(void *, size_t);
  226. _CRTIMP int __cdecl _set_error_mode(int);
  227. #if defined(_M_IX86)
  228. _CRTIMP _secerr_handler_func
  229. __cdecl _set_security_error_handler(_secerr_handler_func);
  230. #endif
  231. _CRTIMP void __cdecl srand(unsigned int);
  232. _CRTIMP double __cdecl strtod(const char *, char **);
  233. _CRTIMP long __cdecl strtol(const char *, char **, int);
  234. _CRTIMP unsigned long __cdecl strtoul(const char *, char **, int);
  235. _CRTIMP int __cdecl system(const char *);
  236. _CRTIMP char * __cdecl _ultoa(unsigned long, char *, int);
  237. _CRTIMP int __cdecl wctomb(char *, wchar_t);
  238. _CRTIMP size_t __cdecl wcstombs(char *, const wchar_t *, size_t);
  239. #ifndef _WSTDLIB_DEFINED
  240. /* wide function prototypes, also declared in wchar.h */
  241. _CRTIMP wchar_t * __cdecl _itow (int, wchar_t *, int);
  242. _CRTIMP wchar_t * __cdecl _ltow (long, wchar_t *, int);
  243. _CRTIMP wchar_t * __cdecl _ultow (unsigned long, wchar_t *, int);
  244. _CRTIMP double __cdecl wcstod(const wchar_t *, wchar_t **);
  245. _CRTIMP long __cdecl wcstol(const wchar_t *, wchar_t **, int);
  246. _CRTIMP unsigned long __cdecl wcstoul(const wchar_t *, wchar_t **, int);
  247. _CRTIMP wchar_t * __cdecl _wgetenv(const wchar_t *);
  248. _CRTIMP int __cdecl _wsystem(const wchar_t *);
  249. _CRTIMP double __cdecl _wtof(const wchar_t *);
  250. _CRTIMP int __cdecl _wtoi(const wchar_t *);
  251. _CRTIMP long __cdecl _wtol(const wchar_t *);
  252. #if _INTEGRAL_MAX_BITS >= 64
  253. _CRTIMP wchar_t * __cdecl _i64tow(__int64, wchar_t *, int);
  254. _CRTIMP wchar_t * __cdecl _ui64tow(unsigned __int64, wchar_t *, int);
  255. _CRTIMP __int64 __cdecl _wtoi64(const wchar_t *);
  256. _CRTIMP __int64 __cdecl _wcstoi64(const wchar_t *, wchar_t **, int);
  257. _CRTIMP unsigned __int64 __cdecl _wcstoui64(const wchar_t *, wchar_t **, int);
  258. #endif
  259. #define _WSTDLIB_DEFINED
  260. #endif
  261. #ifndef _POSIX_
  262. _CRTIMP char * __cdecl _ecvt(double, int, int *, int *);
  263. #if _MSC_VER >= 1200
  264. _CRTIMP __declspec(noreturn) void __cdecl _exit(int);
  265. #else
  266. _CRTIMP void __cdecl _exit(int);
  267. #endif
  268. _CRTIMP char * __cdecl _fcvt(double, int, int *, int *);
  269. _CRTIMP char * __cdecl _fullpath(char *, const char *, size_t);
  270. _CRTIMP char * __cdecl _gcvt(double, int, char *);
  271. unsigned long __cdecl _lrotl(unsigned long, int);
  272. unsigned long __cdecl _lrotr(unsigned long, int);
  273. _CRTIMP void __cdecl _makepath(char *, const char *, const char *, const char *,
  274. const char *);
  275. _onexit_t __cdecl _onexit(_onexit_t);
  276. _CRTIMP void __cdecl perror(const char *);
  277. _CRTIMP int __cdecl _putenv(const char *);
  278. unsigned int __cdecl _rotl(unsigned int, int);
  279. unsigned __int64 __cdecl _rotl64(unsigned __int64, int);
  280. unsigned int __cdecl _rotr(unsigned int, int);
  281. unsigned __int64 __cdecl _rotr64(unsigned __int64, int);
  282. _CRTIMP void __cdecl _searchenv(const char *, const char *, char *);
  283. _CRTIMP void __cdecl _splitpath(const char *, char *, char *, char *, char *);
  284. _CRTIMP void __cdecl _swab(char *, char *, int);
  285. #ifndef _WSTDLIBP_DEFINED
  286. /* wide function prototypes, also declared in wchar.h */
  287. _CRTIMP wchar_t * __cdecl _wfullpath(wchar_t *, const wchar_t *, size_t);
  288. _CRTIMP void __cdecl _wmakepath(wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *,
  289. const wchar_t *);
  290. _CRTIMP void __cdecl _wperror(const wchar_t *);
  291. _CRTIMP int __cdecl _wputenv(const wchar_t *);
  292. _CRTIMP void __cdecl _wsearchenv(const wchar_t *, const wchar_t *, wchar_t *);
  293. _CRTIMP void __cdecl _wsplitpath(const wchar_t *, wchar_t *, wchar_t *, wchar_t *, wchar_t *);
  294. #define _WSTDLIBP_DEFINED
  295. #endif
  296. /* --------- The following functions are OBSOLETE --------- */
  297. /* The Win32 API SetErrorMode, Beep and Sleep should be used instead. */
  298. _CRTIMP void __cdecl _seterrormode(int);
  299. _CRTIMP void __cdecl _beep(unsigned, unsigned);
  300. _CRTIMP void __cdecl _sleep(unsigned long);
  301. /* --------- The preceding functions are OBSOLETE --------- */
  302. #endif /* _POSIX_ */
  303. #if !__STDC__
  304. /* --------- The declarations below should not be in stdlib.h --------- */
  305. /* --------- and will be removed in a future release. Include --------- */
  306. /* --------- ctype.h to obtain these declarations. --------- */
  307. #ifndef tolower /* tolower has been undefined - use function */
  308. _CRTIMP int __cdecl tolower(int);
  309. #endif /* tolower */
  310. #ifndef toupper /* toupper has been undefined - use function */
  311. _CRTIMP int __cdecl toupper(int);
  312. #endif /* toupper */
  313. /* --------- The declarations above will be removed. --------- */
  314. #endif
  315. #if !__STDC__
  316. #ifndef _POSIX_
  317. /* Non-ANSI names for compatibility */
  318. #ifndef __cplusplus
  319. #define max(a,b) (((a) > (b)) ? (a) : (b))
  320. #define min(a,b) (((a) < (b)) ? (a) : (b))
  321. #endif
  322. #define sys_errlist _sys_errlist
  323. #define sys_nerr _sys_nerr
  324. #define environ _environ
  325. _CRTIMP char * __cdecl ecvt(double, int, int *, int *);
  326. _CRTIMP char * __cdecl fcvt(double, int, int *, int *);
  327. _CRTIMP char * __cdecl gcvt(double, int, char *);
  328. _CRTIMP char * __cdecl itoa(int, char *, int);
  329. _CRTIMP char * __cdecl ltoa(long, char *, int);
  330. onexit_t __cdecl onexit(onexit_t);
  331. _CRTIMP int __cdecl putenv(const char *);
  332. _CRTIMP void __cdecl swab(char *, char *, int);
  333. _CRTIMP char * __cdecl ultoa(unsigned long, char *, int);
  334. #endif /* _POSIX_ */
  335. #endif /* __STDC__ */
  336. #ifdef __cplusplus
  337. }
  338. #endif
  339. #ifdef _MSC_VER
  340. #pragma pack(pop)
  341. #endif /* _MSC_VER */
  342. #endif /* _INC_STDLIB */