home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 2.ddi / INCLUDE.ZIP / STDIO.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  7.9 KB  |  246 lines

  1. /*  stdio.h
  2.  
  3.     Definitions for stream input/output.
  4.  
  5.         Copyright (c) Borland International 1987,1988,1990,1991
  6.     All Rights Reserved.
  7. */
  8.  
  9. #ifndef __STDIO_H
  10. #define __STDIO_H
  11.  
  12. #ifdef __DLL__
  13. #define _FAR far
  14. #else
  15. #define _FAR
  16. #endif
  17.  
  18. #if __STDC__
  19. #define _Cdecl
  20. #else
  21. #define _Cdecl  cdecl
  22. #endif
  23.  
  24. #ifndef __PAS__
  25. #define _CType _Cdecl
  26. #else
  27. #define _CType pascal
  28. #endif
  29.  
  30. #ifndef _SIZE_T
  31. #define _SIZE_T
  32. typedef unsigned size_t;
  33. #endif
  34.  
  35. #ifndef NULL
  36. #if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
  37. #define NULL    0
  38. #else
  39. #define NULL    0L
  40. #endif
  41. #endif
  42.  
  43. /* Definition of the file position type
  44. */
  45. typedef long    fpos_t;
  46.  
  47. /* Definition of the control structure for streams
  48. */
  49. typedef struct  {
  50.         short           level;          /* fill/empty level of buffer */
  51.         unsigned        flags;          /* File status flags          */
  52.         char            fd;             /* File descriptor            */
  53.         unsigned char   hold;           /* Ungetc char if no buffer   */
  54.         short           bsize;          /* Buffer size                */
  55.         unsigned char   _FAR *buffer;   /* Data transfer buffer       */
  56.         unsigned char   _FAR *curp;     /* Current active pointer     */
  57.         unsigned        istemp;         /* Temporary file indicator   */
  58.         short           token;          /* Used for validity checking */
  59. }       FILE;                           /* This is the FILE object    */
  60.  
  61. /* Bufferisation type to be used as 3rd argument for "setvbuf" function
  62. */
  63. #define _IOFBF  0
  64. #define _IOLBF  1
  65. #define _IONBF  2
  66.  
  67. /*  "flags" bits definitions
  68. */
  69. #define _F_RDWR 0x0003                  /* Read/write flag       */
  70. #define _F_READ 0x0001                  /* Read only file        */
  71. #define _F_WRIT 0x0002                  /* Write only file       */
  72. #define _F_BUF  0x0004                  /* Malloc'ed Buffer data */
  73. #define _F_LBUF 0x0008                  /* line-buffered file    */
  74. #define _F_ERR  0x0010                  /* Error indicator       */
  75. #define _F_EOF  0x0020                  /* EOF indicator         */
  76. #define _F_BIN  0x0040                  /* Binary file indicator */
  77. #define _F_IN   0x0080                  /* Data is incoming      */
  78. #define _F_OUT  0x0100                  /* Data is outgoing      */
  79. #define _F_TERM 0x0200                  /* File is a terminal    */
  80.  
  81. /* End-of-file constant definition
  82. */
  83. #define EOF (-1)            /* End of file indicator */
  84.  
  85. /* Number of files that can be open simultaneously
  86. */
  87. #if __STDC__
  88. #define FOPEN_MAX 18        /* Able to have 18 files (20 - stdaux & stdprn) */
  89. #else
  90. #define FOPEN_MAX 20        /* Able to have 20 files */
  91. #define SYS_OPEN  20
  92. #endif
  93.  
  94. #define FILENAME_MAX 80
  95.  
  96. /* Default buffer size use by "setbuf" function
  97. */
  98. #define BUFSIZ  512         /* Buffer size for stdio */
  99.  
  100. /* Size of an arry large enough to hold a temporary file name string
  101. */
  102. #define L_ctermid   5       /* CON: plus null byte */
  103. #define L_tmpnam    13      /* tmpnam buffer size */
  104.  
  105. /* Constants to be used as 3rd argument for "fseek" function
  106. */
  107. #define SEEK_CUR    1
  108. #define SEEK_END    2
  109. #define SEEK_SET    0
  110.  
  111. /* Number of unique file names that shall be generated by "tmpnam" function
  112. */
  113. #define TMP_MAX     0xFFFF
  114.  
  115. /* Standard I/O predefined streams
  116. */
  117. extern  FILE    _Cdecl _streams[];
  118.  
  119. #define stdin   (&_streams[0])
  120. #define stdout  (&_streams[1])
  121. #define stderr  (&_streams[2])
  122.  
  123. #if !__STDC__
  124. #define stdaux  (&_streams[3])
  125. #define stdprn  (&_streams[4])
  126. #endif
  127.  
  128. #ifdef __cplusplus
  129. extern "C" {
  130. #endif
  131. void    _Cdecl clearerr(FILE _FAR *__stream);
  132. int     _Cdecl fclose(FILE _FAR *__stream);
  133. int     _Cdecl fflush(FILE _FAR *__stream);
  134. int     _Cdecl fgetc(FILE _FAR *__stream);
  135. int     _Cdecl fgetpos(FILE _FAR *__stream, fpos_t _FAR *__pos);
  136. char   _FAR *_Cdecl fgets(char _FAR *__s, int __n, FILE _FAR *__stream);
  137. FILE   _FAR *_Cdecl fopen(const char _FAR *__path, const char _FAR *__mode);
  138. int     _Cdecl fprintf(FILE _FAR *__stream, const char _FAR *__format, ...);
  139. int     _Cdecl fputc(int __c, FILE _FAR *__stream);
  140. int     _Cdecl fputs(const char _FAR *__s, FILE _FAR *__stream);
  141. size_t  _Cdecl fread(void _FAR *__ptr, size_t __size, size_t __n,
  142.                      FILE _FAR *__stream);
  143. FILE   _FAR *_Cdecl freopen(const char _FAR *__path, const char _FAR *__mode,
  144.                             FILE _FAR *__stream);
  145. int     _Cdecl fscanf(FILE _FAR *__stream, const char _FAR *__format, ...);
  146. int     _Cdecl fseek(FILE _FAR *__stream, long __offset, int __whence);
  147. int     _Cdecl fsetpos(FILE _FAR *__stream, const fpos_t _FAR *__pos);
  148. long    _Cdecl ftell(FILE _FAR *__stream);
  149. size_t  _Cdecl fwrite(const void _FAR *__ptr, size_t __size, size_t __n,
  150.                       FILE _FAR *__stream);
  151.  
  152. #if !defined( _Windows )
  153. char   _FAR *_Cdecl gets(char _FAR *__s);
  154. #endif
  155.  
  156. void    _Cdecl perror(const char _FAR *__s);
  157.  
  158. #if !defined( _Windows )
  159. int     _Cdecl printf(const char _FAR *__format, ...);
  160. int     _Cdecl puts(const char _FAR *__s);
  161. #endif
  162.  
  163. int     _CType remove(const char _FAR *__path);
  164. int     _Cdecl rename(const char _FAR *__oldname,const char _FAR *__newname);
  165. void    _Cdecl rewind(FILE _FAR *__stream);
  166.  
  167. #if !defined( _Windows )
  168. int     _Cdecl scanf(const char _FAR *__format, ...);
  169. #endif
  170.  
  171. void    _Cdecl setbuf(FILE _FAR *__stream, char _FAR *__buf);
  172. int     _Cdecl setvbuf(FILE _FAR *__stream, char _FAR *__buf,
  173.                        int __type, size_t __size);
  174. int     _Cdecl sprintf(char _FAR *__buffer, const char _FAR *__format, ...);
  175. int     _Cdecl sscanf(const char _FAR *__buffer,
  176.                       const char _FAR *__format, ...);
  177. char   _FAR *_Cdecl strerror(int __errnum);
  178. FILE   _FAR *_Cdecl tmpfile(void);
  179. char   _FAR *_Cdecl tmpnam(char _FAR *__s);
  180. int     _Cdecl ungetc(int __c, FILE _FAR *__stream);
  181. int     _Cdecl vfprintf(FILE _FAR *__stream, const char _FAR *__format,
  182.                         void _FAR *__arglist);
  183. int     _Cdecl vfscanf(FILE _FAR *__stream, const char _FAR *__format,
  184.                        void _FAR *__arglist);
  185.  
  186. #if !defined( _Windows )
  187. int     _CType vprintf(const char _FAR *__format, void _FAR *__arglist);
  188. int     _Cdecl vscanf(const char _FAR *__format, void _FAR *__arglist);
  189. #endif
  190.  
  191. int     _Cdecl vsprintf(char _FAR *__buffer, const char _FAR *__format,
  192.                         void _FAR *__arglist);
  193. int     _Cdecl vsscanf(const char _FAR *__buffer, const char _FAR *__format,
  194.                         void _FAR *__arglist);
  195. int     _CType unlink(const char _FAR *__path);
  196. int     _Cdecl getc(FILE _FAR *__fp);
  197.  
  198. #if !defined( _Windows )
  199. int     _Cdecl getchar(void);
  200. int     _Cdecl putchar(const int __c);
  201. #endif
  202.  
  203. int     _Cdecl putc(const int __c, FILE _FAR *__fp);
  204. int     _Cdecl feof(FILE _FAR *__fp);
  205. int     _Cdecl ferror(FILE _FAR *__fp);
  206.  
  207.  
  208. #if !__STDC__
  209. int     _Cdecl fcloseall(void);
  210. FILE   _FAR *_Cdecl fdopen(int __handle, char _FAR *__type);
  211. int     _Cdecl fgetchar(void);
  212. int     _Cdecl flushall(void);
  213. int     _Cdecl fputchar(int __c);
  214. int     _Cdecl getw(FILE _FAR *__stream);
  215. int     _Cdecl putw(int __w, FILE _FAR *__stream);
  216. char   _FAR *_Cdecl _strerror(const char _FAR *__s);
  217. #define fileno(f)       ((f)->fd)
  218. #endif
  219.  
  220. int      _Cdecl _fgetc(FILE _FAR *__stream);           /* used by getc() macro */
  221. int      _Cdecl _fputc(char __c, FILE _FAR *__stream); /* used by putc() macro */
  222. #ifdef  __cplusplus
  223. }
  224. #endif
  225.  
  226. /*  The following macros provide for common functions */
  227.  
  228. #define ferror(f)   ((f)->flags & _F_ERR)
  229. #define feof(f)     ((f)->flags & _F_EOF)
  230.  
  231. #define getc(f) \
  232.   ((--((f)->level) >= 0) ? (unsigned char)(*(f)->curp++) : \
  233.     _fgetc (f))
  234.  
  235. #define putc(c,f) \
  236.   ((++((f)->level) < 0) ? (unsigned char)(*(f)->curp++=(c)) : \
  237.     _fputc ((c),f))
  238.  
  239. #define getchar()  getc(stdin)
  240. #define putchar(c) putc((c), stdout)
  241.  
  242. #define ungetc(c,f) ungetc((c),f)   /* traditionally a macro */
  243.  
  244. #endif
  245.  
  246.