package An official xmake package repository https://xrepo.xmake.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB

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 <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 @@ 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));