Skip to contentSkip to conversation

vfio: selftests: Include <libgen.h> for basename() on non-glibc builds

PATCH Applied Hisam Mehboob 2 participants 2 messages Aug 24 – Sep 25

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vfio: selftests: Include <libgen.h> for basename() on non-glibc builds

sysfs.c calls basename() but does not include its declaration. Glibc exposes basename() through <string.h> with _GNU_SOURCE, while musl declares it in <libgen.h>.

With musl, this results in an implicit-function-declaration error and subsequent type-mismatch errors at the callers.

Include <libgen.h> so the declaration is available on both glibc and musl. This is safe at both call sites: the arguments are local writable char[PATH_MAX] buffers filled by readlink_safe().

Fixes a262fc49e0aa ("KVM: selftests: Build and link selftests/vfio/lib into KVM selftests")

---
v2:
- Changed subject prefix from "selftests/vfio:" to "vfio: selftests:"
- Added David's Reviewed-by tag.

 tools/testing/selftests/vfio/lib/sysfs.c | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/vfio/lib/sysfs.c +1 -0
index 11415448b2e2..daf117a299a6 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 #include <fcntl.h>
+#include <libgen.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
Signature · 1 line
2.51.0
maintainer Applied
#1 lore raw
Quoted 28 lines · On Tue, 25 Aug 2026 03:28:47 +0500 Hisam Mehboob <[email protected]> wrote:

sysfs.c calls basename() but does not include its declaration. Glibc exposes basename() through <string.h> with _GNU_SOURCE, while musl declares it in <libgen.h>.

With musl, this results in an implicit-function-declaration error and subsequent type-mismatch errors at the callers.

Include <libgen.h> so the declaration is available on both glibc and musl. This is safe at both call sites: the arguments are local writable char[PATH_MAX] buffers filled by readlink_safe().

Fixes a262fc49e0aa ("KVM: selftests: Build and link selftests/vfio/lib into KVM selftests")

---
v2:
- Changed subject prefix from "selftests/vfio:" to "vfio: selftests:"
- Added David's Reviewed-by tag.

 tools/testing/selftests/vfio/lib/sysfs.c | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/vfio/lib/sysfs.c +0 -0
index 11415448b2e2..daf117a299a6 100644

tools/testing/selftests/vfio/lib/sysfs.c line 6

Quoted 6 lines
tools/testing/selftests/vfio/lib/sysfs.c +1 -0
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 #include <fcntl.h>
+#include <libgen.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>

Applied to vfio next for v7.4. Thanks,

Alex