aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--io.c12
-rw-r--r--test/fileutils/test_fileutils.rb4
3 files changed, 18 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 4674d493db..9a938f3bfb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Sep 5 18:37:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * io.c (copy_stream_fallback_body): use read method unless readpartial
+ is available. [ruby-dev:36124]
+
Fri Sep 5 18:16:31 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/iconv/iconv.c (iconv_create): strips glibc style option before
diff --git a/io.c b/io.c
index e44d2cfe22..a82e0fd166 100644
--- a/io.c
+++ b/io.c
@@ -7216,6 +7216,13 @@ copy_stream_fallback_body(VALUE arg)
VALUE buf = rb_str_buf_new(buflen);
long rest = stp->copy_length;
off_t off = stp->src_offset;
+ ID read_method = id_readpartial;
+
+ if (stp->src_fd == -1) {
+ if (!rb_respond_to(stp->src, read_method)) {
+ read_method = id_read;
+ }
+ }
while (1) {
long numwrote;
@@ -7229,7 +7236,7 @@ copy_stream_fallback_body(VALUE arg)
l = buflen < rest ? buflen : rest;
}
if (stp->src_fd == -1) {
- rb_funcall(stp->src, id_readpartial, 2, INT2FIX(l), buf);
+ rb_funcall(stp->src, read_method, 2, INT2FIX(l), buf);
}
else {
ssize_t ss;
@@ -7248,6 +7255,9 @@ copy_stream_fallback_body(VALUE arg)
numwrote = NUM2LONG(n);
stp->total += numwrote;
rest -= numwrote;
+ if (read_method == id_read && RSTRING_LEN(buf) == 0) {
+ break;
+ }
}
return Qnil;
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb
index a52eb50071..b4ddee0239 100644
--- a/test/fileutils/test_fileutils.rb
+++ b/test/fileutils/test_fileutils.rb
@@ -977,8 +977,8 @@ end
@f = f
end
- def read(n)
- @f.read(n)
+ def read(*args)
+ @f.read(*args)
end
def write(str)