ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: cremno@mail.ru
To: ruby-core@ruby-lang.org
Subject: [ruby-core:69779] [Ruby trunk - Bug #11319] [Open] "w+" is interpreted as "r+" when reopening stdio streams
Date: Mon, 29 Jun 2015 22:55:44 +0000	[thread overview]
Message-ID: <redmine.issue-11319.20150629225544.f25afa726c552eea@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11319.20150629225544@ruby-lang.org

Issue #11319 has been reported by cremno phobia.

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

* Author: cremno phobia
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~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/

       reply	other threads:[~2015-06-29 22:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-11319.20150629225544@ruby-lang.org>
2015-06-29 22:55 ` cremno [this message]
2015-06-29 23:15 ` [ruby-core:69781] [Ruby trunk - Bug #11319] "w+" is interpreted as "r+" when reopening stdio streams normalperson
2015-08-13 15:53 ` [ruby-core:70369] " nagachika00

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.issue-11319.20150629225544.f25afa726c552eea@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).