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.

523 lines
12 KiB

  1. /***
  2. *stdio.h - definitions/declarations for standard I/O routines
  3. *
  4. * Copyright (c) 1985-1995, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * This file defines the structures, values, macros, and functions
  8. * used by the level 2 I/O ("standard I/O") routines.
  9. * [ANSI/System V]
  10. *
  11. * [Public]
  12. *
  13. ****/
  14. #ifndef _INC_STDIO
  15. #define _INC_STDIO
  16. #if !defined(_WIN32) && !defined(_MAC)
  17. #error ERROR: Only Mac or Win32 targets supported!
  18. #endif
  19. #ifdef _MSC_VER
  20. /*
  21. * Currently, all MS C compilers for Win32 platforms default to 8 byte
  22. * alignment.
  23. */
  24. #pragma pack(push,8)
  25. #endif /* _MSC_VER */
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /* Define _CRTAPI1 (for compatibility with the NT SDK) */
  30. #ifndef _CRTAPI1
  31. #if _MSC_VER >= 800 && _M_IX86 >= 300
  32. #define _CRTAPI1 __cdecl
  33. #else
  34. #define _CRTAPI1
  35. #endif
  36. #endif
  37. /* Define _CRTAPI2 (for compatibility with the NT SDK) */
  38. #ifndef _CRTAPI2
  39. #if _MSC_VER >= 800 && _M_IX86 >= 300
  40. #define _CRTAPI2 __cdecl
  41. #else
  42. #define _CRTAPI2
  43. #endif
  44. #endif
  45. /* Define _CRTIMP */
  46. #ifndef _CRTIMP
  47. #ifdef _NTSDK
  48. /* definition compatible with NT SDK */
  49. #define _CRTIMP
  50. #else /* ndef _NTSDK */
  51. /* current definition */
  52. #ifdef _DLL
  53. #define _CRTIMP __declspec(dllimport)
  54. #else /* ndef _DLL */
  55. #define _CRTIMP
  56. #endif /* _DLL */
  57. #endif /* _NTSDK */
  58. #endif /* _CRTIMP */
  59. /* Define __cdecl for non-Microsoft compilers */
  60. #if ( !defined(_MSC_VER) && !defined(__cdecl) )
  61. #define __cdecl
  62. #endif
  63. #ifndef _SIZE_T_DEFINED
  64. typedef unsigned int size_t;
  65. #define _SIZE_T_DEFINED
  66. #endif
  67. #ifndef _MAC
  68. #ifndef _WCHAR_T_DEFINED
  69. typedef unsigned short wchar_t;
  70. #define _WCHAR_T_DEFINED
  71. #endif
  72. #ifndef _WCTYPE_T_DEFINED
  73. typedef wchar_t wint_t;
  74. typedef wchar_t wctype_t;
  75. #define _WCTYPE_T_DEFINED
  76. #endif
  77. #endif /* ndef _MAC */
  78. #ifndef _VA_LIST_DEFINED
  79. #ifdef _M_ALPHA
  80. typedef struct {
  81. char *a0; /* pointer to first homed integer argument */
  82. int offset; /* byte offset of next parameter */
  83. } va_list;
  84. #else
  85. typedef char * va_list;
  86. #endif
  87. #define _VA_LIST_DEFINED
  88. #endif
  89. /* Buffered I/O macros */
  90. #if defined(_M_MPPC)
  91. #define BUFSIZ 4096
  92. #else /* defined (_M_MPPC) */
  93. #define BUFSIZ 512
  94. #endif /* defined (_M_MPPC) */
  95. /*
  96. * Default number of supported streams. _NFILE is confusing and obsolete, but
  97. * supported anyway for backwards compatibility.
  98. */
  99. #define _NFILE _NSTREAM_
  100. #ifdef _WIN32
  101. #define _NSTREAM_ 512
  102. /*
  103. * Number of entries in _iob[] (declared below). Note that _NSTREAM_ must be
  104. * greater than or equal to _IOB_ENTRIES.
  105. */
  106. #define _IOB_ENTRIES 20
  107. #else /* ndef _WIN32 */
  108. #ifdef _DLL
  109. #define _NSTREAM_ 128
  110. #else
  111. #ifdef _MT
  112. #define _NSTREAM_ 40
  113. #else
  114. #define _NSTREAM_ 20
  115. #endif
  116. #endif /* _DLL */
  117. #endif /* ndef _MAC */
  118. #define EOF (-1)
  119. #ifndef _FILE_DEFINED
  120. struct _iobuf {
  121. char *_ptr;
  122. int _cnt;
  123. char *_base;
  124. int _flag;
  125. int _file;
  126. int _charbuf;
  127. int _bufsiz;
  128. char *_tmpfname;
  129. };
  130. typedef struct _iobuf FILE;
  131. #define _FILE_DEFINED
  132. #endif
  133. #if !defined(_M_MPPC) && !defined(_M_M68K)
  134. /* Directory where temporary files may be created. */
  135. #ifdef _POSIX_
  136. #define _P_tmpdir "/"
  137. #define _wP_tmpdir L"/"
  138. #else
  139. #define _P_tmpdir "\\"
  140. #define _wP_tmpdir L"\\"
  141. #endif
  142. /* L_tmpnam = size of P_tmpdir
  143. * + 1 (in case P_tmpdir does not end in "/")
  144. * + 12 (for the filename string)
  145. * + 1 (for the null terminator)
  146. */
  147. #define L_tmpnam sizeof(_P_tmpdir)+12
  148. #else /* defined(_M_M68K) || defined(_M_MPPC) */
  149. #define L_tmpnam 255
  150. #endif /* !defined(_M_M68K) && defined(_M_MPPC) */
  151. #ifdef _POSIX_
  152. #define L_ctermid 9
  153. #define L_cuserid 32
  154. #endif
  155. /* Seek method constants */
  156. #define SEEK_CUR 1
  157. #define SEEK_END 2
  158. #define SEEK_SET 0
  159. #define FILENAME_MAX 260
  160. #define FOPEN_MAX 20
  161. #define _SYS_OPEN 20
  162. #define TMP_MAX 32767
  163. /* Define NULL pointer value */
  164. #ifndef NULL
  165. #ifdef __cplusplus
  166. #define NULL 0
  167. #else
  168. #define NULL ((void *)0)
  169. #endif
  170. #endif
  171. /* Declare _iob[] array */
  172. #ifndef _STDIO_DEFINED
  173. #ifdef _NTSDK
  174. #ifdef _DLL
  175. extern FILE * _iob;
  176. #else
  177. extern FILE _iob[];
  178. #endif
  179. #else /* ndef _NTSDK */
  180. #if defined(_DLL) && defined(_M_IX86)
  181. #define _iob (__p__iob())
  182. _CRTIMP extern FILE * __cdecl __p__iob(void);
  183. #else /* !(defined(_DLL) && defined(_M_IX86)) */
  184. _CRTIMP extern FILE _iob[];
  185. #endif /* defined(_DLL) && defined(_M_IX86) */
  186. #endif /* _NTSDK */
  187. #endif /* _STDIO_DEFINED */
  188. /* Define file position type */
  189. #ifndef _FPOS_T_DEFINED
  190. #if defined(_M_MPPC) || defined(_M_M68K) || defined(_POSIX_)
  191. typedef long fpos_t;
  192. #else /* !defined(_M_MPPC) && !defined(_M_M68K) */
  193. #if !__STDC__ && _INTEGRAL_MAX_BITS >= 64
  194. typedef __int64 fpos_t;
  195. #else
  196. typedef struct fpos_t {
  197. unsigned int lopart;
  198. int hipart;
  199. } fpos_t;
  200. #endif
  201. #endif /* defined(_M_MPPC) || defined(_M_68K) */
  202. #define _FPOS_T_DEFINED
  203. #endif
  204. #define stdin (&_iob[0])
  205. #define stdout (&_iob[1])
  206. #define stderr (&_iob[2])
  207. #define _IOREAD 0x0001
  208. #define _IOWRT 0x0002
  209. #define _IOFBF 0x0000
  210. #define _IOLBF 0x0040
  211. #define _IONBF 0x0004
  212. #define _IOMYBUF 0x0008
  213. #define _IOEOF 0x0010
  214. #define _IOERR 0x0020
  215. #define _IOSTRG 0x0040
  216. #define _IORW 0x0080
  217. #ifdef _POSIX_
  218. #define _IOAPPEND 0x0200
  219. #endif
  220. /* Function prototypes */
  221. #ifndef _STDIO_DEFINED
  222. _CRTIMP int __cdecl _filbuf(FILE *);
  223. _CRTIMP int __cdecl _flsbuf(int, FILE *);
  224. #ifdef _POSIX_
  225. _CRTIMP FILE * __cdecl _fsopen(const char *, const char *);
  226. #else
  227. _CRTIMP FILE * __cdecl _fsopen(const char *, const char *, int);
  228. #endif
  229. _CRTIMP void __cdecl clearerr(FILE *);
  230. _CRTIMP int __cdecl fclose(FILE *);
  231. _CRTIMP int __cdecl _fcloseall(void);
  232. #ifdef _POSIX_
  233. _CRTIMP FILE * __cdecl fdopen(int, const char *);
  234. #else
  235. _CRTIMP FILE * __cdecl _fdopen(int, const char *);
  236. #endif
  237. _CRTIMP int __cdecl feof(FILE *);
  238. _CRTIMP int __cdecl ferror(FILE *);
  239. _CRTIMP int __cdecl fflush(FILE *);
  240. _CRTIMP int __cdecl fgetc(FILE *);
  241. _CRTIMP int __cdecl _fgetchar(void);
  242. _CRTIMP int __cdecl fgetpos(FILE *, fpos_t *);
  243. _CRTIMP char * __cdecl fgets(char *, int, FILE *);
  244. #ifdef _POSIX_
  245. _CRTIMP int __cdecl fileno(FILE *);
  246. #else
  247. _CRTIMP int __cdecl _fileno(FILE *);
  248. #endif
  249. _CRTIMP int __cdecl _flushall(void);
  250. _CRTIMP FILE * __cdecl fopen(const char *, const char *);
  251. _CRTIMP int __cdecl fprintf(FILE *, const char *, ...);
  252. _CRTIMP int __cdecl fputc(int, FILE *);
  253. _CRTIMP int __cdecl _fputchar(int);
  254. _CRTIMP int __cdecl fputs(const char *, FILE *);
  255. _CRTIMP size_t __cdecl fread(void *, size_t, size_t, FILE *);
  256. _CRTIMP FILE * __cdecl freopen(const char *, const char *, FILE *);
  257. _CRTIMP int __cdecl fscanf(FILE *, const char *, ...);
  258. _CRTIMP int __cdecl fsetpos(FILE *, const fpos_t *);
  259. _CRTIMP int __cdecl fseek(FILE *, long, int);
  260. _CRTIMP long __cdecl ftell(FILE *);
  261. _CRTIMP size_t __cdecl fwrite(const void *, size_t, size_t, FILE *);
  262. _CRTIMP int __cdecl getc(FILE *);
  263. _CRTIMP int __cdecl getchar(void);
  264. _CRTIMP char * __cdecl gets(char *);
  265. _CRTIMP int __cdecl _getw(FILE *);
  266. _CRTIMP void __cdecl perror(const char *);
  267. _CRTIMP int __cdecl _pclose(FILE *);
  268. _CRTIMP FILE * __cdecl _popen(const char *, const char *);
  269. _CRTIMP int __cdecl printf(const char *, ...);
  270. _CRTIMP int __cdecl putc(int, FILE *);
  271. _CRTIMP int __cdecl putchar(int);
  272. _CRTIMP int __cdecl puts(const char *);
  273. _CRTIMP int __cdecl _putw(int, FILE *);
  274. _CRTIMP int __cdecl remove(const char *);
  275. _CRTIMP int __cdecl rename(const char *, const char *);
  276. _CRTIMP void __cdecl rewind(FILE *);
  277. _CRTIMP int __cdecl _rmtmp(void);
  278. _CRTIMP int __cdecl scanf(const char *, ...);
  279. _CRTIMP void __cdecl setbuf(FILE *, char *);
  280. _CRTIMP int __cdecl _setmaxstdio(int);
  281. _CRTIMP int __cdecl setvbuf(FILE *, char *, int, size_t);
  282. _CRTIMP int __cdecl _snprintf(char *, size_t, const char *, ...);
  283. _CRTIMP int __cdecl sprintf(char *, const char *, ...);
  284. _CRTIMP int __cdecl sscanf(const char *, const char *, ...);
  285. _CRTIMP char * __cdecl _tempnam(const char *, const char *);
  286. _CRTIMP FILE * __cdecl tmpfile(void);
  287. _CRTIMP char * __cdecl tmpnam(char *);
  288. _CRTIMP int __cdecl ungetc(int, FILE *);
  289. _CRTIMP int __cdecl _unlink(const char *);
  290. _CRTIMP int __cdecl vfprintf(FILE *, const char *, va_list);
  291. _CRTIMP int __cdecl vprintf(const char *, va_list);
  292. _CRTIMP int __cdecl _vsnprintf(char *, size_t, const char *, va_list);
  293. _CRTIMP int __cdecl vsprintf(char *, const char *, va_list);
  294. #ifndef _MAC
  295. #ifndef _WSTDIO_DEFINED
  296. /* wide function prototypes, also declared in wchar.h */
  297. #ifndef WEOF
  298. #define WEOF (wint_t)(0xFFFF)
  299. #endif
  300. #ifdef _POSIX_
  301. _CRTIMP FILE * __cdecl _wfsopen(const wchar_t *, const wchar_t *);
  302. #else
  303. _CRTIMP FILE * __cdecl _wfsopen(const wchar_t *, const wchar_t *, int);
  304. #endif
  305. _CRTIMP wint_t __cdecl fgetwc(FILE *);
  306. _CRTIMP wint_t __cdecl _fgetwchar(void);
  307. _CRTIMP wint_t __cdecl fputwc(wint_t, FILE *);
  308. _CRTIMP wint_t __cdecl _fputwchar(wint_t);
  309. _CRTIMP wint_t __cdecl getwc(FILE *);
  310. _CRTIMP wint_t __cdecl getwchar(void);
  311. _CRTIMP wint_t __cdecl putwc(wint_t, FILE *);
  312. _CRTIMP wint_t __cdecl putwchar(wint_t);
  313. _CRTIMP wint_t __cdecl ungetwc(wint_t, FILE *);
  314. _CRTIMP wchar_t * __cdecl fgetws(wchar_t *, int, FILE *);
  315. _CRTIMP int __cdecl fputws(const wchar_t *, FILE *);
  316. _CRTIMP wchar_t * __cdecl _getws(wchar_t *);
  317. _CRTIMP int __cdecl _putws(const wchar_t *);
  318. _CRTIMP int __cdecl fwprintf(FILE *, const wchar_t *, ...);
  319. _CRTIMP int __cdecl wprintf(const wchar_t *, ...);
  320. _CRTIMP int __cdecl _snwprintf(wchar_t *, size_t, const wchar_t *, ...);
  321. _CRTIMP int __cdecl swprintf(wchar_t *, const wchar_t *, ...);
  322. _CRTIMP int __cdecl vfwprintf(FILE *, const wchar_t *, va_list);
  323. _CRTIMP int __cdecl vwprintf(const wchar_t *, va_list);
  324. _CRTIMP int __cdecl _vsnwprintf(wchar_t *, size_t, const wchar_t *, va_list);
  325. _CRTIMP int __cdecl vswprintf(wchar_t *, const wchar_t *, va_list);
  326. _CRTIMP int __cdecl fwscanf(FILE *, const wchar_t *, ...);
  327. _CRTIMP int __cdecl swscanf(const wchar_t *, const wchar_t *, ...);
  328. _CRTIMP int __cdecl wscanf(const wchar_t *, ...);
  329. #define getwchar() fgetwc(stdin)
  330. #define putwchar(_c) fputwc((_c),stdout)
  331. #define getwc(_stm) fgetwc(_stm)
  332. #define putwc(_c,_stm) fputwc(_c,_stm)
  333. _CRTIMP FILE * __cdecl _wfdopen(int, const wchar_t *);
  334. _CRTIMP FILE * __cdecl _wfopen(const wchar_t *, const wchar_t *);
  335. _CRTIMP FILE * __cdecl _wfreopen(const wchar_t *, const wchar_t *, FILE *);
  336. _CRTIMP void __cdecl _wperror(const wchar_t *);
  337. _CRTIMP FILE * __cdecl _wpopen(const wchar_t *, const wchar_t *);
  338. _CRTIMP int __cdecl _wremove(const wchar_t *);
  339. _CRTIMP wchar_t * __cdecl _wtempnam(const wchar_t *, const wchar_t *);
  340. _CRTIMP wchar_t * __cdecl _wtmpnam(wchar_t *);
  341. #define _WSTDIO_DEFINED
  342. #endif /* _WSTDIO_DEFINED */
  343. #endif /* ndef _MAC */
  344. #define _STDIO_DEFINED
  345. #endif /* _STDIO_DEFINED */
  346. /* Macro definitions */
  347. #define feof(_stream) ((_stream)->_flag & _IOEOF)
  348. #define ferror(_stream) ((_stream)->_flag & _IOERR)
  349. #define _fileno(_stream) ((_stream)->_file)
  350. #define getc(_stream) (--(_stream)->_cnt >= 0 \
  351. ? 0xff & *(_stream)->_ptr++ : _filbuf(_stream))
  352. #define putc(_c,_stream) (--(_stream)->_cnt >= 0 \
  353. ? 0xff & (*(_stream)->_ptr++ = (char)(_c)) : _flsbuf((_c),(_stream)))
  354. #define getchar() getc(stdin)
  355. #define putchar(_c) putc((_c),stdout)
  356. #ifdef _MT
  357. #undef getc
  358. #undef putc
  359. #undef getchar
  360. #undef putchar
  361. #endif
  362. #if !__STDC__ && !defined(_POSIX_)
  363. /* Non-ANSI names for compatibility */
  364. #define P_tmpdir _P_tmpdir
  365. #define SYS_OPEN _SYS_OPEN
  366. #ifdef _NTSDK
  367. #define fcloseall _fcloseall
  368. #define fdopen _fdopen
  369. #define fgetchar _fgetchar
  370. #define fileno _fileno
  371. #define flushall _flushall
  372. #define fputchar _fputchar
  373. #define getw _getw
  374. #define putw _putw
  375. #define rmtmp _rmtmp
  376. #define tempnam _tempnam
  377. #define unlink _unlink
  378. #else /* ndef _NTSDK */
  379. _CRTIMP int __cdecl fcloseall(void);
  380. _CRTIMP FILE * __cdecl fdopen(int, const char *);
  381. _CRTIMP int __cdecl fgetchar(void);
  382. _CRTIMP int __cdecl fileno(FILE *);
  383. _CRTIMP int __cdecl flushall(void);
  384. _CRTIMP int __cdecl fputchar(int);
  385. _CRTIMP int __cdecl getw(FILE *);
  386. _CRTIMP int __cdecl putw(int, FILE *);
  387. _CRTIMP int __cdecl rmtmp(void);
  388. _CRTIMP char * __cdecl tempnam(const char *, const char *);
  389. _CRTIMP int __cdecl unlink(const char *);
  390. #endif /* _NTSDK */
  391. #endif /* __STDC__ */
  392. #ifdef __cplusplus
  393. }
  394. #endif
  395. #ifdef _MSC_VER
  396. #pragma pack(pop)
  397. #endif /* _MSC_VER */
  398. #endif /* _INC_STDIO */