diff options
author | Karel Zak | 2014-06-09 11:54:32 +0200 |
---|---|---|
committer | Karel Zak | 2014-06-09 11:54:32 +0200 |
commit | d4eaabc86ad36af8f2d0e37ebfc56d53d5a8a21d (patch) | |
tree | e400911d82bef85e70d7316099a92ab3e1227435 /lib/fileutils.c | |
parent | lib/fileutils: add mkdir_p() from libmount (diff) | |
download | kernel-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.c | 12 |
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; +} |