1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* io.c (rb_io_eof, remain_size, read_all, io_read, appendline)

(swallow, rb_io_each_byte, rb_io_getc): revert previous change.

* io.c (rb_io_eof, io_fread, appendline, swallow, rb_io_each_byte)
  (rb_io_getc, rb_getc): call clearerr before getc to avoid
  stdio incompatibility.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8436 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2005-05-12 08:12:42 +00:00
parent 5bac006483
commit d9aec0cbe3
3 changed files with 26 additions and 17 deletions

View file

@ -1,3 +1,12 @@
Thu May 12 17:08:48 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): revert previous change.
* io.c (rb_io_eof, io_fread, appendline, swallow, rb_io_each_byte)
(rb_io_getc, rb_getc): call clearerr before getc to avoid
stdio incompatibility.
Thu May 12 16:52:20 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* lib/rdoc/parsers/parse_c.rb: more readability for mixing

22
io.c
View file

@ -742,8 +742,10 @@ 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);
clearerr(fptr->f);
TRAP_BEG;
ch = getc(fptr->f);
TRAP_END;
@ -983,6 +985,7 @@ io_fread(ptr, len, fptr)
}
rb_thread_wait_fd(fileno(fptr->f));
rb_io_check_closed(fptr);
clearerr(fptr->f);
TRAP_BEG;
c = getc(fptr->f);
TRAP_END;
@ -1044,6 +1047,7 @@ 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)
@ -1084,10 +1088,7 @@ read_all(fptr, siz, str)
rb_str_unlocktmp(str);
if (n == 0 && bytes == 0) {
if (!fptr->f) break;
if (feof(fptr->f)) {
clearerr(fptr->f);
break;
}
if (feof(fptr->f)) break;
if (!ferror(fptr->f)) break;
rb_sys_fail(fptr->path);
}
@ -1276,6 +1277,7 @@ 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,7 +1290,6 @@ 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;
}
@ -1356,6 +1357,7 @@ appendline(fptr, delim, strp)
#else
READ_CHECK(f);
#endif
clearerr(f);
TRAP_BEG;
c = getc(f);
TRAP_END;
@ -1366,7 +1368,6 @@ appendline(fptr, delim, strp)
rb_sys_fail(fptr->path);
continue;
}
clearerr(fptr->f);
#ifdef READ_DATA_PENDING_PTR
return c;
#endif
@ -1434,6 +1435,7 @@ swallow(fptr, term)
#else
READ_CHECK(f);
#endif
clearerr(f);
TRAP_BEG;
c = getc(f);
TRAP_END;
@ -1442,9 +1444,6 @@ swallow(fptr, term)
return Qtrue;
}
} while (c != EOF);
if (!ferror(f)) {
clearerr(f);
}
return Qfalse;
}
@ -1801,6 +1800,7 @@ rb_io_each_byte(io)
rb_io_check_readable(fptr);
f = fptr->f;
READ_CHECK(f);
clearerr(f);
TRAP_BEG;
c = getc(f);
TRAP_END;
@ -1811,7 +1811,6 @@ rb_io_each_byte(io)
rb_sys_fail(fptr->path);
continue;
}
clearerr(f);
break;
}
rb_yield(INT2FIX(c & 0xff));
@ -1846,6 +1845,7 @@ rb_io_getc(io)
retry:
READ_CHECK(f);
clearerr(f);
TRAP_BEG;
c = getc(f);
TRAP_END;
@ -1857,7 +1857,6 @@ rb_io_getc(io)
rb_sys_fail(fptr->path);
goto retry;
}
clearerr(f);
return Qnil;
}
return INT2FIX(c & 0xff);
@ -1872,6 +1871,7 @@ rb_getc(f)
if (!READ_DATA_PENDING(f)) {
rb_thread_wait_fd(fileno(f));
}
clearerr(f);
TRAP_BEG;
c = getc(f);
TRAP_END;

View file

@ -6,8 +6,8 @@ module TestEOF
assert_equal("", f.read(0))
assert_equal("", f.read(0))
assert_equal("", f.read)
assert_equal("", f.read(0))
assert_equal("", f.read(0))
assert_nil(f.read(0))
assert_nil(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_equal("", f.read(0))
assert_equal("", f.read(0))
assert_nil(f.read(0))
assert_nil(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_equal("", f.read(0))
assert_nil(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_equal("", f.read(0))
assert_nil(f.read(0))
assert_equal("", f.read)
}
end