composefs icon indicating copy to clipboard operation
composefs copied to clipboard

musl: basename: use portable implementation for basename API

Open fboudra opened this issue 10 months ago • 3 comments

musl has removed the non-prototype declaration of basename from string.h which now results in build errors with newer clang compilers.

Implement GNU basename behavior using strchr which is portable across libcs.

Fixes: | ../../git/tools/mountcomposefs.c:43:20: | error: call to undeclared function 'basename'; ISO C99 and later do not | support implicit function declarations [-Wimplicit-function-declaration] | 43 | const char *bin = basename(argv0); | | ^ | ../../git/tools/mountcomposefs.c:43:14: | error: incompatible integer to pointer conversion initializing 'const char *' | with an expression of type 'int' [-Wint-conversion] | 43 | const char *bin = basename(argv0); | | ^ ~~~~~~~~~~~~~~~

For reference: https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7

Closes: https://github.com/containers/composefs/issues/272

fboudra avatar Apr 09 '24 07:04 fboudra

maybe just the #include <libgen.h> can do the job.

it includes the posix implementation of the basename https://man7.org/linux/man-pages/man0/libgen.h.0p.html

quaresmajose avatar Apr 09 '24 09:04 quaresmajose

@quaresmajose I tried it initially. It looks like we need to use the gnu implementation in this case, not the posix one (including libgen.h won't be enough). Hence, I ended to propose the approach used in kmod. Pending on the authors to review and see if it's acceptable to them.

fboudra avatar Apr 09 '24 10:04 fboudra

Ok, understand. My suggestion was mainly because I saw several patches for this issue and many uses the libgen.h. Thanks for the clarification.

quaresmajose avatar Apr 09 '24 10:04 quaresmajose

Looks fine to me, I'm not overly excited about carrying re-implementations like this, but its trivial enough to not be worth caring about.

alexlarsson avatar Apr 10 '24 08:04 alexlarsson

Ah, seems to be some formating issues, can you run "make clang-format" and repush?

alexlarsson avatar Apr 10 '24 08:04 alexlarsson

@alexlarsson thanks. formating issue fixed and repushed.

fboudra avatar Apr 10 '24 08:04 fboudra