summaryrefslogtreecommitdiff
path: root/ShellPkg
diff options
context:
space:
mode:
authorLaszlo Ersek <lersek@redhat.com>2014-07-31 15:44:43 +0000
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>2014-07-31 15:44:43 +0000
commit5967886d58e4ac7d46e0c6b7cc34fd9ba94fd6d1 (patch)
treef35d001cb8e14b555f9fae1214e81867427cf12e /ShellPkg
parent94c2a04449a13ae76ad1f337b4e0db91cb6bd144 (diff)
downloadedk2-platforms-5967886d58e4ac7d46e0c6b7cc34fd9ba94fd6d1.tar.xz
ShellPkg: UpdateStdInStdOutStdErr(): append BOM to new unicode file
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 <Lowell_Dennis@Dell.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15725 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg')
-rw-r--r--ShellPkg/Application/Shell/ShellParametersProtocol.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c
index 88453a231c..9d769541c6 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)) {