X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fstrv.c;h=d44a72fc484d09966ac745066499a71cedd05c65;hb=d896ac2d2fbce41a0b11a0618a685adeaf18b8fe;hp=f86dddaf811223b0df1caa8f71c6f0c316440f7b;hpb=dd9c7723fafc8b326188efa86efe00bcbe5abcfd;p=elogind.git diff --git a/src/shared/strv.c b/src/shared/strv.c index f86dddaf8..d44a72fc4 100644 --- a/src/shared/strv.c +++ b/src/shared/strv.c @@ -19,7 +19,6 @@ along with systemd; If not, see . ***/ -#include #include #include #include @@ -81,9 +80,10 @@ void strv_clear(char **l) { *l = NULL; } -void strv_free(char **l) { +char **strv_free(char **l) { strv_clear(l); free(l); + return NULL; } char **strv_copy(char * const *l) { @@ -278,7 +278,7 @@ char **strv_split_newlines(const char *s) { return l; } -int strv_split_quoted(char ***t, const char *s, bool relax) { +int strv_split_quoted(char ***t, const char *s, UnquoteFlags flags) { size_t n = 0, allocated = 0; _cleanup_strv_free_ char **l = NULL; int r; @@ -289,7 +289,7 @@ int strv_split_quoted(char ***t, const char *s, bool relax) { for (;;) { _cleanup_free_ char *word = NULL; - r = unquote_first_word(&s, &word, relax); + r = unquote_first_word(&s, &word, flags); if (r < 0) return r; if (r == 0) @@ -524,6 +524,16 @@ char **strv_uniq(char **l) { return l; } +bool strv_is_uniq(char **l) { + char **i; + + STRV_FOREACH(i, l) + if (strv_find(i+1, *i)) + return false; + + return true; +} + char **strv_remove(char **l, const char *s) { char **f, **t; @@ -664,3 +674,31 @@ int strv_extendf(char ***l, const char *format, ...) { return strv_consume(l, x); } + +char **strv_reverse(char **l) { + unsigned n, i; + + n = strv_length(l); + if (n <= 1) + return l; + + for (i = 0; i < n / 2; i++) { + char *t; + + t = l[i]; + l[i] = l[n-1-i]; + l[n-1-i] = t; + } + + return l; +} + +bool strv_fnmatch(char* const* patterns, const char *s, int flags) { + char* const* p; + + STRV_FOREACH(p, patterns) + if (fnmatch(*p, s, 0) == 0) + return true; + + return false; +}