]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: ShellFileHandleReadLine must return UCS2 lines.
authorJim Dailey <Jim_Dailey@Dell.com>
Wed, 10 Feb 2016 16:53:00 +0000 (08:53 -0800)
committerJaben Carsey <jaben.carsey@intel.com>
Wed, 10 Feb 2016 16:54:15 +0000 (08:54 -0800)
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>
ShellPkg/Library/UefiShellLib/UefiShellLib.c

index 4b53c7080c306f9e69335f2b4a0c8c63b2aaa060..abff0d31149185c855c9e68c06083b764f289c80 100644 (file)
@@ -4084,9 +4084,20 @@ ShellFileHandleReturnLine(
   If the position upon start is 0, then the Ascii Boolean will be set.  This should be\r
   maintained and not changed for all operations with the same file.\r
 \r
+  NOTE: LINES THAT ARE RETURNED BY THIS FUNCTION ARE UCS2, EVEN IF THE FILE BEING READ\r
+        IS IN ASCII FORMAT.\r
+\r
   @param[in]       Handle        SHELL_FILE_HANDLE to read from.\r
-  @param[in, out]  Buffer        The pointer to buffer to read into.\r
-  @param[in, out]  Size          The pointer to number of bytes in Buffer.\r
+  @param[in, out]  Buffer        The pointer to buffer to read into. If this function\r
+                                 returns EFI_SUCCESS, then on output Buffer will\r
+                                 contain a UCS2 string, even if the file being\r
+                                 read is ASCII.\r
+  @param[in, out]  Size          On input, pointer to number of bytes in Buffer.\r
+                                 On output, unchanged unless Buffer is too small\r
+                                 to contain the next line of the file. In that\r
+                                 case Size is set to the number of bytes needed\r
+                                 to hold the next line of the file (as a UCS2\r
+                                 string, even if it is an ASCII file).\r
   @param[in]       Truncate      If the buffer is large enough, this has no effect.\r
                                  If the buffer is is too small and Truncate is TRUE,\r
                                  the line will be truncated.\r
@@ -4165,43 +4176,27 @@ ShellFileHandleReadLine(
     //\r
     // if we have space save it...\r
     //\r
-    if ((CountSoFar + 1) * CharSize < *Size){\r
+    if ((CountSoFar+1)*sizeof(CHAR16) < *Size){\r
       ASSERT(Buffer != NULL);\r
-      if (*Ascii) {\r
-        ((CHAR8*)Buffer)[CountSoFar] = (CHAR8) CharBuffer;\r
-        ((CHAR8*)Buffer)[CountSoFar+1] = '\0';\r
-      }\r
-      else {\r
-        ((CHAR16*)Buffer)[CountSoFar] = CharBuffer;\r
-        ((CHAR16*)Buffer)[CountSoFar+1] = CHAR_NULL;\r
-      }\r
+      ((CHAR16*)Buffer)[CountSoFar] = CharBuffer;\r
+      ((CHAR16*)Buffer)[CountSoFar+1] = CHAR_NULL;\r
     }\r
   }\r
 \r
   //\r
   // if we ran out of space tell when...\r
   //\r
-  if (Status != EFI_END_OF_FILE){\r
-    if ((CountSoFar + 1) * CharSize > *Size){\r
-      *Size = (CountSoFar + 1) * CharSize;\r
-      if (!Truncate) {\r
-        gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);\r
-      } else {\r
-        DEBUG((DEBUG_WARN, "The line was truncated in ShellFileHandleReadLine"));\r
-      }\r
-      return (EFI_BUFFER_TOO_SMALL);\r
-    }\r
-\r
-    if (*Ascii) {\r
-      if (CountSoFar && ((CHAR8*)Buffer)[CountSoFar - 1] == '\r') {\r
-        ((CHAR8*)Buffer)[CountSoFar - 1] = '\0';\r
-      }\r
-    }\r
-    else {\r
-      if (CountSoFar && Buffer[CountSoFar - 1] == L'\r') {\r
-        Buffer[CountSoFar - 1] = CHAR_NULL;\r
-      }\r
+  if ((CountSoFar+1)*sizeof(CHAR16) > *Size){\r
+    *Size = (CountSoFar+1)*sizeof(CHAR16);\r
+    if (!Truncate) {\r
+      gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);\r
+    } else {\r
+      DEBUG((DEBUG_WARN, "The line was truncated in ShellFileHandleReadLine"));\r
     }\r
+    return (EFI_BUFFER_TOO_SMALL);\r
+  }\r
+  while(Buffer[StrLen(Buffer)-1] == L'\r') {\r
+    Buffer[StrLen(Buffer)-1] = CHAR_NULL;\r
   }\r
 \r
   return (Status);\r