From cba8922fd40b9eca203bc1d63bef72dd1edf302c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 27 Jan 2010 22:38:21 +0100 Subject: [PATCH] introduce strv_contains() --- strv.c | 10 ++++++++++ strv.h | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/strv.c b/strv.c index faa878c..7e0810b 100644 --- a/strv.c +++ b/strv.c @@ -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; +} diff --git a/strv.h b/strv.h index 9504ccc..cc21eb1 100644 --- a/strv.h +++ b/strv.h @@ -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)--) -- 2.39.2