summaryrefslogtreecommitdiff
path: root/clients/cli/common.c
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2015-10-05 15:12:14 +0200
committerJiří Klimeš <jklimes@redhat.com>2015-11-09 16:17:39 +0100
commitcd217db21cf166537e38ff971f518ac3f3905288 (patch)
tree4ad9b81610eefc2a78045eda4f609122db481a45 /clients/cli/common.c
parentcfa4195e0c972a8ceb2fc9cc5920139ab14b0661 (diff)
downloadNetworkManager-cd217db21cf166537e38ff971f518ac3f3905288.tar.gz
cli: move unique_connection_name() to common.c as nmc_unique_connection_name()
Diffstat (limited to 'clients/cli/common.c')
-rw-r--r--clients/cli/common.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/clients/cli/common.c b/clients/cli/common.c
index b988679ff9..8317764e3a 100644
--- a/clients/cli/common.c
+++ b/clients/cli/common.c
@@ -1011,6 +1011,29 @@ nmc_secrets_requested (NMSecretAgentSimple *agent,
}
}
+char *
+nmc_unique_connection_name (const GPtrArray *connections, const char *try_name)
+{
+ NMConnection *connection;
+ const char *name;
+ char *new_name;
+ unsigned int num = 1;
+ int i = 0;
+
+ new_name = g_strdup (try_name);
+ while (i < connections->len) {
+ connection = NM_CONNECTION (connections->pdata[i]);
+
+ name = nm_connection_get_id (connection);
+ if (g_strcmp0 (new_name, name) == 0) {
+ g_free (new_name);
+ new_name = g_strdup_printf ("%s-%d", try_name, num++);
+ i = 0;
+ } else
+ i++;
+ }
+ return new_name;
+}
/**
* nmc_cleanup_readline: