strv: drop the escape_separator flag from strv_join_full()

Now that fstab_filter_options() no longer uses strv_join_full() with
escape_separator=true (it splits with EXTRACT_UNESCAPE_RELAX and joins the kept
options verbatim), the escape_separator flag has no users. Drop it from
strv_join_full() and its wrapper strv_join(), and update the remaining callers in
kernel-install and the tests accordingly.
This commit is contained in:
wyu
2026-08-13 11:17:23 +08:00
parent eb5ee83c1f
commit 7b00f957fe
5 changed files with 15 additions and 42 deletions
+3 -17
View File
@@ -529,7 +529,7 @@ int strv_split_colon_pairs(char ***t, const char *s) {
return (int) n;
}
char* strv_join_full(char * const *l, const char *separator, const char *prefix, bool escape_separator) {
char* strv_join_full(char * const *l, const char *separator, const char *prefix) {
char *r, *e;
size_t n, k, m;
@@ -539,17 +539,12 @@ char* strv_join_full(char * const *l, const char *separator, const char *prefix,
k = strlen(separator);
m = strlen_ptr(prefix);
if (escape_separator) /* If the separator was multi-char, we wouldn't know how to escape it. */
assert(k == 1);
n = 0;
STRV_FOREACH(s, l) {
if (s != l)
n += k;
bool needs_escaping = escape_separator && strchr(*s, *separator);
n += m + strlen(*s) * (1 + needs_escaping);
n += m + strlen(*s);
}
r = new(char, n+1);
@@ -564,16 +559,7 @@ char* strv_join_full(char * const *l, const char *separator, const char *prefix,
if (prefix)
e = stpcpy(e, prefix);
bool needs_escaping = escape_separator && strchr(*s, *separator);
if (needs_escaping)
for (size_t i = 0; (*s)[i]; i++) {
if ((*s)[i] == *separator)
*(e++) = '\\';
*(e++) = (*s)[i];
}
else
e = stpcpy(e, *s);
e = stpcpy(e, *s);
}
*e = 0;
+2 -2
View File
@@ -120,9 +120,9 @@ char** strv_split_newlines(const char *s);
* string in the vector is an empty string. */
int strv_split_colon_pairs(char ***t, const char *s);
char* strv_join_full(char * const *l, const char *separator, const char *prefix, bool escape_separator);
char* strv_join_full(char * const *l, const char *separator, const char *prefix);
static inline char *strv_join(char * const *l, const char *separator) {
return strv_join_full(l, separator, NULL, false);
return strv_join_full(l, separator, NULL);
}
bool strv_overlap(char * const *a, char * const *b) _pure_;
+2 -2
View File
@@ -1093,10 +1093,10 @@ static int context_execute(Context *c) {
return r;
if (DEBUG_LOGGING) {
_cleanup_free_ char *x = strv_join_full(c->plugins, "", "\n ", /* escape_separator= */ false);
_cleanup_free_ char *x = strv_join_full(c->plugins, "", "\n ");
log_debug("Using plugins: %s", strna(x));
_cleanup_free_ char *y = strv_join_full(c->envp, "", "\n ", /* escape_separator= */ false);
_cleanup_free_ char *y = strv_join_full(c->envp, "", "\n ");
log_debug("Plugin environment: %s", strna(y));
_cleanup_free_ char *z = strv_join(strv_skip(c->argv, 1), " ");
+1 -1
View File
@@ -64,7 +64,7 @@ static int partial_match_error(
assert(strv_length(s) == n_partial_matches);
_cleanup_free_ char *p = strv_join_full(s, ", ", /* prefix= */ NULL, /* escape_separator= */ false);
_cleanup_free_ char *p = strv_join(s, ", ");
return log_full_errno(LOG_ERR + state->log_level_shift,
SYNTHETIC_ERRNO(EINVAL),
"%s: option '%s' is ambiguous; possibilities: %s",
+7 -20
View File
@@ -159,44 +159,31 @@ TEST(strv_join) {
}
TEST(strv_join_full) {
_cleanup_free_ char *p = strv_join_full((char **)input_table_multiple, ", ", "foo", false);
_cleanup_free_ char *p = strv_join_full((char **)input_table_multiple, ", ", "foo");
assert_se(p);
ASSERT_STREQ(p, "fooone, footwo, foothree");
_cleanup_free_ char *q = strv_join_full((char **)input_table_multiple, ";", "foo", false);
_cleanup_free_ char *q = strv_join_full((char **)input_table_multiple, ";", "foo");
assert_se(q);
ASSERT_STREQ(q, "fooone;footwo;foothree");
_cleanup_free_ char *r = strv_join_full(STRV_MAKE("a", "a;b", "a:c"), ";", NULL, true);
assert_se(r);
ASSERT_STREQ(r, "a;a\\;b;a:c");
_cleanup_free_ char *s = strv_join_full(STRV_MAKE("a", "a;b", "a;;c", ";", ";x"), ";", NULL, true);
assert_se(s);
ASSERT_STREQ(s, "a;a\\;b;a\\;\\;c;\\;;\\;x");
_cleanup_free_ char *t = strv_join_full(STRV_MAKE("a", "a;b", "a:c", ";"), ";", "=", true);
assert_se(t);
ASSERT_STREQ(t, "=a;=a\\;b;=a:c;=\\;");
t = mfree(t);
_cleanup_free_ char *u = strv_join_full((char **)input_table_multiple, NULL, "foo", false);
_cleanup_free_ char *u = strv_join_full((char **)input_table_multiple, NULL, "foo");
assert_se(u);
ASSERT_STREQ(u, "fooone footwo foothree");
_cleanup_free_ char *v = strv_join_full((char **)input_table_one, ", ", "foo", false);
_cleanup_free_ char *v = strv_join_full((char **)input_table_one, ", ", "foo");
assert_se(v);
ASSERT_STREQ(v, "fooone");
_cleanup_free_ char *w = strv_join_full((char **)input_table_none, ", ", "foo", false);
_cleanup_free_ char *w = strv_join_full((char **)input_table_none, ", ", "foo");
assert_se(w);
ASSERT_STREQ(w, "");
_cleanup_free_ char *x = strv_join_full((char **)input_table_two_empties, ", ", "foo", false);
_cleanup_free_ char *x = strv_join_full((char **)input_table_two_empties, ", ", "foo");
assert_se(x);
ASSERT_STREQ(x, "foo, foo");
_cleanup_free_ char *y = strv_join_full((char **)input_table_one_empty, ", ", "foo", false);
_cleanup_free_ char *y = strv_join_full((char **)input_table_one_empty, ", ", "foo");
assert_se(y);
ASSERT_STREQ(y, "foo");
}