Project

General

Profile

Bug #11319

"w+" is interpreted as "r+" when reopening stdio streams

Added by cremno (cremno phobia) over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:69779]

Description

diff --git a/io.c b/io.c
index dfdb422..8358c74 100644
--- a/io.c
+++ b/io.c
@@ -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 9b3e801..1662ac0 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|

Associated revisions

Revision af9e072c
Added by normal over 4 years ago

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@mail.ru

[ruby-core:69779] [Bug #11319]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 51066
Added by normalperson (Eric Wong) over 4 years ago

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@mail.ru

[ruby-core:69779] [Bug #11319]

Revision 51066
Added by normal over 4 years ago

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@mail.ru

[ruby-core:69779] [Bug #11319]

Revision 51066
Added by normal over 4 years ago

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@mail.ru

[ruby-core:69779] [Bug #11319]

Revision 51066
Added by normal over 4 years ago

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@mail.ru

[ruby-core:69779] [Bug #11319]

Revision 51066
Added by normal over 4 years ago

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@mail.ru

[ruby-core:69779] [Bug #11319]

Revision 9c038005
Added by nagachika (Tomoyuki Chikanaga) over 4 years ago

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 <cremno@mail.ru>
      [ruby-core:69779] [Bug #11319]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@51568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 51568
Added by nagachika (Tomoyuki Chikanaga) over 4 years ago

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 <cremno@mail.ru>
  [ruby-core:69779] [Bug #11319]

Revision 813b5f43
Added by usa (Usaku NAKAMURA) over 4 years ago

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 <cremno@mail.ru>
      [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

Revision 51611
Added by usa (Usaku NAKAMURA) over 4 years ago

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 <cremno@mail.ru>
  [ruby-core:69779] [Bug #11319]

History

Updated by normalperson (Eric Wong) over 4 years ago

  • Assignee set to normalperson (Eric Wong)
  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED
#2

Updated by Anonymous over 4 years ago

  • Status changed from Open to Closed

Applied in changeset r51066.


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@mail.ru

[ruby-core:69779] [Bug #11319]

#3

Updated by nagachika (Tomoyuki Chikanaga) over 4 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: DONE

Backported into ruby_2_2 branch at r51568

Also available in: Atom PDF