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