[PATCH] selftests/nolibc: Fix build with host headers and libc
From: david . laight . linux
Date: Sat Feb 14 2026 - 06:57:40 EST
From: David Laight <david.laight.linux@xxxxxxxxx>
Many systems don't have strlcpy() or strlcat().
Change is_nolibc to a #define so that the calls are optimised out.
Create #define wrappers so the code is syntactially valid.
Additionall readdir_r() is likely to be marked deprecated.
So disable "-Wdeprecated-declarations".
Fixes: 6fe8360b16acb ("selftests/nolibc: also test libc-test through regular selftest framework")
Signed-off-by: David Laight <david.laight.linux@xxxxxxxxx>
---
tools/testing/selftests/nolibc/nolibc-test.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 1b9d3b2e2491..eb2421b42e75 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -66,13 +66,18 @@ static const char *argv0;
/* will be used by constructor tests */
static int constructor_test_value;
-static const int is_nolibc =
#ifdef NOLIBC
- 1
+#define is_nolibc 1
#else
- 0
+#define is_nolibc 0
+/* strlcat() and strlcpy() may not be in the system headers. */
+#undef strlcat
+#undef strlcpy
+#define strlcat(d, s, l) 0
+#define strlcpy(d, s, l) 0
+/* readdir_r() is likely to be marked deprecated */
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
-;
/* definition of a series of tests */
struct test {
--
2.39.5