master - lvm-string: add drop_lvname_suffix
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=766dedb62899f764ef75f21b17b86c0f17f9d009 Commit: 766dedb62899f764ef75f21b17b86c0f17f9d009 Parent: 2266a1863f048899dc6f54c4d62ae05b33605349 Author: Zdenek Kabelac <[email protected]> AuthorDate: Mon Oct 21 09:17:57 2019 +0200 Committer: Zdenek Kabelac <[email protected]> CommitterDate: Mon Oct 21 12:14:15 2019 +0200
lvm-string: add drop_lvname_suffix
Internal function to drop suffix out of lvname.
--- lib/misc/lvm-string.c | 24 ++++++++++++++++++++++++ lib/misc/lvm-string.h | 1 + 2 files changed, 25 insertions(+), 0 deletions(-)
lib/misc/lvm-string.c +24 -0
@@ -290,3 +290,27 @@ char *first_substring(const char *str, ...)return r; } + +/* Cut suffix (if present) and write the name into NAME_LEN sized new_name buffer +* When suffix is NULL, everythin past the last '_' is removed. +* Returns 1 when suffix was removed, 0 otherwise. +*/ +int drop_lvname_suffix (char *new_name,const char *name,const char *suffix) +{ +char *c; + +if (!dm_strncpy (new_name, name,NAME_LEN )) { +log_debug (INTERNAL_ERROR "Name is too long." ); +return 0 ; + } + +if (!(c =strrchr (new_name,'_' ))) +return 0 ; + +if (suffix &&strcmp (c +1 , suffix)) +return 0 ; + + *c =0 ;/* remove suffix */ + +return 1 ; +}
lib/misc/lvm-string.h +1 -0
@@ -57,5 +57,6 @@ int is_reserved_lvname(const char *name);* first match or else NULL. */ char *first_substring (const char *str, ...); +int drop_lvname_suffix (char *new_name,const char *name,const char *suffix);#endif