chiark / gitweb /
Prep v234: Apply missing upstream fixes in src/basic (1/6)
[elogind.git] / src / basic / strv.h
index c95a637b43d811b229b5eddf7328c2970142207a..a01f685f9b512c10e0b4aa12e54384113ffe4ccf 100644 (file)
@@ -68,9 +68,9 @@ char **strv_remove(char **l, const char *s);
 char **strv_uniq(char **l);
 #if 0 /// UNNEEDED by elogind
 bool strv_is_uniq(char **l);
+#endif // 0
 
 bool strv_equal(char **a, char **b);
-#endif // 0
 
 #define strv_contains(l, s) (!!strv_find((l), (s)))
 
@@ -90,9 +90,9 @@ static inline bool strv_isempty(char * const *l) {
 char **strv_split(const char *s, const char *separator);
 #if 0 /// UNNEEDED by elogind
 char **strv_split_newlines(const char *s);
+#endif // 0
 
 int strv_split_extract(char ***t, const char *s, const char *separators, ExtractFlags flags);
-#endif // 0
 
 char *strv_join(char **l, const char *separator);
 #if 0 /// UNNEEDED by elogind
@@ -110,18 +110,19 @@ bool strv_overlap(char **a, char **b) _pure_;
 #define STRV_FOREACH(s, l)                      \
         for ((s) = (l); (s) && *(s); (s)++)
 
-#define STRV_FOREACH_BACKWARDS(s, l)            \
-        STRV_FOREACH(s, l)                      \
-                ;                               \
-        for ((s)--; (l) && ((s) >= (l)); (s)--)
+#define STRV_FOREACH_BACKWARDS(s, l)                                \
+        for (s = ({                                                 \
+                        char **_l = l;                              \
+                        _l ? _l + strv_length(_l) - 1U : NULL;      \
+                        });                                         \
+             (l) && ((s) >= (l));                                   \
+             (s)--)
 
 #define STRV_FOREACH_PAIR(x, y, l)               \
         for ((x) = (l), (y) = (x+1); (x) && *(x) && *(y); (x) += 2, (y) = (x + 1))
 
 char **strv_sort(char **l);
-#if 0 /// UNNEEDED by elogind
 void strv_print(char **l);
-#endif // 0
 
 #define STRV_MAKE(...) ((char**) ((const char*[]) { __VA_ARGS__, NULL }))
 
@@ -157,6 +158,11 @@ void strv_print(char **l);
         })
 
 #define STR_IN_SET(x, ...) strv_contains(STRV_MAKE(__VA_ARGS__), x)
+#define STRPTR_IN_SET(x, ...)                                    \
+        ({                                                       \
+                const char* _x = (x);                            \
+                _x && strv_contains(STRV_MAKE(__VA_ARGS__), _x); \
+        })
 
 #define FOREACH_STRING(x, ...)                               \
         for (char **_l = ({                                  \
@@ -185,8 +191,10 @@ static inline bool strv_fnmatch_or_empty(char* const* patterns, const char *s, i
 char ***strv_free_free(char ***l);
 
 char **strv_skip(char **l, size_t n);
+#endif // 0
 
 int strv_extend_n(char ***l, const char *value, size_t n);
 
+#if 0 /// UNNEEDED by elogind
 int fputstrv(FILE *f, char **l, const char *separator, bool *space);
 #endif // 0