Skip to content

Commit

Permalink
* io.c (rb_io_eof, remain_size, read_all, io_read, appendline)
Browse files Browse the repository at this point in the history
  (swallow, rb_io_each_byte, rb_io_getc): don't rely EOF flag.
  [ruby-talk:141527]


git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@8433 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
akr committed May 12, 2005
1 parent 4f25d0b commit edbe041
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
@@ -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.
Expand Down
15 changes: 11 additions & 4 deletions io.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1440,6 +1442,9 @@ swallow(fptr, term)
return Qtrue;
}
} while (c != EOF);
if (!ferror(f)) {
clearerr(f);
}
return Qfalse;
}

Expand Down Expand Up @@ -1806,6 +1811,7 @@ rb_io_each_byte(io)
rb_sys_fail(fptr->path);
continue;
}
clearerr(f);
break;
}
rb_yield(INT2FIX(c & 0xff));
Expand Down Expand Up @@ -1851,6 +1857,7 @@ rb_io_getc(io)
rb_sys_fail(fptr->path);
goto retry;
}
clearerr(f);
return Qnil;
}
return INT2FIX(c & 0xff);
Expand Down
12 changes: 6 additions & 6 deletions test/ruby/ut_eof.rb
Expand Up @@ -6,8 +6,8 @@ def test_eof_0
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))
Expand Down Expand Up @@ -43,8 +43,8 @@ def test_eof_1
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))
Expand All @@ -69,7 +69,7 @@ def test_eof_1
}
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"
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_eof_0_seek
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
Expand Down

0 comments on commit edbe041

Please sign in to comment.