]> git.ozlabs.org Git - ccan/blob - ccan/asort/asort.h
tap: don't _exit on success
[ccan] / ccan / asort / asort.h
1 #ifndef CCAN_ASORT_H
2 #define CCAN_ASORT_H
3 #include <ccan/typesafe_cb/typesafe_cb.h>
4 #include <stdlib.h>
5
6 /**
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
12  *
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.
15  *
16  * The @cmp function should exactly match the type of the @base and
17  * @ctx arguments.  Otherwise it can take three const void *.
18  */
19 #define asort(base, num, cmp, ctx)                                      \
20 _asort((base), (num), sizeof(*(base)),                                  \
21        cast_if_type(int (*)(const void *, const void *, const void *),  \
22                     (cmp), &*(cmp),                                     \
23                     int (*)(const __typeof__(*(base)) *,                \
24                             const __typeof__(*(base)) *,                \
25                             __typeof__(ctx))), (ctx))
26
27 void _asort(void *base, size_t nmemb, size_t size,
28             int(*compar)(const void *, const void *, const void *),
29             const void *ctx);
30
31 #endif /* CCAN_ASORT_H */