summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-07 08:23:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-07 08:23:00 +0000
commita5c2f8843f0fb022e1bc33cad8d6d475958d2f83 (patch)
tree534ab41574c1463fe095a8012ef6521307a7e6d9
parent5a12fb5fb87fe373ad251d68752388148c1363a3 (diff)
* io.c (rb_io_tell): adjustment for ungotten data.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--io.c1
-rw-r--r--test/ruby/test_io.rb6
3 files changed, 11 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 4af7f3e423..1c99e620c9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Mon Sep 7 17:22:59 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * io.c (rb_io_tell): adjustment for ungotten data.
+
Mon Sep 7 17:13:53 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (io_encname_bom_p): removed magic number.
diff --git a/io.c b/io.c
index 31a86da6b9..1e6b26b5e4 100644
--- a/io.c
+++ b/io.c
@@ -1042,6 +1042,7 @@ rb_io_tell(VALUE io)
GetOpenFile(io, fptr);
pos = io_tell(fptr);
if (pos < 0 && errno) rb_sys_fail_path(fptr->pathv);
+ pos -= fptr->rbuf_len;
return OFFT2NUM(pos);
}
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 7a0ecc0cf1..8b1714b01e 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -121,16 +121,22 @@ class TestIO < Test::Unit::TestCase
def test_ungetbyte
t = make_tempfile
t.open
+ t.binmode
t.ungetbyte(0x41)
+ assert_equal(-1, t.pos)
assert_equal(0x41, t.getbyte)
t.rewind
+ assert_equal(0, t.pos)
t.ungetbyte("qux")
+ assert_equal(-3, t.pos)
assert_equal("quxfoo\n", t.gets)
+ assert_equal(4, t.pos)
t.set_encoding("utf-8")
t.ungetbyte(0x89)
t.ungetbyte(0x8e)
t.ungetbyte("\xe7")
t.ungetbyte("\xe7\xb4\x85")
+ assert_equal(-2, t.pos)
assert_equal("\u7d05\u7389bar\n", t.gets)
end