mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 10:40:58 +01:00
shared: add nm_utils_strv_sort() helper
This commit is contained in:
parent
458b422468
commit
be9a5ab308
2 changed files with 38 additions and 0 deletions
|
|
@ -1274,3 +1274,38 @@ fail:
|
|||
NM_SET_OUT (out_ppid, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* _nm_utils_strv_sort:
|
||||
* @strv: pointer containing strings that will be sorted
|
||||
* in-place, %NULL is allowed, unless @len indicates
|
||||
* that there are more elements.
|
||||
* @len: the number of elements in strv. If negative,
|
||||
* strv must be a NULL terminated array and the length
|
||||
* will be calculated first. If @len is a positive
|
||||
* number, all first @len elements in @strv must be
|
||||
* non-NULL, valid strings.
|
||||
*
|
||||
* Ascending sort of the array @strv inplace, using plain strcmp() string
|
||||
* comparison.
|
||||
*/
|
||||
void
|
||||
_nm_utils_strv_sort (const char **strv, gssize len)
|
||||
{
|
||||
gsize l;
|
||||
|
||||
l = len < 0 ? (gsize) NM_PTRARRAY_LEN (strv) : (gsize) len;
|
||||
|
||||
if (l <= 1)
|
||||
return;
|
||||
|
||||
nm_assert (l <= (gsize) G_MAXINT);
|
||||
|
||||
g_qsort_with_data (strv,
|
||||
l,
|
||||
sizeof (const char *),
|
||||
nm_strcmp_p_with_data,
|
||||
NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -484,6 +484,9 @@ nm_utils_strv_make_deep_copied_nonnull (const char **strv)
|
|||
return nm_utils_strv_make_deep_copied (strv) ?: g_new0 (char *, 1);
|
||||
}
|
||||
|
||||
void _nm_utils_strv_sort (const char **strv, gssize len);
|
||||
#define nm_utils_strv_sort(strv, len) _nm_utils_strv_sort (NM_CAST_STRV_MC (strv), len)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define NM_UTILS_NS_PER_SECOND ((gint64) 1000000000)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue