From cd45e5435762d8c6cd13287df7df16b97755176e Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Wed, 19 Dec 2007 12:46:08 +0000 Subject: Introduce cbasename so we don't have to strdup(basename) and free all the time. --- src/rc-misc.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/rc-misc.h') diff --git a/src/rc-misc.h b/src/rc-misc.h index 570d7e79..bcc6b544 100644 --- a/src/rc-misc.h +++ b/src/rc-misc.h @@ -35,6 +35,7 @@ #include #include #include +#include #ifndef LIB # define LIB "lib" @@ -118,4 +119,14 @@ bool rc_conf_yesno (const char *var); char **env_filter (void); char **env_config (void); +/* cbasename never modifies the argument. As such, if there is a trailing + * slash then an empty string is returned. */ +static inline const char *cbasename (const char *argv0) { + char *l = strrchr (argv0, '/'); + + if (l) + return (++l); + return (argv0); +} + #endif -- cgit v1.2.3