]> git.ozlabs.org Git - ccan/blobdiff - ccan/asort/asort.c
New asort routine; unf. breaks under -Wmissing-prototypes etc :(
[ccan] / ccan / asort / asort.c
diff --git a/ccan/asort/asort.c b/ccan/asort/asort.c
new file mode 100644 (file)
index 0000000..cf8d8d9
--- /dev/null
@@ -0,0 +1,21 @@
+#include <ccan/asort/asort.h>
+#include <stdlib.h>
+
+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
+}