X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fstrv.c;h=8c6ba6a6336c1e252218c1c8b6109b81e77e37a1;hb=33c2ce7b200747c172d4899c717a8e9097d84659;hp=fdb658c0a33696a0e5d644f1c2636748ce0c3a5e;hpb=98940a3cd93807b5a3809bb1fb7ab43d450939f1;p=elogind.git diff --git a/src/shared/strv.c b/src/shared/strv.c index fdb658c0a..8c6ba6a63 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 @@ -69,7 +68,7 @@ char *strv_find_startswith(char **l, const char *name) { return NULL; } -void strv_free(char **l) { +void strv_clear(char **l) { char **k; if (!l) @@ -78,7 +77,13 @@ void strv_free(char **l) { for (k = l; *k; k++) free(*k); + *l = NULL; +} + +char **strv_free(char **l) { + strv_clear(l); free(l); + return NULL; } char **strv_copy(char * const *l) { @@ -519,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; @@ -659,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; +}