1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 06:25:37 +03:00

boot: Add strncasecmpa helper function

This commit is contained in:
Jan Janssen 2021-12-02 13:06:07 +01:00
parent 3af5a8c613
commit 245e9d55ae
2 changed files with 25 additions and 0 deletions

View File

@ -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;

View File

@ -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);