-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StrLib: add AsciiGetString and AsciiGetNextString
this allows iterating over single-buffer string-arrays like the ones used by fdt blobs.
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,32 @@ | ||
#ifndef __LIBRARY_STR_H__ | ||
#define __LIBRARY_STR_H__ | ||
|
||
typedef struct { | ||
CONST CHAR8 *Current; | ||
CONST CHAR8 *End; | ||
} ASCII_GETSTRING_STATE; | ||
|
||
CHAR8 *strtok(CHAR8 *s, CONST CHAR8 *delim); | ||
CHAR8 *strtok_r(CHAR8 *s, CONST CHAR8 *delim, CHAR8 **last); | ||
UINTN strlcat(CHAR8 *dst, CONST CHAR8 *src, UINTN siz); | ||
UINTN strspn(CHAR8 CONST *s, CHAR8 CONST *accept); | ||
CHAR8 *strchr(CONST CHAR8 *s, INTN c); | ||
CHAR8 *strpbrk(CONST CHAR8 *s, CONST CHAR8 *accept); | ||
|
||
RETURN_STATUS | ||
EFIAPI | ||
AsciiGetNextString ( | ||
IN OUT ASCII_GETSTRING_STATE *State, | ||
OUT CONST CHAR8 **String | ||
); | ||
|
||
RETURN_STATUS | ||
EFIAPI | ||
AsciiGetString ( | ||
IN CONST CHAR8 *StringArray, | ||
IN UINTN MaxSize, | ||
IN OUT ASCII_GETSTRING_STATE *State, | ||
OUT CONST CHAR8 **String | ||
); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
strchr.c | ||
strpbrk.c | ||
|
||
getstring.c | ||
|
||
[Packages] | ||
MdePkg/MdePkg.dec | ||
EFIDroidPkg/EFIDroidPkg.dec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <Library/BaseLib.h> | ||
#include <Library/StrLib.h> | ||
|
||
RETURN_STATUS | ||
EFIAPI | ||
AsciiGetNextString ( | ||
IN OUT ASCII_GETSTRING_STATE *State, | ||
OUT CONST CHAR8 **String | ||
) | ||
{ | ||
if (State->Current >= State->End) { | ||
return RETURN_NOT_FOUND; | ||
} | ||
|
||
UINTN CurrentLength = AsciiStrnSizeS(State->Current, State->End - State->Current); | ||
if (State->Current + CurrentLength > State->End) { | ||
return RETURN_UNSUPPORTED; | ||
} | ||
|
||
*String = State->Current; | ||
State->Current += CurrentLength; | ||
|
||
return RETURN_SUCCESS; | ||
} | ||
|
||
RETURN_STATUS | ||
EFIAPI | ||
AsciiGetString ( | ||
IN CONST CHAR8 *StringArray, | ||
IN UINTN MaxSize, | ||
IN OUT ASCII_GETSTRING_STATE *State, | ||
OUT CONST CHAR8 **String | ||
) | ||
{ | ||
State->Current = StringArray; | ||
State->End = StringArray + MaxSize; | ||
|
||
return AsciiGetNextString(State, String); | ||
} |