asort.c 618 B

123456789101112131415161718192021
  1. #include <ccan/asort/asort.h>
  2. #include <stdlib.h>
  3. void _asort(void *base, size_t nmemb, size_t size,
  4. int(*compar)(const void *, const void *, const void *ctx),
  5. const void *ctx)
  6. {
  7. #if HAVE_NESTED_FUNCTIONS
  8. /* This gives bogus "warning: no previous prototype for ‘cmp’"
  9. * with gcc 4 with -Wmissing-prototypes. Hence the auto crap. */
  10. auto int cmp(const void *a, const void *b);
  11. int cmp(const void *a, const void *b)
  12. {
  13. return compar(a, b, ctx);
  14. }
  15. qsort(base, nmemb, size, cmp);
  16. #else
  17. #error "Need to open-code quicksort?"
  18. /* qsort is a classic "needed more real-life testing" API. */
  19. #endif
  20. }