summaryrefslogtreecommitdiffstats
path: root/lib/fileutils.c
diff options
context:
space:
mode:
authorKarel Zak2014-06-09 11:54:32 +0200
committerKarel Zak2014-06-09 11:54:32 +0200
commitd4eaabc86ad36af8f2d0e37ebfc56d53d5a8a21d (patch)
treee400911d82bef85e70d7316099a92ab3e1227435 /lib/fileutils.c
parentlib/fileutils: add mkdir_p() from libmount (diff)
downloadkernel-qcow2-util-linux-d4eaabc86ad36af8f2d0e37ebfc56d53d5a8a21d.tar.gz
kernel-qcow2-util-linux-d4eaabc86ad36af8f2d0e37ebfc56d53d5a8a21d.tar.xz
kernel-qcow2-util-linux-d4eaabc86ad36af8f2d0e37ebfc56d53d5a8a21d.zip
lib/fileutils: add stripoff_last_component() from libmount
Signed-off-by: Karel Zak <kzak@redhat.com>
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;
+}