]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/nolibc: fix test_file_stream() on musl libc
authorThomas Weißschuh <linux@weissschuh.net>
Wed, 18 Mar 2026 17:00:33 +0000 (18:00 +0100)
committerThomas Weißschuh <linux@weissschuh.net>
Fri, 20 Mar 2026 16:44:06 +0000 (17:44 +0100)
fwrite() modifying errno is non-standard.

Only validate this behavior on those libc implementations which
implement it.

Fixes: a5f00be9b3b0 ("tools/nolibc: Add a simple test for writing to a FILE and reading it back")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
tools/testing/selftests/nolibc/nolibc-test.c

index 1b9d3b2e2491c93d266c51237616747a8249a446..1aca8468eac4b3b75e7bd0f9f3b3b50c3331a3a3 100644 (file)
@@ -74,6 +74,14 @@ static const int is_nolibc =
 #endif
 ;
 
+static const int is_glibc =
+#ifdef __GLIBC__
+       1
+#else
+       0
+#endif
+;
+
 /* definition of a series of tests */
 struct test {
        const char *name;              /* test name */
@@ -866,7 +874,7 @@ int test_file_stream(void)
 
        errno = 0;
        r = fwrite("foo", 1, 3, f);
-       if (r != 0 || errno != EBADF) {
+       if (r != 0 || ((is_nolibc || is_glibc) && errno != EBADF)) {
                fclose(f);
                return -1;
        }