diff options
author | Thomas Haller <thaller@redhat.com> | 2014-08-26 15:31:06 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-08-26 16:40:31 +0200 |
commit | 8f7a3be4ced8b7ca7af141741c31ffc7aea4edb4 (patch) | |
tree | 2f1c2f4aa35c00117605317633a6970c45d4b50c | |
parent | 9ec1f00a2aa5214ad2fbccad7f917d628d4ab7b2 (diff) | |
download | NetworkManager-8f7a3be4ced8b7ca7af141741c31ffc7aea4edb4.tar.gz |
libnm: add _nm_utils_slist_to_ptr_array()
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | libnm-core/nm-core-internal.h | 1 | ||||
-rw-r--r-- | libnm-core/nm-utils.c | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 1e6dd63892..86f514d143 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -62,6 +62,7 @@ gboolean _nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *s GSList * _nm_utils_hash_values_to_slist (GHashTable *hash); +GPtrArray *_nm_utils_slist_to_ptr_array (GSList *list); #endif diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index fd99bfd206..72e3256df7 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -564,6 +564,34 @@ _nm_utils_hash_values_to_slist (GHashTable *hash) return list; } +/** + * _nm_utils_slist_to_ptr_array: + * @list: a #GSList + * + * Utility function to convert @list to a #GPtrArray. + * + * Returns: (element-type gpointer) (transfer container): a newly + * allocated #GPtrArray containing the values of the liste. The + * caller must free the returned array with g_ptr_array_free(). + * The values will not be owned by the pointer array. + * + * Important: for an empty list, this returns %NULL instead + * of an empty array. + **/ +GPtrArray * +_nm_utils_slist_to_ptr_array (GSList *list) +{ + GPtrArray *array; + + if (!list) + return NULL; + + array = g_ptr_array_new (); + for (; list; list = list->next) + g_ptr_array_add (array, list->data); + return array; +} + static gboolean device_supports_ap_ciphers (guint32 dev_caps, guint32 ap_flags, |