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 302CA198037B for ; Fri, 14 Aug 2015 00:19:23 +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 6B2BCB5D8C1 for ; Fri, 14 Aug 2015 00:54:14 +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 7BEB297A82C for ; Fri, 14 Aug 2015 00:54:17 +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 oiZlqlJySPBO for ; Fri, 14 Aug 2015 00:54:17 +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 1A92897A82B for ; Fri, 14 Aug 2015 00:54:17 +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 0262895241E for ; Fri, 14 Aug 2015 00:54:13 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id B21D11203F8; Fri, 14 Aug 2015 00:54:14 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id 67DD9120036 for ; Fri, 14 Aug 2015 00:54:08 +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=Klmoxf+rxG8Tfk7qT8y3RMt0EBQ=; b=NdcPKSSp94W4Uim02g x3aYBkCXTCt21SSaA36MpkbtDNWovLK1FHFw3q+zV35NJUSMTeECWkczpfvGAUJp 75MGQ+5iEAB4a/NVi4HVuItQeF/HvVF9TfIDwyDQ6D/M6jNSeMYh32P6IPge6pJi q7hD0xmYlmbKY1pnXs7WpsqRw= Received: by filter0454p1mdw1.sendgrid.net with SMTP id filter0454p1mdw1.17598.55CCBD962B 2015-08-13 15:53:58.583153782 +0000 UTC Received: from herokuapp.com (ec2-54-161-3-50.compute-1.amazonaws.com [54.161.3.50]) by ismtpd0001p1iad1.sendgrid.net (SG) with ESMTP id hXnps4UdRa2BYYQ1AxW1Fg for ; Thu, 13 Aug 2015 15:53:58 +0000 (UTC) Date: Thu, 13 Aug 2015 15:53:58 +0000 From: nagachika00@gmail.com 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: 44971 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11319 X-Redmine-Issue-Author: cremno X-Redmine-Issue-Assignee: normalperson X-Redmine-Sender: nagachika 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS48m/xHsZTftknbuiAlO+u8atYsrbZXaU2u3c iro5gXX0ybANyn40RvOj3o7Yjm1t+FLdpGcVuuw+iVxd3va19hktFAP0svAbWl0+ZyCLoHtiYx+ffA tTp9Mzw/Ry7PTw8bTv6Y8+pWJ4d5coplNfo5 X-ML-Name: ruby-core X-Mail-Count: 70369 Subject: [ruby-core:70369] [Ruby trunk - Bug #11319] "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 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/