selftests/nolibc: fix test_file_stream() on musl libc

fwrite() modifying errno is non-standard.

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

Fixes: a5f00be9b3 ("tools/nolibc: Add a simple test for writing to a FILE and reading it back")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
This commit is contained in:
Thomas Weißschuh
2026-03-18 18:00:33 +01:00
parent 55f1d6a9d6
commit 8ba600aa57

View 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;
}