3 #include <ccan/typesafe_cb/typesafe_cb.h>
7 * asort - sort an array of elements
8 * @base: pointer to data to sort
9 * @num: number of elements
10 * @cmp: pointer to comparison function
11 * @ctx: a context pointer for the cmp function
13 * This function does a sort on the given array. The resulting array
14 * will be in ascending sorted order by the provided comparison function.
16 * The @cmp function should exactly match the type of the @base and
17 * @ctx arguments. Otherwise it can take three const void *.
20 #define asort(base, num, cmp, ctx) \
21 _asort((base), (num), sizeof(*(base)), \
23 int (*)(const __typeof__(*(base)) *, \
24 const __typeof__(*(base)) *, \
26 int (*)(const void *, const void *, const void *)), (ctx))
28 #define asort(base, num, cmp, ctx) \
29 _asort((base), (num), sizeof(*(base)), \
30 (int (*)(const void *, const void *, const void *))(cmp), ctx)
33 void _asort(void *base, size_t nmemb, size_t size,
34 int(*compar)(const void *, const void *, const void *),
37 #endif /* CCAN_ASORT_H */