From patchwork Tue Jul 29 22:26:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 34493 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f197.google.com (mail-pd0-f197.google.com [209.85.192.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F1B1B20DCC for ; Tue, 29 Jul 2014 22:27:01 +0000 (UTC) Received: by mail-pd0-f197.google.com with SMTP id y10sf2078255pdj.8 for ; Tue, 29 Jul 2014 15:27:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:reply-to:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=OYBTd/g5jZndxgnm9J+CT018iRVrco/IjYCJ/4nBdck=; b=ThZCa5oe3E2YSZwHf+kWN7MajcPzuxg41hY658VADxdiDXZS5mGwQZDG2sTQVKTK5x 8Ai1iEb1bwM3H/3M1yyfuUp1CF5OTBFS8C+WXGzMRQgR5/YisV6VH/ogEd4o3xjiwGaR I9wDGTDcQAAcQOQXH9J3hLohJA4xctXyeTF1+bsXe5mrUjD272z9hd8LPfmq3bgFJKs4 +VnlbBBiyt2o5LV1j2mFFIUehhOND0MNa1wBXapbXUIqTD2oiutR3G7gB0TbviijBs51 G+gTdTEUAIPWvMg07+liHZeI2awsubgFY5zOOi826qw+KJ7mgmiU0up6Tr2mQRrPo5lU EcWA== X-Gm-Message-State: ALoCoQnwWuOaco+aFiiC2tc4v6uh1Nrr+vimwHUm5Krn3HIdWCbPQ8FTQJ9Tx4GECat0zIslZ8zK X-Received: by 10.66.145.33 with SMTP id sr1mr63552pab.18.1406672821052; Tue, 29 Jul 2014 15:27:01 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.96.199 with SMTP id k65ls276825qge.3.gmail; Tue, 29 Jul 2014 15:27:00 -0700 (PDT) X-Received: by 10.220.119.8 with SMTP id x8mr52339vcq.62.1406672820856; Tue, 29 Jul 2014 15:27:00 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id ss10si223595vcb.92.2014.07.29.15.27.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Jul 2014 15:27:00 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id id10so586221vcb.7 for ; Tue, 29 Jul 2014 15:27:00 -0700 (PDT) X-Received: by 10.220.118.136 with SMTP id v8mr68982vcq.50.1406672820731; Tue, 29 Jul 2014 15:27:00 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp277447vcb; Tue, 29 Jul 2014 15:27:00 -0700 (PDT) X-Received: by 10.50.66.197 with SMTP id h5mr25324411igt.34.1406672820008; Tue, 29 Jul 2014 15:27:00 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id d11si1416882igz.33.2014.07.29.15.26.59 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 29 Jul 2014 15:26:59 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XCFr8-0006no-43; Tue, 29 Jul 2014 22:26:50 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XCFr5-0006nj-Vu for edk2-devel@lists.sourceforge.net; Tue, 29 Jul 2014 22:26:48 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=lersek@redhat.com; helo=mx1.redhat.com; Received: from mx1.redhat.com ([209.132.183.28]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1XCFr4-00050F-Hc for edk2-devel@lists.sourceforge.net; Tue, 29 Jul 2014 22:26:47 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s6TMQc4q012504 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Jul 2014 18:26:38 -0400 Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s6TMQYWt027236; Tue, 29 Jul 2014 18:26:37 -0400 From: Laszlo Ersek To: edk2-devel@lists.sourceforge.net, Lowell_Dennis@Dell.com Date: Wed, 30 Jul 2014 00:26:32 +0200 Message-Id: <1406672792-7151-3-git-send-email-lersek@redhat.com> In-Reply-To: <1406672792-7151-1-git-send-email-lersek@redhat.com> References: <1406672792-7151-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Spam-Score: -2.2 (--) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1XCFr4-00050F-Hc Subject: [edk2] [PATCH 2/2] ShellPkg: UpdateStdInStdOutStdErr(): append BOM to new unicode file X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lersek@redhat.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 The >> operator redirects stdout to a file, using append mode and unicode encoding. Write the BOM when redirection happens to a new file (which starts out empty). This makes the >> operator behave similarly to the > operator, when the redirection target doesn't exist originally: OutUnicode && OutAppend && FileSize == 0 // >> to new unicode file vs. OutUnicode && !OutAppend // > to any unicode file (Note that (FileSize == 0) is equivalent to "new file" in this context, due to the earlier "Check that filetypes (Unicode/Ascii) do not change during an append".) Reported-by: Lowell Dennis Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Reviewed-by: Jaben Carsey --- ShellPkg/Application/Shell/ShellParametersProtocol.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c index 88453a2..9d76954 100644 --- a/ShellPkg/Application/Shell/ShellParametersProtocol.c +++ b/ShellPkg/Application/Shell/ShellParametersProtocol.c @@ -1111,12 +1111,18 @@ UpdateStdInStdOutStdErr( } else if (!OutAppend && OutUnicode && !EFI_ERROR(Status)) { Status = WriteFileTag (TempHandle); } else if (OutAppend) { - // - // Move to end of file - // Status = ShellInfoObject.NewEfiShellProtocol->GetFileSize(TempHandle, &FileSize); if (!EFI_ERROR(Status)) { - Status = ShellInfoObject.NewEfiShellProtocol->SetFilePosition(TempHandle, FileSize); + // + // When appending to a new unicode file, write the file tag. + // Otherwise (ie. when appending to a new ASCII file, or an + // existent file with any encoding), just seek to the end. + // + Status = (FileSize == 0 && OutUnicode) ? + WriteFileTag (TempHandle) : + ShellInfoObject.NewEfiShellProtocol->SetFilePosition ( + TempHandle, + FileSize); } } if (!OutUnicode && !EFI_ERROR(Status)) {