Source code of Windows XP (NT5)
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.

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