]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: UpdateStdInStdOutStdErr(): append BOM to new unicode file
authorLaszlo Ersek <lersek@redhat.com>
Thu, 31 Jul 2014 15:44:43 +0000 (15:44 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 31 Jul 2014 15:44:43 +0000 (15:44 +0000)
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

ShellPkg/Application/Shell/ShellParametersProtocol.c

index 88453a231ce71954a281e6c9772a18fff876923a..9d769541c6fdd5a2d1eefe91f080dc14d7c7dc56 100644 (file)
@@ -1111,12 +1111,18 @@ UpdateStdInStdOutStdErr(
           } else if (!OutAppend && OutUnicode && !EFI_ERROR(Status)) {\r
             Status = WriteFileTag (TempHandle);\r
           } else if (OutAppend) {\r
-            //\r
-            // Move to end of file\r
-            //\r
             Status = ShellInfoObject.NewEfiShellProtocol->GetFileSize(TempHandle, &FileSize);\r
             if (!EFI_ERROR(Status)) {\r
-              Status = ShellInfoObject.NewEfiShellProtocol->SetFilePosition(TempHandle, FileSize);\r
+              //\r
+              // When appending to a new unicode file, write the file tag.\r
+              // Otherwise (ie. when appending to a new ASCII file, or an\r
+              // existent file with any encoding), just seek to the end.\r
+              //\r
+              Status = (FileSize == 0 && OutUnicode) ?\r
+                         WriteFileTag (TempHandle) :\r
+                         ShellInfoObject.NewEfiShellProtocol->SetFilePosition (\r
+                                                                TempHandle,\r
+                                                                FileSize);\r
             }\r
           }\r
           if (!OutUnicode && !EFI_ERROR(Status)) {\r