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

David Matlack <[email protected]>
Newsgroups org.kernel.vger.kvm,org.kernel.vger.linux-kernel,org.kernel.vger.linux-kselftest
Message-ID <[email protected]>
On 2026-08-21 05:21 PM, Hisam Mehboob wrote:

nit: "vfio: selftests: ..."

> 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().
> 
> Link: https://lore.kernel.org/kvm/CALzav=fs4bqMM7BXNPXqhtbqGzA+LW5fgx2-1Q5=sTN5+krYhw@mail.gmail.com/
> Fixes: a262fc49e0aa ("KVM: selftests: Build and link selftests/vfio/lib into KVM selftests")
> Signed-off-by: Hisam Mehboob <[email protected]>

Reviewed-by: David Matlack <[email protected]>

> ---
>  tools/testing/selftests/vfio/lib/sysfs.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/testing/selftests/vfio/lib/sysfs.c b/tools/testing/selftests/vfio/lib/sysfs.c
> index 11415448b2e2..daf117a299a6 100644
> --- a/tools/testing/selftests/vfio/lib/sysfs.c
> +++ b/tools/testing/selftests/vfio/lib/sysfs.c
> @@ -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>
> -- 
> 2.51.0
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.