chiark / gitweb /
util: use GNU comparison function prototype for qsort_safe()
authorLennart Poettering <lennart@poettering.net>
Thu, 14 May 2015 09:30:14 +0000 (11:30 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 08:56:08 +0000 (09:56 +0100)
src/shared/util.h

index b4e0b77..1b30151 100644 (file)
@@ -780,12 +780,12 @@ int shall_restore_state(void);
  * Normal qsort requires base to be nonnull. Here were require
  * that only if nmemb > 0.
  */
-static inline void qsort_safe(void *base, size_t nmemb, size_t size,
-                              int (*compar)(const void *, const void *)) {
-        if (nmemb) {
-                assert(base);
-                qsort(base, nmemb, size, compar);
-        }
+static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_fn_t compar) {
+        if (nmemb <= 0)
+                return;
+
+        assert(base);
+        qsort(base, nmemb, size, compar);
 }
 
 int proc_cmdline(char **ret);