summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-23 19:53:45 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-23 19:53:45 +0000
commit0a4fc3d71ba383af2eb2da62509d3c5537eebb68 (patch)
treeb9353d3b26f0ff6144fc628574d90bec093b90d4 /io.c
parenta3ecd5c83d57fb1556a40113f1b0c69c87261e33 (diff)
* 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 <sakai@tom.sfc.keio.ac.jp>. [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
Diffstat (limited to 'io.c')
-rw-r--r--io.c43
1 files changed, 21 insertions, 22 deletions
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)) {
@@ -3806,6 +3807,20 @@ argf_to_io()
}
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;
VALUE *argv;
@@ -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);
@@ -3881,20 +3894,6 @@ argf_readchar()
}
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;
VALUE *argv;