asort: Use qsort_r if the system provides it.
authorAndreas Schlick <schlick@lavabit.com>
Sat, 2 Apr 2011 01:30:08 +0000 (12:00 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Sat, 2 Apr 2011 01:30:08 +0000 (12:00 +1030)
tools/ccanlint/file_analysis.c needs to include config.h to set _GNU_SOURCE
before any other header file includes stdlib.h.

ccan/asort/asort.c
ccan/asort/asort.h
tools/ccanlint/file_analysis.c

index 9f5868619095b354c28da27d3e6efd18557790ba..f5ed8f863f6f400cdcbb72217146a9387c52a6eb 100644 (file)
@@ -1,6 +1,8 @@
 #include <ccan/asort/asort.h>
 #include <stdlib.h>
 
+#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 */
index eaaa5b19f418a96a46a951570ad0a9bbf00ed3b0..5024a057cde5d548fe9986dc5e2abc375190cec6 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef CCAN_ASORT_H
 #define CCAN_ASORT_H
+#include "config.h"
 #include <ccan/typesafe_cb/typesafe_cb.h>
 #include <stdlib.h>
 
@@ -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 */
index d8d2d3e936378218b0491a9cec940d203e8d09a5..7ce65479bde929cb3e036ff73514522a9f4cddad 100644 (file)
@@ -1,3 +1,4 @@
+#include "config.h"
 #include "ccanlint.h"
 #include <ccan/talloc/talloc.h>
 #include <ccan/str/str.h>