[#70257] [Ruby trunk - Feature #11420] [Open] Introduce ID key table into MRI — ko1@...

Issue #11420 has been reported by Koichi Sasada.

11 messages 2015/08/06

[ruby-core:70369] [Ruby trunk - Bug #11319] "w+" is interpreted as "r+" when reopening stdio streams

From: nagachika00@...
Date: 2015-08-13 15:53:58 UTC
List: ruby-core #70369
Issue #11319 has been updated by Tomoyuki Chikanaga.

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

----------------------------------------
Bug #11319: "w+" is interpreted as "r+" when reopening stdio streams
https://bugs.ruby-lang.org/issues/11319#change-53774

* Author: cremno phobia
* Status: Closed
* Priority: Normal
* Assignee: Eric Wong
* ruby -v: 
* Backport: 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: DONE
----------------------------------------
~~~diff
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|

~~~



-- 
https://bugs.ruby-lang.org/

In This Thread

Prev Next