summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-05-12 07:28:16 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-05-12 07:28:16 +0000
commit84eca25a328b2ae05b68b5cf4dd9b8bad2ab4647 (patch)
treea9f7ebb1a8fd54deb6f0b162e356b28de9c4d23b /io.c
parentbdbbf18c4a93547fbd648f405ec4f19f943124f8 (diff)
* io.c (rb_io_eof, remain_size, read_all, io_read, appendline)
(swallow, rb_io_each_byte, rb_io_getc): don't rely EOF flag. [ruby-talk:141527] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8433 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/io.c b/io.c
index 918ebd1f01..9b67d4c615 100644
--- a/io.c
+++ b/io.c
@@ -742,7 +742,6 @@ rb_io_eof(io)
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
- if (feof(fptr->f)) return Qtrue;
if (READ_DATA_PENDING(fptr->f)) return Qfalse;
READ_CHECK(fptr->f);
TRAP_BEG;
@@ -1045,7 +1044,6 @@ remain_size(fptr)
off_t siz = BUFSIZ;
off_t pos;
- if (feof(fptr->f)) return 0;
if (fstat(fileno(fptr->f), &st) == 0 && S_ISREG(st.st_mode)
#ifdef __BEOS__
&& (st.st_dev > 3)
@@ -1086,7 +1084,10 @@ read_all(fptr, siz, str)
rb_str_unlocktmp(str);
if (n == 0 && bytes == 0) {
if (!fptr->f) break;
- if (feof(fptr->f)) break;
+ if (feof(fptr->f)) {
+ clearerr(fptr->f);
+ break;
+ }
if (!ferror(fptr->f)) break;
rb_sys_fail(fptr->path);
}
@@ -1275,7 +1276,6 @@ io_read(argc, argv, io)
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
- if (feof(fptr->f)) return Qnil;
if (len == 0) return str;
rb_str_locktmp(str);
@@ -1288,6 +1288,7 @@ io_read(argc, argv, io)
if (n == 0) {
if (!fptr->f) return Qnil;
if (feof(fptr->f)) {
+ clearerr(fptr->f);
rb_str_resize(str, 0);
return Qnil;
}
@@ -1365,6 +1366,7 @@ appendline(fptr, delim, strp)
rb_sys_fail(fptr->path);
continue;
}
+ clearerr(fptr->f);
#ifdef READ_DATA_PENDING_PTR
return c;
#endif
@@ -1440,6 +1442,9 @@ swallow(fptr, term)
return Qtrue;
}
} while (c != EOF);
+ if (!ferror(f)) {
+ clearerr(f);
+ }
return Qfalse;
}
@@ -1806,6 +1811,7 @@ rb_io_each_byte(io)
rb_sys_fail(fptr->path);
continue;
}
+ clearerr(f);
break;
}
rb_yield(INT2FIX(c & 0xff));
@@ -1851,6 +1857,7 @@ rb_io_getc(io)
rb_sys_fail(fptr->path);
goto retry;
}
+ clearerr(f);
return Qnil;
}
return INT2FIX(c & 0xff);