summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/io.c b/io.c
index f170c4c379..b7c14ec565 100644
--- a/io.c
+++ b/io.c
@@ -626,17 +626,21 @@ read_all(port)
#endif
)
{
+ off_t pos;
+
if (st.st_size == 0) {
- getc(fptr->f); /* force EOF */
- return rb_str_new(0, 0);
+ int c = getc(fptr->f);
+
+ if (c == EOF) {
+ return rb_str_new(0, 0);
+ }
+ ungetc(c, fptr->f);
}
- else {
- off_t pos = ftello(fptr->f);
- if (st.st_size > pos && pos >= 0) {
- siz = st.st_size - pos + 1;
- if (siz > LONG_MAX) {
- rb_raise(rb_eIOError, "file too big for single read");
- }
+ pos = ftello(fptr->f);
+ if (st.st_size > pos && pos >= 0) {
+ siz = st.st_size - pos + 1;
+ if (siz > LONG_MAX) {
+ rb_raise(rb_eIOError, "file too big for single read");
}
}
}