Browse Source

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.
Andreas Schlick 15 years ago
parent
commit
e8c85e38cc
3 changed files with 10 additions and 0 deletions
  1. 4 0
      ccan/asort/asort.c
  2. 5 0
      ccan/asort/asort.h
  3. 1 0
      tools/ccanlint/file_analysis.c

+ 4 - 0
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 */

+ 5 - 0
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 */

+ 1 - 0
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>