diff options
| author | Thomas Haller <thaller@redhat.com> | 2018-04-11 14:10:22 +0200 |
|---|---|---|
| committer | Thomas Haller <thaller@redhat.com> | 2018-04-18 07:55:15 +0200 |
| commit | be9a5ab308f13977f07a33135b3792ccbd1d6e67 (patch) | |
| tree | c72cda1f9d94751c28882ea6a60f605ffcf3bb58 /shared/nm-utils/nm-shared-utils.c | |
| parent | 458b422468b30b4738eb245c35c150925c8399e9 (diff) | |
| download | NetworkManager-be9a5ab308f13977f07a33135b3792ccbd1d6e67.tar.gz | |
shared: add nm_utils_strv_sort() helper
Diffstat (limited to 'shared/nm-utils/nm-shared-utils.c')
| -rw-r--r-- | shared/nm-utils/nm-shared-utils.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/shared/nm-utils/nm-shared-utils.c b/shared/nm-utils/nm-shared-utils.c index ca5238b42b..582ccfffcf 100644 --- a/shared/nm-utils/nm-shared-utils.c +++ b/shared/nm-utils/nm-shared-utils.c @@ -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); +} |
