diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c index e83621b..8aa555a 100644 --- a/libkmod/libkmod-config.c +++ b/libkmod/libkmod-config.c @@ -794,7 +794,7 @@ static int conf_files_insert_sorted(struct kmod_ctx *ctx, bool is_single = false; if (name == NULL) { - name = basename(path); + name = gnu_basename(path); is_single = true; } diff --git a/shared/util.c b/shared/util.c index e2bab83..0e16670 100644 --- a/shared/util.c +++ b/shared/util.c @@ -172,9 +172,9 @@ 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); + modname = gnu_basename(path); if (modname == NULL || modname[0] == '\0') return NULL; diff --git a/shared/util.h b/shared/util.h index c4a3916..073dc5a 100644 --- a/shared/util.h +++ b/shared/util.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -76,6 +77,12 @@ do { \ __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));