mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
lvm-string: add drop_lvname_suffix
Internal function to drop suffix out of lvname.
This commit is contained in:
parent
2266a1863f
commit
766dedb628
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user