1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/* ISC license. */
#include <skalibs/sysdeps.h>
#include <skalibs/nonposix.h>
#include <stdlib.h>
#ifdef SKALIBS_HASQSORTR_POSIX
void qsortr (void *base, size_t n, size_t width, cmp_func_ref f, void *data)
{
qsort_r(base, n, width, f, data) ;
}
#else
#ifdef SKALIBS_HASQSORTR_FREEBSD
void qsortr (void *base, size_t n, size_t width, cmp_func_ref f, void *data)
{
qsort_r(base, n, width, data, f) ;
}
#else
#include <skalibs/functypes.h>
#include <skalibs/posixplz.h>
struct aux_s
{
cmp_func_ref f ;
void *data ;
} ;
static struct aux_s *qsortr_aux_here ;
static int cmp (void const *a, void const *b)
{
return (*qsortr_aux_here->f)(a, b, qsortr_aux_here->data) ;
}
void qsortr (void *base, size_t n, size_t width, cmp_func_ref f, void *data)
{
struct aux_s aux = { .f = f, .data = data } ;
qsortr_aux_here = &aux ;
qsort(base, n, width, &cmp) ;
}
#endif
#endif
|