diff mbox series

[kvmtool,1/2] Get basename() from <libgen.h> for musl compat

Message ID 20240727-musl-v1-1-35013d2f97a0@gmx.net (mailing list archive)
State New, archived
Headers show
Series Fix compilation with musl-libc based toolchains | expand

Commit Message

J. Neuschäfer July 27, 2024, 8:11 a.m. UTC
According to the manpage, basename is defined in <libgen.h>.
Not including it results in a compilation failure on musl-libc:

vfio/core.c:538:22: error: implicit declaration of function 'basename' [-Werror=implicit-function-declaration]
  538 |         group_name = basename(group_path);
      |                      ^~~~~~~~

Signed-off-by: J. Neuschäfer <j.neuschaefer@gmx.net>
---
 vfio/core.c | 1 +
 1 file changed, 1 insertion(+)


--
2.43.0

Comments

Alyssa Ross July 27, 2024, 10:58 a.m. UTC | #1
On Sat, Jul 27, 2024 at 10:11:14AM GMT, J. Neuschäfer wrote:
> According to the manpage, basename is defined in <libgen.h>.
> Not including it results in a compilation failure on musl-libc:

That's not quite what the man page says — there are two versions of
basename, the POSIX version and the GNU version, with differing
behaviour.

> vfio/core.c:538:22: error: implicit declaration of function 'basename' [-Werror=implicit-function-declaration]
>   538 |         group_name = basename(group_path);
>       |                      ^~~~~~~~

In this case, it should be safe to switch to the POSIX version, because
group_path is writeable and not used after this, so

Reviewed-by: Alyssa Ross <hi@alyssa.is>

but it would be nicer if the commit message was clearer, because it
currently reads like it's just including a missing header, rather than
changing the behaviour of the function.

> Signed-off-by: J. Neuschäfer <j.neuschaefer@gmx.net>
> ---
>  vfio/core.c | 1 +
>  1 file changed, 1 insertion(+)
J. Neuschäfer July 27, 2024, 4:43 p.m. UTC | #2
On Sat, Jul 27, 2024 at 12:58:37PM +0200, Alyssa Ross wrote:
> On Sat, Jul 27, 2024 at 10:11:14AM GMT, J. Neuschäfer wrote:
> > According to the manpage, basename is defined in <libgen.h>.
> > Not including it results in a compilation failure on musl-libc:
> 
> That's not quite what the man page says — there are two versions of
> basename, the POSIX version and the GNU version, with differing
> behaviour.

Right, thanks for catching that!

> > vfio/core.c:538:22: error: implicit declaration of function 'basename' [-Werror=implicit-function-declaration]
> >   538 |         group_name = basename(group_path);
> >       |                      ^~~~~~~~
> 
> In this case, it should be safe to switch to the POSIX version, because
> group_path is writeable and not used after this, so
> 
> Reviewed-by: Alyssa Ross <hi@alyssa.is>
> 
> but it would be nicer if the commit message was clearer, because it
> currently reads like it's just including a missing header, rather than
> changing the behaviour of the function.

I'll update and respin.


-- jn
diff mbox series

Patch

diff --git a/vfio/core.c b/vfio/core.c
index 3ff2c0b..8f88489 100644
--- a/vfio/core.c
+++ b/vfio/core.c
@@ -3,6 +3,7 @@ 
 #include "kvm/ioport.h"

 #include <linux/list.h>
+#include <libgen.h>

 #define VFIO_DEV_DIR		"/dev/vfio"
 #define VFIO_DEV_NODE		VFIO_DEV_DIR "/vfio"