From 94c2a04449a13ae76ad1f337b4e0db91cb6bd144 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Thu, 31 Jul 2014 15:44:30 +0000 Subject: ShellPkg: UpdateStdInStdOutStdErr(): extract WriteFileTag() Drop TagBuffer in the process. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Reviewed-by: Jaben Carsey git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15724 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Application/Shell/ShellParametersProtocol.c | 48 +++++++++++++++------- 1 file changed, 33 insertions(+), 15 deletions(-) (limited to 'ShellPkg') diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c index 7809a0e0d7..88453a231c 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.
This program and the accompanying materials @@ -593,6 +594,36 @@ RemoveFileTag( return (EFI_SUCCESS); } +/** + 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 @@ -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 -- cgit v1.2.3