selftests/nolibc: Fix build with host headers and libc

Many systems don't have strlcpy() or strlcat() and readdir_r() is
deprecated. This makes the tests fail to build with the host headers.
Disable the 'directories' test and define strlcpy(), strlcat() and
readdir_r() using #defines so that the code compiles.

Fixes: 6fe8360b16 ("selftests/nolibc: also test libc-test through regular selftest framework")
Signed-off-by: David Laight <david.laight.linux@gmail.com>
Link: https://patch.msgid.link/20260223101735.2922-4-david.laight.linux@gmail.com
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
This commit is contained in:
David Laight 2026-02-23 10:17:21 +00:00 committed by Thomas Weißschuh
parent 8ba600aa57
commit 27532c645e

View File

@ -82,6 +82,20 @@ static const int is_glibc =
#endif
;
#if !defined(NOLIBC)
/* Some disabled tests may not compile. */
/* 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 */
#undef readdir_r
#define readdir_r(dir, dirent, result) ((errno = EINVAL), -1)
#endif
/* definition of a series of tests */
struct test {
const char *name; /* test name */
@ -1416,7 +1430,7 @@ int run_syscall(int min, int max)
CASE_TEST(fork); EXPECT_SYSZR(1, test_fork(FORK_STANDARD)); break;
CASE_TEST(getdents64_root); EXPECT_SYSNE(1, test_getdents64("/"), -1); break;
CASE_TEST(getdents64_null); EXPECT_SYSER(1, test_getdents64("/dev/null"), -1, ENOTDIR); break;
CASE_TEST(directories); EXPECT_SYSZR(proc, test_dirent()); break;
CASE_TEST(directories); EXPECT_SYSZR(is_nolibc && proc, test_dirent()); break;
CASE_TEST(getrandom); EXPECT_SYSZR(1, test_getrandom()); break;
CASE_TEST(gettimeofday_tv); EXPECT_SYSZR(1, gettimeofday(&tv, NULL)); break;
CASE_TEST(gettimeofday_tv_tz);EXPECT_SYSZR(1, gettimeofday(&tv, &tz)); break;