1 /* Licensed under LGPLv2.1+ - see LICENSE file for details */
5 #include <ccan/order/order.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 total_order_cast((cmp), *(base), (ctx)), (ctx))
25 #if HAVE_QSORT_R_PRIVATE_LAST
26 #define _asort(b, n, s, cmp, ctx) qsort_r(b, n, s, cmp, ctx)
28 void _asort(void *base, size_t nmemb, size_t size,
29 _total_order_cb compar, void *ctx);
32 #endif /* CCAN_ASORT_H */