diff options
author | zlg <zlg@zlg.space> | 2022-01-09 16:41:26 -0800 |
---|---|---|
committer | zlg <zlg@zlg.space> | 2022-01-09 16:41:26 -0800 |
commit | 2b68c3d06fb2961ae3797d1ef461cff655f328b2 (patch) | |
tree | 8731595b523ec3dcad0e9a70992de5f0a4a95a01 /ch8/8-02_syscalls.h | |
parent | Solve Exercise 8-2: fopen and fillbuf (diff) | |
download | knr-2b68c3d06fb2961ae3797d1ef461cff655f328b2.tar.gz knr-2b68c3d06fb2961ae3797d1ef461cff655f328b2.tar.bz2 knr-2b68c3d06fb2961ae3797d1ef461cff655f328b2.tar.xz knr-2b68c3d06fb2961ae3797d1ef461cff655f328b2.zip |
Refactor syscalls.h for ch8 exercises
The refactor includes implementations for fflush and fclose as well,
needed in 8-03.
Diffstat (limited to '')
-rw-r--r-- | ch8/8-02_syscalls.h | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/ch8/8-02_syscalls.h b/ch8/8-02_syscalls.h deleted file mode 100644 index 728c5af..0000000 --- a/ch8/8-02_syscalls.h +++ /dev/null @@ -1,47 +0,0 @@ -/* 8-02_syscalls.h - * - * A simpler stdio.h to aid in exercises 8-2 - */ - -long lseek(int fd, long offset, int origin); - -struct _flags { - unsigned int _READ : 1; - unsigned int _WRITE : 1; - unsigned int _UNBUF : 1; - unsigned int _EOF : 1; - unsigned int _ERR : 1; -} flags; - -typedef struct _iobuf { - int cnt; - char *ptr; - char *base; - struct _flags flags; - int fd; -} my_FILE; - -my_FILE _iob[FOPEN_MAX] = { - /* stdin is read-only */ - { 0, (char *) 0, (char *) 0, {1, 0, 0, 0, 0}, 0 }, - /* stdout is write only */ - { 0, (char *) 0, (char *) 0, {0, 1, 0, 0, 0}, 1 }, - /* stderr is written AND not buffered */ - { 0, (char *) 0, (char *) 0, {0, 1, 1, 0, 0}, 2 } -}; - -#define feof(p) (((p)->flags._EOF) != 0) -#define ferror(p) (((p)->flags._ERR) != 0) -#define fileno(p) ((p)->fd) -#define my_getc(p) (--(p)->cnt >= 0 ? (unsigned char) *(p)->ptr++ : my__fillbuf(p)) -#define getchar() getc(stdin) - -int my_fempty(struct _flags flags) { - if (!flags._READ && !flags._WRITE && !flags._UNBUF && !flags._EOF && !flags._ERR) { - return 1; - } else { - return 0; - } -} - -int my_fclose(my_FILE*); |