X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellLib%2FUefiShellLib.c;h=5e5e6271bf24d418aaa7f04ff29925aee0be1754;hb=1d32246161af275d7a2d17ade4a8fa53ea37a556;hp=4b53c7080c306f9e69335f2b4a0c8c63b2aaa060;hpb=d2a0d2e6acea4d6a3dbe31b68a9a7fe7511cb478;p=mirror_edk2.git diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c index 4b53c7080c..5e5e6271bf 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -2,7 +2,7 @@ Provides interface to shell functionality for shell commands and applications. Copyright 2016 Dell Inc. - Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -373,6 +373,8 @@ EFIAPI ShellInitialize ( ) { + EFI_STATUS Status; + // // if auto initialize is not false then skip // @@ -383,7 +385,8 @@ ShellInitialize ( // // deinit the current stuff // - ASSERT_EFI_ERROR(ShellLibDestructor(gImageHandle, gST)); + Status = ShellLibDestructor (gImageHandle, gST); + ASSERT_EFI_ERROR (Status); // // init the new stuff @@ -3283,7 +3286,7 @@ StrnCatGrow ( Prompt the user and return the resultant answer to the requestor. This function will display the requested question on the shell prompt and then - wait for an apropriate answer to be input from the console. + wait for an appropriate answer to be input from the console. if the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_YESNO, ShellPromptResponseTypeQuitContinue or SHELL_PROMPT_REQUEST_TYPE_YESNOCANCEL then *Response is of type SHELL_PROMPT_RESPONSE. @@ -4071,6 +4074,9 @@ ShellFileHandleReturnLine( Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii); } + if (Status == EFI_END_OF_FILE && RetVal != NULL && *RetVal != CHAR_NULL) { + Status = EFI_SUCCESS; + } if (EFI_ERROR(Status) && (RetVal != NULL)) { FreePool(RetVal); RetVal = NULL; @@ -4084,9 +4090,20 @@ ShellFileHandleReturnLine( If the position upon start is 0, then the Ascii Boolean will be set. This should be maintained and not changed for all operations with the same file. + NOTE: LINES THAT ARE RETURNED BY THIS FUNCTION ARE UCS2, EVEN IF THE FILE BEING READ + IS IN ASCII FORMAT. + @param[in] Handle SHELL_FILE_HANDLE to read from. - @param[in, out] Buffer The pointer to buffer to read into. - @param[in, out] Size The pointer to number of bytes in Buffer. + @param[in, out] Buffer The pointer to buffer to read into. If this function + returns EFI_SUCCESS, then on output Buffer will + contain a UCS2 string, even if the file being + read is ASCII. + @param[in, out] Size On input, pointer to number of bytes in Buffer. + On output, unchanged unless Buffer is too small + to contain the next line of the file. In that + case Size is set to the number of bytes needed + to hold the next line of the file (as a UCS2 + string, even if it is an ASCII file). @param[in] Truncate If the buffer is large enough, this has no effect. If the buffer is is too small and Truncate is TRUE, the line will be truncated. @@ -4165,43 +4182,27 @@ ShellFileHandleReadLine( // // if we have space save it... // - if ((CountSoFar + 1) * CharSize < *Size){ + if ((CountSoFar+1)*sizeof(CHAR16) < *Size){ ASSERT(Buffer != NULL); - if (*Ascii) { - ((CHAR8*)Buffer)[CountSoFar] = (CHAR8) CharBuffer; - ((CHAR8*)Buffer)[CountSoFar+1] = '\0'; - } - else { - ((CHAR16*)Buffer)[CountSoFar] = CharBuffer; - ((CHAR16*)Buffer)[CountSoFar+1] = CHAR_NULL; - } + ((CHAR16*)Buffer)[CountSoFar] = CharBuffer; + ((CHAR16*)Buffer)[CountSoFar+1] = CHAR_NULL; } } // // if we ran out of space tell when... // - if (Status != EFI_END_OF_FILE){ - if ((CountSoFar + 1) * CharSize > *Size){ - *Size = (CountSoFar + 1) * CharSize; - if (!Truncate) { - gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition); - } else { - DEBUG((DEBUG_WARN, "The line was truncated in ShellFileHandleReadLine")); - } - return (EFI_BUFFER_TOO_SMALL); - } - - if (*Ascii) { - if (CountSoFar && ((CHAR8*)Buffer)[CountSoFar - 1] == '\r') { - ((CHAR8*)Buffer)[CountSoFar - 1] = '\0'; - } - } - else { - if (CountSoFar && Buffer[CountSoFar - 1] == L'\r') { - Buffer[CountSoFar - 1] = CHAR_NULL; - } + if ((CountSoFar+1)*sizeof(CHAR16) > *Size){ + *Size = (CountSoFar+1)*sizeof(CHAR16); + if (!Truncate) { + gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition); + } else { + DEBUG((DEBUG_WARN, "The line was truncated in ShellFileHandleReadLine")); } + return (EFI_BUFFER_TOO_SMALL); + } + while(Buffer[StrLen(Buffer)-1] == L'\r') { + Buffer[StrLen(Buffer)-1] = CHAR_NULL; } return (Status);