mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-05 17:00:29 +01:00
libnm: add _nm_utils_ptrarray_find_first() utility function
This commit is contained in:
parent
0a3c1f5774
commit
3377cd7e18
2 changed files with 28 additions and 0 deletions
|
|
@ -112,6 +112,8 @@ GPtrArray *_nm_utils_copy_array (const GPtrArray *array,
|
|||
GDestroyNotify free_func);
|
||||
GPtrArray *_nm_utils_copy_object_array (const GPtrArray *array);
|
||||
|
||||
gssize _nm_utils_ptrarray_find_first (gpointer *list, gssize len, gconstpointer needle);
|
||||
|
||||
gboolean _nm_utils_string_in_list (const char *str,
|
||||
const char **valid_strings);
|
||||
|
||||
|
|
|
|||
|
|
@ -631,6 +631,32 @@ _nm_utils_copy_object_array (const GPtrArray *array)
|
|||
return _nm_utils_copy_array (array, g_object_ref, g_object_unref);
|
||||
}
|
||||
|
||||
/* have @list of type 'gpointer *' instead of 'gconstpointer *' to
|
||||
* reduce the necessity for annoying const-casts. */
|
||||
gssize
|
||||
_nm_utils_ptrarray_find_first (gpointer *list, gssize len, gconstpointer needle)
|
||||
{
|
||||
gssize i;
|
||||
|
||||
if (len == 0)
|
||||
return -1;
|
||||
|
||||
if (len > 0) {
|
||||
g_return_val_if_fail (list, -1);
|
||||
for (i = 0; i < len; i++) {
|
||||
if (list[i] == needle)
|
||||
return i;
|
||||
}
|
||||
} else {
|
||||
g_return_val_if_fail (needle, -1);
|
||||
for (i = 0; list && list[i]; i++) {
|
||||
if (list[i] == needle)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
GVariant *
|
||||
_nm_utils_bytes_to_dbus (const GValue *prop_value)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue