From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 258A31960015 for ; Tue, 30 Jun 2015 07:30:45 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id B67C9B5D8F3 for ; Tue, 30 Jun 2015 07:55:58 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 8599297A826 for ; Tue, 30 Jun 2015 07:55:59 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Authentication-Results: funfun.nagaokaut.ac.jp (amavisd-new); dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=sendgrid.me Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mbL2axDDim5g for ; Tue, 30 Jun 2015 07:55:59 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 1F9D397A820 for ; Tue, 30 Jun 2015 07:55:59 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 30A1C952439 for ; Tue, 30 Jun 2015 07:55:57 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id A687E120432; Tue, 30 Jun 2015 07:55:55 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o2.heroku.sendgrid.net (o2.heroku.sendgrid.net [67.228.50.55]) by neon.ruby-lang.org (Postfix) with ESMTPS id 14C6B1203F8 for ; Tue, 30 Jun 2015 07:55:51 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=Ifyj2JVkArYOZXsWNZlVP11jWcU=; b=b5MlHlw19jomSbUl1G dhN053ooGkfAJp0JLB6/A0/XGBg7A9T8CumFUmHWbSNKiuZ9beDV/Wc3WR/cV8pj sEOup4xkXpk/iilCinqb/xVgx7qhbJHCZ3/UFcHcUXdasUUZ1LtxwHuAMiIg7l/J /NA6/R7LGwAprFA3dczWj+9LY= Received: by filter0576p1mdw1.sendgrid.net with SMTP id filter0576p1mdw1.7254.5591CCF06 2015-06-29 22:55:45.395712279 +0000 UTC Received: from ismtpd-033.iad1.sendgrid.net ([UNAVAILABLE]. [10.42.2.100]) by 10.42.243.12:2500 (trex/5.2.13); Mon, 29 Jun 2015 22:55:47 GMT Received: from herokuapp.com (ec2-54-145-225-192.compute-1.amazonaws.com [54.145.225.192]) by ismtpd-033 (SG) with ESMTP id 14e41888d71.11ae.9c3704 for ; Mon, 29 Jun 2015 22:55:45 +0000 (UTC) Date: Mon, 29 Jun 2015 22:55:44 +0000 From: cremno@mail.ru To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 44360 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11319 X-Redmine-Issue-Author: cremno X-Redmine-Sender: cremno X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS6N8GVvXLrA9RYhrevP3NzcBL3l6Xg31UugPF Dk/usDSl3RCaYS8gfCe+/sI3HPRPwyneldhrMVO51Jo4IiRPAzC6h20MOLxXdMK6CivTC1m0p7U8o4 lrNZq7tjykjG7WDbbrP2TrZIgzGnXhxW2t0V X-SendGrid-Contentd-ID: {"test_id":"1435618548"} X-ML-Name: ruby-core X-Mail-Count: 69779 Subject: [ruby-core:69779] [Ruby trunk - Bug #11319] [Open] "w+" is interpreted as "r+" when reopening stdio streams X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "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/