From 14728b9406dccbf6a74f21aaa1cc524273edbb15 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 28 Nov 2017 16:37:53 +0100 Subject: string-util: rework strextend() to optionally inset separators between each appended string This adds a new flavour of strextend(), called strextend_with_separator(), which takes an optional separator string. If specified, the separator is inserted between each appended string, as well as before the first one, but only if the original string was non-empty. This new call is particularly useful when appending new options to mount option strings and suchlike, which need to be comma-separated, and initially start out from an empty string. --- src/basic/string-util.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/basic/string-util.h') diff --git a/src/basic/string-util.h b/src/basic/string-util.h index f68b5f2f3..7276cfd6f 100644 --- a/src/basic/string-util.h +++ b/src/basic/string-util.h @@ -174,7 +174,9 @@ char *strreplace(const char *text, const char *old_string, const char *new_strin char *strip_tab_ansi(char **p, size_t *l); -char *strextend(char **x, ...) _sentinel_; +char *strextend_with_separator(char **x, const char *separator, ...) _sentinel_; + +#define strextend(x, ...) strextend_with_separator(x, NULL, __VA_ARGS__) char *strrep(const char *s, unsigned n); -- cgit v1.2.3