decide which qsort_r to use based on what it is available
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 16 May 2011 13:08:40 +0000 (15:08 +0200)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 16 May 2011 13:08:40 +0000 (15:08 +0200)
Conflicts:

src/util.c

src/CMakeLists.txt
src/util.c

index 9bd0fde..87fc4b4 100644 (file)
@@ -1,4 +1,16 @@
 
+INCLUDE(CheckFunctionExists)
+CHECK_FUNCTION_EXISTS(qsort_r HAVE_QSORT_R)
+CHECK_FUNCTION_EXISTS(__qsort_r HAVE___QSORT_R)
+
+IF (HAVE_QSORT_R)
+  ADD_DEFINITIONS(-DHAVE_QSORT_R=1)
+ENDIF (HAVE_QSORT_R)
+
+IF (HAVE___QSORT_R)
+  ADD_DEFINITIONS(-DHAVE___QSORT_R=1)
+ENDIF (HAVE___QSORT_R)
+
 SET(libsatsolver_SRCS
     bitmap.c poolarch.c poolvendor.c poolid.c strpool.c dirpool.c
     solver.c solverdebug.c repo_solv.c evr.c pool.c
index b04771e..a08f4ce 100644 (file)
@@ -98,29 +98,31 @@ sat_timems(unsigned int subtract)
   return r - subtract;
 }
 
-#ifdef USE_OWN_QSORT
-#include "qsort_r.c"
-#else
-
 /* bsd's qsort_r has different arguments, so we define our
    own version in case we need to do some clever mapping
+
    see also: http://sources.redhat.com/ml/libc-alpha/2008-12/msg00003.html
  */
 #if defined(__GLIBC__)
 
+# if HAVE_QSORT_R || HAVE___QSORT_R
 void
 sat_sort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *compard)
 {
-# if __GLIBC_PREREQ(2, 8)
+# if HAVE_QSORT_R
   qsort_r(base, nmemb, size, compar, compard);
 # else
   /* backported for SLE10-SP2 */
   __qsort_r(base, nmemb, size, compar, compard);
 # endif
+
 }
+#else /* qsort_r or __qsort_r on glibc */
+/* use own version of qsort if none available */
+#include "qsort_r.c"
+#endif
 
-#else
+#else /* not glibc */
 
 struct sat_sort_data {
   int (*compar)(const void *, const void *, void *);
@@ -145,8 +147,6 @@ sat_sort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, cons
 
 #endif
 
-#endif /* USE_OWN_QSORT */
-
 char *
 sat_dupjoin(const char *str1, const char *str2, const char *str3)
 {