]> sourceware.org Git - lvm2.git/commitdiff
lvm-string: add drop_lvname_suffix
authorZdenek Kabelac <zkabelac@redhat.com>
Mon, 21 Oct 2019 07:17:57 +0000 (09:17 +0200)
committerZdenek Kabelac <zkabelac@redhat.com>
Mon, 21 Oct 2019 10:14:15 +0000 (12:14 +0200)
Internal function to drop suffix out of lvname.

lib/misc/lvm-string.c
lib/misc/lvm-string.h

index 4034b405d1b8b6809e8f07343888e00bc857b9d3..d96d431947936c5f6d421e3ea34340923ff5c444 100644 (file)
@@ -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;
+}
index 4e7404a8da8642d68e990b5c9252fe0c1f9a2312..5d2f95a73a7ea239adbcbcf41c8d64dc9c56d162 100644 (file)
@@ -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
This page took 0.037191 seconds and 5 git commands to generate.