summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--io.c3
-rw-r--r--test/ruby/test_io.rb10
2 files changed, 13 insertions, 0 deletions
diff --git a/io.c b/io.c
index 9720145fc1..b1d985e4f5 100644
--- a/io.c
+++ b/io.c
@@ -5648,6 +5648,9 @@ io_reopen(VALUE io, VALUE nfile)
if (io_fflush(fptr) < 0)
rb_sys_fail(0);
}
+ else {
+ io_tell(fptr);
+ }
/* copy rb_io_t structure */
fptr->mode = orig->mode | (fptr->mode & FMODE_PREP);
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 8a5b878f3b..42614e00cb 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -1270,6 +1270,16 @@ class TestIO < Test::Unit::TestCase
assert_equal("foo\n", f.gets)
}
end
+
+ open(__FILE__) do |f|
+ f.gets
+ f2 = open(t.path)
+ f2.gets
+ assert_nothing_raised {
+ f.reopen(f2)
+ assert_equal("bar\n", f.gets, '[ruby-core:24240]')
+ }
+ end
end
def test_foreach