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.

592 lines
17 KiB

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