summaryrefslogtreecommitdiffstats
path: root/lib/fileutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fileutils.c')
-rw-r--r--lib/fileutils.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/fileutils.c b/lib/fileutils.c
index 3d4553179..a1b475757 100644
--- a/lib/fileutils.c
+++ b/lib/fileutils.c
@@ -117,3 +117,15 @@ int mkdir_p(const char *path, mode_t mode)
free(dir);
return rc;
}
+
+/* returns basename and keeps dirname in the @path, if @path is "/" (root)
+ * then returns empty string */
+char *stripoff_last_component(char *path)
+{
+ char *p = path ? strrchr(path, '/') : NULL;
+
+ if (!p)
+ return NULL;
+ *p = '\0';
+ return p + 1;
+}