teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0786-strv-introduce-strv_join_prefix.patch

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