From 0a4fc3d71ba383af2eb2da62509d3c5537eebb68 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 23 Dec 2003 19:53:45 +0000 Subject: * io.c (read_all): do not return nil at the end of file. [ruby-dev:22334] * io.c (argf_read): do not depend on nil at eof behavior of IO#read(). * eval.c (rb_thread_join): dup exception before re-raising it. * io.c (rb_io_eof): call clearerr() to prevent side effect. this patch is supplied by Masahiro Sakai . [ruby-dev:22234] * pack.c (OFF16): get offset for big endian machines. * pack.c (pack_pack): use OFF16 instead of OFF16B. [ruby-dev:22344] * pack.c (pack_unpack): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5266 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 8ecf0c1426..de3d7230d8 100644 --- a/io.c +++ b/io.c @@ -230,8 +230,8 @@ rb_io_check_readable(fptr) !fptr->f2) { io_seek(fptr, 0, SEEK_CUR); } - fptr->mode |= FMODE_RBUF; #endif + fptr->mode |= FMODE_RBUF; } void @@ -247,6 +247,7 @@ rb_io_check_writable(fptr) io_seek(fptr, 0, SEEK_CUR); } #endif + fptr->mode &= ~FMODE_RBUF; } int @@ -568,6 +569,7 @@ rb_io_eof(io) ungetc(ch, fptr->f); return Qfalse; } + clearerr(fptr->f); return Qtrue; } @@ -778,7 +780,6 @@ read_all(fptr, siz, str) long bytes = 0; long n; - if (feof(fptr->f)) return Qnil; READ_CHECK(fptr->f); if (siz == 0) siz = BUFSIZ; if (NIL_P(str)) { @@ -3805,6 +3806,20 @@ argf_to_io() return current_file; } +static VALUE +argf_eof() +{ + if (current_file) { + if (init_p == 0) return Qtrue; + ARGF_FORWARD(); + if (rb_io_eof(current_file)) { + next_p = 1; + return Qtrue; + } + } + return Qfalse; +} + static VALUE argf_read(argc, argv) int argc; @@ -3824,18 +3839,16 @@ argf_read(argc, argv) else { tmp = io_read(argc, argv, current_file); } - if (NIL_P(tmp)) { + if (NIL_P(str)) str = tmp; + else rb_str_append(str, tmp); + if (NIL_P(tmp) || argc == 0) { if (next_p != -1) { argf_close(current_file); next_p = 1; goto retry; } - return str; } - else if (NIL_P(str)) str = tmp; - else rb_str_append(str, tmp); - if (argc == 0) goto retry; - if (argc == 1) { + else if (argc == 1) { if (RSTRING(str)->len < len) { len -= RSTRING(str)->len; argv[0] = INT2NUM(len); @@ -3880,20 +3893,6 @@ argf_readchar() return c; } -static VALUE -argf_eof() -{ - if (current_file) { - if (init_p == 0) return Qtrue; - ARGF_FORWARD(); - if (rb_io_eof(current_file)) { - next_p = 1; - return Qtrue; - } - } - return Qfalse; -} - static VALUE argf_each_line(argc, argv) int argc; -- cgit v1.2.3