chiark / gitweb /
Unifiy free() usage
[elogind.git] / src / basic / strv.c
index 31d83f3efd9a7e38e8a65ec3bab9f885c48efbc7..dab34d8e74ee91de78965975fa53ba479035521b 100644 (file)
@@ -201,6 +201,8 @@ int strv_extend_strv(char ***a, char **b) {
         return 0;
 }
 
+/// UNNEEDED by elogind
+#if 0
 int strv_extend_strv_concat(char ***a, char **b, const char *suffix) {
         int r;
         char **s;
@@ -221,6 +223,7 @@ int strv_extend_strv_concat(char ***a, char **b, const char *suffix) {
 
         return 0;
 }
+#endif // 0
 
 char **strv_split(const char *s, const char *separator) {
         const char *word, *state;
@@ -273,15 +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;
 }
-#endif // 0
 
-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;
@@ -292,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;
@@ -315,6 +317,7 @@ int strv_split_quoted(char ***t, const char *s, UnquoteFlags flags) {
 
         return 0;
 }
+#endif // 0
 
 char *strv_join(char **l, const char *separator) {
         char *r, *e;
@@ -350,6 +353,8 @@ char *strv_join(char **l, const char *separator) {
         return r;
 }
 
+/// UNNEEDED by elogind
+#if 0
 char *strv_join_quoted(char **l) {
         char *buf = NULL;
         char **s;
@@ -386,6 +391,7 @@ char *strv_join_quoted(char **l) {
         free(buf);
         return NULL;
 }
+#endif // 0
 
 int strv_push(char ***l, char *value) {
         char **c;
@@ -626,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;
 
@@ -651,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;
@@ -663,7 +669,6 @@ bool strv_equal(char **a, char **b) {
 
         return true;
 }
-#endif // 0
 
 void strv_print(char **l) {
         char **s;
@@ -672,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;
@@ -706,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) {