mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-22 22:03:43 +03:00
Rename strv_split_extract() to strv_split_full()
Now that _full() is gone, we can rename _extract() to have the usual suffix we use for the more featureful version.
This commit is contained in:
parent
03b62851a9
commit
90e30d767a
@ -687,7 +687,7 @@ char **replace_env_argv(char **argv, char **env) {
|
||||
if (e) {
|
||||
int r;
|
||||
|
||||
r = strv_split_extract(&m, e, WHITESPACE, EXTRACT_RELAX|EXTRACT_UNQUOTE);
|
||||
r = strv_split_full(&m, e, WHITESPACE, EXTRACT_RELAX|EXTRACT_UNQUOTE);
|
||||
if (r < 0) {
|
||||
ret[k] = NULL;
|
||||
strv_free(ret);
|
||||
|
@ -279,7 +279,7 @@ char **strv_split_newlines(const char *s) {
|
||||
return l;
|
||||
}
|
||||
|
||||
int strv_split_extract(char ***t, const char *s, const char *separators, ExtractFlags flags) {
|
||||
int strv_split_full(char ***t, const char *s, const char *separators, ExtractFlags flags) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
size_t n = 0, allocated = 0;
|
||||
int r;
|
||||
|
@ -74,12 +74,12 @@ static inline bool strv_isempty(char * const *l) {
|
||||
|
||||
char **strv_split_newlines(const char *s);
|
||||
|
||||
int strv_split_extract(char ***t, const char *s, const char *separators, ExtractFlags flags);
|
||||
int strv_split_full(char ***t, const char *s, const char *separators, ExtractFlags flags);
|
||||
static inline char **strv_split(const char *s, const char *separators) {
|
||||
char **ret;
|
||||
int r;
|
||||
|
||||
r = strv_split_extract(&ret, s, separators, 0);
|
||||
r = strv_split_full(&ret, s, separators, 0);
|
||||
if (r < 0)
|
||||
return NULL;
|
||||
|
||||
|
@ -124,7 +124,7 @@ static int spawn_getter(const char *getter) {
|
||||
_cleanup_strv_free_ char **words = NULL;
|
||||
|
||||
assert(getter);
|
||||
r = strv_split_extract(&words, getter, WHITESPACE, EXTRACT_UNQUOTE);
|
||||
r = strv_split_full(&words, getter, WHITESPACE, EXTRACT_UNQUOTE);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to split getter option: %m");
|
||||
|
||||
|
@ -101,7 +101,7 @@ _public_ int sd_listen_fds_with_names(int unset_environment, char ***names) {
|
||||
|
||||
e = getenv("LISTEN_FDNAMES");
|
||||
if (e) {
|
||||
n_names = strv_split_extract(&l, e, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
|
||||
n_names = strv_split_full(&l, e, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
|
||||
if (n_names < 0) {
|
||||
unsetenv_all(unset_environment);
|
||||
return n_names;
|
||||
|
@ -251,7 +251,7 @@ int x11_read_data(Context *c, sd_bus_message *m) {
|
||||
if (in_section && first_word(l, "Option")) {
|
||||
_cleanup_strv_free_ char **a = NULL;
|
||||
|
||||
r = strv_split_extract(&a, l, WHITESPACE, EXTRACT_UNQUOTE);
|
||||
r = strv_split_full(&a, l, WHITESPACE, EXTRACT_UNQUOTE);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -274,7 +274,7 @@ int x11_read_data(Context *c, sd_bus_message *m) {
|
||||
} else if (!in_section && first_word(l, "Section")) {
|
||||
_cleanup_strv_free_ char **a = NULL;
|
||||
|
||||
r = strv_split_extract(&a, l, WHITESPACE, EXTRACT_UNQUOTE);
|
||||
r = strv_split_full(&a, l, WHITESPACE, EXTRACT_UNQUOTE);
|
||||
if (r < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
@ -489,7 +489,7 @@ static int read_next_mapping(const char* filename,
|
||||
if (IN_SET(l[0], 0, '#'))
|
||||
continue;
|
||||
|
||||
r = strv_split_extract(&b, l, WHITESPACE, EXTRACT_UNQUOTE);
|
||||
r = strv_split_full(&b, l, WHITESPACE, EXTRACT_UNQUOTE);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -301,7 +301,7 @@ int overlay_mount_parse(CustomMount **l, size_t *n, const char *s, bool read_onl
|
||||
CustomMount *m;
|
||||
int k;
|
||||
|
||||
k = strv_split_extract(&lower, s, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
|
||||
k = strv_split_full(&lower, s, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
|
||||
if (k < 0)
|
||||
return k;
|
||||
if (k < 2)
|
||||
|
@ -340,7 +340,7 @@ static int bus_append_exec_command(sd_bus_message *m, const char *field, const c
|
||||
return log_error_errno(r, "Failed to parse path: %m");
|
||||
}
|
||||
|
||||
r = strv_split_extract(&l, eq, NULL, EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE);
|
||||
r = strv_split_full(&l, eq, NULL, EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse command line: %m");
|
||||
|
||||
|
@ -238,7 +238,7 @@ static void test_strv_unquote(const char *quoted, char **list) {
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
r = strv_split_extract(&s, quoted, WHITESPACE, EXTRACT_UNQUOTE);
|
||||
r = strv_split_full(&s, quoted, WHITESPACE, EXTRACT_UNQUOTE);
|
||||
assert_se(r == (int) strv_length(list));
|
||||
assert_se(s);
|
||||
j = strv_join(s, " | ");
|
||||
@ -257,7 +257,7 @@ static void test_invalid_unquote(const char *quoted) {
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
r = strv_split_extract(&s, quoted, WHITESPACE, EXTRACT_UNQUOTE);
|
||||
r = strv_split_full(&s, quoted, WHITESPACE, EXTRACT_UNQUOTE);
|
||||
assert_se(s == NULL);
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
@ -287,39 +287,39 @@ static void test_strv_split(void) {
|
||||
|
||||
strv_free_erase(l);
|
||||
|
||||
assert_se(strv_split_extract(&l, " one two\t three", NULL, 0) == 3);
|
||||
assert_se(strv_split_full(&l, " one two\t three", NULL, 0) == 3);
|
||||
assert_se(strv_equal(l, (char**) input_table_multiple));
|
||||
|
||||
strv_free_erase(l);
|
||||
|
||||
assert_se(strv_split_extract(&l, " 'one' \" two\t three \" ' four five'", NULL, EXTRACT_UNQUOTE) == 3);
|
||||
assert_se(strv_split_full(&l, " 'one' \" two\t three \" ' four five'", NULL, EXTRACT_UNQUOTE) == 3);
|
||||
assert_se(strv_equal(l, (char**) input_table_quoted));
|
||||
|
||||
l = strv_free_erase(l);
|
||||
|
||||
/* missing last quote causes extraction to fail. */
|
||||
assert_se(strv_split_extract(&l, " 'one' \" two\t three \" ' four five", NULL, EXTRACT_UNQUOTE) == -EINVAL);
|
||||
assert_se(strv_split_full(&l, " 'one' \" two\t three \" ' four five", NULL, EXTRACT_UNQUOTE) == -EINVAL);
|
||||
assert_se(!l);
|
||||
|
||||
/* missing last quote, but the last element is _not_ ignored with EXTRACT_RELAX. */
|
||||
assert_se(strv_split_extract(&l, " 'one' \" two\t three \" ' four five", NULL, EXTRACT_UNQUOTE | EXTRACT_RELAX) == 3);
|
||||
assert_se(strv_split_full(&l, " 'one' \" two\t three \" ' four five", NULL, EXTRACT_UNQUOTE | EXTRACT_RELAX) == 3);
|
||||
assert_se(strv_equal(l, (char**) input_table_quoted));
|
||||
|
||||
l = strv_free_erase(l);
|
||||
|
||||
/* missing separator between items */
|
||||
assert_se(strv_split_extract(&l, " 'one' \" two\t three \"' four five'", NULL, EXTRACT_UNQUOTE | EXTRACT_RELAX) == 2);
|
||||
assert_se(strv_split_full(&l, " 'one' \" two\t three \"' four five'", NULL, EXTRACT_UNQUOTE | EXTRACT_RELAX) == 2);
|
||||
assert_se(strv_equal(l, (char**) input_table_quoted_joined));
|
||||
|
||||
l = strv_free_erase(l);
|
||||
|
||||
assert_se(strv_split_extract(&l, " 'one' \" two\t three \"' four five", NULL,
|
||||
assert_se(strv_split_full(&l, " 'one' \" two\t three \"' four five", NULL,
|
||||
EXTRACT_UNQUOTE | EXTRACT_RELAX | EXTRACT_CUNESCAPE_RELAX) == 2);
|
||||
assert_se(strv_equal(l, (char**) input_table_quoted_joined));
|
||||
|
||||
l = strv_free_erase(l);
|
||||
|
||||
assert_se(strv_split_extract(&l, "\\", NULL, EXTRACT_UNQUOTE | EXTRACT_RELAX | EXTRACT_CUNESCAPE_RELAX) == 1);
|
||||
assert_se(strv_split_full(&l, "\\", NULL, EXTRACT_UNQUOTE | EXTRACT_RELAX | EXTRACT_CUNESCAPE_RELAX) == 1);
|
||||
assert_se(strv_equal(l, STRV_MAKE("\\")));
|
||||
}
|
||||
|
||||
@ -337,22 +337,22 @@ static void test_strv_split_empty(void) {
|
||||
assert_se(strv_isempty(l));
|
||||
l = strv_free(l);
|
||||
|
||||
assert_se(strv_split_extract(&l, "", NULL, 0) == 0);
|
||||
assert_se(strv_split_full(&l, "", NULL, 0) == 0);
|
||||
assert_se(l);
|
||||
assert_se(strv_isempty(l));
|
||||
l = strv_free(l);
|
||||
|
||||
assert_se(strv_split_extract(&l, "", NULL, EXTRACT_UNQUOTE) == 0);
|
||||
assert_se(strv_split_full(&l, "", NULL, EXTRACT_UNQUOTE) == 0);
|
||||
assert_se(l);
|
||||
assert_se(strv_isempty(l));
|
||||
l = strv_free(l);
|
||||
|
||||
assert_se(strv_split_extract(&l, "", WHITESPACE, EXTRACT_UNQUOTE) == 0);
|
||||
assert_se(strv_split_full(&l, "", WHITESPACE, EXTRACT_UNQUOTE) == 0);
|
||||
assert_se(l);
|
||||
assert_se(strv_isempty(l));
|
||||
l = strv_free(l);
|
||||
|
||||
assert_se(strv_split_extract(&l, "", WHITESPACE, EXTRACT_UNQUOTE | EXTRACT_RELAX) == 0);
|
||||
assert_se(strv_split_full(&l, "", WHITESPACE, EXTRACT_UNQUOTE | EXTRACT_RELAX) == 0);
|
||||
assert_se(l);
|
||||
assert_se(strv_isempty(l));
|
||||
strv_free(l);
|
||||
@ -367,34 +367,34 @@ static void test_strv_split_empty(void) {
|
||||
assert_se(strv_isempty(l));
|
||||
l = strv_free(l);
|
||||
|
||||
assert_se(strv_split_extract(&l, " ", NULL, 0) == 0);
|
||||
assert_se(strv_split_full(&l, " ", NULL, 0) == 0);
|
||||
assert_se(l);
|
||||
assert_se(strv_isempty(l));
|
||||
l = strv_free(l);
|
||||
|
||||
assert_se(strv_split_extract(&l, " ", WHITESPACE, EXTRACT_UNQUOTE) == 0);
|
||||
assert_se(strv_split_full(&l, " ", WHITESPACE, EXTRACT_UNQUOTE) == 0);
|
||||
assert_se(l);
|
||||
assert_se(strv_isempty(l));
|
||||
l = strv_free(l);
|
||||
|
||||
assert_se(strv_split_extract(&l, " ", NULL, EXTRACT_UNQUOTE) == 0);
|
||||
assert_se(strv_split_full(&l, " ", NULL, EXTRACT_UNQUOTE) == 0);
|
||||
assert_se(l);
|
||||
assert_se(strv_isempty(l));
|
||||
l = strv_free(l);
|
||||
|
||||
assert_se(strv_split_extract(&l, " ", NULL, EXTRACT_UNQUOTE | EXTRACT_RELAX) == 0);
|
||||
assert_se(strv_split_full(&l, " ", NULL, EXTRACT_UNQUOTE | EXTRACT_RELAX) == 0);
|
||||
assert_se(l);
|
||||
assert_se(strv_isempty(l));
|
||||
}
|
||||
|
||||
static void test_strv_split_extract(void) {
|
||||
static void test_strv_split_full(void) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
const char *str = ":foo\\:bar::waldo:";
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
r = strv_split_extract(&l, str, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
|
||||
r = strv_split_full(&l, str, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
|
||||
assert_se(r == (int) strv_length(l));
|
||||
assert_se(streq_ptr(l[0], ""));
|
||||
assert_se(streq_ptr(l[1], "foo:bar"));
|
||||
@ -1023,7 +1023,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
test_strv_split();
|
||||
test_strv_split_empty();
|
||||
test_strv_split_extract();
|
||||
test_strv_split_full();
|
||||
test_strv_split_colon_pairs();
|
||||
test_strv_split_newlines();
|
||||
test_strv_split_nulstr();
|
||||
|
@ -118,7 +118,7 @@ int udev_builtin_run(sd_device *dev, UdevBuiltinCommand cmd, const char *command
|
||||
if (!builtins[cmd])
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
r = strv_split_extract(&argv, command, NULL,
|
||||
r = strv_split_full(&argv, command, NULL,
|
||||
EXTRACT_UNQUOTE | EXTRACT_RELAX | EXTRACT_RETAIN_ESCAPE);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
@ -747,7 +747,7 @@ int udev_event_spawn(UdevEvent *event,
|
||||
return log_device_error_errno(event->dev, errno,
|
||||
"Failed to create pipe for command '%s': %m", cmd);
|
||||
|
||||
r = strv_split_extract(&argv, cmd, NULL, EXTRACT_UNQUOTE | EXTRACT_RELAX | EXTRACT_RETAIN_ESCAPE);
|
||||
r = strv_split_full(&argv, cmd, NULL, EXTRACT_UNQUOTE | EXTRACT_RELAX | EXTRACT_RETAIN_ESCAPE);
|
||||
if (r < 0)
|
||||
return log_device_error_errno(event->dev, r, "Failed to split command: %m");
|
||||
|
||||
|
@ -385,7 +385,7 @@ int xdg_autostart_format_exec_start(
|
||||
* NOTE: Technically, XDG only specifies " as quotes, while this also
|
||||
* accepts '.
|
||||
*/
|
||||
r = strv_split_extract(&exec_split, exec, NULL, EXTRACT_UNQUOTE | EXTRACT_RELAX);
|
||||
r = strv_split_full(&exec_split, exec, NULL, EXTRACT_UNQUOTE | EXTRACT_RELAX);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user