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 5AF0A1960057 for ; Tue, 30 Jun 2015 07:50:51 +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 36D5FB5D96F for ; Tue, 30 Jun 2015 08:16:05 +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 106FB97A832 for ; Tue, 30 Jun 2015 08:16:06 +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 FbRP2X_yNQ1R for ; Tue, 30 Jun 2015 08:16:05 +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 C909597A820 for ; Tue, 30 Jun 2015 08:16:05 +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 CF58C95243A for ; Tue, 30 Jun 2015 08:16:04 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 431D4120433; Tue, 30 Jun 2015 08:16:03 +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 2F98912040F for ; Tue, 30 Jun 2015 08:15:59 +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=sGCwAswUikL33Xl2Mu87kXfLOAY=; b=gYX8wA/imzImqm8PlS u0TjPWIWki8rIW18JhPaVa1sHqgR+TLvhcmk16fC+TjIFjAJWhD/pugq2Opxk8ER 1HPQRdYQnfFTmnRPjHeUFs2kHfX3ltXsmwPHLmN0Us8AoWAtbO8I8RBoj+kKT4ty f+OuWEz6suqsGTLZCWogiSwvU= Received: by filter0606p1mdw1.sendgrid.net with SMTP id filter0606p1mdw1.18140.5591D1AB39 2015-06-29 23:15:56.058276265 +0000 UTC Received: from herokuapp.com (ec2-54-167-140-216.compute-1.amazonaws.com [54.167.140.216]) by ismtpd-019 (SG) with ESMTP id 14e419b07e8.5cad.38a264 for ; Mon, 29 Jun 2015 23:15:56 +0000 (UTC) Date: Mon, 29 Jun 2015 23:15:55 +0000 From: normalperson@yhbt.net 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: 44362 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11319 X-Redmine-Issue-Author: cremno X-Redmine-Issue-Assignee: normalperson X-Redmine-Sender: normalperson 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS5LefybUS+PmMzd4HCs29CM5EEAEe6XpMQkm1 eRcHC9Ejll8AWoWlS3/3BHJCHkDiOeBAeWipwQuzlTSelKl1MiU1JvOW32hvV91N2xFs9xrriscJJe 1rGNJ6M/WzlDQ4dQO4dyYry4jEbfDrir3xnS X-ML-Name: ruby-core X-Mail-Count: 69781 Subject: [ruby-core:69781] [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 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/