diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-09-11 13:22:31 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-09-13 17:02:58 +0900 |
commit | 2b9a7d2e96f5f852cdf8cc704930ea2ee456f6a1 (patch) | |
tree | 6d60a8fbdf1f3f25ddba5687922bdcd364621260 /src/basic/strv.c | |
parent | 7c1cb6f1989074e144b1625607950fce80c951ec (diff) | |
download | systemd-2b9a7d2e96f5f852cdf8cc704930ea2ee456f6a1.tar.gz |
strv: introduce strv_join_prefix()
Diffstat (limited to 'src/basic/strv.c')
-rw-r--r-- | src/basic/strv.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/basic/strv.c b/src/basic/strv.c index abf3fc4c7b..493fad16a1 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -339,21 +339,22 @@ int strv_split_extract(char ***t, const char *s, const char *separators, Extract return (int) n; } -char *strv_join(char **l, const char *separator) { +char *strv_join_prefix(char **l, const char *separator, const char *prefix) { char *r, *e; char **s; - size_t n, k; + size_t n, k, m; if (!separator) separator = " "; k = strlen(separator); + m = strlen_ptr(prefix); n = 0; STRV_FOREACH(s, l) { if (s != l) n += k; - n += strlen(*s); + n += m + strlen(*s); } r = new(char, n+1); @@ -365,6 +366,9 @@ char *strv_join(char **l, const char *separator) { if (s != l) e = stpcpy(e, separator); + if (prefix) + e = stpcpy(e, prefix); + e = stpcpy(e, *s); } |