From 069219577b58451a390b322821746f492ca5a6e2 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Fri, 12 Apr 2013 16:55:45 -0400 Subject: [PATCH] Add function to find a needle in a string array Signed-off-by: Stefan Berger Reviewed-by: Corey Bryant Tested-by: Corey Bryant --- src/libvirt_private.syms | 1 + src/util/virstring.c | 14 ++++++++++++++ src/util/virstring.h | 2 ++ 3 files changed, 17 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 449696d112..64a6e3d0c4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1723,6 +1723,7 @@ virStorageFileResize; # util/virstring.h +virStringArrayHasString; virStringFreeList; virStringJoin; virStringSplit; diff --git a/src/util/virstring.c b/src/util/virstring.c index 0420ca37f9..122ebb8f0f 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -166,3 +166,17 @@ void virStringFreeList(char **strings) } VIR_FREE(strings); } + + +bool +virStringArrayHasString(char **strings, const char *needle) +{ + size_t i = 0; + + while (strings[i]) { + if (STREQ(strings[i++], needle)) + return true; + } + + return false; +} diff --git a/src/util/virstring.h b/src/util/virstring.h index a569fe080a..2ceadc6b84 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -35,4 +35,6 @@ char *virStringJoin(const char **strings, void virStringFreeList(char **strings); +bool virStringArrayHasString(char **strings, const char *needle); + #endif /* __VIR_STRING_H__ */