summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-12-10 12:20:38 +0100
committerThomas Haller <thaller@redhat.com>2017-12-18 12:11:07 +0100
commitbfcbc0063c919674f4ee2b33644a0beac639cab2 (patch)
treef51f9b27021a06e4875f1f0f55d52313d2316603
parentd5c212b145b84461deea8523a64b42540d99c663 (diff)
downloadNetworkManager-bfcbc0063c919674f4ee2b33644a0beac639cab2.tar.gz
libnm: use nm_utils_strdict_get_keys() for getting attribute-names of ip-routes
Use the new helper methods to avoid duplicate code.
-rw-r--r--libnm-core/nm-setting-ip-config.c36
1 files changed, 4 insertions, 32 deletions
diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c
index 212ca7b511..45a0ce9019 100644
--- a/libnm-core/nm-setting-ip-config.c
+++ b/libnm-core/nm-setting-ip-config.c
@@ -1136,28 +1136,9 @@ _nm_ip_route_get_attributes_direct (NMIPRoute *route)
const char **
_nm_ip_route_get_attribute_names (const NMIPRoute *route, gboolean sorted, guint *out_length)
{
- const char **names;
- guint length;
-
g_return_val_if_fail (route != NULL, NULL);
- if ( !route->attributes
- || !g_hash_table_size (route->attributes)) {
- NM_SET_OUT (out_length, 0);
- return NULL;
- }
-
- names = (const char **) g_hash_table_get_keys_as_array (route->attributes, &length);
- if ( sorted
- && length > 1) {
- g_qsort_with_data (names,
- length,
- sizeof (char *),
- nm_strcmp_p_with_data,
- NULL);
- }
- NM_SET_OUT (out_length, length);
- return names;
+ return nm_utils_strdict_get_keys (route->attributes, sorted, out_length);
}
/**
@@ -1171,21 +1152,12 @@ _nm_ip_route_get_attribute_names (const NMIPRoute *route, gboolean sorted, guint
char **
nm_ip_route_get_attribute_names (NMIPRoute *route)
{
- char **names;
- guint i, len;
+ const char **names;
g_return_val_if_fail (route != NULL, NULL);
- names = (char **) _nm_ip_route_get_attribute_names (route, TRUE, &len);
- if (!names)
- return g_new0 (char *, 1);
-
- nm_assert (len > 0 && names && names[len] == NULL);
- for (i = 0; i < len; i++) {
- nm_assert (names[i]);
- names[i] = g_strdup (names[i]);
- }
- return names;
+ names = _nm_ip_route_get_attribute_names (route, TRUE, NULL);
+ return nm_utils_strv_make_deep_copied_nonnull (names);
}
/**