summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-01-11 11:59:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-01-11 11:59:00 +0000
commit54198fca16edef9ec2828edad7b9dd82693d19c8 (patch)
treefe5fed90346bc6ff366b6819d8d6a13729730b91 /io.c
parent0be6a1f5c873e6e2074ebbe47ca83863890ecceb (diff)
* 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
Diffstat (limited to 'io.c')
-rw-r--r--io.c10
1 files changed, 7 insertions, 3 deletions
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;
}