aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--io.c16
2 files changed, 21 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 7a0efbcaef..7a50c34011 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Jun 11 23:33:13 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * io.c (io_fread): bypass buffered read if reading buffer is empty.
+
+ * io.c (remain_size): do not add extra one byte.
+
Wed Jun 11 12:15:17 2008 Tanaka Akira <akr@fsij.org>
* bootstraptest/runner.rb (assert_normal_exit): hide stderr output
diff --git a/io.c b/io.c
index d5ffa0cf6c..ced6a7aed7 100644
--- a/io.c
+++ b/io.c
@@ -1298,6 +1298,20 @@ io_fread(VALUE str, long offset, rb_io_t *fptr)
long n = len;
int c;
+ if (READ_DATA_PENDING(fptr) == 0) {
+ while (n > 0) {
+ c = rb_read_internal(fptr->fd, RSTRING_PTR(str)+offset, n);
+ if (c == 0) break;
+ if (c < 0) {
+ rb_sys_fail(fptr->path);
+ }
+ offset += c;
+ if ((n -= c) <= 0) break;
+ rb_thread_wait_fd(fptr->fd);
+ }
+ return len - n;
+ }
+
while (n > 0) {
c = read_buffered_data(RSTRING_PTR(str)+offset, n, fptr);
if (c > 0) {
@@ -1347,7 +1361,7 @@ remain_size(rb_io_t *fptr)
io_fflush(fptr);
pos = lseek(fptr->fd, 0, SEEK_CUR);
if (st.st_size >= pos && pos >= 0) {
- siz += st.st_size - pos + 1;
+ siz += st.st_size - pos;
if (siz > LONG_MAX) {
rb_raise(rb_eIOError, "file too big for single read");
}