master - string: Add first_substring().
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=12925d8b70c88e1a7a98e69ab896eb16ed2602fc Commit: 12925d8b70c88e1a7a98e69ab896eb16ed2602fc Parent: 5af311ddd8f5c03839b1c2a8feff5eb8dfde5606 Author: Alasdair G Kergon <[email protected]> AuthorDate: Thu Jul 14 14:46:38 2016 +0100 Committer: Alasdair G Kergon <[email protected]> CommitterDate: Thu Jul 14 14:46:38 2016 +0100
string: Add first_substring().
--- lib/misc/lvm-string.c | 16 ++++++++++++++++ lib/misc/lvm-string.h | 8 ++++++++ 2 files changed, 24 insertions(+), 0 deletions(-)
lib/misc/lvm-string.c +16 -0
@@ -243,3 +243,19 @@ char *build_dm_uuid(struct dm_pool *mem, const struct logical_volume *lv,return dlid; } + +char *first_substring (const char *str, ...) +{ +char *substr, *r =NULL ; +va_list ap; + +va_start (ap, str); + + while ((substr = va_arg(ap, char *))) +if ((r =strstr (str, substr))) +break ; + +va_end (ap); + +return r; +}
lib/misc/lvm-string.h +8 -0
@@ -49,4 +49,12 @@ void copy_systemid_chars(const char *src, char *dst);int apply_lvname_restrictions (const char *name);int is_reserved_lvname (const char *name); +/* +* Provided with a NULL-terminated argument list of const char * +* substrings that might be contained within the string str, use +* strstr() to search str for each in turn and return a pointer to the +* first match or else NULL. +*/ +char *first_substring (const char *str, ...); +#endif