summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-10-19 04:52:25 +0200
committerLennart Poettering <lennart@poettering.net>2012-10-19 04:53:45 +0200
commit857a493d55f94731394e4d9f61ffce661858e9a0 (patch)
treec22dbe69057894a6a76f8ba8d074a560af40a5bb /src/shared
parent9590dfe771d1f499703414c5c5cf21eec7ef69a4 (diff)
set: introduce strv_sort()
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/strv.c15
-rw-r--r--src/shared/strv.h2
2 files changed, 17 insertions, 0 deletions
diff --git a/src/shared/strv.c b/src/shared/strv.c
index 822b2dc888..1b8e27bc1b 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -735,3 +735,18 @@ bool strv_overlap(char **a, char **b) {
return false;
}
+
+static int str_compare(const void *_a, const void *_b) {
+ const char **a = (const char**) _a, **b = (const char**) _b;
+
+ return strcmp(*a, *b);
+}
+
+char **strv_sort(char **l) {
+
+ if (strv_isempty(l))
+ return l;
+
+ qsort(l, strv_length(l), sizeof(char*), str_compare);
+ return l;
+}
diff --git a/src/shared/strv.h b/src/shared/strv.h
index 81e33356f9..45558d8960 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -80,3 +80,5 @@ bool strv_overlap(char **a, char **b);
#define STRV_FOREACH_BACKWARDS(s, l) \
for (; (l) && ((s) >= (l)); (s)--)
+
+char **strv_sort(char **l);