summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-02-19 16:11:54 +0100
committerThomas Haller <thaller@redhat.com>2020-02-19 16:24:55 +0100
commitcba938f3ee36b39732597c8d914ed8fddaac81b2 (patch)
treec968f2d0e5c68217483b6e5127cd65ae6224f488
parentf4d12f7b59b682dbc73af2602f3bb7f5e91417ce (diff)
downloadNetworkManager-cba938f3ee36b39732597c8d914ed8fddaac81b2.tar.gz
shared: add nm_utils_named_values_from_str_dict_full() to allow different sort order (or none)
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.c8
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h13
2 files changed, 18 insertions, 3 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c
index aad16a7d00..0b28077119 100644
--- a/shared/nm-glib-aux/nm-shared-utils.c
+++ b/shared/nm-glib-aux/nm-shared-utils.c
@@ -2357,7 +2357,10 @@ nm_utils_fd_read_loop_exact (int fd, void *buf, size_t nbytes, bool do_poll)
/*****************************************************************************/
NMUtilsNamedValue *
-nm_utils_named_values_from_str_dict (GHashTable *hash, guint *out_len)
+nm_utils_named_values_from_str_dict_with_sort (GHashTable *hash,
+ guint *out_len,
+ GCompareDataFunc compare_func,
+ gpointer user_data)
{
GHashTableIter iter;
NMUtilsNamedValue *values;
@@ -2380,7 +2383,8 @@ nm_utils_named_values_from_str_dict (GHashTable *hash, guint *out_len)
values[i].name = NULL;
values[i].value_ptr = NULL;
- nm_utils_named_value_list_sort (values, len, NULL, NULL);
+ if (compare_func)
+ nm_utils_named_value_list_sort (values, len, compare_func, user_data);
NM_SET_OUT (out_len, len);
return values;
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index a58be69608..a5d2ee7292 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -1207,7 +1207,18 @@ typedef struct {
};
} NMUtilsNamedValue;
-NMUtilsNamedValue *nm_utils_named_values_from_str_dict (GHashTable *hash, guint *out_len);
+NMUtilsNamedValue *nm_utils_named_values_from_str_dict_with_sort (GHashTable *hash,
+ guint *out_len,
+ GCompareDataFunc compare_func,
+ gpointer user_data);
+
+static inline NMUtilsNamedValue *
+nm_utils_named_values_from_str_dict (GHashTable *hash, guint *out_len)
+{
+ G_STATIC_ASSERT (G_STRUCT_OFFSET (NMUtilsNamedValue, name) == 0);
+
+ return nm_utils_named_values_from_str_dict_with_sort (hash, out_len, nm_strcmp_p_with_data, NULL);
+}
gssize nm_utils_named_value_list_find (const NMUtilsNamedValue *arr,
gsize len,