]> git.ozlabs.org Git - ccan/blob - ccan/asort/asort.c
New asort routine; unf. breaks under -Wmissing-prototypes etc :(
[ccan] / ccan / asort / asort.c
1 #include <ccan/asort/asort.h>
2 #include <stdlib.h>
3
4 void _asort(void *base, size_t nmemb, size_t size,
5             int(*compar)(const void *, const void *, const void *ctx),
6             const void *ctx)
7 {
8 #if HAVE_NESTED_FUNCTIONS
9         /* This gives bogus "warning: no previous prototype for ‘cmp’"
10          * with gcc 4 with -Wmissing-prototypes.  But there's no way
11          * to predeclare it, so we lose. */
12         int cmp(const void *a, const void *b)
13         {
14                 return compar(a, b, ctx);
15         }
16         qsort(base, nmemb, size, cmp);
17 #else
18         #error "Need to open-code quicksort?"
19         /* qsort is a classic "needed more real-life testing" API. */
20 #endif
21 }