]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg: Refine the cod logic of FileHandleLib.
authorQiu Shumin <shumin.qiu@intel.com>
Fri, 19 Jun 2015 02:05:10 +0000 (02:05 +0000)
committershenshushi <shenshushi@Edk2>
Fri, 19 Jun 2015 02:05:10 +0000 (02:05 +0000)
When the file is empty, make FileHandleReadLine in FileHandleLib return EFI_SUCCESS instead of EFI_BUFFER_TOO_SMALL.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <shumin.qiu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17668 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c

index e1f3e89b8c80d89786456c7cadac78c45a9d4d6e..96f16cad53aac1ec4e53a1a6060b8b773e1b75bd 100644 (file)
@@ -909,25 +909,29 @@ FileHandleReturnLine(
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
-  Function to read a single line (up to but not including the \n) from a EFI_FILE_HANDLE.\r
+  Function to read a single line (up to but not including the \n) from a file.\r
 \r
   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
 \r
   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
-  @param[in]       Handle        FileHandle to read from\r
-  @param[in, out]  Buffer        pointer to buffer to read into\r
-  @param[in, out]  Size          pointer to number of bytes in buffer\r
-  @param[in]       Truncate      if TRUE then allows for truncation of the line to fit.\r
-                                 if FALSE will reset the position to the begining of the\r
-                                 line if the buffer is not large enough.\r
-  @param[in, out]  Ascii         Boolean value for indicating whether the file is Ascii (TRUE) or UCS2 (FALSE);\r
-\r
-  @retval EFI_SUCCESS           the operation was sucessful.  the line is stored in\r
+  @param[in]       Handle        FileHandle 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]       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
+                                 If the buffer is is too small and Truncate is FALSE,\r
+                                 then no read will occur.\r
+\r
+  @param[in, out]  Ascii         Boolean value for indicating whether the file is\r
+                                 Ascii (TRUE) or UCS2 (FALSE).\r
+\r
+  @retval EFI_SUCCESS           The operation was successful.  The line is stored in\r
                                 Buffer.\r
   @retval EFI_INVALID_PARAMETER Handle was NULL.\r
   @retval EFI_INVALID_PARAMETER Size was NULL.\r
                                 Buffer.\r
   @retval EFI_INVALID_PARAMETER Handle was NULL.\r
   @retval EFI_INVALID_PARAMETER Size was NULL.\r
-  @retval EFI_BUFFER_TOO_SMALL  Size was not enough space to store the line.\r
-                                Size was updated to minimum space required.\r
+  @retval EFI_BUFFER_TOO_SMALL  Size was not large enough to store the line.\r
+                                Size was updated to the minimum space required.\r
   @sa FileHandleRead\r
 **/\r
 EFI_STATUS\r
   @sa FileHandleRead\r
 **/\r
 EFI_STATUS\r
@@ -942,20 +946,29 @@ FileHandleReadLine(
 {\r
   EFI_STATUS  Status;\r
   CHAR16      CharBuffer;\r
 {\r
   EFI_STATUS  Status;\r
   CHAR16      CharBuffer;\r
+  UINT64      FileSize;\r
   UINTN       CharSize;\r
   UINTN       CountSoFar;\r
   UINT64      OriginalFilePosition;\r
 \r
   UINTN       CharSize;\r
   UINTN       CountSoFar;\r
   UINT64      OriginalFilePosition;\r
 \r
-\r
   if (Handle == NULL\r
     ||Size   == NULL\r
     ||(Buffer==NULL&&*Size!=0)\r
    ){\r
     return (EFI_INVALID_PARAMETER);\r
   if (Handle == NULL\r
     ||Size   == NULL\r
     ||(Buffer==NULL&&*Size!=0)\r
    ){\r
     return (EFI_INVALID_PARAMETER);\r
-  }\r
+  } \r
+  \r
   if (Buffer != NULL) {\r
     *Buffer = CHAR_NULL;\r
   }\r
   if (Buffer != NULL) {\r
     *Buffer = CHAR_NULL;\r
   }\r
+  \r
+  Status = FileHandleGetSize (Handle, &FileSize);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  } else if (FileSize == 0) {\r
+    return EFI_SUCCESS;\r
+  }  \r
+  \r
   FileHandleGetPosition(Handle, &OriginalFilePosition);\r
   if (OriginalFilePosition == 0) {\r
     CharSize = sizeof(CHAR16);\r
   FileHandleGetPosition(Handle, &OriginalFilePosition);\r
   if (OriginalFilePosition == 0) {\r
     CharSize = sizeof(CHAR16);\r