summaryrefslogtreecommitdiff
path: root/MdePkg
diff options
context:
space:
mode:
authorQiu Shumin <shumin.qiu@intel.com>2015-08-24 07:42:27 +0000
committershenshushi <shenshushi@Edk2>2015-08-24 07:42:27 +0000
commitba1806251ff8ff695175b92ab5732eadbcd2f72e (patch)
tree9dbf1aa640dccc3a9e475edecb6b1f148887c3b5 /MdePkg
parent29b3a74986b67e3831e405a0197e8e7e30db843d (diff)
downloadedk2-ba1806251ff8ff695175b92ab5732eadbcd2f72e.zip
edk2-ba1806251ff8ff695175b92ab5732eadbcd2f72e.tar.gz
edk2-ba1806251ff8ff695175b92ab5732eadbcd2f72e.tar.bz2
MdePkg/Library/UefiFileHandleLib: Make FileHandleReadLine return the right buffer size.
1. '\r' char will not return in buffer so buffer size should exclude the number of '\r' char. 2. When 'Truncate' is TRUE return the truncated string with 'EFI_SUCCESS' status. 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@18276 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg')
-rw-r--r--MdePkg/Include/Library/FileHandleLib.h2
-rw-r--r--MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c34
2 files changed, 25 insertions, 11 deletions
diff --git a/MdePkg/Include/Library/FileHandleLib.h b/MdePkg/Include/Library/FileHandleLib.h
index b5ac19a..fdbdc3a 100644
--- a/MdePkg/Include/Library/FileHandleLib.h
+++ b/MdePkg/Include/Library/FileHandleLib.h
@@ -379,6 +379,8 @@ FileHandleGetFileName (
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.
+ The function will not return the \r and \n character in buffer. When an empty line is
+ read a CHAR_NULL character will be returned in buffer.
@param[in] Handle FileHandle to read from.
@param[in, out] Buffer The pointer to buffer to read into.
diff --git a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
index f6cbfad..a31d12b 100644
--- a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
+++ b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
@@ -913,6 +913,8 @@ FileHandleReturnLine(
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.
+ The function will not return the \r and \n character in buffer. When an empty line is
+ read a CHAR_NULL character will be returned in buffer.
@param[in] Handle FileHandle to read from.
@param[in, out] Buffer The pointer to buffer to read into.
@@ -949,6 +951,7 @@ FileHandleReadLine(
UINT64 FileSize;
UINTN CharSize;
UINTN CountSoFar;
+ UINTN CrCount;
UINT64 OriginalFilePosition;
if (Handle == NULL
@@ -958,14 +961,15 @@ FileHandleReadLine(
return (EFI_INVALID_PARAMETER);
}
- if (Buffer != NULL) {
+ if (Buffer != NULL && *Size != 0) {
*Buffer = CHAR_NULL;
- }
+ }
Status = FileHandleGetSize (Handle, &FileSize);
if (EFI_ERROR (Status)) {
return Status;
} else if (FileSize == 0) {
+ *Ascii = TRUE;
return EFI_SUCCESS;
}
@@ -982,6 +986,7 @@ FileHandleReadLine(
}
}
+ CrCount = 0;
for (CountSoFar = 0;;CountSoFar++){
CharBuffer = 0;
if (*Ascii) {
@@ -996,31 +1001,38 @@ FileHandleReadLine(
|| (CharBuffer == '\n' && *Ascii)
){
break;
+ } else if (
+ (CharBuffer == L'\r' && !(*Ascii)) ||
+ (CharBuffer == '\r' && *Ascii)
+ ) {
+ CrCount++;
+ continue;
}
//
// if we have space save it...
//
- if ((CountSoFar+1)*sizeof(CHAR16) < *Size){
+ if ((CountSoFar+1-CrCount)*sizeof(CHAR16) < *Size){
ASSERT(Buffer != NULL);
- ((CHAR16*)Buffer)[CountSoFar] = CharBuffer;
- ((CHAR16*)Buffer)[CountSoFar+1] = CHAR_NULL;
+ ((CHAR16*)Buffer)[CountSoFar-CrCount] = CharBuffer;
+ ((CHAR16*)Buffer)[CountSoFar+1-CrCount] = CHAR_NULL;
}
}
//
// if we ran out of space tell when...
//
- if ((CountSoFar+1)*sizeof(CHAR16) > *Size){
- *Size = (CountSoFar+1)*sizeof(CHAR16);
+ if ((CountSoFar+1-CrCount)*sizeof(CHAR16) > *Size){
+ *Size = (CountSoFar+1-CrCount)*sizeof(CHAR16);
if (!Truncate) {
+ if (Buffer != NULL && *Size != 0) {
+ ZeroMem(Buffer, *Size);
+ }
FileHandleSetPosition(Handle, OriginalFilePosition);
+ return (EFI_BUFFER_TOO_SMALL);
} else {
DEBUG((DEBUG_WARN, "The line was truncated in FileHandleReadLine"));
+ return (EFI_SUCCESS);
}
- return (EFI_BUFFER_TOO_SMALL);
- }
- while(Buffer[StrLen(Buffer)-1] == L'\r') {
- Buffer[StrLen(Buffer)-1] = CHAR_NULL;
}
return (Status);