/* some interesting bits from /usr/include/stdio.h */ typedef unsigned int size_t; #define NULL 0 #define BUFSIZ 1024 #define _NFILE 20 /* initial number of streams: SPARC ABI and default */ #define _IOFBF 0000 /* full buffered */ #define _IOLBF 0100 /* line buffered */ #define _IONBF 0004 /* not buffered */ #define _IOEOF 0020 /* EOF reached on read */ #define _IOERR 0040 /* I/O error from system */ #define _IOREAD 0001 /* currently reading */ #define _IOWRT 0002 /* currently writing */ #define _IORW 0200 /* opened for reading and writing */ #define _IOMYBUF 0010 /* stdio malloc()'d buffer */ #define EOF (-1) #define stdin (&__iob[0]) #define stdout (&__iob[1]) #define stderr (&__iob[2]) typedef struct { int _cnt; /* number of available characters in buffer */ unsigned char *_ptr; /* next character from/to here in buffer */ unsigned char *_base; /* the buffer */ unsigned char _flag; /* the state of the stream */ unsigned char _file; /* UNIX System file descriptor */ } FILE; extern FILE __iob[_NFILE]; extern int fprintf(FILE *, const char *, ...); extern int vfprintf(FILE *, const char *, va_list); extern int fgetc(FILE *); extern int getc(FILE *); extern int getchar(void); extern int __filbuf(FILE *); /* when the code does not have to be reentrant then getc(), ... become macros, not function calls */ #ifndef _REENTRANT #define getc(p) (--(p)->_cnt < 0 ? __filbuf(p) : (int)*(p)->_ptr++) #define putc(x, p) (--(p)->_cnt < 0 ? __flsbuf((unsigned char) (x), (p)) \ : (int)(*(p)->_ptr++ = (x))) #define getchar() getc(stdin) #define putchar(x) putc((x), stdout) #define clearerr(p) ((void)((p)->_flag &= ~(_IOERR | _IOEOF))) #define feof(p) ((p)->_flag & _IOEOF) #define ferror(p) ((p)->_flag & _IOERR) #endif /* _REENTRANT */