diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/nm-utils/nm-shared-utils.c | 27 | ||||
-rw-r--r-- | shared/nm-utils/nm-shared-utils.h | 4 |
2 files changed, 31 insertions, 0 deletions
diff --git a/shared/nm-utils/nm-shared-utils.c b/shared/nm-utils/nm-shared-utils.c index 732ce23bd7..8a7890b093 100644 --- a/shared/nm-utils/nm-shared-utils.c +++ b/shared/nm-utils/nm-shared-utils.c @@ -1148,3 +1148,30 @@ nm_utils_named_values_from_str_dict (GHashTable *hash, guint *out_len) NM_SET_OUT (out_len, len); return values; } + +const char ** +nm_utils_strdict_get_keys (const GHashTable *hash, + gboolean sorted, + guint *out_length) +{ + const char **names; + guint length; + + if ( !hash + || !g_hash_table_size ((GHashTable *) hash)) { + NM_SET_OUT (out_length, 0); + return NULL; + } + + names = (const char **) g_hash_table_get_keys_as_array ((GHashTable *) hash, &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; +} diff --git a/shared/nm-utils/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h index 17024d591f..81a66d5b28 100644 --- a/shared/nm-utils/nm-shared-utils.h +++ b/shared/nm-utils/nm-shared-utils.h @@ -443,6 +443,10 @@ typedef struct { NMUtilsNamedValue *nm_utils_named_values_from_str_dict (GHashTable *hash, guint *out_len); +const char **nm_utils_strdict_get_keys (const GHashTable *hash, + gboolean sorted, + guint *out_length); + /*****************************************************************************/ #define NM_UTILS_NS_PER_SECOND ((gint64) 1000000000) |