From 54198fca16edef9ec2828edad7b9dd82693d19c8 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 11 Jan 2005 11:59:00 +0000 Subject: * io.c (remain_size): use buffered data instead of unreading to avoid inconsistency of text mode. fixed: [ruby-dev:25446] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7767 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index b2496b7b1f..f3c7ed6081 100644 --- a/io.c +++ b/io.c @@ -1120,7 +1120,7 @@ remain_size(fptr) OpenFile *fptr; { struct stat st; - off_t siz = BUFSIZ; + off_t siz = READ_DATA_PENDING_COUNT(fptr); off_t pos; if (fstat(fptr->fd, &st) == 0 && S_ISREG(st.st_mode) @@ -1129,14 +1129,18 @@ remain_size(fptr) #endif ) { - pos = io_tell(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 + 1; if (siz > LONG_MAX) { rb_raise(rb_eIOError, "file too big for single read"); } } } + else { + siz += BUFSIZ; + } return (long)siz; } -- cgit v1.2.3