home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / stdio.h < prev    next >
C/C++ Source or Header  |  1998-06-16  |  12KB  |  473 lines

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