summaryrefslogtreecommitdiff
path: root/src/basic/strv.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-11-23 16:27:15 +0100
committerLennart Poettering <lennart@poettering.net>2018-11-26 14:06:01 +0100
commit52f1552073047195d51901f7e5a5a4fa3189034e (patch)
treef49a11b7b2dc534829c483e48b95809efd86b04e /src/basic/strv.h
parentd7b659ef01a5fefcc959bca13e63f87c9fe315a1 (diff)
downloadsystemd-52f1552073047195d51901f7e5a5a4fa3189034e.tar.gz
strv: add new macro STARTSWITH_SET()
This is to startswith() what PATH_STARTSWITH_SET() is to path_startswith(). Or in other words, checks if the specified string has any of the listed prefixes, and if so, returns the remainder of the string.
Diffstat (limited to 'src/basic/strv.h')
-rw-r--r--src/basic/strv.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/basic/strv.h b/src/basic/strv.h
index 5f1803d87d..aa4cd4aaca 100644
--- a/src/basic/strv.h
+++ b/src/basic/strv.h
@@ -144,6 +144,18 @@ void strv_print(char **l);
_x && strv_contains(STRV_MAKE(__VA_ARGS__), _x); \
})
+#define STARTSWITH_SET(p, ...) \
+ ({ \
+ const char *_p = (p); \
+ char *_found = NULL, **_i; \
+ STRV_FOREACH(_i, STRV_MAKE(__VA_ARGS__)) { \
+ _found = startswith(_p, *_i); \
+ if (_found) \
+ break; \
+ } \
+ _found; \
+ })
+
#define FOREACH_STRING(x, ...) \
for (char **_l = ({ \
char **_ll = STRV_MAKE(__VA_ARGS__); \