25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 * POSSIBILITY OF SUCH DAMAGE. |
26 * POSSIBILITY OF SUCH DAMAGE. |
27 */ |
27 */ |
28 |
28 |
29 #define _GNU_SOURCE /* we want to use qsort_r(), if available */ |
29 #define _GNU_SOURCE /* we want to use qsort_r(), if available */ |
|
30 #define __STDC_WANT_LIB_EXT1__ 1 /* use qsort_s, if available */ |
|
31 |
30 |
32 |
31 #include "ucx/array.h" |
33 #include "ucx/array.h" |
32 #include "ucx/utils.h" |
34 #include "ucx/utils.h" |
33 |
35 |
34 #include <string.h> |
36 #include <string.h> |
40 #define ucx_array_sort_impl qsort_r |
42 #define ucx_array_sort_impl qsort_r |
41 #endif /* glibc version >= 2.8 */ |
43 #endif /* glibc version >= 2.8 */ |
42 #elif /* not __GLIBC__ */ defined(__APPLE__) || defined(__FreeBSD__) |
44 #elif /* not __GLIBC__ */ defined(__APPLE__) || defined(__FreeBSD__) |
43 #define ucx_array_sort_impl ucx_qsort_r |
45 #define ucx_array_sort_impl ucx_qsort_r |
44 #define USE_UCX_QSORT_R |
46 #define USE_UCX_QSORT_R |
45 #endif /* __GLIBC__, __APLE__, __FreeBSD__ */ |
47 #elif /* not (__APPLE || __FreeBSD__) */ defined(__sun) |
|
48 #if __STDC_VERSION__ >= 201112L |
|
49 #define ucx_array_sort_impl qsort_s |
|
50 #endif |
|
51 #endif /* __GLIBC__, __APLE__, __FreeBSD__, __sun */ |
46 #endif /* UCX_ARRAY_DISABLE_QSORT */ |
52 #endif /* UCX_ARRAY_DISABLE_QSORT */ |
47 |
53 |
48 #ifndef ucx_array_sort_impl |
54 #ifndef ucx_array_sort_impl |
49 #define ucx_array_sort_impl ucx_mergesort |
55 #define ucx_array_sort_impl ucx_mergesort |
50 #endif |
56 #endif |
296 cmp_func func; |
302 cmp_func func; |
297 void *data; |
303 void *data; |
298 }; |
304 }; |
299 |
305 |
300 static int cmp_func_swap_args(void *data, const void *x, const void *y) { |
306 static int cmp_func_swap_args(void *data, const void *x, const void *y) { |
301 struct cmpfnc_swapargs_info* info = data; |
307 cmpfnc_swapargs_info* info = data; |
302 return info->func(x, y, info->data); |
308 return info->func(x, y, info->data); |
303 } |
309 } |
304 |
310 |
305 static void ucx_qsort_r(void *array, size_t count, size_t elemsize, |
311 static void ucx_qsort_r(void *array, size_t count, size_t elemsize, |
306 cmp_func cmpfnc, void *data) { |
312 cmp_func cmpfnc, void *data) { |