]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Add strtolower8/16
authorJan Janssen <medhefgo@web.de>
Thu, 26 May 2022 07:57:16 +0000 (09:57 +0200)
committerJan Janssen <medhefgo@web.de>
Tue, 31 May 2022 13:10:45 +0000 (15:10 +0200)
src/boot/efi/efi-string.c
src/boot/efi/efi-string.h
src/boot/efi/test-efi-string.c

index 3962070e61871ffb0782ede7665646f5933e1f8d..17372ae9d4476588f4d81346bf1a8414a6221c53 100644 (file)
@@ -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)                              \
index 1cc65a677af40f0c01f5ee63bdc2714c55136d8c..2b9a1dfb97f72af6dedaf156902f9d9b6f4db485 100644 (file)
@@ -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);
 
index 42d5f52e0fefe1eeb1b1f8053bad1515563c7c31..83cb6456886f67572e8bb59b4c44137494ca9209 100644 (file)
@@ -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);