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.

448 lines
11 KiB

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