home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / DEV.Z / STDIO.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-08  |  13.3 KB  |  541 lines

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