# --- T2-COPYRIGHT-NOTE-BEGIN --- # T2 SDE: package/*/kmod/portable-basename.patch.musl # Copyright (C) 2024 The T2 SDE Project # # This Copyright note is generated by scripts/Create-CopyPatch, # more information can be found in the files COPYING and README. # # This patch file is dual-licensed. It is available under the license the # patched project is licensed under, as long as it is an OpenSource license # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms # of the GNU General Public License version 2 as used by the T2 SDE. # --- T2-COPYRIGHT-NOTE-END --- Credits: AlpineLinux Upstream PR #32 musl has removed the non-prototype declaration of basename from string.h [1] which now results in build errors with clang-17+ compiler. https://github.com/kmod-project/kmod/pull/32 --- diff -aur a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c --- a/libkmod/libkmod-config.c +++ b/libkmod/libkmod-config.c @@ -794,7 +794,7 @@ bool is_single = false; if (name == NULL) { - name = basename(path); + name = gnu_basename(path); is_single = true; } diff -aur a/shared/util.c b/shared/util.c --- a/shared/util.c +++ b/shared/util.c @@ -172,9 +172,9 @@ char *path_to_modname(const char *path, char buf[static PATH_MAX], size_t *len) { - char *modname; + const char *modname; - modname = basename(path); + modname = gnu_basename(path); if (modname == NULL || modname[0] == '\0') return NULL; diff -aur a/shared/util.h b/shared/util.h --- a/shared/util.h +++ b/shared/util.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -76,6 +77,12 @@ __p->__v = (val); \ } while(0) +static _always_inline_ const char *gnu_basename(const char *s) +{ + const char *p = strrchr(s, '/'); + return p ? p+1 : s; +} + static _always_inline_ unsigned int ALIGN_POWER2(unsigned int u) { return 1 << ((sizeof(u) * 8) - __builtin_clz(u - 1)); diff -aur a/testsuite/testsuite.c b/testsuite/testsuite.c --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -70,7 +70,7 @@ printf("Usage:\n" "\t%s [options] \n" - "Options:\n", basename(progname)); + "Options:\n", gnu_basename(progname)); for (itr = options, itr_short = options_short; itr->name != NULL; itr++, itr_short++) diff -aur a/tools/depmod.c b/tools/depmod.c --- a/tools/depmod.c +++ b/tools/depmod.c @@ -761,7 +761,7 @@ if (name != NULL) namelen = strlen(name); else { - name = basename(dir); + name = gnu_basename(dir); namelen = strlen(name); dirlen -= namelen + 1; } diff -aur a/tools/kmod.c b/tools/kmod.c --- a/tools/kmod.c +++ b/tools/kmod.c @@ -68,7 +68,7 @@ "Options:\n" "\t-V, --version show version\n" "\t-h, --help show this help\n\n" - "Commands:\n", basename(argv[0])); + "Commands:\n", gnu_basename(argv[0])); for (i = 0; i < ARRAY_SIZE(kmod_cmds); i++) { if (kmod_cmds[i]->help != NULL) { @@ -154,1 +154,1 @@ - cmd = basename(argv[0]); + cmd = gnu_basename(argv[0]);