diff mbox

[edk2,1/2] ShellPkg: UpdateStdInStdOutStdErr(): extract WriteFileTag()

Message ID 1406672792-7151-2-git-send-email-lersek@redhat.com
State Accepted
Commit 94c2a04449a13ae76ad1f337b4e0db91cb6bd144
Headers show

Commit Message

Laszlo Ersek July 29, 2014, 10:26 p.m. UTC
Drop TagBuffer in the process.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 .../Application/Shell/ShellParametersProtocol.c    | 48 +++++++++++++++-------
 1 file changed, 33 insertions(+), 15 deletions(-)
diff mbox

Patch

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