diff options
author | 2025-04-28 14:40:03 +0200 | |
---|---|---|
committer | 2025-05-21 15:32:01 +0200 | |
commit | 7a7cd445d9275be8e4650d390156595685c3ac03 (patch) | |
tree | dada5c5b2ecd6b52efdd70f6ea6cc492d11b974d /tools/testing/selftests/nolibc/nolibc-test.c | |
parent | tools/nolibc: add strstr() (diff) | |
download | wireguard-linux-7a7cd445d9275be8e4650d390156595685c3ac03.tar.xz wireguard-linux-7a7cd445d9275be8e4650d390156595685c3ac03.zip |
tools/nolibc: add %m printf format
The %m format can be used to format the current errno.
It is non-standard but supported by other commonly used libcs like glibc and
musl, so applications do rely on them.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-2-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Diffstat (limited to '')
-rw-r--r-- | tools/testing/selftests/nolibc/nolibc-test.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 3e15a25ccddf..b7440a667db6 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1393,6 +1393,23 @@ static int test_scanf(void) return 0; } +int test_strerror(void) +{ + char buf[100]; + ssize_t ret; + + memset(buf, 'A', sizeof(buf)); + + errno = EINVAL; + ret = snprintf(buf, sizeof(buf), "%m"); + if (is_nolibc) { + if (ret < 6 || memcmp(buf, "errno=", 6)) + return 1; + } + + return 0; +} + static int run_printf(int min, int max) { int test; @@ -1421,6 +1438,7 @@ static int run_printf(int min, int max) CASE_TEST(number_width); EXPECT_VFPRINTF(10, " 1", "%10d", 1); break; CASE_TEST(width_trunc); EXPECT_VFPRINTF(25, " ", "%25d", 1); break; CASE_TEST(scanf); EXPECT_ZR(1, test_scanf()); break; + CASE_TEST(strerror); EXPECT_ZR(1, test_strerror()); break; case __LINE__: return ret; /* must be last */ /* note: do not set any defaults so as to permit holes above */ |