stdio.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma src "/sys/src/libstdio"
  2. #pragma lib "libstdio.a"
  3. /*
  4. * pANS astdio.h
  5. */
  6. /*
  7. * According to X3J11, there is only one i/o buffer
  8. * and it must not be occupied by both input and output data.
  9. * If rp<wp, we must have state==RD and
  10. * if wp<rp, we must have state==WR, so that getc and putc work correctly.
  11. * On open, rp, wp and buf are set to 0, so first getc or putc will call _IO_getc
  12. * or _IO_putc, which will allocate the buffer.
  13. * If setvbuf(., ., _IONBF, .) is called, bufl is set to 0 and
  14. * buf, rp and wp are pointed at unbuf.
  15. * If setvbuf(., ., _IOLBF, .) is called, _IO_putc leaves wp and rp pointed at the
  16. * end of the buffer so that it can be called on each putc to check whether it's got
  17. * a newline. This nonsense is in order to avoid impacting performance of the other
  18. * buffering modes more than necessary -- putting the test in putc adds many
  19. * instructions that are wasted in non-_IOLBF mode:
  20. * #define putc(c, f) (_IO_ctmp=(c),\
  21. * (f)->wp>=(f)->rp || (f)->flags&LINEBUF && _IO_ctmp=='\n'\
  22. * ?_IO_putc(_IO_ctmp, f)\
  23. * :*(f)->wp++=_IO_ctmp)
  24. *
  25. */
  26. typedef struct{
  27. int fd; /* UNIX file pointer */
  28. char flags; /* bits for must free buffer on close, line-buffered */
  29. char state; /* last operation was read, write, position, error, eof */
  30. char *buf; /* pointer to i/o buffer */
  31. char *rp; /* read pointer (or write end-of-buffer) */
  32. char *wp; /* write pointer (or read end-of-buffer) */
  33. char *lp; /* actual write pointer used when line-buffering */
  34. long bufl; /* actual length of buffer */
  35. char unbuf[1]; /* tiny buffer for unbuffered io (used for ungetc?) */
  36. }FILE;
  37. typedef long fpos_t;
  38. #ifndef NULL
  39. #define NULL 0
  40. #endif
  41. /*
  42. * Third arg of setvbuf
  43. */
  44. #define _IOFBF 1 /* block-buffered */
  45. #define _IOLBF 2 /* line-buffered */
  46. #define _IONBF 3 /* unbuffered */
  47. #define BUFSIZ 4096 /* size of setbuf buffer */
  48. #define EOF (-1) /* returned on end of file */
  49. #define FOPEN_MAX 100 /* max files open */
  50. #define FILENAME_MAX BUFSIZ /* silly filename length */
  51. #define L_tmpnam 20 /* sizeof "/tmp/abcdefghij9999 */
  52. #ifndef SEEK_SET /* also defined in unistd.h */
  53. #define SEEK_CUR 1
  54. #define SEEK_END 2
  55. #define SEEK_SET 0
  56. #endif
  57. #define TMP_MAX 64 /* very hard to set correctly */
  58. #define stderr (&_IO_stream[2])
  59. #define stdin (&_IO_stream[0])
  60. #define stdout (&_IO_stream[1])
  61. #define _IO_CHMASK 0377 /* mask for 8 bit characters */
  62. FILE *tmpfile(void);
  63. char *tmpnam(char *);
  64. int fclose(FILE *);
  65. int fflush(FILE *);
  66. FILE *fopen(const char *, const char *);
  67. FILE *fdopen(const int, const char *);
  68. FILE *freopen(const char *, const char *, FILE *);
  69. void setbuf(FILE *, char *);
  70. int setvbuf(FILE *, char *, int, long);
  71. int fprintf(FILE *, const char *, ...);
  72. int fscanf(FILE *, const char *, ...);
  73. int printf(const char *, ...);
  74. int scanf(const char *, ...);
  75. int sprintf(char *, const char *, ...);
  76. int snprintf(char *, int, const char *, ...);
  77. int sscanf(const char *, const char *, ...);
  78. int vfprintf(FILE *, const char *, va_list);
  79. int vprintf(const char *, va_list);
  80. int vsprintf(char *, const char *, va_list);
  81. int vsnprintf(char *, int, const char *, va_list);
  82. int vfscanf(FILE *, const char *, va_list);
  83. int fgetc(FILE *);
  84. char *fgets(char *, int, FILE *);
  85. int fputc(int, FILE *);
  86. int fputs(const char *, FILE *);
  87. int getc(FILE *);
  88. #define getc(f) ((f)->rp>=(f)->wp?_IO_getc(f):*(f)->rp++&_IO_CHMASK)
  89. int _IO_getc(FILE *f);
  90. int getchar(void);
  91. #define getchar() getc(stdin)
  92. char *gets(char *);
  93. int putc(int, FILE *);
  94. #define putc(c, f) ((f)->wp>=(f)->rp?_IO_putc(c, f):(*(f)->wp++=c)&_IO_CHMASK)
  95. int _IO_putc(int, FILE *);
  96. int putchar(int);
  97. #define putchar(c) putc(c, stdout)
  98. int puts(const char *);
  99. int ungetc(int, FILE *);
  100. long fread(void *, long, long, FILE *);
  101. long fwrite(const void *, long, long, FILE *);
  102. int fgetpos(FILE *, fpos_t *);
  103. int fseek(FILE *, long, int);
  104. int fseeko(FILE *, long long, int);
  105. int fsetpos(FILE *, const fpos_t *);
  106. long ftell(FILE *);
  107. long long ftello(FILE *);
  108. void rewind(FILE *);
  109. void clearerr(FILE *);
  110. int feof(FILE *);
  111. int ferror(FILE *);
  112. void perror(const char *);
  113. extern FILE _IO_stream[FOPEN_MAX];
  114. FILE *sopenr(const char *);
  115. FILE *sopenw(void);
  116. char *sclose(FILE *);
  117. int fileno(FILE *);