richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
984f77
From 23ef6c470418b50119dc0bf13b681bfeae820352 Mon Sep 17 00:00:00 2001
984f77
From: Yu Watanabe <watanabe.yu+github@gmail.com>
984f77
Date: Tue, 11 Sep 2018 13:22:31 +0900
984f77
Subject: [PATCH] strv: introduce strv_join_prefix()
984f77
984f77
(cherry picked from commit 2b9a7d2e96f5f852cdf8cc704930ea2ee456f6a1)
984f77
984f77
Related: #2049788
984f77
---
984f77
 src/basic/strv.c | 10 +++++++---
984f77
 src/basic/strv.h |  5 ++++-
984f77
 2 files changed, 11 insertions(+), 4 deletions(-)
984f77
984f77
diff --git a/src/basic/strv.c b/src/basic/strv.c
984f77
index b3716233b5..f1605e4fbb 100644
984f77
--- a/src/basic/strv.c
984f77
+++ b/src/basic/strv.c
984f77
@@ -335,21 +335,22 @@ int strv_split_extract(char ***t, const char *s, const char *separators, Extract
984f77
         return (int) n;
984f77
 }
984f77
 
984f77
-char *strv_join(char **l, const char *separator) {
984f77
+char *strv_join_prefix(char **l, const char *separator, const char *prefix) {
984f77
         char *r, *e;
984f77
         char **s;
984f77
-        size_t n, k;
984f77
+        size_t n, k, m;
984f77
 
984f77
         if (!separator)
984f77
                 separator = " ";
984f77
 
984f77
         k = strlen(separator);
984f77
+        m = strlen_ptr(prefix);
984f77
 
984f77
         n = 0;
984f77
         STRV_FOREACH(s, l) {
984f77
                 if (s != l)
984f77
                         n += k;
984f77
-                n += strlen(*s);
984f77
+                n += m + strlen(*s);
984f77
         }
984f77
 
984f77
         r = new(char, n+1);
984f77
@@ -361,6 +362,9 @@ char *strv_join(char **l, const char *separator) {
984f77
                 if (s != l)
984f77
                         e = stpcpy(e, separator);
984f77
 
984f77
+                if (prefix)
984f77
+                        e = stpcpy(e, prefix);
984f77
+
984f77
                 e = stpcpy(e, *s);
984f77
         }
984f77
 
984f77
diff --git a/src/basic/strv.h b/src/basic/strv.h
984f77
index a09d76706d..9285bc2642 100644
984f77
--- a/src/basic/strv.h
984f77
+++ b/src/basic/strv.h
984f77
@@ -71,7 +71,10 @@ char **strv_split_newlines(const char *s);
984f77
 
984f77
 int strv_split_extract(char ***t, const char *s, const char *separators, ExtractFlags flags);
984f77
 
984f77
-char *strv_join(char **l, const char *separator);
984f77
+char *strv_join_prefix(char **l, const char *separator, const char *prefix);
984f77
+static inline char *strv_join(char **l, const char *separator) {
984f77
+        return strv_join_prefix(l, separator, NULL);
984f77
+}
984f77
 
984f77
 char **strv_parse_nulstr(const char *s, size_t l);
984f77
 char **strv_split_nulstr(const char *s);