X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fasort%2Fasort.c;fp=ccan%2Fasort%2Fasort.c;h=cf8d8d9d196afe0613a5133b37c14c6c06ea034f;hb=009f261242b7e1f5482e097315c82a4185a708bf;hp=0000000000000000000000000000000000000000;hpb=76ae790f2cc2cb1e46bb0b9e5002c7feb6a79df1;p=ccan diff --git a/ccan/asort/asort.c b/ccan/asort/asort.c new file mode 100644 index 00000000..cf8d8d9d --- /dev/null +++ b/ccan/asort/asort.c @@ -0,0 +1,21 @@ +#include +#include + +void _asort(void *base, size_t nmemb, size_t size, + int(*compar)(const void *, const void *, const void *ctx), + const void *ctx) +{ +#if HAVE_NESTED_FUNCTIONS + /* This gives bogus "warning: no previous prototype for ‘cmp’" + * with gcc 4 with -Wmissing-prototypes. But there's no way + * to predeclare it, so we lose. */ + int cmp(const void *a, const void *b) + { + return compar(a, b, ctx); + } + qsort(base, nmemb, size, cmp); +#else + #error "Need to open-code quicksort?" + /* qsort is a classic "needed more real-life testing" API. */ +#endif +}