diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | io.c | 3 | ||||
-rw-r--r-- | test/ruby/test_io.rb | 9 |
3 files changed, 19 insertions, 0 deletions
@@ -1,3 +1,10 @@ +Tue Jun 30 08:24:08 2015 Eric Wong <e@80x24.org> + + * io.c (rb_io_oflags_modestr): handle O_TRUNC correctly + * test/ruby/test_io.rb (test_reopen_stdio): new test + Patch-by: cremno phobia <cremno@mail.ru> + [ruby-core:69779] [Bug #11319] + Tue Jun 30 02:47:02 2015 Eric Wong <e@80x24.org> * include/ruby/st.h (struct st_table): hide struct list_head @@ -5046,6 +5046,9 @@ rb_io_oflags_modestr(int oflags) case O_WRONLY: return MODE_BINARY("w", "wb"); case O_RDWR: + if (oflags & O_TRUNC) { + return MODE_BINARY("w+", "wb+"); + } return MODE_BINARY("r+", "rb+"); } } diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 9b3e80160d..9ded25b051 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2069,6 +2069,15 @@ End } end + def test_reopen_stdio + mkcdtmpdir { + fname = 'bug11319' + File.write(fname, 'hello') + system(EnvUtil.rubybin, '-e', "STDOUT.reopen('#{fname}', 'w+')") + assert_equal('', File.read(fname)) + } + end + def test_reopen_mode feature7067 = '[ruby-core:47694]' make_tempfile {|t| |