diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | io.c | 15 | ||||
-rw-r--r-- | test/ruby/ut_eof.rb | 12 |
3 files changed, 23 insertions, 10 deletions
@@ -1,3 +1,9 @@ +Thu May 12 16:15:01 2005 Tanaka Akira <akr@m17n.org> + + * 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] + Thu May 12 15:56:20 2005 Tilman Sauerbeck <tilman@code-monkey.de> * lib/rdoc/parsers/parse_c.rb: show parsing progress for C files. @@ -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); diff --git a/test/ruby/ut_eof.rb b/test/ruby/ut_eof.rb index e6f6eddd6f..b7219ddb51 100644 --- a/test/ruby/ut_eof.rb +++ b/test/ruby/ut_eof.rb @@ -6,8 +6,8 @@ module TestEOF assert_equal("", f.read(0)) assert_equal("", f.read(0)) assert_equal("", f.read) - assert_nil(f.read(0)) - assert_nil(f.read(0)) + assert_equal("", f.read(0)) + assert_equal("", f.read(0)) } open_file("") {|f| assert_nil(f.read(1)) @@ -43,8 +43,8 @@ module TestEOF assert_equal("" , f.read(0)) assert_equal("" , f.read(0)) assert_equal("", f.read) - assert_nil(f.read(0)) - assert_nil(f.read(0)) + assert_equal("", f.read(0)) + assert_equal("", f.read(0)) } open_file("a") {|f| assert_equal("a", f.read(1)) @@ -69,7 +69,7 @@ module TestEOF } open_file("a") {|f| assert_equal("a", f.read) - assert_nil(f.read(0)) + assert_equal("", f.read(0)) } open_file("a") {|f| s = "x" @@ -109,7 +109,7 @@ module TestEOF assert_equal(10, f.pos) assert_equal("", f.read(0)) assert_equal("", f.read) - assert_nil(f.read(0)) + assert_equal("", f.read(0)) assert_equal("", f.read) } end |