diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index 04e390b0fa7..443a3bd3800 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -649,6 +649,27 @@ UINTN strnlena(const CHAR8 *p, UINTN maxlen) { return c; } +INTN strncasecmpa(const CHAR8 *a, const CHAR8 *b, UINTN maxlen) { + if (!a || !b) + return CMP(a, b); + + while (maxlen > 0) { + CHAR8 ca = *a, cb = *b; + if (ca >= 'A' && ca <= 'Z') + ca += 'a' - 'A'; + if (cb >= 'A' && cb <= 'Z') + cb += 'a' - 'A'; + if (!ca || ca != cb) + return ca - cb; + + a++; + b++; + maxlen--; + } + + return 0; +} + CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz) { CHAR8 *n; diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index 425d25d73f9..07ffcdc1ef9 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -130,6 +130,10 @@ EFI_STATUS readdir_harder(EFI_FILE_HANDLE handle, EFI_FILE_INFO **buffer, UINTN UINTN strnlena(const CHAR8 *p, UINTN maxlen); CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz); +INTN strncasecmpa(const CHAR8 *a, const CHAR8 *b, UINTN maxlen); +static inline BOOLEAN strncaseeqa(const CHAR8 *a, const CHAR8 *b, UINTN maxlen) { + return strncasecmpa(a, b, maxlen) == 0; +} BOOLEAN is_ascii(const CHAR16 *f);