X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=src%2Fbasic%2Fstrv.c;h=dab34d8e74ee91de78965975fa53ba479035521b;hb=d76bb3c179b7a32b109e39aa87ff09c8f5a8c178;hp=5bf066ff00e9199d259729fab14a4692e0c7fcba;hpb=5db0e7adf018c82dd63cd21d31dd313dff5561af;p=elogind.git diff --git a/src/basic/strv.c b/src/basic/strv.c index 5bf066ff0..dab34d8e7 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -276,14 +276,13 @@ char **strv_split_newlines(const char *s) { return l; if (isempty(l[n-1])) { - free(l[n-1]); - l[n-1] = NULL; + l[n-1] = mfree(l[n-1]); } return l; } -int strv_split_quoted(char ***t, const char *s, UnquoteFlags flags) { +int strv_split_extract(char ***t, const char *s, const char *separators, ExtractFlags flags) { size_t n = 0, allocated = 0; _cleanup_strv_free_ char **l = NULL; int r; @@ -294,11 +293,12 @@ int strv_split_quoted(char ***t, const char *s, UnquoteFlags flags) { for (;;) { _cleanup_free_ char *word = NULL; - r = unquote_first_word(&s, &word, flags); + r = extract_first_word(&s, &word, separators, flags); if (r < 0) return r; - if (r == 0) + if (r == 0) { break; + } if (!GREEDY_REALLOC(l, allocated, n + 2)) return -ENOMEM; @@ -632,6 +632,8 @@ char **strv_split_nulstr(const char *s) { return r; } +/// UNNEEDED by elogind +#if 0 bool strv_overlap(char **a, char **b) { char **i; @@ -657,8 +659,6 @@ char **strv_sort(char **l) { return l; } -/// UNNEEDED by elogind -#if 0 bool strv_equal(char **a, char **b) { if (!a || !b) return a == b; @@ -669,7 +669,6 @@ bool strv_equal(char **a, char **b) { return true; } -#endif // 0 void strv_print(char **l) { char **s; @@ -678,8 +677,6 @@ void strv_print(char **l) { puts(*s); } -/// UNNEEDED by elogind -#if 0 int strv_extendf(char ***l, const char *format, ...) { va_list ap; char *x; @@ -712,6 +709,26 @@ char **strv_reverse(char **l) { return l; } + +char **strv_shell_escape(char **l, const char *bad) { + char **s; + + /* Escapes every character in every string in l that is in bad, + * edits in-place, does not roll-back on error. */ + + STRV_FOREACH(s, l) { + char *v; + + v = shell_escape(*s, bad); + if (!v) + return NULL; + + free(*s); + *s = v; + } + + return l; +} #endif // 0 bool strv_fnmatch(char* const* patterns, const char *s, int flags) {