Lines 37-43
Link Here
|
37 |
|
37 |
|
38 |
#include <stdlib.h> |
38 |
#include <stdlib.h> |
39 |
|
39 |
|
40 |
#ifdef I_AM_QSORT_R |
40 |
#if defined(I_AM_QSORT_R) |
|
|
41 |
typedef int cmp_t(const void *, const void *, void *); |
42 |
#elif defined(I_AM_QSORT_R_COMPAT) |
41 |
typedef int cmp_t(void *, const void *, const void *); |
43 |
typedef int cmp_t(void *, const void *, const void *); |
42 |
#else |
44 |
#else |
43 |
typedef int cmp_t(const void *, const void *); |
45 |
typedef int cmp_t(const void *, const void *); |
Lines 65-71
Link Here
|
65 |
#define vecswap(a, b, n) \ |
67 |
#define vecswap(a, b, n) \ |
66 |
if ((n) > 0) swapfunc(a, b, n) |
68 |
if ((n) > 0) swapfunc(a, b, n) |
67 |
|
69 |
|
68 |
#ifdef I_AM_QSORT_R |
70 |
#if defined(I_AM_QSORT_R) |
|
|
71 |
#define CMP(t, x, y) (cmp((x), (y), (t))) |
72 |
#elif defined(I_AM_QSORT_R_COMPAT) |
69 |
#define CMP(t, x, y) (cmp((t), (x), (y))) |
73 |
#define CMP(t, x, y) (cmp((t), (x), (y))) |
70 |
#else |
74 |
#else |
71 |
#define CMP(t, x, y) (cmp((x), (y))) |
75 |
#define CMP(t, x, y) (cmp((x), (y))) |
Lines 73-79
Link Here
|
73 |
|
77 |
|
74 |
static inline char * |
78 |
static inline char * |
75 |
med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk |
79 |
med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk |
76 |
#ifndef I_AM_QSORT_R |
80 |
#if !defined(I_AM_QSORT_R) && !defined(I_AM_QSORT_R_COMPAT) |
77 |
__unused |
81 |
__unused |
78 |
#endif |
82 |
#endif |
79 |
) |
83 |
) |
Lines 83-91
Link Here
|
83 |
:(CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c )); |
87 |
:(CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c )); |
84 |
} |
88 |
} |
85 |
|
89 |
|
86 |
#ifdef I_AM_QSORT_R |
90 |
#if defined(I_AM_QSORT_R) |
87 |
void |
91 |
void |
88 |
qsort_r(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp) |
92 |
(qsort_r)(void *a, size_t n, size_t es, cmp_t *cmp, void *thunk) |
|
|
93 |
#elif defined(I_AM_QSORT_R_COMPAT) |
94 |
void |
95 |
__qsort_r_compat(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp) |
89 |
#else |
96 |
#else |
90 |
#define thunk NULL |
97 |
#define thunk NULL |
91 |
void |
98 |
void |
Lines 168-175
Link Here
|
168 |
if (d1 <= d2) { |
175 |
if (d1 <= d2) { |
169 |
/* Recurse on left partition, then iterate on right partition */ |
176 |
/* Recurse on left partition, then iterate on right partition */ |
170 |
if (d1 > es) { |
177 |
if (d1 > es) { |
171 |
#ifdef I_AM_QSORT_R |
178 |
#if defined(I_AM_QSORT_R) |
172 |
qsort_r(a, d1 / es, es, thunk, cmp); |
179 |
qsort_r(a, d1 / es, es, cmp, thunk); |
|
|
180 |
#elif defined(I_AM_QSORT_R_COMPAT) |
181 |
__qsort_r_compat(a, d1 / es, es, thunk, cmp); |
173 |
#else |
182 |
#else |
174 |
qsort(a, d1 / es, es, cmp); |
183 |
qsort(a, d1 / es, es, cmp); |
175 |
#endif |
184 |
#endif |
Lines 184-191
Link Here
|
184 |
} else { |
193 |
} else { |
185 |
/* Recurse on right partition, then iterate on left partition */ |
194 |
/* Recurse on right partition, then iterate on left partition */ |
186 |
if (d2 > es) { |
195 |
if (d2 > es) { |
187 |
#ifdef I_AM_QSORT_R |
196 |
#if defined(I_AM_QSORT_R) |
188 |
qsort_r(pn - d2, d2 / es, es, thunk, cmp); |
197 |
qsort_r(pn - d2, d2 / es, es, cmp, thunk); |
|
|
198 |
#elif defined(I_AM_QSORT_R_COMPAT) |
199 |
__qsort_r_compat(pn - d2, d2 / es, es, thunk, cmp); |
189 |
#else |
200 |
#else |
190 |
qsort(pn - d2, d2 / es, es, cmp); |
201 |
qsort(pn - d2, d2 / es, es, cmp); |
191 |
#endif |
202 |
#endif |