diff options
author | Thomas Weißschuh <thomas.weissschuh@linutronix.de> | 2025-04-11 11:00:42 +0200 |
---|---|---|
committer | Thomas Weißschuh <linux@weissschuh.net> | 2025-04-22 10:56:26 +0200 |
commit | 9b070d97d9e52195c3a2ee084fdd7c45b6b35adf (patch) | |
tree | d29ebcc088af8be1cd05ac70f1d4fd2a53d33d41 | |
parent | 4de88a88bcbe4cf89477d8c6a9145fdfd929bc96 (diff) |
tools/nolibc: add tolower() and toupper()
The kselftest harness uses these functions.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
-rw-r--r-- | tools/include/nolibc/string.h | 17 | ||||
-rw-r--r-- | tools/testing/selftests/nolibc/nolibc-test.c | 5 |
2 files changed, 22 insertions, 0 deletions
diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h index ba84ab700e30..f0d335f0e467 100644 --- a/tools/include/nolibc/string.h +++ b/tools/include/nolibc/string.h @@ -289,6 +289,23 @@ char *strrchr(const char *s, int c) return (char *)ret; } +static __attribute__((unused)) +int tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + return c - 'A' + 'a'; + return c; +} + +static __attribute__((unused)) +int toupper(int c) +{ + if (c >= 'a' && c <= 'z') + return c - 'a' + 'A'; + return c; +} + + /* make sure to include all global symbols */ #include "nolibc.h" diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 143dddfcd01a..b6f736fdeadf 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -39,6 +39,7 @@ #include <stdint.h> #include <unistd.h> #include <limits.h> +#include <ctype.h> #endif #endif @@ -1280,6 +1281,10 @@ int run_stdlib(int min, int max) CASE_TEST(strerror_EINVAL); EXPECT_STREQ(is_nolibc, strerror(EINVAL), "errno=22"); break; CASE_TEST(strerror_int_max); EXPECT_STREQ(is_nolibc, strerror(INT_MAX), "errno=2147483647"); break; CASE_TEST(strerror_int_min); EXPECT_STREQ(is_nolibc, strerror(INT_MIN), "errno=-2147483648"); break; + CASE_TEST(tolower); EXPECT_EQ(1, tolower('A'), 'a'); break; + CASE_TEST(tolower_noop); EXPECT_EQ(1, tolower('a'), 'a'); break; + CASE_TEST(toupper); EXPECT_EQ(1, toupper('a'), 'A'); break; + CASE_TEST(toupper_noop); EXPECT_EQ(1, toupper('A'), 'A'); break; case __LINE__: return ret; /* must be last */ |