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