On Thu, 2009-04-23 at 18:15 +0100, Alan Jenkins wrote: > Sorry, I didn't explain myself very well. When I objected to the > macro, what I really disliked was the way it was compressed into one > line. I think the original 3-line my_basename() function was much > clearer. Ah, ok. I need to kill some of my darlings it seems... Is this patch better? >From 8f80cd791a9008387c1c457d551bca73277c18e9 Mon Sep 17 00:00:00 2001 From: Andreas Robinson <andr345@xxxxxxxxx> Date: Thu, 23 Apr 2009 19:49:16 +0200 Subject: [PATCH] Rewrite my_basename() for clarity --- util.c | 12 ++++++++++++ util.h | 2 +- 2 files changed, 13 insertions(+), 1 deletions(-) diff --git a/util.c b/util.c index 0ee6064..577718a 100644 --- a/util.c +++ b/util.c @@ -114,6 +114,18 @@ char *underscores(char *string) } /* + * Get the basename in a pathname. + * Unlike the standard implementation, this does not copy the string. + */ +char *my_basename(const char *path) +{ + const char *base = strrchr(path, '/'); + if (base) + return (char *) base + 1; + return (char *) path; +} + +/* * Find the next string in an ELF section. */ const char *next_string(const char *string, unsigned long *secsize) diff --git a/util.h b/util.h index c73ad21..fbda299 100644 --- a/util.h +++ b/util.h @@ -7,6 +7,7 @@ char *getline_wrapped(FILE *file, unsigned int *linenum); void filename2modname(char *modname, const char *filename); char *underscores(char *string); +char *my_basename(const char *path); const char *next_string(const char *string, unsigned long *secsize); @@ -40,6 +41,5 @@ void *get_section64(void *file, unsigned long filesize, #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