diff options
Diffstat (limited to '8.2/stdio.h')
-rw-r--r-- | 8.2/stdio.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/8.2/stdio.h b/8.2/stdio.h new file mode 100644 index 0000000..f7520de --- /dev/null +++ b/8.2/stdio.h @@ -0,0 +1,48 @@ +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +#undef NULL +#define NULL 0 +#define EOF (-1) +#define BUFSIZ 8192 +#define OPN_MAX 20 + +struct flag_field { + unsigned int is_read : 1; + unsigned int is_write : 1; + unsigned int is_unbuf : 1; + unsigned int is_buf : 1; + unsigned int is_eof : 1; + unsigned int is_err : 1; +}; + +typedef struct _iobuff { + int cnt; + char *ptr; + char *base; + struct flag_field flag; + int fd; +} FILE; + +extern FILE _iob[OPN_MAX]; + +#define stdin (&_iob[0]); +#define stdout (&_iob[1]); +#define stderr (&_iob[2]); + +int _fillbuf(FILE *); +int _flushbuf(int, FILE *); +FILE *fopen(char *name, char *mode); + +#define feof(p) (!!((p)->flag & _EOF)) +#define ferror(p) (!!((p)->flag & _ERR)) +#define fileno(p) ((p)->fd) + +#define getc(p) (--(p)->cnt >= 0 \ + ? (unsigned char) *(p)->ptr++ : _fillbuf(p)) +#define putc(x, p) (--(p)->cnt >= 0 \ + ? *(p)->ptr++ = x : _flushbuf(x, p)) + +#define getchar() getc(stdin) +#define putchar(x) putc(x, stdin) |