4 #include <ccan/typesafe_cb/typesafe_cb.h>
8 * asort - sort an array of elements
9 * @base: pointer to data to sort
10 * @num: number of elements
11 * @cmp: pointer to comparison function
12 * @ctx: a context pointer for the cmp function
14 * This function does a sort on the given array. The resulting array
15 * will be in ascending sorted order by the provided comparison function.
17 * The @cmp function should exactly match the type of the @base and
18 * @ctx arguments. Otherwise it can take three const void *.
20 #define asort(base, num, cmp, ctx) \
21 _asort((base), (num), sizeof(*(base)), \
22 cast_if_type(int (*)(const void *, const void *, void *), \
24 int (*)(const __typeof__(*(base)) *, \
25 const __typeof__(*(base)) *, \
26 __typeof__(ctx))), (ctx))
28 #if HAVE_QSORT_R_PRIVATE_LAST
29 #define _asort(b, n, s, cmp, ctx) qsort_r(b, n, s, cmp, ctx)
31 void _asort(void *base, size_t nmemb, size_t size,
32 int(*compar)(const void *, const void *, void *),
36 #endif /* CCAN_ASORT_H */