From: Andreas Schlick Date: Sat, 2 Apr 2011 01:30:08 +0000 (+1030) Subject: asort: Use qsort_r if the system provides it. X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=e8c85e38cc6e0094c8d9e286e1706756035b95e0;ds=sidebyside asort: Use qsort_r if the system provides it. tools/ccanlint/file_analysis.c needs to include config.h to set _GNU_SOURCE before any other header file includes stdlib.h. --- diff --git a/ccan/asort/asort.c b/ccan/asort/asort.c index 9f586861..f5ed8f86 100644 --- a/ccan/asort/asort.c +++ b/ccan/asort/asort.c @@ -1,6 +1,8 @@ #include #include +#if !HAVE_QSORT_R_PRIVATE_LAST + #if HAVE_NESTED_FUNCTIONS void _asort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *, void *ctx), @@ -269,3 +271,5 @@ _asort (void *const pbase, size_t total_elems, size_t size, } } #endif /* !HAVE_NESTED_FUNCTIONS */ + +#endif /* !HAVE_QSORT_R_PRIVATE_LAST */ diff --git a/ccan/asort/asort.h b/ccan/asort/asort.h index eaaa5b19..5024a057 100644 --- a/ccan/asort/asort.h +++ b/ccan/asort/asort.h @@ -1,5 +1,6 @@ #ifndef CCAN_ASORT_H #define CCAN_ASORT_H +#include "config.h" #include #include @@ -24,8 +25,12 @@ _asort((base), (num), sizeof(*(base)), \ const __typeof__(*(base)) *, \ __typeof__(ctx))), (ctx)) +#if HAVE_QSORT_R_PRIVATE_LAST +#define _asort(b, n, s, cmp, ctx) qsort_r(b, n, s, cmp, ctx) +#else void _asort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *, void *), void *ctx); +#endif #endif /* CCAN_ASORT_H */ diff --git a/tools/ccanlint/file_analysis.c b/tools/ccanlint/file_analysis.c index d8d2d3e9..7ce65479 100644 --- a/tools/ccanlint/file_analysis.c +++ b/tools/ccanlint/file_analysis.c @@ -1,3 +1,4 @@ +#include "config.h" #include "ccanlint.h" #include #include