summaryrefslogtreecommitdiff
path: root/MdePkg
diff options
context:
space:
mode:
authorQiu Shumin <shumin.qiu@intel.com>2015-06-19 02:05:10 +0000
committershenshushi <shenshushi@Edk2>2015-06-19 02:05:10 +0000
commitbfc2fc9e90ae15bec3e4f84e31bf1c1fe34a915e (patch)
tree26a469e8c574d94f70fcd86e94bf13fb3d7ad4a0 /MdePkg
parent2d28f3b73e657127738e3713a948eb2725b86174 (diff)
downloadedk2-platforms-bfc2fc9e90ae15bec3e4f84e31bf1c1fe34a915e.tar.xz
MdePkg: Refine the cod logic of FileHandleLib.
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
Diffstat (limited to 'MdePkg')
-rw-r--r--MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
index e1f3e89b8c..96f16cad53 100644
--- a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
+++ b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
@@ -909,25 +909,29 @@ FileHandleReturnLine(
}
/**
- Function to read a single line (up to but not including the \n) from a EFI_FILE_HANDLE.
+ Function to read a single line (up to but not including the \n) from a file.
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.
- @param[in] Handle FileHandle to read from
- @param[in, out] Buffer pointer to buffer to read into
- @param[in, out] Size pointer to number of bytes in buffer
- @param[in] Truncate if TRUE then allows for truncation of the line to fit.
- if FALSE will reset the position to the begining of the
- line if the buffer is not large enough.
- @param[in, out] Ascii Boolean value for indicating whether the file is Ascii (TRUE) or UCS2 (FALSE);
-
- @retval EFI_SUCCESS the operation was sucessful. the line is stored in
+ @param[in] Handle FileHandle 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] 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.
+ If the buffer is is too small and Truncate is FALSE,
+ then no read will occur.
+
+ @param[in, out] Ascii Boolean value for indicating whether the file is
+ Ascii (TRUE) or UCS2 (FALSE).
+
+ @retval EFI_SUCCESS The operation was successful. The line is stored in
Buffer.
@retval EFI_INVALID_PARAMETER Handle was NULL.
@retval EFI_INVALID_PARAMETER Size was NULL.
- @retval EFI_BUFFER_TOO_SMALL Size was not enough space to store the line.
- Size was updated to minimum space required.
+ @retval EFI_BUFFER_TOO_SMALL Size was not large enough to store the line.
+ Size was updated to the minimum space required.
@sa FileHandleRead
**/
EFI_STATUS
@@ -942,20 +946,29 @@ FileHandleReadLine(
{
EFI_STATUS Status;
CHAR16 CharBuffer;
+ UINT64 FileSize;
UINTN CharSize;
UINTN CountSoFar;
UINT64 OriginalFilePosition;
-
if (Handle == NULL
||Size == NULL
||(Buffer==NULL&&*Size!=0)
){
return (EFI_INVALID_PARAMETER);
- }
+ }
+
if (Buffer != NULL) {
*Buffer = CHAR_NULL;
}
+
+ Status = FileHandleGetSize (Handle, &FileSize);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ } else if (FileSize == 0) {
+ return EFI_SUCCESS;
+ }
+
FileHandleGetPosition(Handle, &OriginalFilePosition);
if (OriginalFilePosition == 0) {
CharSize = sizeof(CHAR16);