]> git.ozlabs.org Git - ccan/blob - ccan/asort/asort.h
tal: allow notifiers on NULL.
[ccan] / ccan / asort / asort.h
1 /* Licensed under LGPLv2.1+ - see LICENSE file for details */
2 #ifndef CCAN_ASORT_H
3 #define CCAN_ASORT_H
4 #include "config.h"
5 #include <ccan/order/order.h>
6 #include <stdlib.h>
7
8 /**
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
14  *
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.
17  *
18  * The @cmp function should exactly match the type of the @base and
19  * @ctx arguments.  Otherwise it can take three const void *.
20  */
21 #define asort(base, num, cmp, ctx)                                      \
22 _asort((base), (num), sizeof(*(base)),                                  \
23        total_order_cast((cmp), *(base), (ctx)), (ctx))
24
25 #if HAVE_QSORT_R_PRIVATE_LAST
26 #define _asort(b, n, s, cmp, ctx) qsort_r(b, n, s, cmp, ctx)
27 #else
28 void _asort(void *base, size_t nmemb, size_t size,
29             _total_order_cb compar, void *ctx);
30 #endif
31
32 #endif /* CCAN_ASORT_H */