stdio.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #ifndef _STDIO_H_
  2. #define _STDIO_H_
  3. #pragma lib "/$M/lib/ape/libap.a"
  4. /*
  5. * pANS stdio.h
  6. */
  7. #include <stdarg.h>
  8. #include <stddef.h>
  9. #include <sys/types.h>
  10. /*
  11. * According to X3J11, there is only one i/o buffer
  12. * and it must not be occupied by both input and output data.
  13. *
  14. * If rp<wp, we must have state==RD and
  15. * if wp<rp, we must have state==WR, so that getc and putc work correctly.
  16. * On open, rp, wp and buf are set to 0, so first getc or putc will call
  17. * _IO_getc or _IO_putc, which will allocate the buffer.
  18. * If setvbuf(., ., _IONBF, .) is called, bufl is set to 0 and
  19. * buf, rp and wp are pointed at unbuf.
  20. * If setvbuf(., ., _IOLBF, .) is called, _IO_putc leaves wp and rp pointed at
  21. * the end of the buffer so that it can be called on each putc to check whether
  22. * it's got a newline. This nonsense is in order to avoid impacting performance
  23. * of the other buffering modes more than necessary -- putting the test in putc
  24. * adds many instructions that are wasted in non-_IOLBF mode:
  25. * #define putc(c, f) (_IO_ctmp=(c),\
  26. * (f)->wp>=(f)->rp || (f)->flags&LINEBUF && _IO_ctmp=='\n'?\
  27. * _IO_putc(_IO_ctmp, f): *(f)->wp++=_IO_ctmp)
  28. */
  29. typedef struct{
  30. int fd; /* UNIX file pointer */
  31. char flags; /* bits for must free buffer on close, line-buffered */
  32. char state; /* last operation was read, write, position, error, eof */
  33. unsigned char *buf; /* pointer to i/o buffer */
  34. unsigned char *rp; /* read pointer (or write end-of-buffer) */
  35. unsigned char *wp; /* write pointer (or read end-of-buffer) */
  36. unsigned char *lp; /* actual write pointer used when line-buffering */
  37. size_t bufl; /* actual length of buffer */
  38. unsigned char unbuf[1]; /* tiny buffer for unbuffered io (used for ungetc?) */
  39. int junk;
  40. }FILE;
  41. typedef off_t fpos_t;
  42. #ifndef NULL
  43. #ifdef __cplusplus
  44. #define NULL 0
  45. #else
  46. #define NULL ((void*)0)
  47. #endif
  48. #endif
  49. /*
  50. * Third arg of setvbuf
  51. */
  52. #define _IOFBF 1 /* block-buffered */
  53. #define _IOLBF 2 /* line-buffered */
  54. #define _IONBF 3 /* unbuffered */
  55. #define BUFSIZ 8192 /* size of setbuf buffer */
  56. #define EOF (-1) /* returned on end of file */
  57. #define FOPEN_MAX 128 /* max files open */
  58. #define FILENAME_MAX BUFSIZ /* silly filename length */
  59. #define L_tmpnam 20 /* sizeof "/tmp/abcdefghij9999 */
  60. #define L_cuserid 32 /* maximum size user name */
  61. #define L_ctermid 32 /* size of name of controlling tty */
  62. #ifndef SEEK_SET /* also defined in unistd.h */
  63. #define SEEK_CUR 1
  64. #define SEEK_END 2
  65. #define SEEK_SET 0
  66. #endif
  67. #define TMP_MAX 64 /* very hard to set correctly */
  68. #define stderr (&_IO_stream[2])
  69. #define stdin (&_IO_stream[0])
  70. #define stdout (&_IO_stream[1])
  71. extern FILE _IO_stream[FOPEN_MAX];
  72. #ifdef __cplusplus
  73. extern "C" {
  74. #endif
  75. int _IO_getc(FILE *f);
  76. int _IO_putc(int, FILE *);
  77. void clearerr(FILE *);
  78. int fclose(FILE *);
  79. FILE *fdopen(const int, const char *);
  80. int feof(FILE *);
  81. int ferror(FILE *);
  82. int fflush(FILE *);
  83. int fgetc(FILE *);
  84. int fgetpos(FILE *, fpos_t *);
  85. char *fgets(char *, int, FILE *);
  86. int fileno(FILE *);
  87. FILE *fopen(const char *, const char *);
  88. int fprintf(FILE *, const char *, ...);
  89. int fputc(int, FILE *);
  90. int fputs(const char *, FILE *);
  91. size_t fread(void *, size_t, size_t, FILE *);
  92. FILE *freopen(const char *, const char *, FILE *);
  93. int fscanf(FILE *, const char *, ...);
  94. int fseek(FILE *, long, int);
  95. int fseeko(FILE *, off_t, int);
  96. int fsetpos(FILE *, const fpos_t *);
  97. long ftell(FILE *);
  98. off_t ftello(FILE *);
  99. size_t fwrite(const void *, size_t, size_t, FILE *);
  100. int getc(FILE *);
  101. #define getc(f) ((f)->rp>=(f)->wp? _IO_getc(f): *(f)->rp++)
  102. int getchar(void);
  103. #define getchar() getc(stdin)
  104. char *gets(char *);
  105. void perror(const char *);
  106. int printf(const char *, ...);
  107. int putc(int, FILE *);
  108. /* assignment to f->junk eliminates warnings about unused result of operation */
  109. #define putc(c, f) ((f)->junk = ((f)->wp>=(f)->rp? \
  110. _IO_putc(c, f): (*(f)->wp++ = (c))))
  111. int putchar(int);
  112. #define putchar(c) putc(c, stdout)
  113. int puts(const char *);
  114. int remove(const char *);
  115. int rename(const char *, const char *);
  116. void rewind(FILE *);
  117. int scanf(const char *, ...);
  118. void setbuf(FILE *, char *);
  119. int setvbuf(FILE *, char *, int, size_t);
  120. /*
  121. * NB: C99 now requires *snprintf to return the number of characters
  122. * that would have been written, had there been room.
  123. */
  124. int snprintf(char *, size_t, const char *, ...);
  125. int sprintf(char *, const char *, ...);
  126. int sscanf(const char *, const char *, ...);
  127. FILE *tmpfile(void);
  128. char *tmpnam(char *);
  129. int ungetc(int, FILE *);
  130. int vfprintf(FILE *, const char *, va_list);
  131. int vfscanf(FILE *, const char *, va_list);
  132. int vprintf(const char *, va_list);
  133. int vsnprintf(char *, size_t, const char *, va_list);
  134. int vsprintf(char *, const char *, va_list);
  135. #ifdef _POSIX_SOURCE
  136. int fileno(FILE *);
  137. FILE* fdopen(int, const char*);
  138. char *ctermid(char *);
  139. #endif
  140. #ifdef _REENTRANT_SOURCE
  141. char *tmpnam_r(char *);
  142. char *ctermid_r(char *);
  143. #endif
  144. #ifdef _BSD_EXTENSION
  145. #pragma lib "/$M/lib/ape/libbsd.a"
  146. FILE *popen(char *, char *);
  147. int pclose(FILE *);
  148. #endif
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152. #endif