From: nagachika00@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:70369] [Ruby trunk - Bug #11319] "w+" is interpreted as "r+" when reopening stdio streams
Date: Thu, 13 Aug 2015 15:53:58 +0000 [thread overview]
Message-ID: <redmine.journal-53774.20150813155357.471b5c1ae440b933@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11319.20150629225544@ruby-lang.org
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/
prev parent reply other threads:[~2015-08-13 15:19 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 ` [ruby-core:69779] [Ruby trunk - Bug #11319] [Open] "w+" is interpreted as "r+" when reopening stdio streams cremno
2015-06-29 23:15 ` [ruby-core:69781] [Ruby trunk - Bug #11319] " normalperson
2015-08-13 15:53 ` nagachika00 [this message]
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.journal-53774.20150813155357.471b5c1ae440b933@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).