From c4a7b2c56e907e39fa9a6cdb21c1970464abd44e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 19 Mar 2014 00:54:41 +0100 Subject: util: add new FOREACH_STRING() macro as syntactic sugar to iterate through a number of fixed strings --- src/shared/strv.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/shared') diff --git a/src/shared/strv.h b/src/shared/strv.h index b356d034c6..e26ab828d2 100644 --- a/src/shared/strv.h +++ b/src/shared/strv.h @@ -119,3 +119,15 @@ void strv_print(char **l); }) #define STR_IN_SET(x, ...) strv_contains(STRV_MAKE(__VA_ARGS__), x) + +#define FOREACH_STRING(x, ...) \ + for (char **_l = ({ \ + char **_ll = STRV_MAKE(__VA_ARGS__); \ + x = _ll ? _ll[0] : NULL; \ + _ll; \ + }); \ + _l && *_l; \ + x = ({ \ + _l ++; \ + _l[0]; \ + })) -- cgit v1.2.3-54-g00ecf