introduce strv_contains()

This commit is contained in:
Lennart Poettering
2010-01-27 22:38:21 +01:00
parent 4a72ff34c6
commit cba8922fd4
2 changed files with 13 additions and 1 deletions

10
strv.c
View File

@@ -145,3 +145,13 @@ fail:
return NULL;
}
bool strv_contains(char **l, const char *s) {
char **i;
STRV_FOREACH(i, l)
if (streq(*i, s))
return true;
return false;
}

4
strv.h
View File

@@ -12,10 +12,12 @@ unsigned strv_length(char **l);
char **strv_merge(char **a, char **b);
bool strv_contains(char **l, const char *s);
char **strv_new(const char *x, ...) __sentinel;
#define STRV_FOREACH(s, l) \
for ((s) = (l); (l) && *(s); (s)++)
for ((s) = (l); (s) && *(s); (s)++)
#define STRV_FOREACH_BACKWARDS(s, l) \
for (; (l) && ((s) >= (l)); (s)--)