Combines five implementations found in depmod.c, insmod.c, modprobe.c and util.c. The new version is implemented as a macro. Signed-off-by: Andreas Robinson <andr345@xxxxxxxxx> --- depmod.c | 7 ------- insmod.c | 6 +----- modprobe.c | 5 +---- tables.c | 7 ++++--- util.c | 6 +----- util.h | 1 + 6 files changed, 8 insertions(+), 24 deletions(-) diff --git a/depmod.c b/depmod.c index d740c1b..30d870c 100644 --- a/depmod.c +++ b/depmod.c @@ -273,13 +273,6 @@ int needconv(const char *elfhdr) abort(); } -static char *my_basename(const char *name) -{ - const char *base = strrchr(name, '/'); - if (base) return (char *)base + 1; - return (char *)name; -} - static struct module *grab_module(const char *dirname, const char *filename) { struct module *new; diff --git a/insmod.c b/insmod.c index 84b66d0..3a2a910 100644 --- a/insmod.c +++ b/insmod.c @@ -114,11 +114,7 @@ int main(int argc, char *argv[]) exit(1); } - p = strrchr(argv[0], '/'); - if (p) - p++; - else - p=argv[0]; + p = my_basename(argv[0]); if (argv[1] && (streq(argv[1], "--version") || streq(argv[1], "-V"))) { puts(PACKAGE " version " VERSION); diff --git a/modprobe.c b/modprobe.c index 1a97714..8660f51 100644 --- a/modprobe.c +++ b/modprobe.c @@ -160,10 +160,7 @@ static int add_modules_dep_line(char *line, /* Is this the module we are looking for? */ *ptr = '\0'; - if (strrchr(line, '/')) - modname = strrchr(line, '/') + 1; - else - modname = line; + modname = my_basename(line); len = strlen(modname); if (strchr(modname, '.')) diff --git a/tables.c b/tables.c index 1dccaf3..e3f005f 100644 --- a/tables.c +++ b/tables.c @@ -4,15 +4,16 @@ #include <ctype.h> #include "depmod.h" #include "tables.h" +#include "util.h" /* Turn /lib/modules/2.5.49/kernel/foo.ko(.gz) => foo */ static void make_shortname(char *dest, const char *src) { char *ext; - const char *slash; + const char *bname; - slash = strrchr(src, '/') ?: src-1; - strcpy(dest, slash + 1); + bname = my_basename(src); + strcpy(dest, bname); ext = strchr(dest, '.'); if (ext) *ext = '\0'; diff --git a/util.c b/util.c index 8c16e8e..b65b090 100644 --- a/util.c +++ b/util.c @@ -67,11 +67,7 @@ void filename2modname(char *modname, const char *filename) const char *afterslash; unsigned int i; - afterslash = strrchr(filename, '/'); - if (!afterslash) - afterslash = filename; - else - afterslash++; + afterslash = my_basename(filename); /* Convert to underscores, stop at first . */ for (i = 0; afterslash[i] && afterslash[i] != '.'; i++) { diff --git a/util.h b/util.h index d258dd3..9d41529 100644 --- a/util.h +++ b/util.h @@ -12,5 +12,6 @@ const char *next_string(const char *string, unsigned long *secsize); #define streq(a,b) (strcmp((a),(b)) == 0) #define strstarts(a,start) (strncmp((a),(start), strlen(start)) == 0) +#define my_basename(path) ((strrchr((path), '/') ?: (path) - 1) + 1) #endif -- 1.5.6.3 -- To unsubscribe from this list: send the line "unsubscribe linux-modules" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html