* [ruby-core:69779] [Ruby trunk - Bug #11319] [Open] "w+" is interpreted as "r+" when reopening stdio streams
[not found] <redmine.issue-11319.20150629225544@ruby-lang.org>
@ 2015-06-29 22:55 ` cremno
2015-06-29 23:15 ` [ruby-core:69781] [Ruby trunk - Bug #11319] " normalperson
2015-08-13 15:53 ` [ruby-core:70369] " nagachika00
2 siblings, 0 replies; 3+ messages in thread
From: cremno @ 2015-06-29 22:55 UTC (permalink / raw)
To: ruby-core
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/
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [ruby-core:69781] [Ruby trunk - Bug #11319] "w+" is interpreted as "r+" when reopening stdio streams
[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 ` normalperson
2015-08-13 15:53 ` [ruby-core:70369] " nagachika00
2 siblings, 0 replies; 3+ messages in thread
From: normalperson @ 2015-06-29 23:15 UTC (permalink / raw)
To: ruby-core
Issue #11319 has been updated by Eric Wong.
Assignee set to 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
----------------------------------------
Bug #11319: "w+" is interpreted as "r+" when reopening stdio streams
https://bugs.ruby-lang.org/issues/11319#change-53157
* Author: cremno phobia
* Status: Open
* Priority: Normal
* Assignee: Eric Wong
* ruby -v:
* Backport: 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED
----------------------------------------
~~~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/
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [ruby-core:70369] [Ruby trunk - Bug #11319] "w+" is interpreted as "r+" when reopening stdio streams
[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
2 siblings, 0 replies; 3+ messages in thread
From: nagachika00 @ 2015-08-13 15:53 UTC (permalink / raw)
To: ruby-core
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/
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-08-13 15:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[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 ` [ruby-core:70369] " nagachika00
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).