From 28849dbadb7cd127f7f89e8892ec94c6a05070da Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 21 Aug 2014 16:22:34 +0200 Subject: service,strv: introduce strv_find_startswith() and make use of it Unlike strv_find_prefix() the new call will return a pointer to the suffix of the item we found, instead of the whole item. This is more closer inline with what startswith() does, and allows us to simplify a couple of invocations. --- src/shared/strv.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/shared/strv.c') diff --git a/src/shared/strv.c b/src/shared/strv.c index 6448f3170f..0df978d23b 100644 --- a/src/shared/strv.c +++ b/src/shared/strv.c @@ -52,6 +52,23 @@ char *strv_find_prefix(char **l, const char *name) { return NULL; } +char *strv_find_startswith(char **l, const char *name) { + char **i, *e; + + assert(name); + + /* Like strv_find_prefix, but actually returns only the + * suffix, not the whole item */ + + STRV_FOREACH(i, l) { + e = startswith(*i, name); + if (e) + return e; + } + + return NULL; +} + void strv_free(char **l) { char **k; -- cgit v1.2.3-54-g00ecf