aboutsummaryrefslogtreecommitdiff
path: root/src/rc-misc.h
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-12-19 12:46:08 +0000
committerRoy Marples <roy@marples.name>2007-12-19 12:46:08 +0000
commitcd45e5435762d8c6cd13287df7df16b97755176e (patch)
treeef0c7fb0a96e103e2a0dd79ee8c0f47f62ae7174 /src/rc-misc.h
parent2f7218c9849e667ba20d76e4dfe46b4bb195063a (diff)
Introduce cbasename so we don't have to strdup(basename) and free all the time.
Diffstat (limited to 'src/rc-misc.h')
-rw-r--r--src/rc-misc.h11
1 files changed, 11 insertions, 0 deletions
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 <sys/stat.h>
#include <errno.h>
#include <stdbool.h>
+#include <string.h>
#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