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.

410 lines
12 KiB

  1. /***
  2. *stdlib.h - declarations/definitions for commonly used library functions
  3. *
  4. * Copyright (c) 1985-2000, 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. #if !defined(_WCHAR_T_DEFINED) && !defined(_NATIVE_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. #endif /* MB_CUR_MAX */
  105. /* Minimum and maximum macros */
  106. #define __max(a,b) (((a) > (b)) ? (a) : (b))
  107. #define __min(a,b) (((a) < (b)) ? (a) : (b))
  108. /*
  109. * Sizes for buffers used by the _makepath() and _splitpath() functions.
  110. * note that the sizes include space for 0-terminator
  111. */
  112. #define _MAX_PATH 260 /* max. length of full pathname */
  113. #define _MAX_DRIVE 3 /* max. length of drive component */
  114. #define _MAX_DIR 256 /* max. length of path component */
  115. #define _MAX_FNAME 256 /* max. length of file name component */
  116. #define _MAX_EXT 256 /* max. length of extension component */
  117. /*
  118. * Argument values for _set_error_mode().
  119. */
  120. #define _OUT_TO_DEFAULT 0
  121. #define _OUT_TO_STDERR 1
  122. #define _OUT_TO_MSGBOX 2
  123. #define _REPORT_ERRMODE 3
  124. #if defined(_M_IX86)
  125. /*
  126. * Typedefs and argument values for _set_security_error_handler()
  127. */
  128. #define _SECERR_BUFFER_OVERRUN 1 /* void* arg ignored */
  129. typedef void (__cdecl * _secerr_handler_func)(int, void *);
  130. #endif
  131. /* External variable declarations */
  132. #if defined(_MT) || defined(_DLL)
  133. _CRTIMP int * __cdecl _errno(void);
  134. _CRTIMP unsigned long * __cdecl __doserrno(void);
  135. #define errno (*_errno())
  136. #define _doserrno (*__doserrno())
  137. #else /* ndef _MT && ndef _DLL */
  138. _CRTIMP extern int errno; /* XENIX style error number */
  139. _CRTIMP extern unsigned long _doserrno; /* OS system error value */
  140. #endif /* _MT || _DLL */
  141. _CRTIMP extern char * _sys_errlist[]; /* perror error message table */
  142. _CRTIMP extern int _sys_nerr; /* # of entries in sys_errlist table */
  143. _CRTIMP extern int __argc; /* count of cmd line args */
  144. _CRTIMP extern char ** __argv; /* pointer to table of cmd line args */
  145. _CRTIMP extern wchar_t ** __wargv; /* pointer to table of wide cmd line args */
  146. #ifdef _POSIX_
  147. extern char ** environ; /* pointer to environment table */
  148. #else
  149. _CRTIMP extern char ** _environ; /* pointer to environment table */
  150. _CRTIMP extern wchar_t ** _wenviron; /* pointer to wide environment table */
  151. #endif /* _POSIX_ */
  152. _CRTIMP extern char * _pgmptr; /* points to the module (EXE) name */
  153. _CRTIMP extern wchar_t * _wpgmptr; /* points to the module (EXE) wide name */
  154. _CRTIMP extern int _fmode; /* default file translation mode */
  155. _CRTIMP extern int _fileinfo; /* open file info mode (for spawn) */
  156. /* Windows major/minor and O.S. version numbers */
  157. _CRTIMP extern unsigned int _osplatform;
  158. _CRTIMP extern unsigned int _osver;
  159. _CRTIMP extern unsigned int _winver;
  160. _CRTIMP extern unsigned int _winmajor;
  161. _CRTIMP extern unsigned int _winminor;
  162. /* function prototypes */
  163. #if _MSC_VER >= 1200
  164. _CRTIMP __declspec(noreturn) void __cdecl abort(void);
  165. _CRTIMP __declspec(noreturn) void __cdecl exit(int);
  166. #else
  167. _CRTIMP void __cdecl abort(void);
  168. _CRTIMP void __cdecl exit(int);
  169. #endif
  170. #if defined(_M_MRX000)
  171. _CRTIMP int __cdecl abs(int);
  172. #else
  173. int __cdecl abs(int);
  174. #endif
  175. int __cdecl atexit(void (__cdecl *)(void));
  176. _CRTIMP double __cdecl atof(const char *);
  177. _CRTIMP int __cdecl atoi(const char *);
  178. _CRTIMP long __cdecl atol(const char *);
  179. _CRTIMP void * __cdecl bsearch(const void *, const void *, size_t, size_t,
  180. int (__cdecl *)(const void *, const void *));
  181. _CRTIMP void * __cdecl calloc(size_t, size_t);
  182. _CRTIMP div_t __cdecl div(int, int);
  183. _CRTIMP void __cdecl free(void *);
  184. _CRTIMP char * __cdecl getenv(const char *);
  185. _CRTIMP char * __cdecl _itoa(int, char *, int);
  186. #if _INTEGRAL_MAX_BITS >= 64
  187. _CRTIMP char * __cdecl _i64toa(__int64, char *, int);
  188. _CRTIMP char * __cdecl _ui64toa(unsigned __int64, char *, int);
  189. _CRTIMP __int64 __cdecl _atoi64(const char *);
  190. _CRTIMP __int64 __cdecl _strtoi64(const char *, char **, int);
  191. _CRTIMP unsigned __int64 __cdecl _strtoui64(const char *, char **, int);
  192. #endif
  193. #if defined(_M_MRX000)
  194. _CRTIMP long __cdecl labs(long);
  195. #else
  196. long __cdecl labs(long);
  197. #endif
  198. _CRTIMP ldiv_t __cdecl ldiv(long, long);
  199. _CRTIMP char * __cdecl _ltoa(long, char *, int);
  200. _CRTIMP void * __cdecl malloc(size_t);
  201. _CRTIMP int __cdecl mblen(const char *, size_t);
  202. _CRTIMP size_t __cdecl _mbstrlen(const char *s);
  203. _CRTIMP int __cdecl mbtowc(wchar_t *, const char *, size_t);
  204. _CRTIMP size_t __cdecl mbstowcs(wchar_t *, const char *, size_t);
  205. _CRTIMP void __cdecl qsort(void *, size_t, size_t, int (__cdecl *)
  206. (const void *, const void *));
  207. _CRTIMP int __cdecl rand(void);
  208. _CRTIMP void * __cdecl realloc(void *, size_t);
  209. _CRTIMP int __cdecl _set_error_mode(int);
  210. #if defined(_M_IX86)
  211. _CRTIMP _secerr_handler_func
  212. __cdecl _set_security_error_handler(_secerr_handler_func);
  213. #endif
  214. _CRTIMP void __cdecl srand(unsigned int);
  215. _CRTIMP double __cdecl strtod(const char *, char **);
  216. _CRTIMP long __cdecl strtol(const char *, char **, int);
  217. _CRTIMP unsigned long __cdecl strtoul(const char *, char **, int);
  218. _CRTIMP int __cdecl system(const char *);
  219. _CRTIMP char * __cdecl _ultoa(unsigned long, char *, int);
  220. _CRTIMP int __cdecl wctomb(char *, wchar_t);
  221. _CRTIMP size_t __cdecl wcstombs(char *, const wchar_t *, size_t);
  222. #ifndef _WSTDLIB_DEFINED
  223. /* wide function prototypes, also declared in wchar.h */
  224. _CRTIMP wchar_t * __cdecl _itow (int, wchar_t *, int);
  225. _CRTIMP wchar_t * __cdecl _ltow (long, wchar_t *, int);
  226. _CRTIMP wchar_t * __cdecl _ultow (unsigned long, wchar_t *, int);
  227. _CRTIMP double __cdecl wcstod(const wchar_t *, wchar_t **);
  228. _CRTIMP long __cdecl wcstol(const wchar_t *, wchar_t **, int);
  229. _CRTIMP unsigned long __cdecl wcstoul(const wchar_t *, wchar_t **, int);
  230. _CRTIMP wchar_t * __cdecl _wgetenv(const wchar_t *);
  231. _CRTIMP int __cdecl _wsystem(const wchar_t *);
  232. _CRTIMP double __cdecl _wtof(const wchar_t *);
  233. _CRTIMP int __cdecl _wtoi(const wchar_t *);
  234. _CRTIMP long __cdecl _wtol(const wchar_t *);
  235. #if _INTEGRAL_MAX_BITS >= 64
  236. _CRTIMP wchar_t * __cdecl _i64tow(__int64, wchar_t *, int);
  237. _CRTIMP wchar_t * __cdecl _ui64tow(unsigned __int64, wchar_t *, int);
  238. _CRTIMP __int64 __cdecl _wtoi64(const wchar_t *);
  239. _CRTIMP __int64 __cdecl _wcstoi64(const wchar_t *, wchar_t **, int);
  240. _CRTIMP unsigned __int64 __cdecl _wcstoui64(const wchar_t *, wchar_t **, int);
  241. #endif
  242. #define _WSTDLIB_DEFINED
  243. #endif
  244. #ifndef _POSIX_
  245. _CRTIMP char * __cdecl _ecvt(double, int, int *, int *);
  246. #if _MSC_VER >= 1200
  247. _CRTIMP __declspec(noreturn) void __cdecl _exit(int);
  248. #else
  249. _CRTIMP void __cdecl _exit(int);
  250. #endif
  251. _CRTIMP char * __cdecl _fcvt(double, int, int *, int *);
  252. _CRTIMP char * __cdecl _fullpath(char *, const char *, size_t);
  253. _CRTIMP char * __cdecl _gcvt(double, int, char *);
  254. unsigned long __cdecl _lrotl(unsigned long, int);
  255. unsigned long __cdecl _lrotr(unsigned long, int);
  256. _CRTIMP void __cdecl _makepath(char *, const char *, const char *, const char *,
  257. const char *);
  258. _onexit_t __cdecl _onexit(_onexit_t);
  259. _CRTIMP void __cdecl perror(const char *);
  260. _CRTIMP int __cdecl _putenv(const char *);
  261. unsigned int __cdecl _rotl(unsigned int, int);
  262. unsigned int __cdecl _rotr(unsigned int, int);
  263. _CRTIMP void __cdecl _searchenv(const char *, const char *, char *);
  264. _CRTIMP void __cdecl _splitpath(const char *, char *, char *, char *, char *);
  265. _CRTIMP void __cdecl _swab(char *, char *, int);
  266. #ifndef _WSTDLIBP_DEFINED
  267. /* wide function prototypes, also declared in wchar.h */
  268. _CRTIMP wchar_t * __cdecl _wfullpath(wchar_t *, const wchar_t *, size_t);
  269. _CRTIMP void __cdecl _wmakepath(wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *,
  270. const wchar_t *);
  271. _CRTIMP void __cdecl _wperror(const wchar_t *);
  272. _CRTIMP int __cdecl _wputenv(const wchar_t *);
  273. _CRTIMP void __cdecl _wsearchenv(const wchar_t *, const wchar_t *, wchar_t *);
  274. _CRTIMP void __cdecl _wsplitpath(const wchar_t *, wchar_t *, wchar_t *, wchar_t *, wchar_t *);
  275. #define _WSTDLIBP_DEFINED
  276. #endif
  277. /* --------- The following functions are OBSOLETE --------- */
  278. /* The Win32 API SetErrorMode, Beep and Sleep should be used instead. */
  279. _CRTIMP void __cdecl _seterrormode(int);
  280. _CRTIMP void __cdecl _beep(unsigned, unsigned);
  281. _CRTIMP void __cdecl _sleep(unsigned long);
  282. /* --------- The preceding functions are OBSOLETE --------- */
  283. #endif /* _POSIX_ */
  284. #if !__STDC__
  285. /* --------- The declarations below should not be in stdlib.h --------- */
  286. /* --------- and will be removed in a future release. Include --------- */
  287. /* --------- ctype.h to obtain these declarations. --------- */
  288. #ifndef tolower /* tolower has been undefined - use function */
  289. _CRTIMP int __cdecl tolower(int);
  290. #endif /* tolower */
  291. #ifndef toupper /* toupper has been undefined - use function */
  292. _CRTIMP int __cdecl toupper(int);
  293. #endif /* toupper */
  294. /* --------- The declarations above will be removed. --------- */
  295. #endif
  296. #if !__STDC__
  297. #ifndef _POSIX_
  298. /* Non-ANSI names for compatibility */
  299. #ifndef __cplusplus
  300. #define max(a,b) (((a) > (b)) ? (a) : (b))
  301. #define min(a,b) (((a) < (b)) ? (a) : (b))
  302. #endif
  303. #define sys_errlist _sys_errlist
  304. #define sys_nerr _sys_nerr
  305. #define environ _environ
  306. _CRTIMP char * __cdecl ecvt(double, int, int *, int *);
  307. _CRTIMP char * __cdecl fcvt(double, int, int *, int *);
  308. _CRTIMP char * __cdecl gcvt(double, int, char *);
  309. _CRTIMP char * __cdecl itoa(int, char *, int);
  310. _CRTIMP char * __cdecl ltoa(long, char *, int);
  311. onexit_t __cdecl onexit(onexit_t);
  312. _CRTIMP int __cdecl putenv(const char *);
  313. _CRTIMP void __cdecl swab(char *, char *, int);
  314. _CRTIMP char * __cdecl ultoa(unsigned long, char *, int);
  315. #endif /* _POSIX_ */
  316. #endif /* __STDC__ */
  317. #ifdef __cplusplus
  318. }
  319. #endif
  320. #ifdef _MSC_VER
  321. #pragma pack(pop)
  322. #endif /* _MSC_VER */
  323. #endif /* _INC_STDLIB */