summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schlick <schlick@lavabit.com>2011-04-02 12:00:08 +1030
committerRusty Russell <rusty@rustcorp.com.au>2011-04-02 12:00:08 +1030
commite8c85e38cc6e0094c8d9e286e1706756035b95e0 (patch)
tree924d86563397742805f30b6054e499e1eaf0cd84
parent4c00ae05fa9ccac14883c44de158620e301ff8e6 (diff)
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.
-rw-r--r--ccan/asort/asort.c4
-rw-r--r--ccan/asort/asort.h5
-rw-r--r--tools/ccanlint/file_analysis.c1
3 files changed, 10 insertions, 0 deletions
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 <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 */
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 <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 */
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 <ccan/talloc/talloc.h>
#include <ccan/str/str.h>