aports/main/kmod/portable-basename.patch
Dermot Bradley e794d41d83 main/kmod: fix basename issue due to musl change
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
2024-02-21 07:43:38 +00:00

107 lines
2.6 KiB
Diff

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 <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
@@ -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] <test>\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) {
@@ -156,7 +156,7 @@
const char *cmd;
size_t i;
- cmd = basename(argv[0]);
+ cmd = gnu_basename(argv[0]);
for (i = 0; i < ARRAY_SIZE(kmod_compat_cmds); i++) {
if (streq(kmod_compat_cmds[i]->name, cmd))