]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
add qsort_r wrapper to fix differences between BSD and GNU qsort_r
authorNicolas Gilles <nicolas.gilles@gmail.com>
Tue, 29 Apr 2014 17:35:09 +0000 (19:35 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 7 May 2014 15:20:36 +0000 (17:20 +0200)
The order of parameters of both qsort_r and its compar function differ,
the wrapper matches the GNU version and swaps things around on FreeBSD.

src/idnode.c
src/tvheadend.h
src/wrappers.c

index 192e929a3e79eecad6cc970aba79fc1091af5bcc..e3ea6aba81c850ed2c8a8fb9250593db7a3bb0ff 100644 (file)
@@ -642,7 +642,7 @@ void
 idnode_set_sort
   ( idnode_set_t *is, idnode_sort_t *sort )
 {
-  qsort_r(is->is_array, is->is_count, sizeof(idnode_t*), idnode_cmp_sort, (void*)sort);
+  tvh_qsort_r(is->is_array, is->is_count, sizeof(idnode_t*), idnode_cmp_sort, (void*)sort);
 }
 
 void
index 83d29fe3d495e3dcdd370b9a572f6cadd8c3599a..9076710c0e498f6dec1277f275fab5569125ea7c 100644 (file)
@@ -657,6 +657,8 @@ qsort_r(void *base, size_t nmemb, size_t size,
        int (*cmp)(const void *, const void *, void *), void *aux);
 #endif /* ENABLE_QSORT_R */
 
+void tvh_qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg);
+
 /* printing */
 #ifndef __WORDSIZE
 # if ULONG_MAX == 0xffffffffffffffff
index 3968572efdbb02d56b179dc1a2d4aed848e401b0..82535abf666fc35f2cefc26a4de456e94f46edf3 100644 (file)
@@ -168,3 +168,31 @@ qsort_r(void *base, size_t nmemb, size_t size,
   qsort(base, nmemb, size, qsort_r_wrap);
 }
 #endif /* ENABLE_QSORT_R */
+
+
+#if defined(PLATFORM_FREEBSD)
+struct tvh_qsort_data {
+    void *arg;
+    int (*compar)(const void *, const void *, void *);
+};
+
+
+static int
+tvh_qsort_swap(void *arg, const void *a, const void *b)
+{
+    struct tvh_qsort_data *data = arg;
+    return data->compar(a, b, data->arg);
+}
+#endif /* PLATFORM_FREEBSD */
+
+
+void
+tvh_qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg)
+{
+#if defined(PLATFORM_FREEBSD)
+    struct tvh_qsort_data swap_arg = {arg, compar};
+    qsort_r(base, nmemb, size, &swap_arg, tvh_qsort_swap);
+#else
+    qsort_r(base, nmemb, size, compar, arg);
+#endif
+}