From: Khem Raj Date: Sun, 10 Dec 2023 01:35:59 +0000 (-0800) Subject: Use portable implementation for basename API X-Git-Tag: v33~53 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=11eb9bc67c319900ab00523997323a97d2d08ad2;p=thirdparty%2Fkmod.git Use portable implementation for basename API musl has removed the non-prototype declaration of basename from string.h [1] which now results in build errors with clang-17+ compiler Implement GNU basename behavior using strchr which is portable across libcs Fixes ../git/tools/kmod.c:71:19: error: call to undeclared function 'basename'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 71 | "Commands:\n", basename(argv[0])); | ^ [1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7 Suggested-by: Rich Felker Signed-off-by: Khem Raj [ Implement a basename() function in missing.h and ensure we always use the right include rather than having a separate gnu_basename() ] Signed-off-by: Lucas De Marchi --- diff --git a/configure.ac b/configure.ac index a80780e3..9527aa2a 100644 --- a/configure.ac +++ b/configure.ac @@ -53,7 +53,9 @@ CC_CHECK_FUNC_BUILTIN([__builtin_uaddll_overflow], [ ], [ ]) AC_CHECK_MEMBERS([struct stat.st_mtim], [], [], [#include ]) # musl 1.0 and bionic 4.4 don't have strndupa -AC_CHECK_DECLS_ONCE([strndupa]) +# basename may be only available in libgen.h with the POSIX behavior, +# not desired here +AC_CHECK_DECLS_ONCE([[strndupa], [basename]], [], [], [[#include ]]) # RHEL 5 and older do not have be32toh AC_CHECK_DECLS_ONCE([be32toh]) diff --git a/shared/missing.h b/shared/missing.h index 26294441..7df62356 100644 --- a/shared/missing.h +++ b/shared/missing.h @@ -38,6 +38,7 @@ static inline int finit_module(int fd, const char *uargs, int flags) #endif #if !HAVE_DECL_STRNDUPA +#include #define strndupa(s, n) \ ({ \ const char *__old = (s); \ @@ -48,6 +49,15 @@ static inline int finit_module(int fd, const char *uargs, int flags) }) #endif +#if !HAVE_DECL_BASENAME +#include +static inline const char *basename(const char *s) +{ + const char *p = strrchr(s, '/'); + return p ? p + 1 : s; +} +#endif + #if !HAVE_DECL_BE32TOH #include #include diff --git a/shared/util.c b/shared/util.c index e2bab83a..437bc697 100644 --- a/shared/util.c +++ b/shared/util.c @@ -172,7 +172,7 @@ char *modname_normalize(const char *modname, char buf[static PATH_MAX], size_t * char *path_to_modname(const char *path, char buf[static PATH_MAX], size_t *len) { - char *modname; + const char *modname; modname = basename(path); if (modname == NULL || modname[0] == '\0') diff --git a/shared/util.h b/shared/util.h index c4a3916b..2a377dd6 100644 --- a/shared/util.h +++ b/shared/util.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/tools/kmod.c b/tools/kmod.c index 1015575f..e1a73bea 100644 --- a/tools/kmod.c +++ b/tools/kmod.c @@ -24,6 +24,7 @@ #include #include +#include #include