diff options
author | pgen <p.gen.progs@gmail.com> | 2022-10-10 22:16:48 +0200 |
---|---|---|
committer | pgen <p.gen.progs@gmail.com> | 2022-10-10 22:16:48 +0200 |
commit | b332fef5c3ce3dce9e85857e8905f7291e0b1a6e (patch) | |
tree | ea62851102449e84ae17239b8eec4ff4d03c367a /fgetc.c | |
parent | 2548023fc17c2c46e045c58a176a1c452cb83c3f (diff) |
Improve byte reading from stdin
Diffstat (limited to 'fgetc.c')
-rw-r--r-- | fgetc.c | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -28,7 +28,23 @@ static long next_buffer_pos = 0; /* Next free position in the getc buffer. */ int my_fgetc(FILE * input) { - return (next_buffer_pos > 0) ? getc_buffer[--next_buffer_pos] : fgetc(input); + int c; + + if (next_buffer_pos > 0) + return getc_buffer[--next_buffer_pos]; + else + { + errno = 0; + c = fgetc(input); + + while (c == EOF && errno == EAGAIN) + { + errno = 0; + c = fgetc(input); + } + + return c; + } } /* =============================== */ |