diff options
author | Jim Dailey <Jim_Dailey@Dell.com> | 2016-02-10 08:53:00 -0800 |
---|---|---|
committer | Hao Wu <hao.a.wu@intel.com> | 2016-07-13 20:41:52 +0800 |
commit | 1cfe36af68ecc5b3ba4b6ffb253904773dbe7b0c (patch) | |
tree | cc711b243b96dd4cb0e003d54e63eeaa236f305e /ShellPkg/Library/UefiShellLib | |
parent | 404d220bf81a3873dc863d299c1de75f73478602 (diff) | |
download | edk2-1cfe36af68ecc5b3ba4b6ffb253904773dbe7b0c.tar.gz edk2-1cfe36af68ecc5b3ba4b6ffb253904773dbe7b0c.tar.bz2 edk2-1cfe36af68ecc5b3ba4b6ffb253904773dbe7b0c.zip |
ShellPkg: ShellFileHandleReadLine must return UCS2 lines.
An earlier change had this function returning the type of lines that were in
the file being read (ASCII or UCS2). The way it is used, UCS2 output is
expected, even when the file being read is ASCII. This change restores that
behavior and documents it.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jim Dailey <Jim_Dailey@Dell.com>
Tested-by: Ryan Harkin <ryan.harkin@linaro.org>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
(cherry picked from commit 2dda8a12329700f9026236d83be4de9e5369f97f)
Diffstat (limited to 'ShellPkg/Library/UefiShellLib')
-rw-r--r-- | ShellPkg/Library/UefiShellLib/UefiShellLib.c | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c index 4b53c7080c..abff0d3114 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -4084,9 +4084,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 +4176,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);
|