mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-17 01:51:00 +03:00
libzutil: add zfs_{base,dir}name()
Reviewed-by: John Kennedy <john.kennedy@delphix.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Ryan Moeller <ryan@iXsystems.com> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #12105
This commit is contained in:
parent
3aa81a6635
commit
0854d4c186
@ -160,6 +160,9 @@ _LIBZUTIL_H void color_start(char *color);
|
||||
_LIBZUTIL_H void color_end(void);
|
||||
_LIBZUTIL_H int printf_color(char *color, char *format, ...);
|
||||
|
||||
_LIBZUTIL_H const char *zfs_basename(const char *path);
|
||||
_LIBZUTIL_H ssize_t zfs_dirnamelen(const char *path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user