]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: UpdateStdInStdOutStdErr(): extract WriteFileTag()
authorLaszlo Ersek <lersek@redhat.com>
Thu, 31 Jul 2014 15:44:30 +0000 (15:44 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 31 Jul 2014 15:44:30 +0000 (15:44 +0000)
Drop TagBuffer in the process.

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@15724 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Application/Shell/ShellParametersProtocol.c

index 7809a0e0d720708ada43364ac5283bc769f58e4b..88453a231ce71954a281e6c9772a18fff876923a 100644 (file)
@@ -2,6 +2,7 @@
   Member functions of EFI_SHELL_PARAMETERS_PROTOCOL and functions for creation,\r
   manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.\r
 \r
+  Copyright (C) 2014, Red Hat, Inc.\r
   Copyright (c) 2013 Hewlett-Packard Development Company, L.P.\r
   Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
@@ -593,6 +594,36 @@ RemoveFileTag(
   return (EFI_SUCCESS);\r
 }\r
 \r
+/**\r
+  Write the unicode file tag to the specified file.\r
+\r
+  It is the caller's responsibility to ensure that\r
+  ShellInfoObject.NewEfiShellProtocol has been initialized before calling this\r
+  function.\r
+\r
+  @param[in] FileHandle  The file to write the unicode file tag to.\r
+\r
+  @return  Status code from ShellInfoObject.NewEfiShellProtocol->WriteFile.\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+WriteFileTag (\r
+  IN SHELL_FILE_HANDLE FileHandle\r
+  )\r
+{\r
+  CHAR16     FileTag;\r
+  UINTN      Size;\r
+  EFI_STATUS Status;\r
+\r
+  FileTag = gUnicodeFileTag;\r
+  Size = sizeof FileTag;\r
+  Status = ShellInfoObject.NewEfiShellProtocol->WriteFile (FileHandle, &Size,\r
+                                                  &FileTag);\r
+  ASSERT (EFI_ERROR (Status) || Size == sizeof FileTag);\r
+  return Status;\r
+}\r
+\r
+\r
 /**\r
   Funcion will replace the current StdIn and StdOut in the ShellParameters protocol\r
   structure by parsing NewCommandLine.  The current values are returned to the\r
@@ -638,7 +669,6 @@ UpdateStdInStdOutStdErr(
   BOOLEAN           OutAppend;\r
   BOOLEAN           ErrAppend;\r
   UINTN             Size;\r
-  CHAR16            TagBuffer[2];\r
   SPLIT_LIST        *Split;\r
   CHAR16            *FirstLocation;\r
 \r
@@ -1050,13 +1080,7 @@ UpdateStdInStdOutStdErr(
         }\r
         Status = ShellOpenFileByName(StdErrFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE,0);\r
         if (!ErrAppend && ErrUnicode && !EFI_ERROR(Status)) {\r
-          //\r
-          // Write out the gUnicodeFileTag\r
-          //\r
-          Size = sizeof(CHAR16);\r
-          TagBuffer[0] = gUnicodeFileTag;\r
-          TagBuffer[1] = CHAR_NULL;\r
-          ShellInfoObject.NewEfiShellProtocol->WriteFile(TempHandle, &Size, TagBuffer);\r
+          Status = WriteFileTag (TempHandle);\r
         }\r
         if (!ErrUnicode && !EFI_ERROR(Status)) {\r
           TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);\r
@@ -1085,13 +1109,7 @@ UpdateStdInStdOutStdErr(
           if (StrStr(StdOutFileName, L"NUL")==StdOutFileName) {\r
             //no-op\r
           } else if (!OutAppend && OutUnicode && !EFI_ERROR(Status)) {\r
-            //\r
-            // Write out the gUnicodeFileTag\r
-            //\r
-            Size = sizeof(CHAR16);\r
-            TagBuffer[0] = gUnicodeFileTag;\r
-            TagBuffer[1] = CHAR_NULL;\r
-            ShellInfoObject.NewEfiShellProtocol->WriteFile(TempHandle, &Size, TagBuffer);\r
+            Status = WriteFileTag (TempHandle);\r
           } else if (OutAppend) {\r
             //\r
             // Move to end of file\r