1 /* Licensed under LGPLv2.1+ - see LICENSE file for details */
5 #include <ccan/typesafe_cb/typesafe_cb.h>
9 * asort - sort an array of elements
10 * @base: pointer to data to sort
11 * @num: number of elements
12 * @cmp: pointer to comparison function
13 * @ctx: a context pointer for the cmp function
15 * This function does a sort on the given array. The resulting array
16 * will be in ascending sorted order by the provided comparison function.
18 * The @cmp function should exactly match the type of the @base and
19 * @ctx arguments. Otherwise it can take three const void *.
21 #define asort(base, num, cmp, ctx) \
22 _asort((base), (num), sizeof(*(base)), \
23 typesafe_cb_cast(int (*)(const void *, const void *, void *), \
24 int (*)(const __typeof__(*(base)) *, \
25 const __typeof__(*(base)) *, \
30 #if HAVE_QSORT_R_PRIVATE_LAST
31 #define _asort(b, n, s, cmp, ctx) qsort_r(b, n, s, cmp, ctx)
33 void _asort(void *base, size_t nmemb, size_t size,
34 int(*compar)(const void *, const void *, void *),
38 #endif /* CCAN_ASORT_H */