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.

495 lines
14 KiB

  1. /***
  2. *stdlib.h - declarations/definitions for commonly used library functions
  3. *
  4. * Copyright (c) 1985-1994, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * This include file contains the function declarations for
  8. * commonly used library functions which either don't fit somewhere
  9. * else, or, like toupper/tolower, can't be declared in the normal
  10. * place for other reasons.
  11. * [ANSI]
  12. *
  13. ****/
  14. #ifndef _INC_STDLIB
  15. #define _INC_STDLIB
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /* Define _CRTAPI1 (for compatibility with the NT SDK) */
  20. #ifndef _CRTAPI1
  21. #if ( (_MSC_VER >= 800) && (_M_IX86 >= 300) )
  22. #define _CRTAPI1 __cdecl
  23. #else
  24. #define _CRTAPI1
  25. #endif
  26. #endif
  27. /* Define _CRTAPI2 (for compatibility with the NT SDK) */
  28. #ifndef _CRTAPI2
  29. #if ( (_MSC_VER >= 800) && (_M_IX86 >= 300) )
  30. #define _CRTAPI2 __cdecl
  31. #else
  32. #define _CRTAPI2
  33. #endif
  34. #endif
  35. /* Define _CRTIMP */
  36. #ifndef _CRTIMP
  37. #ifdef _NTSDK
  38. /* definition compatible with NT SDK */
  39. #define _CRTIMP
  40. #else /* ndef _NTSDK */
  41. /* current definition */
  42. #ifdef _DLL
  43. #define _CRTIMP __declspec(dllimport)
  44. #else /* ndef _DLL */
  45. #define _CRTIMP
  46. #endif /* _DLL */
  47. #endif /* _NTSDK */
  48. #endif /* _CRTIMP */
  49. /* Define __cdecl for non-Microsoft compilers */
  50. #if ( !defined(_MSC_VER) && !defined(__cdecl) )
  51. #define __cdecl
  52. #endif
  53. #ifndef _SIZE_T_DEFINED
  54. typedef unsigned int size_t;
  55. #define _SIZE_T_DEFINED
  56. #endif
  57. #ifndef _WCHAR_T_DEFINED
  58. typedef unsigned short wchar_t;
  59. #define _WCHAR_T_DEFINED
  60. #endif
  61. /* Define NULL pointer value */
  62. #ifndef NULL
  63. #ifdef __cplusplus
  64. #define NULL 0
  65. #else
  66. #define NULL ((void *)0)
  67. #endif
  68. #endif
  69. /* Definition of the argument values for the exit() function */
  70. #define EXIT_SUCCESS 0
  71. #define EXIT_FAILURE 1
  72. #ifndef _ONEXIT_T_DEFINED
  73. typedef int (__cdecl * _onexit_t)(void);
  74. #if !__STDC__
  75. /* Non-ANSI name for compatibility */
  76. #define onexit_t _onexit_t
  77. #endif
  78. #define _ONEXIT_T_DEFINED
  79. #endif
  80. /* Data structure definitions for div and ldiv runtimes. */
  81. #ifndef _DIV_T_DEFINED
  82. typedef struct _div_t {
  83. int quot;
  84. int rem;
  85. } div_t;
  86. typedef struct _ldiv_t {
  87. long quot;
  88. long rem;
  89. } ldiv_t;
  90. #define _DIV_T_DEFINED
  91. #endif
  92. /* Maximum value that can be returned by the rand function. */
  93. #define RAND_MAX 0x7fff
  94. /*
  95. * Maximum number of bytes in multi-byte character in the current locale
  96. * (also defined in ctype.h).
  97. */
  98. #ifndef MB_CUR_MAX
  99. #ifdef _NTSDK
  100. /* definition compatible with NT SDK */
  101. #ifdef _DLL
  102. #define __mb_cur_max (*__mb_cur_max_dll)
  103. #define MB_CUR_MAX (*__mb_cur_max_dll)
  104. extern int *__mb_cur_max_dll;
  105. #else /* ndef _DLL */
  106. #define MB_CUR_MAX __mb_cur_max
  107. extern int __mb_cur_max;
  108. #endif /* _DLL */
  109. #else /* ndef _NTSDK */
  110. /* current definition */
  111. #if defined(_DLL) && defined(_M_IX86)
  112. #define MB_CUR_MAX (*__p___mb_cur_max())
  113. _CRTIMP int * __cdecl __p___mb_cur_max(void);
  114. #else /* !(defined(_DLL) && defined(_M_IX86)) */
  115. #define MB_CUR_MAX __mb_cur_max
  116. _CRTIMP extern int __mb_cur_max;
  117. #endif /* defined(_DLL) && defined(_M_IX86) */
  118. #endif /* _NTSDK */
  119. #endif /* MB_CUR_MAX */
  120. /* Minimum and maximum macros */
  121. #define __max(a,b) (((a) > (b)) ? (a) : (b))
  122. #define __min(a,b) (((a) < (b)) ? (a) : (b))
  123. /*
  124. * Sizes for buffers used by the _makepath() and _splitpath() functions.
  125. * note that the sizes include space for 0-terminator
  126. */
  127. #define _MAX_PATH 260 /* max. length of full pathname */
  128. #define _MAX_DRIVE 3 /* max. length of drive component */
  129. #define _MAX_DIR 256 /* max. length of path component */
  130. #define _MAX_FNAME 256 /* max. length of file name component */
  131. #define _MAX_EXT 256 /* max. length of extension component */
  132. /* External variable declarations */
  133. #ifdef _MT
  134. _CRTIMP int * __cdecl _errno(void);
  135. _CRTIMP unsigned long * __cdecl __doserrno(void);
  136. #define errno (*_errno())
  137. #define _doserrno (*__doserrno())
  138. #else /* ndef _MT */
  139. _CRTIMP extern int errno; /* XENIX style error number */
  140. _CRTIMP extern unsigned long _doserrno; /* OS system error value */
  141. #endif /* _MT */
  142. #ifdef _NTSDK
  143. /* Definitions and declarations compatible with the NT SDK */
  144. #ifdef _DLL
  145. extern char ** _sys_errlist; /* perror error message table */
  146. #define _sys_nerr (*_sys_nerr_dll)
  147. #define __argc (*__argc_dll)
  148. #define __argc (*__argc_dll)
  149. #define __argv (*__argv_dll)
  150. #define __wargv (*__wargv_dll)
  151. #define _environ (*_environ_dll)
  152. #define _wenviron (*_wenviron_dll)
  153. #define _fmode (*_fmode_dll)
  154. #define _fileinfo (*_fileinfo_dll)
  155. extern int * _sys_nerr_dll; /* # of entries in sys_errlist table */
  156. extern int * __argc_dll; /* count of cmd line args */
  157. extern char *** __argv_dll; /* pointer to table of cmd line args */
  158. extern wchar_t *** __wargv_dll; /* pointer to table of wide cmd line args */
  159. extern char *** _environ_dll; /* pointer to environment table */
  160. extern wchar_t *** _wenviron_dll; /* pointer to wide environment table */
  161. extern int * _fmode_dll; /* default file translation mode */
  162. extern int * _fileinfo_dll; /* open file info mode (for spawn) */
  163. #define _pgmptr (*_pgmptr_dll)
  164. #define _wpgmptr (*_wpgmptr_dll)
  165. #define _osver (*_osver_dll)
  166. #define _winver (*_winver_dll)
  167. #define _winmajor (*_winmajor_dll)
  168. #define _winminor (*_winminor_dll)
  169. extern char ** _pgmptr_dll;
  170. extern wchar_t ** _wpgmptr_dll;
  171. extern unsigned int * _osver_dll;
  172. extern unsigned int * _winver_dll;
  173. extern unsigned int * _winmajor_dll;
  174. extern unsigned int * _winminor_dll;
  175. #else /* ndef _DLL */
  176. extern char * _sys_errlist[]; /* perror error message table */
  177. extern int _sys_nerr; /* # of entries in sys_errlist table */
  178. extern int __argc; /* count of cmd line args */
  179. extern char ** __argv; /* pointer to table of cmd line args */
  180. extern wchar_t ** __wargv; /* pointer to table of wide cmd line args */
  181. #ifdef _POSIX_
  182. extern char ** environ; /* pointer to environment table */
  183. #else
  184. extern char ** _environ; /* pointer to environment table */
  185. extern wchar_t ** _wenviron; /* pointer to wide environment table */
  186. #endif
  187. extern int _fmode; /* default file translation mode */
  188. extern int _fileinfo; /* open file info mode (for spawn) */
  189. extern char * _pgmptr; /* points to the module (EXE) name */
  190. extern wchar_t * _wpgmptr; /* points to the module (EXE) wide name */
  191. /* Windows major/minor and O.S. version numbers */
  192. extern unsigned int _osver;
  193. extern unsigned int _winver;
  194. extern unsigned int _winmajor;
  195. extern unsigned int _winminor;
  196. #endif /* _DLL */
  197. #else /* ndef _NTSDK */
  198. /* Current definitions and declarations */
  199. _CRTIMP extern char * _sys_errlist[]; /* perror error message table */
  200. _CRTIMP extern int _sys_nerr; /* # of entries in sys_errlist table */
  201. #if defined(_DLL) && defined(_M_IX86)
  202. #define __argc (*__p___argc()) /* count of cmd line args */
  203. #define __argv (*__p___argv()) /* pointer to table of cmd line args */
  204. #define __wargv (*__p___wargv()) /* pointer to table of wide cmd line args */
  205. #define _environ (*__p__environ()) /* pointer to environment table */
  206. #define _wenviron (*__p__wenviron()) /* pointer to wide environment table */
  207. #define _fmode (*__p__fmode())
  208. #define _osver (*__p__osver())
  209. #define _pgmptr (*__p__pgmptr()) /* points to the module (EXE) name */
  210. #define _wpgmptr (*__p__wpgmptr()) /* points to the module (EXE) wide name */
  211. #define _winver (*__p__winver())
  212. #define _winmajor (*__p__winmajor())
  213. #define _winminor (*__p__winminor())
  214. _CRTIMP int * __cdecl __p___argc(void);
  215. _CRTIMP char *** __cdecl __p___argv(void);
  216. _CRTIMP wchar_t *** __cdecl __p___wargv(void);
  217. _CRTIMP char *** __cdecl __p__environ(void);
  218. _CRTIMP wchar_t *** __cdecl __p__wenviron(void);
  219. _CRTIMP int * __cdecl __p__fmode(void);
  220. _CRTIMP unsigned int * __cdecl __p__osver(void);
  221. _CRTIMP char ** __cdecl __p__pgmptr(void);
  222. _CRTIMP wchar_t ** __cdecl __p__wpgmptr(void);
  223. _CRTIMP unsigned int * __cdecl __p__winver(void);
  224. _CRTIMP unsigned int * __cdecl __p__winmajor(void);
  225. _CRTIMP unsigned int * __cdecl __p__winminor(void);
  226. #else /* !(defined(_DLL) && defined(_M_IX86)) */
  227. _CRTIMP extern int __argc; /* count of cmd line args */
  228. _CRTIMP extern char ** __argv; /* pointer to table of cmd line args */
  229. _CRTIMP extern wchar_t ** __wargv; /* pointer to table of wide cmd line args */
  230. _CRTIMP extern char ** _environ; /* pointer to environment table */
  231. _CRTIMP extern wchar_t ** _wenviron; /* pointer to wide environment table */
  232. _CRTIMP extern int _fmode; /* default file translation mode */
  233. _CRTIMP extern int _fileinfo; /* open file info mode (for spawn) */
  234. _CRTIMP extern char * _pgmptr; /* points to the module (EXE) name */
  235. _CRTIMP extern wchar_t * _wpgmptr; /* points to the module (EXE) wide name */
  236. /* Windows major/minor and O.S. version numbers */
  237. _CRTIMP extern unsigned int _osver;
  238. _CRTIMP extern unsigned int _winver;
  239. _CRTIMP extern unsigned int _winmajor;
  240. _CRTIMP extern unsigned int _winminor;
  241. #endif /* defined(_DLL) && defined(_M_IX86) */
  242. #endif /* _NTSDK */
  243. /* function prototypes */
  244. _CRTIMP void __cdecl abort(void);
  245. int __cdecl abs(int);
  246. int __cdecl atexit(void (__cdecl *)(void));
  247. _CRTIMP double __cdecl atof(const char *);
  248. _CRTIMP int __cdecl atoi(const char *);
  249. _CRTIMP long __cdecl atol(const char *);
  250. _CRTIMP void * __cdecl bsearch(const void *, const void *, size_t, size_t,
  251. int (__cdecl *)(const void *, const void *));
  252. _CRTIMP void * __cdecl calloc(size_t, size_t);
  253. _CRTIMP div_t __cdecl div(int, int);
  254. _CRTIMP void __cdecl exit(int);
  255. _CRTIMP void __cdecl free(void *);
  256. _CRTIMP char * __cdecl getenv(const char *);
  257. _CRTIMP char * __cdecl _itoa(int, char *, int);
  258. long __cdecl labs(long);
  259. _CRTIMP ldiv_t __cdecl ldiv(long, long);
  260. _CRTIMP char * __cdecl _ltoa(long, char *, int);
  261. _CRTIMP void * __cdecl malloc(size_t);
  262. _CRTIMP int __cdecl mblen(const char *, size_t);
  263. _CRTIMP size_t __cdecl _mbstrlen(const char *s);
  264. _CRTIMP int __cdecl mbtowc(wchar_t *, const char *, size_t);
  265. _CRTIMP size_t __cdecl mbstowcs(wchar_t *, const char *, size_t);
  266. _CRTIMP void __cdecl qsort(void *, size_t, size_t, int (__cdecl *)
  267. (const void *, const void *));
  268. _CRTIMP int __cdecl rand(void);
  269. _CRTIMP void * __cdecl realloc(void *, size_t);
  270. _CRTIMP void __cdecl srand(unsigned int);
  271. _CRTIMP double __cdecl strtod(const char *, char **);
  272. _CRTIMP long __cdecl strtol(const char *, char **, int);
  273. _CRTIMP unsigned long __cdecl strtoul(const char *, char **, int);
  274. _CRTIMP int __cdecl system(const char *);
  275. _CRTIMP char * __cdecl _ultoa(unsigned long, char *, int);
  276. _CRTIMP int __cdecl wctomb(char *, wchar_t);
  277. _CRTIMP size_t __cdecl wcstombs(char *, const wchar_t *, size_t);
  278. #ifndef _WSTDLIB_DEFINED
  279. /* wide function prototypes, also declared in wchar.h */
  280. _CRTIMP wchar_t * __cdecl _itow (int, wchar_t *, int);
  281. _CRTIMP wchar_t * __cdecl _ltow (long, wchar_t *, int);
  282. _CRTIMP wchar_t * __cdecl _ultow (unsigned long, wchar_t *, int);
  283. _CRTIMP double __cdecl wcstod(const wchar_t *, wchar_t **);
  284. _CRTIMP long __cdecl wcstol(const wchar_t *, wchar_t **, int);
  285. _CRTIMP unsigned long __cdecl wcstoul(const wchar_t *, wchar_t **, int);
  286. _CRTIMP wchar_t * __cdecl _wgetenv(const wchar_t *);
  287. _CRTIMP int __cdecl _wsystem(const wchar_t *);
  288. _CRTIMP int __cdecl _wtoi(const wchar_t *);
  289. _CRTIMP long __cdecl _wtol(const wchar_t *);
  290. #define _WSTDLIB_DEFINED
  291. #endif
  292. #ifndef _POSIX_
  293. _CRTIMP char * __cdecl _ecvt(double, int, int *, int *);
  294. _CRTIMP void __cdecl _exit(int);
  295. _CRTIMP char * __cdecl _fcvt(double, int, int *, int *);
  296. _CRTIMP char * __cdecl _fullpath(char *, const char *, size_t);
  297. _CRTIMP char * __cdecl _gcvt(double, int, char *);
  298. unsigned long __cdecl _lrotl(unsigned long, int);
  299. unsigned long __cdecl _lrotr(unsigned long, int);
  300. _CRTIMP void __cdecl _makepath(char *, const char *, const char *, const char *,
  301. const char *);
  302. _onexit_t __cdecl _onexit(_onexit_t);
  303. _CRTIMP void __cdecl perror(const char *);
  304. _CRTIMP int __cdecl _putenv(const char *);
  305. unsigned int __cdecl _rotl(unsigned int, int);
  306. unsigned int __cdecl _rotr(unsigned int, int);
  307. _CRTIMP void __cdecl _searchenv(const char *, const char *, char *);
  308. _CRTIMP void __cdecl _splitpath(const char *, char *, char *, char *, char *);
  309. _CRTIMP void __cdecl _swab(char *, char *, int);
  310. #ifndef _WSTDLIBP_DEFINED
  311. /* wide function prototypes, also declared in wchar.h */
  312. _CRTIMP wchar_t * __cdecl _wfullpath(wchar_t *, const wchar_t *, size_t);
  313. _CRTIMP void __cdecl _wmakepath(wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *,
  314. const wchar_t *);
  315. _CRTIMP void __cdecl _wperror(const wchar_t *);
  316. _CRTIMP int __cdecl _wputenv(const wchar_t *);
  317. _CRTIMP void __cdecl _wsearchenv(const wchar_t *, const wchar_t *, wchar_t *);
  318. _CRTIMP void __cdecl _wsplitpath(const wchar_t *, wchar_t *, wchar_t *, wchar_t *, wchar_t *);
  319. #define _WSTDLIBP_DEFINED
  320. #endif
  321. /* --------- The following functions are OBSOLETE --------- */
  322. /* The Win32 API SetErrorMode, Beep and Sleep should be used instead. */
  323. _CRTIMP void _seterrormode(int);
  324. _CRTIMP void _beep(unsigned, unsigned);
  325. _CRTIMP void _sleep(unsigned long);
  326. /* --------- The preceding functions are OBSOLETE --------- */
  327. #endif /* _POSIX_ */
  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. #if !__STDC__
  335. /* Non-ANSI names for compatibility */
  336. #ifdef _NTSDK
  337. #ifndef _POSIX_
  338. #ifndef __cplusplus
  339. #define max(a,b) (((a) > (b)) ? (a) : (b))
  340. #define min(a,b) (((a) < (b)) ? (a) : (b))
  341. #endif
  342. #define sys_errlist _sys_errlist
  343. #define sys_nerr _sys_nerr
  344. #define environ _environ
  345. #define DOS_MODE _DOS_MODE
  346. #define OS2_MODE _OS2_MODE
  347. #define ecvt _ecvt
  348. #define fcvt _fcvt
  349. #define gcvt _gcvt
  350. #define itoa _itoa
  351. #define ltoa _ltoa
  352. #define onexit _onexit
  353. #define putenv _putenv
  354. #define swab _swab
  355. #define ultoa _ultoa
  356. #endif /* _POSIX_ */
  357. #else /* ndef _NTSDK */
  358. #ifndef __cplusplus
  359. #define max(a,b) (((a) > (b)) ? (a) : (b))
  360. #define min(a,b) (((a) < (b)) ? (a) : (b))
  361. #endif
  362. #define sys_errlist _sys_errlist
  363. #define sys_nerr _sys_nerr
  364. #define environ _environ
  365. _CRTIMP char * __cdecl ecvt(double, int, int *, int *);
  366. _CRTIMP char * __cdecl fcvt(double, int, int *, int *);
  367. _CRTIMP char * __cdecl gcvt(double, int, char *);
  368. _CRTIMP char * __cdecl itoa(int, char *, int);
  369. _CRTIMP char * __cdecl ltoa(long, char *, int);
  370. onexit_t __cdecl onexit(onexit_t);
  371. _CRTIMP int __cdecl putenv(const char *);
  372. _CRTIMP void __cdecl swab(char *, char *, int);
  373. _CRTIMP char * __cdecl ultoa(unsigned long, char *, int);
  374. #endif /* _NTSDK */
  375. #endif /* __STDC__ */
  376. #ifdef __cplusplus
  377. }
  378. #endif
  379. #endif /* _INC_STDLIB */