* [PATCH] io.c: reopen stdio streams correctly when given "w+"
@ 2015-06-29 23:20 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-06-29 23:20 UTC (permalink / raw)
To: spew
* 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]
---
io.c | 3 +++
test/ruby/test_io.rb | 9 +++++++++
2 files changed, 12 insertions(+)
diff --git a/io.c b/io.c
index 8844987..6c62c97 100644
--- a/io.c
+++ b/io.c
@@ -5033,6 +5033,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..9ded25b 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|
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-06-29 23:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-29 23:20 [PATCH] io.c: reopen stdio streams correctly when given "w+" Eric Wong
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).