diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2021-02-02 22:27:09 +0000 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2021-02-02 22:53:31 +0000 |
commit | cb347d263d38ee3d9fb9be588a6efd77bca218ea (patch) | |
tree | d1f248cd0fc4b89c1f7c4a46bacf770233012952 /src/boot/efi/util.c | |
parent | fffd5e8ee312c7ef55058b61b2b619c7e3c48925 (diff) | |
download | systemd-cb347d263d38ee3d9fb9be588a6efd77bca218ea.tar.gz |
boot: Add startswith() and endswith() functions with no_case variants
Adapted from string-util
Diffstat (limited to 'src/boot/efi/util.c')
-rw-r--r-- | src/boot/efi/util.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index 50ad757565..8adf3f5fe4 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -375,6 +375,62 @@ CHAR8 *strchra(CHAR8 *s, CHAR8 c) { return NULL; } +const CHAR16 *startswith(const CHAR16 *s, const CHAR16 *prefix) { + UINTN l; + + l = StrLen(prefix); + if (StrnCmp(s, prefix, l) == 0) + return s + l; + + return NULL; +} + +const CHAR16 *endswith(const CHAR16 *s, const CHAR16 *postfix) { + UINTN sl, pl; + + sl = StrLen(s); + pl = StrLen(postfix); + + if (pl == 0) + return s + sl; + + if (sl < pl) + return NULL; + + if (StrnCmp(s + sl - pl, postfix, pl) != 0) + return NULL; + + return s + sl - pl; +} + +const CHAR16 *startswith_no_case(const CHAR16 *s, const CHAR16 *prefix) { + UINTN l; + + l = StrLen(prefix); + if (StriCmp(s, prefix) == 0) + return s + l; + + return NULL; +} + +const CHAR16 *endswith_no_case(const CHAR16 *s, const CHAR16 *postfix) { + UINTN sl, pl; + + sl = StrLen(s); + pl = StrLen(postfix); + + if (pl == 0) + return s + sl; + + if (sl < pl) + return NULL; + + if (StriCmp(s + sl - pl, postfix) != 0) + return NULL; + + return s + sl - pl; +} + EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **ret, UINTN *ret_size) { _cleanup_(FileHandleClosep) EFI_FILE_HANDLE handle = NULL; _cleanup_freepool_ CHAR8 *buf = NULL; |