path-util: beef up PATH_STARTSWITH_SET() macro a bit

Let's remove duplicate evaluation, and let's return the result of the
succesful path_startswith() call, i.e. the suffix to the matching
prefix.
This commit is contained in:
Lennart Poettering
2018-11-23 16:50:39 +01:00
parent 0cbd293e12
commit d898ed65ab
2 changed files with 29 additions and 7 deletions

View File

@@ -71,13 +71,13 @@ static inline bool path_equal_ptr(const char *a, const char *b) {
#define PATH_STARTSWITH_SET(p, ...) \
({ \
char **s; \
bool _found = false; \
STRV_FOREACH(s, STRV_MAKE(__VA_ARGS__)) \
if (path_startswith(p, *s)) { \
_found = true; \
break; \
} \
const char *_p = (p); \
char *_found = NULL, **_i; \
STRV_FOREACH(_i, STRV_MAKE(__VA_ARGS__)) { \
_found = path_startswith(_p, *_i); \
if (_found) \
break; \
} \
_found; \
})