From 813b5f43cb44a64a7630bc3858e85caa607f8105 Mon Sep 17 00:00:00 2001 From: usa Date: Mon, 17 Aug 2015 08:45:57 +0000 Subject: merge revision(s) 51066: [Backport #11319] * io.c (rb_io_oflags_modestr): handle O_TRUNC correctly * test/ruby/test_io.rb (test_reopen_stdio): new test Patch-by: cremno phobia [ruby-core:69779] [Bug #11319] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@51611 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ io.c | 3 +++ test/ruby/test_io.rb | 9 +++++++++ version.h | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 299d045036..8fbee6d0b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Mon Aug 17 17:43:56 2015 Eric Wong + + * io.c (rb_io_oflags_modestr): handle O_TRUNC correctly + * test/ruby/test_io.rb (test_reopen_stdio): new test + Patch-by: cremno phobia + [ruby-core:69779] [Bug #11319] + Mon Aug 17 17:42:18 2015 Benoit Daloze * lib/net/ftp.rb (makeport): close the TCPServer diff --git a/io.c b/io.c index 95229903ca..b86ebe8e7f 100644 --- a/io.c +++ b/io.c @@ -4958,6 +4958,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 77ab97317a..18e37d6d0b 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1979,6 +1979,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| diff --git a/version.h b/version.h index 5225ecdd77..2c917e4eb1 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.1.7" #define RUBY_RELEASE_DATE "2015-08-17" -#define RUBY_PATCHLEVEL 393 +#define RUBY_PATCHLEVEL 394 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 8 -- cgit v1.2.3