mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 11:50:14 +01:00
shared: add nm_utils_strdict_get_keys() helper
At various places we get the (string) keys of a GHashTable. Add a helper function that does that, including an argument for optional sorting. The helper function is there to get reduce code duplication.
This commit is contained in:
parent
0735b35dd0
commit
fe7b4641d6
2 changed files with 31 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue