From: Jan Janssen Date: Thu, 26 May 2022 07:57:16 +0000 (+0200) Subject: boot: Add strtolower8/16 X-Git-Tag: v252-rc1~892^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=98850528bf693df6a3b2d1c63f75e8aa00d7d312;p=thirdparty%2Fsystemd.git boot: Add strtolower8/16 --- diff --git a/src/boot/efi/efi-string.c b/src/boot/efi/efi-string.c index 3962070e618..17372ae9d44 100644 --- a/src/boot/efi/efi-string.c +++ b/src/boot/efi/efi-string.c @@ -43,6 +43,17 @@ size_t strlen16(const char16_t *s) { (_c >= 'A' && _c <= 'Z') ? _c + ('a' - 'A') : _c; \ }) +#define DEFINE_STRTOLOWER(type, name) \ + void name(type *s) { \ + if (!s) \ + return; \ + for (; *s; s++) \ + *s = TOLOWER(*s); \ + } + +DEFINE_STRTOLOWER(char, strtolower8); +DEFINE_STRTOLOWER(char16_t, strtolower16); + #define DEFINE_STRNCASECMP(type, name, tolower) \ int name(const type *s1, const type *s2, size_t n) { \ if (!s1 || !s2) \ diff --git a/src/boot/efi/efi-string.h b/src/boot/efi/efi-string.h index 1cc65a677af..2b9a1dfb97f 100644 --- a/src/boot/efi/efi-string.h +++ b/src/boot/efi/efi-string.h @@ -11,6 +11,9 @@ size_t strnlen16(const char16_t *s, size_t n); size_t strlen8(const char *s); size_t strlen16(const char16_t *s); +void strtolower8(char *s); +void strtolower16(char16_t *s); + int strncmp8(const char *s1, const char *s2, size_t n); int strncmp16(const char16_t *s1, const char16_t *s2, size_t n); diff --git a/src/boot/efi/test-efi-string.c b/src/boot/efi/test-efi-string.c index 42d5f52e0fe..83cb6456886 100644 --- a/src/boot/efi/test-efi-string.c +++ b/src/boot/efi/test-efi-string.c @@ -41,6 +41,32 @@ TEST(strnlen16) { assert_se(strnlen16(u"12\0004", 5) == 2); } +TEST(strtolower8) { + char s[] = "\0001234abcDEF!\0zZ"; + + strtolower8(NULL); + + strtolower8(s); + assert_se(memcmp(s, "\0001234abcDEF!\0zZ", sizeof(s)) == 0); + + s[0] = '#'; + strtolower8(s); + assert_se(memcmp(s, "#1234abcdef!\0zZ", sizeof(s)) == 0); +} + +TEST(strtolower16) { + char16_t s[] = u"\0001234abcDEF!\0zZ"; + + strtolower16(NULL); + + strtolower16(s); + assert_se(memcmp(s, u"\0001234abcDEF!\0zZ", sizeof(s)) == 0); + + s[0] = '#'; + strtolower16(s); + assert_se(memcmp(s, u"#1234abcdef!\0zZ", sizeof(s)) == 0); +} + TEST(strncmp8) { assert_se(strncmp8(NULL, "", 10) < 0); assert_se(strncmp8("", NULL, 10) > 0);