chiark / gitweb /
basic/strv: use existing qsort_safe() helper
[elogind.git] / src / basic / strv.c
index 4d3cce8260c3d78272f983fc9d61a2fc0c0af03d..f0c764b17ae16dc74cd53a485d8dcf78f21bc57c 100644 (file)
@@ -322,6 +322,7 @@ char **strv_split_newlines(const char *s) {
 
         return l;
 }
+#endif // 0
 
 int strv_split_extract(char ***t, const char *s, const char *separators, ExtractFlags flags) {
         _cleanup_strv_free_ char **l = NULL;
@@ -360,7 +361,6 @@ int strv_split_extract(char ***t, const char *s, const char *separators, Extract
 
         return (int) n;
 }
-#endif // 0
 
 char *strv_join(char **l, const char *separator) {
         char *r, *e;
@@ -572,6 +572,9 @@ int strv_extend_front(char ***l, const char *value) {
 
         /* Like strv_extend(), but prepends rather than appends the new entry */
 
+        if (!value)
+                return 0;
+
         n = strv_length(*l);
 
         /* Increase and overflow check. */
@@ -579,12 +582,9 @@ int strv_extend_front(char ***l, const char *value) {
         if (m < n)
                 return -ENOMEM;
 
-        if (value) {
-                v = strdup(value);
-                if (!v)
-                        return -ENOMEM;
-        } else
-                v = NULL;
+        v = strdup(value);
+        if (!v)
+                return -ENOMEM;
 
         c = realloc_multiply(*l, sizeof(char*), m);
         if (!c) {
@@ -782,15 +782,10 @@ static int str_compare(const void *_a, const void *_b) {
 }
 
 char **strv_sort(char **l) {
-
-        if (strv_isempty(l))
-                return l;
-
-        qsort(l, strv_length(l), sizeof(char*), str_compare);
+        qsort_safe(l, strv_length(l), sizeof(char*), str_compare);
         return l;
 }
 
-#if 0 /// UNNEEDED by elogind
 bool strv_equal(char **a, char **b) {
 
         if (strv_isempty(a))
@@ -813,6 +808,7 @@ void strv_print(char **l) {
                 puts(*s);
 }
 
+#if 0 /// UNNEEDED by elogind
 int strv_extendf(char ***l, const char *format, ...) {
         va_list ap;
         char *x;