#ifndef TAKA_STDIO //DEFINE NULL #ifndef NULL #define NULL 0 #endif //DEFINE EOF #ifndef EOF #define EOF (-1) #endif //DEFINE BUFSIZ #ifndef BUFSIZ #define BUFSIZ 1024 #endif //DEFINE OPEN_MAX #ifndef OPEN_MAX #define OPEN_MAX 20 #endif typedef struct _iobuf { int counts; char *currentPtr; char *basePtr; int flag; int fd; } FILE; extern FILE _iob[OPEN_MAX]; //DEFINE stdin, stdout, stderr #define stdin &(_iob[0]) #define stdout &(_iob[1]) #define stderr &(_iob[1]) enum _flags{ _READ = 0x01, /*読み出しファイル用にオープン*/ _WRITE = 0x02, /*書き込みファイル用にオープン*/ _UNBUF = 0x04, /*バッファされていないファイル*/ _EOF = 0x08, /*このファイルでEOF に達した */ _ERR = 0x10, /*このファイルでエラーが発生 */ }; int _fillbuf(FILE* fp); int _flushbuf(int x, FILE* fp); //DEFINE feof, ferror, fileno #define feof(p) (((p)->flag & _EOF) != 0) #define ferror(p) (((p)->flag & _ERR) != 0) #define filneno(p) ((p)->fd) //DEFINE getc, putc, getchar, putchar #define getc(p) (--(p)->counts >= 0 \ ? (unsigned char) *(p)->currentPtr++ : _fillbuf(p)) #define putc(x, p) (--(p)->counts >= 0 \ ? *(p)->currentPtr++ = (x) : _flushbuf((x), p)) #define getchar() getc(stdin) #define putchar(x) putc((x), stdout) /*functions*/ FILE *fopen(const char *filename, const char* mode); int fclose(FILE *stream); int fflush(FILE *stream); int fgetc(FILE *stream); char *fgets(char *s, int n, FILE *stream); int fputc(int c, FILE *stream); int fputs(const char *s, FILE *stream); #endif