ruby-changes:38985
From: normal <ko1@a...>
Date: Tue, 30 Jun 2015 08:25:11 +0900 (JST)
Subject: [ruby-changes:38985] normal:r51066 (trunk): io.c: reopen stdio streams correctly when given "w+"
normal 2015-06-30 08:24:56 +0900 (Tue, 30 Jun 2015) New Revision: 51066 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51066 Log: io.c: reopen stdio streams correctly when given "w+" * 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@m...> [ruby-core:69779] [Bug #11319] Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 51065) +++ ChangeLog (revision 51066) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Jun 30 08:24:08 2015 Eric Wong <e@8...> + + * 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@m...> + [ruby-core:69779] [Bug #11319] + Tue Jun 30 02:47:02 2015 Eric Wong <e@8...> * include/ruby/st.h (struct st_table): hide struct list_head Index: io.c =================================================================== --- io.c (revision 51065) +++ io.c (revision 51066) @@ -5046,6 +5046,9 @@ rb_io_oflags_modestr(int oflags) https://github.com/ruby/ruby/blob/trunk/io.c#L5046 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+"); } } Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 51065) +++ test/ruby/test_io.rb (revision 51066) @@ -2069,6 +2069,15 @@ End https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2069 } 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| -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/