diff options
author | наб <[email protected]> | 2021-06-03 17:17:09 +0200 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2021-06-11 09:10:05 -0700 |
commit | 0854d4c186f52066ba0bd2da4282c5fde4bd9326 (patch) | |
tree | ba1030f34d82767a3d6fbee764bf0af5ecb8bdf7 /lib/libzutil/zutil_device_path.c | |
parent | 3aa81a6635bf025298a40bf7b62ab57c556cfbbe (diff) |
libzutil: add zfs_{base,dir}name()
Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Ryan Moeller <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #12105
Diffstat (limited to 'lib/libzutil/zutil_device_path.c')
-rw-r--r-- | lib/libzutil/zutil_device_path.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/libzutil/zutil_device_path.c b/lib/libzutil/zutil_device_path.c index bcdc72baa..435c444b2 100644 --- a/lib/libzutil/zutil_device_path.c +++ b/lib/libzutil/zutil_device_path.c @@ -31,6 +31,22 @@ #include <libzutil.h> +/* Substring from after the last slash, or the string itself if none */ +const char * +zfs_basename(const char *path) +{ + const char *bn = strrchr(path, '/'); + return (bn ? bn + 1 : path); +} + +/* Return index of last slash or -1 if none */ +ssize_t +zfs_dirnamelen(const char *path) +{ + const char *end = strrchr(path, '/'); + return (end ? end - path : -1); +} + /* * Given a shorthand device name check if a file by that name exists in any * of the 'zpool_default_import_path' or ZPOOL_IMPORT_PATH directories. If |