Commit e8c85e38 authored by Andreas Schlick's avatar Andreas Schlick Committed by Rusty Russell

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.
parent 4c00ae05
#include <ccan/asort/asort.h> #include <ccan/asort/asort.h>
#include <stdlib.h> #include <stdlib.h>
#if !HAVE_QSORT_R_PRIVATE_LAST
#if HAVE_NESTED_FUNCTIONS #if HAVE_NESTED_FUNCTIONS
void _asort(void *base, size_t nmemb, size_t size, void _asort(void *base, size_t nmemb, size_t size,
int(*compar)(const void *, const void *, void *ctx), int(*compar)(const void *, const void *, void *ctx),
...@@ -269,3 +271,5 @@ _asort (void *const pbase, size_t total_elems, size_t size, ...@@ -269,3 +271,5 @@ _asort (void *const pbase, size_t total_elems, size_t size,
} }
} }
#endif /* !HAVE_NESTED_FUNCTIONS */ #endif /* !HAVE_NESTED_FUNCTIONS */
#endif /* !HAVE_QSORT_R_PRIVATE_LAST */
#ifndef CCAN_ASORT_H #ifndef CCAN_ASORT_H
#define CCAN_ASORT_H #define CCAN_ASORT_H
#include "config.h"
#include <ccan/typesafe_cb/typesafe_cb.h> #include <ccan/typesafe_cb/typesafe_cb.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -24,8 +25,12 @@ _asort((base), (num), sizeof(*(base)), \ ...@@ -24,8 +25,12 @@ _asort((base), (num), sizeof(*(base)), \
const __typeof__(*(base)) *, \ const __typeof__(*(base)) *, \
__typeof__(ctx))), (ctx)) __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, void _asort(void *base, size_t nmemb, size_t size,
int(*compar)(const void *, const void *, void *), int(*compar)(const void *, const void *, void *),
void *ctx); void *ctx);
#endif
#endif /* CCAN_ASORT_H */ #endif /* CCAN_ASORT_H */
#include "config.h"
#include "ccanlint.h" #include "ccanlint.h"
#include <ccan/talloc/talloc.h> #include <ccan/talloc/talloc.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment