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.

462 lines
14 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. #ifndef _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. #if defined(_DLL) && defined(_M_IX86)
  165. #define __argc (*__p___argc()) /* count of cmd line args */
  166. #define __argv (*__p___argv()) /* pointer to table of cmd line args */
  167. #define __wargv (*__p___wargv()) /* pointer to table of wide cmd line args */
  168. #define _environ (*__p__environ()) /* pointer to environment table */
  169. #ifdef _POSIX_
  170. extern char ** environ; /* pointer to environment table */
  171. #else
  172. #define _wenviron (*__p__wenviron()) /* pointer to wide environment table */
  173. #endif /* _POSIX_ */
  174. #define _pgmptr (*__p__pgmptr()) /* points to the module (EXE) name */
  175. #define _wpgmptr (*__p__wpgmptr()) /* points to the module (EXE) wide name */
  176. _CRTIMP int * __cdecl __p___argc(void);
  177. _CRTIMP char *** __cdecl __p___argv(void);
  178. _CRTIMP wchar_t *** __cdecl __p___wargv(void);
  179. _CRTIMP char *** __cdecl __p__environ(void);
  180. _CRTIMP wchar_t *** __cdecl __p__wenviron(void);
  181. _CRTIMP char ** __cdecl __p__pgmptr(void);
  182. _CRTIMP wchar_t ** __cdecl __p__wpgmptr(void);
  183. #else
  184. _CRTIMP extern int __argc; /* count of cmd line args */
  185. _CRTIMP extern char ** __argv; /* pointer to table of cmd line args */
  186. _CRTIMP extern wchar_t ** __wargv; /* pointer to table of wide cmd line args */
  187. #ifdef _POSIX_
  188. extern char ** environ; /* pointer to environment table */
  189. #else
  190. _CRTIMP extern char ** _environ; /* pointer to environment table */
  191. _CRTIMP extern wchar_t ** _wenviron; /* pointer to wide environment table */
  192. #endif /* _POSIX_ */
  193. _CRTIMP extern char * _pgmptr; /* points to the module (EXE) name */
  194. _CRTIMP extern wchar_t * _wpgmptr; /* points to the module (EXE) wide name */
  195. #endif
  196. _CRTIMP extern int _fmode; /* default file translation mode */
  197. _CRTIMP extern int _fileinfo; /* open file info mode (for spawn) */
  198. /* Windows major/minor and O.S. version numbers */
  199. _CRTIMP extern unsigned int _osplatform;
  200. _CRTIMP extern unsigned int _osver;
  201. _CRTIMP extern unsigned int _winver;
  202. _CRTIMP extern unsigned int _winmajor;
  203. _CRTIMP extern unsigned int _winminor;
  204. /* function prototypes */
  205. #if _MSC_VER >= 1200
  206. _CRTIMP __declspec(noreturn) void __cdecl abort(void);
  207. _CRTIMP __declspec(noreturn) void __cdecl exit(int);
  208. #else
  209. _CRTIMP void __cdecl abort(void);
  210. _CRTIMP void __cdecl exit(int);
  211. #endif
  212. int __cdecl abs(int);
  213. __int64 __cdecl _abs64(__int64);
  214. int __cdecl atexit(void (__cdecl *)(void));
  215. _CRTIMP double __cdecl atof(const char *);
  216. _CRTIMP int __cdecl atoi(const char *);
  217. _CRTIMP long __cdecl atol(const char *);
  218. _CRTIMP void * __cdecl bsearch(const void *, const void *, size_t, size_t,
  219. int (__cdecl *)(const void *, const void *));
  220. unsigned short __cdecl _byteswap_ushort(unsigned short);
  221. unsigned long __cdecl _byteswap_ulong (unsigned long);
  222. unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64);
  223. _CRTIMP _CRTNOALIAS _CRTRESTRICT void * __cdecl calloc(size_t, size_t);
  224. _CRTIMP div_t __cdecl div(int, int);
  225. _CRTIMP _CRTNOALIAS void __cdecl free(void *);
  226. _CRTIMP char * __cdecl getenv(const char *);
  227. _CRTIMP char * __cdecl _itoa(int, char *, int);
  228. #if _INTEGRAL_MAX_BITS >= 64
  229. _CRTIMP char * __cdecl _i64toa(__int64, char *, int);
  230. _CRTIMP char * __cdecl _ui64toa(unsigned __int64, char *, int);
  231. _CRTIMP __int64 __cdecl _atoi64(const char *);
  232. _CRTIMP __int64 __cdecl _strtoi64(const char *, char **, int);
  233. _CRTIMP unsigned __int64 __cdecl _strtoui64(const char *, char **, int);
  234. #endif
  235. long __cdecl labs(long);
  236. _CRTIMP ldiv_t __cdecl ldiv(long, long);
  237. _CRTIMP char * __cdecl _ltoa(long, char *, int);
  238. _CRTIMP _CRTNOALIAS _CRTRESTRICT void * __cdecl malloc(size_t);
  239. _CRTIMP int __cdecl mblen(const char *, size_t);
  240. _CRTIMP size_t __cdecl _mbstrlen(const char *s);
  241. _CRTIMP int __cdecl mbtowc(wchar_t *, const char *, size_t);
  242. _CRTIMP size_t __cdecl mbstowcs(wchar_t *, const char *, size_t);
  243. _CRTIMP void __cdecl qsort(void *, size_t, size_t, int (__cdecl *)
  244. (const void *, const void *));
  245. _CRTIMP int __cdecl rand(void);
  246. _CRTIMP _CRTNOALIAS _CRTRESTRICT void * __cdecl realloc(void *, size_t);
  247. _CRTIMP int __cdecl _set_error_mode(int);
  248. #if defined(_M_IX86)
  249. _CRTIMP _secerr_handler_func
  250. __cdecl _set_security_error_handler(_secerr_handler_func);
  251. #endif
  252. _CRTIMP void __cdecl srand(unsigned int);
  253. _CRTIMP double __cdecl strtod(const char *, char **);
  254. _CRTIMP long __cdecl strtol(const char *, char **, int);
  255. _CRTIMP unsigned long __cdecl strtoul(const char *, char **, int);
  256. _CRTIMP int __cdecl system(const char *);
  257. _CRTIMP char * __cdecl _ultoa(unsigned long, char *, int);
  258. _CRTIMP int __cdecl wctomb(char *, wchar_t);
  259. _CRTIMP size_t __cdecl wcstombs(char *, const wchar_t *, size_t);
  260. #ifndef _WSTDLIB_DEFINED
  261. /* wide function prototypes, also declared in wchar.h */
  262. _CRTIMP wchar_t * __cdecl _itow (int, wchar_t *, int);
  263. _CRTIMP wchar_t * __cdecl _ltow (long, wchar_t *, int);
  264. _CRTIMP wchar_t * __cdecl _ultow (unsigned long, wchar_t *, int);
  265. _CRTIMP double __cdecl wcstod(const wchar_t *, wchar_t **);
  266. _CRTIMP long __cdecl wcstol(const wchar_t *, wchar_t **, int);
  267. _CRTIMP unsigned long __cdecl wcstoul(const wchar_t *, wchar_t **, int);
  268. _CRTIMP wchar_t * __cdecl _wgetenv(const wchar_t *);
  269. _CRTIMP int __cdecl _wsystem(const wchar_t *);
  270. _CRTIMP double __cdecl _wtof(const wchar_t *);
  271. _CRTIMP int __cdecl _wtoi(const wchar_t *);
  272. _CRTIMP long __cdecl _wtol(const wchar_t *);
  273. #if _INTEGRAL_MAX_BITS >= 64
  274. _CRTIMP wchar_t * __cdecl _i64tow(__int64, wchar_t *, int);
  275. _CRTIMP wchar_t * __cdecl _ui64tow(unsigned __int64, wchar_t *, int);
  276. _CRTIMP __int64 __cdecl _wtoi64(const wchar_t *);
  277. _CRTIMP __int64 __cdecl _wcstoi64(const wchar_t *, wchar_t **, int);
  278. _CRTIMP unsigned __int64 __cdecl _wcstoui64(const wchar_t *, wchar_t **, int);
  279. #endif
  280. #define _WSTDLIB_DEFINED
  281. #endif
  282. #ifndef _POSIX_
  283. _CRTIMP char * __cdecl _ecvt(double, int, int *, int *);
  284. #if _MSC_VER >= 1200
  285. _CRTIMP __declspec(noreturn) void __cdecl _exit(int);
  286. #else
  287. _CRTIMP void __cdecl _exit(int);
  288. #endif
  289. _CRTIMP char * __cdecl _fcvt(double, int, int *, int *);
  290. _CRTIMP char * __cdecl _fullpath(char *, const char *, size_t);
  291. _CRTIMP char * __cdecl _gcvt(double, int, char *);
  292. unsigned long __cdecl _lrotl(unsigned long, int);
  293. unsigned long __cdecl _lrotr(unsigned long, int);
  294. _CRTIMP void __cdecl _makepath(char *, const char *, const char *, const char *,
  295. const char *);
  296. _onexit_t __cdecl _onexit(_onexit_t);
  297. _CRTIMP void __cdecl perror(const char *);
  298. _CRTIMP int __cdecl _putenv(const char *);
  299. unsigned int __cdecl _rotl(unsigned int, int);
  300. unsigned __int64 __cdecl _rotl64(unsigned __int64, int);
  301. unsigned int __cdecl _rotr(unsigned int, int);
  302. unsigned __int64 __cdecl _rotr64(unsigned __int64, int);
  303. _CRTIMP void __cdecl _searchenv(const char *, const char *, char *);
  304. _CRTIMP void __cdecl _splitpath(const char *, char *, char *, char *, char *);
  305. _CRTIMP void __cdecl _swab(char *, char *, int);
  306. #ifndef _WSTDLIBP_DEFINED
  307. /* wide function prototypes, also declared in wchar.h */
  308. _CRTIMP wchar_t * __cdecl _wfullpath(wchar_t *, const wchar_t *, size_t);
  309. _CRTIMP void __cdecl _wmakepath(wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *,
  310. const wchar_t *);
  311. _CRTIMP void __cdecl _wperror(const wchar_t *);
  312. _CRTIMP int __cdecl _wputenv(const wchar_t *);
  313. _CRTIMP void __cdecl _wsearchenv(const wchar_t *, const wchar_t *, wchar_t *);
  314. _CRTIMP void __cdecl _wsplitpath(const wchar_t *, wchar_t *, wchar_t *, wchar_t *, wchar_t *);
  315. #define _WSTDLIBP_DEFINED
  316. #endif
  317. /* --------- The following functions are OBSOLETE --------- */
  318. /* The Win32 API SetErrorMode, Beep and Sleep should be used instead. */
  319. _CRTIMP void __cdecl _seterrormode(int);
  320. _CRTIMP void __cdecl _beep(unsigned, unsigned);
  321. _CRTIMP void __cdecl _sleep(unsigned long);
  322. /* --------- The preceding functions are OBSOLETE --------- */
  323. #endif /* _POSIX_ */
  324. #if !__STDC__
  325. /* --------- The declarations below should not be in stdlib.h --------- */
  326. /* --------- and will be removed in a future release. Include --------- */
  327. /* --------- ctype.h to obtain these declarations. --------- */
  328. #ifndef tolower /* tolower has been undefined - use function */
  329. _CRTIMP int __cdecl tolower(int);
  330. #endif /* tolower */
  331. #ifndef toupper /* toupper has been undefined - use function */
  332. _CRTIMP int __cdecl toupper(int);
  333. #endif /* toupper */
  334. /* --------- The declarations above will be removed. --------- */
  335. #endif
  336. #if !__STDC__
  337. #ifndef _POSIX_
  338. /* Non-ANSI names for compatibility */
  339. #ifndef __cplusplus
  340. #define max(a,b) (((a) > (b)) ? (a) : (b))
  341. #define min(a,b) (((a) < (b)) ? (a) : (b))
  342. #endif
  343. #define sys_errlist _sys_errlist
  344. #define sys_nerr _sys_nerr
  345. #define environ _environ
  346. _CRTIMP char * __cdecl ecvt(double, int, int *, int *);
  347. _CRTIMP char * __cdecl fcvt(double, int, int *, int *);
  348. _CRTIMP char * __cdecl gcvt(double, int, char *);
  349. _CRTIMP char * __cdecl itoa(int, char *, int);
  350. _CRTIMP char * __cdecl ltoa(long, char *, int);
  351. onexit_t __cdecl onexit(onexit_t);
  352. _CRTIMP int __cdecl putenv(const char *);
  353. _CRTIMP void __cdecl swab(char *, char *, int);
  354. _CRTIMP char * __cdecl ultoa(unsigned long, char *, int);
  355. #endif /* _POSIX_ */
  356. #endif /* __STDC__ */
  357. #ifdef __cplusplus
  358. }
  359. #endif
  360. #ifdef _MSC_VER
  361. #pragma pack(pop)
  362. #endif /* _MSC_VER */
  363. #endif /* _INC_STDLIB */