mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 00:47:10 +09:00
string-util: add a mechanism for strextend_with_separator() for specifying "ignore" arguments
in strv_new() we have STRV_IGNORE for skipping over an argument in the argument list. Let's add the same to strextend_with_separator(): strextend_with_separator(&x, "foo", POINTER_MAX, "bar"); will result in "foobar" being appended to "x". (POINTER_MAX Which is different from NULL, which terminates the argument list). This is useful for ternary op situations. (We should probably get rid of STRV_IGNORE and just use POINTER_MAX everywhere directly, but that's for another time.)
This commit is contained in:
@@ -832,6 +832,8 @@ char* strextend_with_separator_internal(char **x, const char *separator, ...) {
|
||||
t = va_arg(ap, const char *);
|
||||
if (!t)
|
||||
break;
|
||||
if (t == POINTER_MAX)
|
||||
continue;
|
||||
|
||||
n = strlen(t);
|
||||
|
||||
@@ -864,6 +866,8 @@ char* strextend_with_separator_internal(char **x, const char *separator, ...) {
|
||||
t = va_arg(ap, const char *);
|
||||
if (!t)
|
||||
break;
|
||||
if (t == POINTER_MAX)
|
||||
continue;
|
||||
|
||||
if (need_separator && separator)
|
||||
p = stpcpy(p, separator);
|
||||
|
||||
Reference in New Issue
Block a user