stdio.h 4.1 KB

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