зеркало из https://github.com/github/ruby.git
* io.c (io_reopen): unread current buffer before telling the
position, for the case of reopening same file. [ruby-dev:39479] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
c7afd1aef4
Коммит
6069202867
|
@ -1,3 +1,8 @@
|
|||
Thu Oct 15 14:57:58 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* io.c (io_reopen): unread current buffer before telling the
|
||||
position, for the case of reopening same file. [ruby-dev:39479]
|
||||
|
||||
Thu Oct 15 14:20:58 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/iconv/iconv.c (iconv_create): cannot retry with given block.
|
||||
|
|
14
io.c
14
io.c
|
@ -5654,13 +5654,6 @@ io_reopen(VALUE io, VALUE nfile)
|
|||
rb_io_fmode_modestr(orig->mode));
|
||||
}
|
||||
}
|
||||
if (orig->mode & FMODE_READABLE) {
|
||||
pos = io_tell(orig);
|
||||
}
|
||||
if (orig->mode & FMODE_WRITABLE) {
|
||||
if (io_fflush(orig) < 0)
|
||||
rb_sys_fail(0);
|
||||
}
|
||||
if (fptr->mode & FMODE_WRITABLE) {
|
||||
if (io_fflush(fptr) < 0)
|
||||
rb_sys_fail(0);
|
||||
|
@ -5668,6 +5661,13 @@ io_reopen(VALUE io, VALUE nfile)
|
|||
else {
|
||||
io_tell(fptr);
|
||||
}
|
||||
if (orig->mode & FMODE_READABLE) {
|
||||
pos = io_tell(orig);
|
||||
}
|
||||
if (orig->mode & FMODE_WRITABLE) {
|
||||
if (io_fflush(orig) < 0)
|
||||
rb_sys_fail(0);
|
||||
}
|
||||
|
||||
/* copy rb_io_t structure */
|
||||
fptr->mode = orig->mode | (fptr->mode & FMODE_PREP);
|
||||
|
|
|
@ -1286,6 +1286,15 @@ class TestIO < Test::Unit::TestCase
|
|||
assert_equal("bar\n", f.gets, '[ruby-core:24240]')
|
||||
}
|
||||
end
|
||||
|
||||
open(__FILE__) do |f|
|
||||
f2 = open(t.path)
|
||||
f.reopen(f2)
|
||||
assert_equal("foo\n", f.gets)
|
||||
assert_equal("bar\n", f.gets)
|
||||
f.reopen(f2)
|
||||
assert_equal("baz\n", f.gets, '[ruby-dev:39479]')
|
||||
end
|
||||
end
|
||||
|
||||
def test_foreach
|
||||
|
|
Загрузка…
Ссылка в новой задаче