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