richardphibel / rpms / systemd

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