Skip to content

Commit

Permalink
* io.c (rb_io_tell): adjustment for ungotten data.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Sep 7, 2009
1 parent 5a12fb5 commit a5c2f88
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Mon Sep 7 17:22:59 2009 Nobuyoshi Nakada <[email protected]>

* io.c (rb_io_tell): adjustment for ungotten data.

Mon Sep 7 17:13:53 2009 Nobuyoshi Nakada <[email protected]>

* io.c (io_encname_bom_p): removed magic number.
Expand Down
1 change: 1 addition & 0 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions test/ruby/test_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,22 @@ def test_ungetc
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

Expand Down

0 comments on commit a5c2f88

Please sign in to comment.