diff --git a/src/stdio/__stdio_read.c b/src/stdio/__stdio_read.c index 6cd7b0733a85a3e83deb5c14ed1f6616888d3480..5947344438b30559206d0966210455c28a9c6615 100644 --- a/src/stdio/__stdio_read.c +++ b/src/stdio/__stdio_read.c @@ -21,7 +21,6 @@ size_t __stdio_read(FILE *f, unsigned char *buf, size_t len) pthread_cleanup_pop(0); if (cnt <= 0) { f->flags |= F_EOF ^ ((F_ERR^F_EOF) & cnt); - f->rpos = f->rend = 0; return cnt; } if (cnt <= iov[0].iov_len) return cnt; diff --git a/src/stdio/__toread.c b/src/stdio/__toread.c index 52624f3d4f2370edbbd8d40a418ee48d06b4a98d..b08f5bb440345efefc5dd0f4d8679e0a56eb91e0 100644 --- a/src/stdio/__toread.c +++ b/src/stdio/__toread.c @@ -5,12 +5,12 @@ int __toread(FILE *f) f->mode |= f->mode-1; if (f->wpos > f->buf) f->write(f, 0, 0); f->wpos = f->wbase = f->wend = 0; - if (f->flags & (F_EOF|F_NORD)) { - if (f->flags & F_NORD) f->flags |= F_ERR; + if (f->flags & F_NORD) { + f->flags |= F_ERR; return EOF; } - f->rpos = f->rend = f->buf; - return 0; + f->rpos = f->rend = f->buf + f->buf_size; + return (f->flags & F_EOF) ? EOF : 0; } void __stdio_exit_needed(void); diff --git a/src/stdio/__uflow.c b/src/stdio/__uflow.c index e28922c2ff461a960c37501d6cbe298fe8ca68f4..2a88bca6b123cc2143911783a09a9cac0ce53773 100644 --- a/src/stdio/__uflow.c +++ b/src/stdio/__uflow.c @@ -1,11 +1,11 @@ #include "stdio_impl.h" -/* This function will never be called if there is already data - * buffered for reading. Thus we can get by with very few branches. */ +/* This function assumes it will never be called if there is already + * data buffered for reading. */ int __uflow(FILE *f) { unsigned char c; - if ((f->rend || !__toread(f)) && f->read(f, &c, 1)==1) return c; + if (!__toread(f) && f->read(f, &c, 1)==1) return c; return EOF; } diff --git a/src/stdio/ungetc.c b/src/stdio/ungetc.c index 7f56f8d5f07b79dba384f9ef02fe2b8c160b6467..180673a47663ad57b11d3e6525c35cc23858939a 100644 --- a/src/stdio/ungetc.c +++ b/src/stdio/ungetc.c @@ -6,7 +6,8 @@ int ungetc(int c, FILE *f) FLOCK(f); - if ((!f->rend && __toread(f)) || f->rpos <= f->buf - UNGET) { + if (!f->rpos) __toread(f); + if (!f->rpos || f->rpos <= f->buf - UNGET) { FUNLOCK(f); return EOF; } diff --git a/src/stdio/ungetwc.c b/src/stdio/ungetwc.c index 8cc85a6bfd2a00b615ecccdc96fbfc519e4b77f5..913f7168ed4935870b89b4f023640843b7d5b25d 100644 --- a/src/stdio/ungetwc.c +++ b/src/stdio/ungetwc.c @@ -19,7 +19,8 @@ wint_t ungetwc(wint_t c, FILE *f) f->mode |= f->mode+1; - if ((!f->rend && __toread(f)) || f->rpos < f->buf - UNGET + l) { + if (!f->rpos) __toread(f); + if (!f->rpos || f->rpos < f->buf - UNGET + l) { FUNLOCK(f); return EOF; }