home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c220 / 4.ddi / INC / STDIO.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-16  |  7.6 KB  |  228 lines

  1. /*
  2.  *   stdio.h -- ANSI 
  3.  *
  4.  *   Standard input/output facilities.
  5.  *
  6.  *           Copyright (c) 1990, MetaWare Incorporated
  7.  */
  8.  
  9. #ifndef _STDIO_H
  10. #define _STDIO_H
  11.  
  12. #define BUFSIZ      (512)
  13. #define BUFSIZE   (BUFSIZ)
  14. #define EOF      (-1)
  15. #define NULL      ((void *)0)
  16. #ifndef _SIZE_T_DEFINED
  17. #define _SIZE_T_DEFINED
  18. typedef unsigned int size_t;
  19. #endif
  20.  
  21. #include <stdarg.h>
  22.  
  23. typedef long fpos_t;
  24. #define FOPEN_MAX  (25)      /* Maximum number of open files */
  25. #define SYS_OPEN (25)
  26. #define FILENAME_MAX  (128)     /* Recommended size for file name buffer. */
  27.  
  28. /* Elements of the File_flags set:    */
  29. #define _BUFFERED    (0x01)
  30.         /* Later ANSI additions: */
  31.         #define _IOFBF _BUFFERED
  32.         #define _IOLBF _BUFFERED        /* Line-buffered not supported yet. */
  33.         #define _IONBF 0                /* No bits. */
  34. #define _READING    (0x02)
  35. #define _WRITING    (0x04)
  36. #define _APPENDING    (0x08)
  37. #define _END_OF_FILE    (0x10)
  38. #define _ERROR        (0x20)
  39. #define _FORMATTED_TEXT (0x40)
  40. #define _UNINITIALIZED    (0x80)
  41. #define _SETBUF_BUFFER    (0x100)
  42. #define _TEMP_FILE    (0x200)
  43. #define _CTRL_Z     (0x400)
  44. #define _WROTE_LAST    (0x800)
  45. typedef short int File_flags;
  46. /* type  File_flags = set of
  47.    (Buffered, Reading, Writing, Appending, End_of_file,
  48.     Error, Formatted_text, Uninitialized, Setbuf_buffer, Temp_file);
  49. */
  50. typedef char Buffer[BUFSIZ];
  51.  
  52. typedef struct {
  53.       char * _ptr;         /* Pointer to current byte in buffer */
  54.       int _cnt;          /* Bytes remaining in buffer */
  55.       Buffer *_base;         /* Address of buffer */
  56.       File_flags _flag;
  57.       char _fd;              /* Associated file handle */
  58.       char Padding;         /* Round out to even # bytes. */
  59.       int _nextline;
  60.       } _iobuf;
  61.  
  62. typedef _iobuf FILE;
  63.  
  64. extern _iobuf _iob[/*FOPEN_MAX*/];
  65. /* For upwards compatibility we put the bufsiz in a parallel array.
  66.  * This prevents the need for all previous customers to recompile.
  67.  * Versions of UNIX have played this same game.
  68.  */
  69. extern unsigned _bufsiz[/*FOPEN_MAX*/];
  70.  
  71. #define stdin    (&_iob[0])
  72. #define stdout    (&_iob[1])
  73. #define stderr    (&_iob[2])
  74.  
  75. #ifdef __HIGHC__
  76. #define P_tmpdir "\\"
  77. #endif
  78. #define L_tmpnam (18)     /* length of file name string generated by tmpnam */
  79.             /* only 13 chars are used by loc, but goc needs 18 */
  80. #define TMP_MAX  (1000)  /* min number of unique names generated by tmpnam */
  81. #define SEEK_SET (0)     /*From_beginning*/
  82. #define SEEK_CUR (1)     /*From_current*/
  83. #define SEEK_END (2)     /*From_end*/
  84.  
  85. /*  #define _IOFBF 1  */
  86. /*  #define _IOLBF 2  */
  87. /*  #define _IONBF 3  */
  88.  
  89. /* the MS definitions of the following are not implemented .........
  90. _IOREAD _IOWRT _IOFBF _IOLBF _IONBF _IOMYBUF _IOEOF _IOERR _IOSTRG _IORW
  91. note that we have some of these names defined for our own purposes, but
  92. they may not behave in the same way............caution is in order here!!!
  93. */
  94.  
  95. #ifdef __HIGHC__
  96. extern int unlink(const char *__pathname);
  97. #endif
  98. extern int remove(const char *__pathname);
  99. /* extern int rmtmp(void); */
  100. extern int rename(const char *__old, const char *__new);
  101. extern FILE *tmpfile(void);
  102. extern char *tmpnam(char *__s);
  103. /* extern char * tempnam(char *, char *); */
  104. extern int fclose(FILE *__stream);
  105. /* extern int fcloseall(void); */
  106. extern int fflush(FILE *__stream);
  107. /* extern int flushall(void); */
  108. extern FILE *fopen(const char *__pathname, const char *__type);
  109. extern FILE *freopen(const char *__pathname, const char *__type, FILE *__stream);
  110. extern int setvbuf(FILE *__stream, char *__buf, int __mode, size_t __size);
  111. extern void setbuf(FILE *__stream, char *__buf);
  112. extern size_t fread(void *__ptr, size_t __size, size_t __nelem, FILE *__stream);
  113. extern size_t fwrite(const void *__ptr, size_t __size, size_t __nelem, FILE *__stream);
  114. extern int fgetc(FILE *__stream);
  115.  
  116. #undef getc
  117. extern int getc(FILE *__stream);
  118.  
  119. #define getc(F) ( ((F)->_cnt > 0) &&         \
  120.          ( *(F)->_ptr != '\r' || !((F)->_flag & _FORMATTED_TEXT) ) \
  121.          ?    (F)->_cnt--, *(F)->_ptr++  \
  122.          :    fgetc(F)             \
  123.         )
  124. #undef getchar
  125. extern int getchar(void);
  126. #define getchar() (getc(stdin))
  127. extern char *gets(char *__s);
  128. /* extern int getw(FILE *); */
  129. extern char *fgets(char *__s, int __n, FILE *__stream);
  130. extern int fputs(const char *__s, FILE *__stream);
  131. extern int fputc(int __c, FILE *__stream);
  132. #ifdef __HIGHC__
  133. extern int fputchar(int __c);
  134. extern int fgetchar(void);
  135. #endif
  136.  
  137. #undef putc
  138. extern int putc(int __c, FILE *__stream);
  139.  
  140. /* WARNING!  putc refers to its parameter c twice, since newlines     */
  141. /* have to be special-cased due to required DOS translation.        */
  142.  
  143. #define putc(c,F) ( ((F)->_cnt > 0) && ((c) != '\n') \
  144.            ?    (F)->_cnt--, *(F)->_ptr++ = (c)  \
  145.            :    fputc(c,F) \
  146.           )
  147.  
  148. #undef putchar
  149. extern int putchar(int __c);
  150. #define putchar(c) (putc(c, stdout))
  151. extern int puts(const char *__s);
  152. /* extern int putw(int, FILE *); */
  153. extern int ungetc(int __c, FILE *__stream);
  154. extern int fseek(FILE *__stream, long __offset, int __ptrname);
  155. extern int fsetpos(FILE *__stream, const fpos_t *__pos);
  156. extern int fgetpos(FILE *__stream, fpos_t *__pos);
  157. extern long ftell(FILE *__stream);
  158. extern void rewind(FILE *__stream);
  159.  
  160. #undef clearerr
  161. extern void clearerr(FILE *__stream);
  162. /* clear _ERROR and _END_OF_FILE */
  163. #define clearerr(stream) ((stream)->_flag &= ~(_ERROR | _END_OF_FILE))
  164.  
  165. #undef feof
  166. extern int feof(FILE *__stream);
  167. #define feof(stream) ((stream)->_flag & _END_OF_FILE)
  168.  
  169. #undef ferror
  170. extern int ferror(FILE *__stream);
  171. #define ferror(stream) ((stream)->_flag & _ERROR)
  172.  
  173. extern FILE *_fdopen(int __fd, const char *__type);
  174. extern FILE *_fsopen(const char *__pathname, const char *__type, int __share_f);
  175. extern int _unlink(const char *__pathname);
  176. extern int _fputchar(int __c);
  177. extern int _fgetchar(void);
  178.  
  179. #if __HIGHC__ 
  180. extern FILE *fdopen(int __fd, const char *__type);
  181. #endif
  182.  
  183. #define _fileno(__stream) ((__stream)->_fd)
  184.  
  185. #define _O_TEXT   0x4000    /* low level text files */
  186. #define _O_BINARY 0x8000    /* low level binary files */
  187.  
  188. #ifdef __HIGHC__
  189. #define fileno(stream) ((stream)->_fd)
  190. #endif
  191.  
  192. extern void perror(const char *__s);  /* MSVERSION & ANSI
  193. OLD HIGHC VERSION extern char *perror(const char *s); */
  194.  
  195. #if __1167 && __HIGHC__    /* Tell compiler that x87 libraries do not kill 1167 registers. */
  196.         /* This produces more efficient code. */
  197. pragma calling_convention(_DEFAULT_CALLING_CONVENTION | _NO_1167);
  198. #endif
  199. extern int vprintf(const char *__format, va_list __arg);
  200. extern int vfprintf(FILE *__stream, const char *__format, va_list __arg);
  201. extern int vsprintf(char *__s, const char *__format, va_list __arg);
  202. extern int printf(const char *__format, ...);
  203. extern int fprintf(FILE *__stream, const char *__format, ...);
  204. extern int sprintf(char *__s, const char *__format, ...);
  205. extern int fscanf(FILE *__stream, const char *__format, ...);
  206. extern int scanf(const char *__format, ...);
  207. extern int sscanf(char *__s, const char *__format, ...);
  208. #if __1167 && __HIGHC__
  209. pragma calling_convention();
  210. #endif
  211.  
  212. extern void _setmode(FILE *__stream, int __mode);
  213. /* values for _setmode's mode argument */
  214. #define _TEXT      (0)      /* _setmode(F,_TEXT) makes F a text file */
  215. #define _BINARY   (1)      /* _setmode(F,_BINARY) makes F a binary file */
  216. /* used to set _fmode */
  217. #define _USER_FILES_BINARY     (1)
  218. #define _STDIN_AND_STDOUT_BINARY (2)
  219. #define _STDERR_BINARY         (4)
  220. #define _ALL_FILES_BINARY     \
  221.          (_USER_FILES_BINARY | _STDIN_AND_STDOUT_BINARY | _STDERR_BINARY)
  222. #define _ALL_FILES_TEXT      (~_ALL_FILES_BINARY)
  223. #define _USER_FILES_TEXT     (_fmode & ~_USER_FILES_BINARY)
  224. #define _STDIN_AND_STDOUT_TEXT     (_fmode & ~_STDIN_AND_STDOUT_BINARY)
  225. #define _STDERR_TEXT         (_fmode & ~_STDERR_BINARY)
  226.  
  227. #endif /* _STDIO_H */
  228.