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