home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / INC.PAK / STDIO.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  16KB  |  401 lines

  1. /*  stdio.h
  2.  
  3.     Definitions for stream input/output.
  4.  
  5. */
  6.  
  7. /*
  8.  *      C/C++ Run Time Library - Version 6.5
  9.  *
  10.  *      Copyright (c) 1987, 1994 by Borland International
  11.  *      All Rights Reserved.
  12.  *
  13.  */
  14.  
  15. #ifndef __STDIO_H
  16. #define __STDIO_H
  17.  
  18. #if !defined(___DEFS_H)
  19. #include <_defs.h>
  20. #endif
  21.  
  22. #if !defined(___NFILE_H)
  23. #include <_nfile.h>
  24. #endif
  25.  
  26. #ifndef NULL
  27. #include <_null.h>
  28. #endif
  29.  
  30.  
  31. #if !defined(RC_INVOKED)
  32.  
  33. #if defined(__STDC__)
  34. #pragma warn -nak
  35. #endif
  36.  
  37. #pragma option -a-
  38.  
  39. #endif  /* !RC_INVOKED */
  40.  
  41.  
  42. #ifndef _SIZE_T
  43. #define _SIZE_T
  44. typedef unsigned size_t;
  45. #endif
  46.  
  47. /* Definition of the file position type
  48. */
  49. typedef long    fpos_t;
  50.  
  51. /* An external reference to _floatconvert (using #pragma extref _floatconvert)
  52.  * forces floating point format conversions to be linked.
  53.  */
  54. extern int _floatconvert;
  55.  
  56. /* Bufferisation type to be used as 3rd argument for "setvbuf" function
  57. */
  58. #define _IOFBF  0
  59. #define _IOLBF  1
  60. #define _IONBF  2
  61.  
  62. /*  "flags" bits definitions
  63. */
  64. #define _F_RDWR 0x0003                  /* Read/write flag       */
  65. #define _F_READ 0x0001                  /* Read only file        */
  66. #define _F_WRIT 0x0002                  /* Write only file       */
  67. #define _F_BUF  0x0004                  /* Malloc'ed Buffer data */
  68. #define _F_LBUF 0x0008                  /* line-buffered file    */
  69. #define _F_ERR  0x0010                  /* Error indicator       */
  70. #define _F_EOF  0x0020                  /* EOF indicator         */
  71. #define _F_BIN  0x0040                  /* Binary file indicator */
  72. #define _F_IN   0x0080                  /* Data is incoming      */
  73. #define _F_OUT  0x0100                  /* Data is outgoing      */
  74. #define _F_TERM 0x0200                  /* File is a terminal    */
  75.  
  76. /* End-of-file constant definition
  77. */
  78. #define EOF (-1)            /* End of file indicator */
  79.  
  80. /* Default buffer size use by "setbuf" function
  81. */
  82. #define BUFSIZ  512         /* Buffer size for stdio */
  83.  
  84. /* Size of an arry large enough to hold a temporary file name string
  85. */
  86. #define L_ctermid   5       /* CON: plus null byte */
  87. #define P_tmpdir    ""      /* temporary directory */
  88. #define L_tmpnam    13      /* tmpnam buffer size */
  89.  
  90. /* Constants to be used as 3rd argument for "fseek" function
  91. */
  92. #define SEEK_CUR    1
  93. #define SEEK_END    2
  94. #define SEEK_SET    0
  95.  
  96. /* Number of unique file names that shall be generated by "tmpnam" function
  97. */
  98. #define TMP_MAX     0xFFFF
  99.  
  100.  
  101. #if !defined(__FLAT__)
  102.  
  103. /* Definition of the control structure for streams
  104. */
  105. typedef struct  {
  106.         int             level;          /* fill/empty level of buffer */
  107.         unsigned        flags;          /* File status flags          */
  108.         char            fd;             /* File descriptor            */
  109.         unsigned char   hold;           /* Ungetc char if no buffer   */
  110.         int             bsize;          /* Buffer size                */
  111.         unsigned char   _FAR *buffer;   /* Data transfer buffer       */
  112.         unsigned char   _FAR *curp;     /* Current active pointer     */
  113.         unsigned        istemp;         /* Temporary file indicator   */
  114.         short           token;          /* Used for validity checking */
  115. }       FILE;                           /* This is the FILE object    */
  116.  
  117. /* Number of files that can be open simultaneously
  118. */
  119. #if defined(__STDC__)
  120. #define FOPEN_MAX (_NFILE_ - 2) /* (_NFILE_ - stdaux & stdprn) */
  121. #else
  122. #define FOPEN_MAX (_NFILE_)     /* Able to have 20 files */
  123. #define SYS_OPEN  (_NFILE_)
  124. #endif
  125.  
  126. #define FILENAME_MAX 80
  127.  
  128. /* Standard I/O predefined streams
  129. */
  130.  
  131. #if !defined( _RTLDLL )
  132. extern  FILE    _RTLENTRY _streams[];
  133. extern  unsigned    _RTLENTRY _nfile;
  134.  
  135. #define stdin   (&_streams[0])
  136. #define stdout  (&_streams[1])
  137. #define stderr  (&_streams[2])
  138. #define stdaux  (&_streams[3])
  139. #define stdprn  (&_streams[4])
  140.  
  141. #else
  142.  
  143. #ifdef __cplusplus
  144. extern "C" {
  145. #endif
  146. FILE far * far _RTLENTRY __getStream(int);
  147. #ifdef __cplusplus
  148. }
  149. #endif
  150.  
  151. #define stdin   __getStream(0)
  152. #define stdout  __getStream(1)
  153. #define stderr  __getStream(2)
  154.  
  155. #endif  /* _RTLDLL  */
  156.  
  157. #ifdef __cplusplus
  158. extern "C" {
  159. #endif
  160. void    _RTLENTRY          clearerr(FILE _FAR *__stream);
  161. int     _RTLENTRY _EXPFUNC fclose(FILE _FAR *__stream);
  162. int     _RTLENTRY _EXPFUNC fflush(FILE _FAR *__stream);
  163. int     _RTLENTRY _EXPFUNC fgetc(FILE _FAR *__stream);
  164. int     _RTLENTRY          fgetpos(FILE _FAR *__stream, fpos_t _FAR *__pos);
  165. char   _FAR *_RTLENTRY _EXPFUNC fgets(char _FAR *__s, int __n, FILE _FAR *__stream);
  166. FILE   _FAR *_RTLENTRY _EXPFUNC fopen(const char _FAR *__path, const char _FAR *__mode);
  167. int     _RTLENTRY _EXPFUNC fprintf(FILE _FAR *__stream, const char _FAR *__format, ...);
  168. int     _RTLENTRY _EXPFUNC fputc(int __c, FILE _FAR *__stream);
  169. int     _RTLENTRY _EXPFUNC fputs(const char _FAR *__s, FILE _FAR *__stream);
  170. size_t  _RTLENTRY _EXPFUNC fread(void _FAR *__ptr, size_t __size, size_t __n,
  171.                      FILE _FAR *__stream);
  172. FILE   _FAR *_RTLENTRY _EXPFUNC freopen(const char _FAR *__path, const char _FAR *__mode,
  173.                             FILE _FAR *__stream);
  174. int     _RTLENTRY _EXPFUNC fscanf(FILE _FAR *__stream, const char _FAR *__format, ...);
  175. int     _RTLENTRY _EXPFUNC fseek(FILE _FAR *__stream, long __offset, int __whence);
  176. int     _RTLENTRY          fsetpos(FILE _FAR *__stream, const fpos_t _FAR *__pos);
  177. long    _RTLENTRY _EXPFUNC ftell(FILE _FAR *__stream);
  178. size_t  _RTLENTRY _EXPFUNC fwrite(const void _FAR *__ptr, size_t __size, size_t __n,
  179.                       FILE _FAR *__stream);
  180. char   _FAR *_RTLENTRY     gets(char _FAR *__s);
  181. void    _RTLENTRY          perror(const char _FAR *__s);
  182. int     _RTLENTRY          printf(const char _FAR *__format, ...);
  183. int     _RTLENTRY          puts(const char _FAR *__s);
  184. int     _RTLENTRYF         remove(const char _FAR *__path);
  185. int     _RTLENTRYF _EXPFUNC rename(const char _FAR *__oldname,const char _FAR *__newname);
  186. void    _RTLENTRY _EXPFUNC rewind(FILE _FAR *__stream);
  187. int     _RTLENTRY          scanf(const char _FAR *__format, ...);
  188. void    _RTLENTRY          setbuf(FILE _FAR *__stream, char _FAR *__buf);
  189. int     _RTLENTRY _EXPFUNC setvbuf(FILE _FAR *__stream, char _FAR *__buf,
  190.                                    int __type, size_t __size);
  191. int     _RTLENTRY _EXPFUNC sprintf(char _FAR *__buffer, const char _FAR *__format, ...);
  192. int     _RTLENTRY _EXPFUNC sscanf(const char _FAR *__buffer,
  193.                                   const char _FAR *__format, ...);
  194. char   _FAR *_RTLENTRY _EXPFUNC strerror(int __errnum);
  195. FILE   _FAR *_RTLENTRY _EXPFUNC tmpfile(void);
  196. char   _FAR *_RTLENTRY _EXPFUNC tmpnam(char _FAR *__s);
  197. int     _RTLENTRY _EXPFUNC ungetc(int __c, FILE _FAR *__stream);
  198. int     _RTLENTRY _EXPFUNC vfprintf(FILE _FAR *__stream, const char _FAR *__format,
  199.                                     void _FAR *__arglist);
  200. int     _RTLENTRY _EXPFUNC vfscanf(FILE _FAR *__stream, const char _FAR *__format,
  201.                                    void _FAR *__arglist);
  202. int     _RTLENTRYF         vprintf(const char _FAR *__format, void _FAR *__arglist);
  203. int     _RTLENTRY          vscanf(const char _FAR *__format, void _FAR *__arglist);
  204. int     _RTLENTRY _EXPFUNC vsprintf(char _FAR *__buffer, const char _FAR *__format,
  205.                                     void _FAR *__arglist);
  206. int     _RTLENTRY _EXPFUNC vsscanf(const char _FAR *__buffer, const char _FAR *__format,
  207.                                    void _FAR *__arglist);
  208. int     _RTLENTRYF         unlink(const char _FAR *__path);
  209. int     _RTLENTRY          getc(FILE _FAR *__fp);
  210.  
  211. int     _RTLENTRY          getchar(void);
  212. int     _RTLENTRY          putchar(const int __c);
  213.  
  214. int     _RTLENTRY          putc(const int __c, FILE _FAR *__fp);
  215. int     _RTLENTRY          feof(FILE _FAR *__fp);
  216. int     _RTLENTRY          ferror(FILE _FAR *__fp);
  217.  
  218. int     _RTLENTRY _EXPFUNC fcloseall(void);
  219. FILE    _FAR *_RTLENTRY _EXPFUNC fdopen(int __handle, char _FAR *__type);
  220. int     _RTLENTRY _EXPFUNC fgetchar(void);
  221. int     _RTLENTRY _EXPFUNC flushall(void);
  222. int     _RTLENTRY _EXPFUNC fputchar(int __c);
  223. FILE    _FAR * _RTLENTRY   _fsopen (const char _FAR *__path, const char _FAR *__mode,
  224.                   int __shflag);
  225. int     _RTLENTRY          getw(FILE _FAR *__stream);
  226. int     _RTLENTRY          putw(int __w, FILE _FAR *__stream);
  227. int     _RTLENTRY          rmtmp(void);
  228. char    _FAR * _RTLENTRY _EXPFUNC _strerror(const char _FAR *__s);
  229. char    _FAR * _RTLENTRY _EXPFUNC tempnam(char _FAR *__dir, char _FAR *__pfx);
  230.  
  231. #define fileno(f)       ((f)->fd)
  232.  
  233. int      _RTLENTRY _EXPFUNC _fgetc(FILE _FAR *__stream);           /* used by getc() macro */
  234. int      _RTLENTRY _EXPFUNC _fputc(char __c, FILE _FAR *__stream); /* used by putc() macro */
  235. void     _RTLENTRY _InitEasyWin(void);  /* Initialization call for Easy Windows */
  236.  
  237. #ifdef  __cplusplus
  238. }
  239. #endif
  240.  
  241. #else    /* defined __FLAT__ */
  242.  
  243. /* Definition of the control structure for streams
  244. */
  245. typedef struct  {
  246.         unsigned char  *curp;       /* Current active pointer     */
  247.         unsigned char  *buffer;     /* Data transfer buffer       */
  248.         int             level;      /* fill/empty level of buffer */
  249.         int             bsize;      /* Buffer size                */
  250.         unsigned short  istemp;     /* Temporary file indicator   */
  251.         unsigned short  flags;      /* File status flags          */
  252.         short           token;      /* Used for validity checking */
  253.         char            fd;         /* File descriptor            */
  254.         unsigned char   hold;       /* Ungetc char if no buffer   */
  255. }       FILE;                       /* This is the FILE object    */
  256.  
  257. /* Number of files that can be open simultaneously
  258. */
  259. #if __STDC__
  260. #define FOPEN_MAX (_NFILE_)
  261. #else
  262. #define FOPEN_MAX (_NFILE_)
  263. #define SYS_OPEN  (_NFILE_)
  264. #endif
  265.  
  266. #define FILENAME_MAX 260
  267.  
  268. /* Standard I/O predefined streams
  269. */
  270. extern  FILE        _RTLENTRY _EXPDATA _streams[];
  271. extern  unsigned    _RTLENTRY _EXPDATA _nfile;
  272.  
  273. #define stdin   (&_streams[0])
  274. #define stdout  (&_streams[1])
  275. #define stderr  (&_streams[2])
  276.  
  277. #ifdef __cplusplus
  278. extern "C" {
  279. #endif
  280. void    _RTLENTRY _EXPFUNC clearerr(FILE * __stream);
  281. int     _RTLENTRY _EXPFUNC fclose(FILE * __stream);
  282. int     _RTLENTRY _EXPFUNC fflush(FILE * __stream);
  283. int     _RTLENTRY _EXPFUNC fgetc(FILE * __stream);
  284. int     _RTLENTRY _EXPFUNC fgetpos(FILE * __stream, fpos_t*__pos);
  285. char  * _RTLENTRY _EXPFUNC fgets(char * __s, int __n, FILE * __stream);
  286. FILE  * _RTLENTRY _EXPFUNC fopen(const char * __path, const char * __mode);
  287. int     _RTLENTRY _EXPFUNC fprintf(FILE * __stream, const char * __format, ...);
  288. int     _RTLENTRY _EXPFUNC fputc(int __c, FILE * __stream);
  289. int     _RTLENTRY _EXPFUNC fputs(const char * __s, FILE * __stream);
  290. size_t  _RTLENTRY _EXPFUNC fread(void * __ptr, size_t __size, size_t __n,
  291.                                  FILE * __stream);
  292. FILE  * _RTLENTRY _EXPFUNC freopen(const char * __path, const char * __mode,
  293.                                    FILE * __stream);
  294. int     _RTLENTRY _EXPFUNC fscanf(FILE * __stream, const char * __format, ...);
  295. int     _RTLENTRY _EXPFUNC fseek(FILE * __stream, long __offset, int __whence);
  296. int     _RTLENTRY _EXPFUNC fsetpos(FILE * __stream, const fpos_t*__pos);
  297. long    _RTLENTRY _EXPFUNC ftell(FILE * __stream);
  298. size_t  _RTLENTRY _EXPFUNC fwrite(const void * __ptr, size_t __size, size_t __n,
  299.                             FILE * __stream);
  300. char  * _RTLENTRY _EXPFUNC gets(char * __s);
  301.  
  302. #if defined(__OS2__) || defined(__WIN32__)
  303. int     _RTLENTRY _EXPFUNC _pclose(FILE *__stream);
  304. #endif
  305.  
  306. void    _RTLENTRY _EXPFUNC perror(const char * __s);
  307.  
  308. #if defined(__OS2__) || defined(__WIN32__)
  309. FILE *  _RTLENTRY _EXPFUNC _popen(const char * __command, const char * __mode);
  310. #endif
  311.  
  312. int     _RTLENTRY _EXPFUNC printf(const char * __format, ...);
  313. int     _RTLENTRY _EXPFUNC puts(const char * __s);
  314.  
  315. int     _RTLENTRYF _EXPFUNC remove(const char * __path);
  316. int     _RTLENTRYF _EXPFUNC rename(const char * __oldname,const char * __newname);
  317. void    _RTLENTRY  _EXPFUNC rewind(FILE * __stream);
  318. int     _RTLENTRY  _EXPFUNC scanf(const char * __format, ...);
  319. void    _RTLENTRY  _EXPFUNC setbuf(FILE * __stream, char * __buf);
  320. int     _RTLENTRY  _EXPFUNC setvbuf(FILE * __stream, char * __buf,
  321.                                     int __type, size_t __size);
  322. int     _RTLENTRY  _EXPFUNC sprintf(char * __buffer, const char * __format, ...);
  323. int     _RTLENTRY  _EXPFUNC sscanf(const char * __buffer,
  324.                                    const char * __format, ...);
  325. char  * _RTLENTRY _EXPFUNC strerror(int __errnum);
  326. FILE  * _RTLENTRY _EXPFUNC tmpfile(void);
  327. char  * _RTLENTRY _EXPFUNC tmpnam(char * __s);
  328. int     _RTLENTRY _EXPFUNC ungetc(int __c, FILE * __stream);
  329. int     _RTLENTRY _EXPFUNC vfprintf(FILE * __stream, const char * __format,
  330.                             void * __arglist);
  331. int     _RTLENTRY _EXPFUNC vfscanf(FILE * __stream, const char * __format,
  332.                             void * __arglist);
  333. int     _RTLENTRYF _EXPFUNC vprintf(const char * __format, void * __arglist);
  334. int     _RTLENTRY _EXPFUNC vscanf(const char * __format, void * __arglist);
  335. int     _RTLENTRY _EXPFUNC vsprintf(char * __buffer, const char * __format,
  336.                         void * __arglist);
  337. int     _RTLENTRY _EXPFUNC vsscanf(const char * __buffer, const char * __format,
  338.                         void * __arglist);
  339. int     _RTLENTRYF _EXPFUNC unlink(const char * __path);
  340.  
  341. int     _RTLENTRY _EXPFUNC getc(FILE * __fp);
  342. int     _RTLENTRY _EXPFUNC getchar(void);
  343. int     _RTLENTRY _EXPFUNC putchar(const int __c);
  344. int     _RTLENTRY _EXPFUNC putc(const int __c, FILE * __fp);
  345. int     _RTLENTRY _EXPFUNC feof(FILE * __fp);
  346. int     _RTLENTRY _EXPFUNC ferror(FILE * __fp);
  347.  
  348. int     _RTLENTRY _EXPFUNC fcloseall(void);
  349. FILE  * _RTLENTRY _EXPFUNC fdopen(int __handle, char * __type);
  350. int     _RTLENTRY _EXPFUNC fgetchar(void);
  351. int     _RTLENTRY _EXPFUNC flushall(void);
  352. int     _RTLENTRY _EXPFUNC fputchar(int __c);
  353. FILE  * _RTLENTRY _EXPFUNC _fsopen (const char * __path, const char * __mode,
  354.                               int __shflag);
  355. int     _RTLENTRY _EXPFUNC getw(FILE * __stream);
  356. int     _RTLENTRY _EXPFUNC putw(int __w, FILE * __stream);
  357. int     _RTLENTRY _EXPFUNC rmtmp(void);
  358. char  * _RTLENTRY _EXPFUNC _strerror(const char * __s);
  359. char  * _RTLENTRY _EXPFUNC tempnam(char * __dir, char * __pfx);
  360. #define fileno(f)       ((f)->fd)
  361.  
  362. int      _RTLENTRY _EXPFUNC _fgetc(FILE * __stream);           /* used by getc() macro */
  363. int      _RTLENTRY _EXPFUNC _fputc(char __c, FILE * __stream); /* used by putc() macro */
  364. #ifdef  __cplusplus
  365. }
  366. #endif
  367.  
  368. #endif  /* __FLAT__ */
  369.  
  370. /*  The following macros provide for common functions */
  371.  
  372. #define ferror(f)   ((f)->flags & _F_ERR)
  373. #define feof(f)     ((f)->flags & _F_EOF)
  374.  
  375. #define getc(f) \
  376.   ((--((f)->level) >= 0) ? (unsigned char)(*(f)->curp++) : \
  377.     _fgetc (f))
  378.  
  379. #define putc(c,f) \
  380.   ((++((f)->level) < 0) ? (unsigned char)(*(f)->curp++=(c)) : \
  381.     _fputc ((c),f))
  382.  
  383. #define getchar()  getc(stdin)
  384. #define putchar(c) putc((c), stdout)
  385.  
  386. #define ungetc(c,f) ungetc((c),f)   /* traditionally a macro */
  387.  
  388.  
  389. #if !defined(RC_INVOKED)
  390.  
  391. #pragma option -a. /* restore default packing */
  392.  
  393. #if defined(__STDC__)
  394. #pragma warn .nak
  395. #endif
  396.  
  397. #endif  /* !RC_INVOKED */
  398.  
  399.  
  400. #endif  /* __STDIO_H */
  401.