diff options
author | Thomas Haller <thaller@redhat.com> | 2017-12-08 10:44:36 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-12-11 15:53:24 +0100 |
commit | 7b08331b9d333aaa33e8f025069eb05f80b15ed4 (patch) | |
tree | 006e291e068229ffa7d4a91c3aa5d931d59133e2 /clients/cli/utils.c | |
parent | 4a38e9338dd1bba68ff267d7716c6e8dd135c3d7 (diff) | |
download | NetworkManager-th/cli-strsplit.tar.gz |
cli: drop nmc_strsplit_set()th/cli-strsplit
In most cases, it copies the entire strv needlessly.
We can do better.
Also, the max_tokens argument is handled wrongly (albeit
not used anywhere anymore).
Diffstat (limited to 'clients/cli/utils.c')
-rw-r--r-- | clients/cli/utils.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/clients/cli/utils.c b/clients/cli/utils.c index f20e24ce09..3814e6830b 100644 --- a/clients/cli/utils.c +++ b/clients/cli/utils.c @@ -603,9 +603,14 @@ int nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote, char ***argv, int *argc) { + gs_free const char **arr0 = NULL; char **arr; - arr = nmc_strsplit_set (line ? line : "", delim ? delim : " \t", 0); + arr0 = nm_utils_strsplit_set (line ?: "", delim ?: " \t"); + if (!arr0) + arr = g_new0 (char *, 1); + else + arr = g_strdupv ((char **) arr0); if (unquote) { int i = 0; @@ -613,7 +618,7 @@ nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote, size_t l; const char *quotes = "\"'"; - while (arr && arr[i]) { + while (arr[i]) { s = arr[i]; l = strlen (s); if (l >= 2) { @@ -628,7 +633,6 @@ nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote, *argv = arr; *argc = g_strv_length (arr); - return 0; } |