summaryrefslogtreecommitdiffstats
path: root/fgetc.c
diff options
context:
space:
mode:
authorpgen <p.gen.progs@gmail.com>2022-10-10 22:16:48 +0200
committerpgen <p.gen.progs@gmail.com>2022-10-10 22:16:48 +0200
commitb332fef5c3ce3dce9e85857e8905f7291e0b1a6e (patch)
treeea62851102449e84ae17239b8eec4ff4d03c367a /fgetc.c
parent2548023fc17c2c46e045c58a176a1c452cb83c3f (diff)
Improve byte reading from stdin
Diffstat (limited to 'fgetc.c')
-rw-r--r--fgetc.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/fgetc.c b/fgetc.c
index 95f7fd1..cf755d8 100644
--- a/fgetc.c
+++ b/fgetc.c
@@ -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;
+ }
}
/* =============================== */