diff --git a/src/idnode.c b/src/idnode.c index 192e929a..e3ea6aba 100644 --- a/src/idnode.c +++ b/src/idnode.c @@ -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 diff --git a/src/tvheadend.h b/src/tvheadend.h index 83d29fe3..9076710c 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -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 diff --git a/src/wrappers.c b/src/wrappers.c index 3968572e..82535abf 100644 --- a/src/wrappers.c +++ b/src/wrappers.c @@ -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 +}