]> git.proxmox.com Git - libgit2.git/commitdiff
qsort_r/qsort_s: detect their support
authorEdward Thomson <ethomson@edwardthomson.com>
Wed, 30 Sep 2015 09:49:04 +0000 (05:49 -0400)
committerEdward Thomson <ethomson@edwardthomson.com>
Wed, 30 Sep 2015 09:49:04 +0000 (05:49 -0400)
CMakeLists.txt
src/util.c

index a0ef89f760c163c4dcedd3689890ac5a5e34699e..e6c06413b94bd74b0d246b87234e144d98039528 100644 (file)
@@ -432,11 +432,6 @@ ELSE ()
        ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-const-variable)
        ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-function)
 
-       CHECK_FUNCTION_EXISTS(futimens HAVE_FUTIMENS)
-       IF (HAVE_FUTIMENS)
-               ADD_DEFINITIONS(-DHAVE_FUTIMENS)
-       ENDIF ()
-
        IF (APPLE) # Apple deprecated OpenSSL
                ADD_C_FLAG_IF_SUPPORTED(-Wno-deprecated-declarations)
        ENDIF()
@@ -447,6 +442,21 @@ ELSE ()
        ENDIF ()
 ENDIF()
 
+CHECK_FUNCTION_EXISTS(futimens HAVE_FUTIMENS)
+IF (HAVE_FUTIMENS)
+       ADD_DEFINITIONS(-DHAVE_FUTIMENS)
+ENDIF ()
+
+CHECK_FUNCTION_EXISTS(qsort_r HAVE_QSORT_R)
+IF (HAVE_QSORT_R)
+       ADD_DEFINITIONS(-DHAVE_QSORT_R)
+ENDIF ()
+
+CHECK_FUNCTION_EXISTS(qsort_s HAVE_QSORT_S)
+IF (HAVE_QSORT_S)
+       ADD_DEFINITIONS(-DHAVE_QSORT_S)
+ENDIF ()
+
 IF( NOT CMAKE_CONFIGURATION_TYPES )
        # Build Debug by default
        IF (NOT CMAKE_BUILD_TYPE)
index b3929bca232f2f84d88e8573216173590f3ab22e..9e67f434743f69b1074fe9f15b8d2a77a6dc1157 100644 (file)
@@ -611,7 +611,7 @@ size_t git__unescape(char *str)
        return (pos - str);
 }
 
-#if defined(GIT_WIN32) || defined(BSD)
+#if defined(HAVE_QSORT_S) || (defined(HAVE_QSORT_R) && defined(BSD))
 typedef struct {
        git__sort_r_cmp cmp;
        void *payload;
@@ -628,21 +628,16 @@ static int GIT_STDLIB_CALL git__qsort_r_glue_cmp(
 void git__qsort_r(
        void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload)
 {
-#if defined(__MINGW32__) || defined(AMIGA) || \
-       defined(__OpenBSD__) || defined(__NetBSD__) || \
-       defined(__gnu_hurd__) || defined(__ANDROID_API__) || \
-       defined(__sun) || defined(__CYGWIN__) || \
-       (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8) || \
-       (defined(_MSC_VER) && _MSC_VER < 1500)
-       git__insertsort_r(els, nel, elsize, NULL, cmp, payload);
-#elif defined(GIT_WIN32)
-       git__qsort_r_glue glue = { cmp, payload };
-       qsort_s(els, nel, elsize, git__qsort_r_glue_cmp, &glue);
-#elif defined(BSD)
+#if defined(HAVE_QSORT_R) && defined(BSD)
        git__qsort_r_glue glue = { cmp, payload };
        qsort_r(els, nel, elsize, &glue, git__qsort_r_glue_cmp);
-#else
+#elif defined(HAVE_QSORT_R) && defined(__GLIBC__)
        qsort_r(els, nel, elsize, cmp, payload);
+#elif defined(HAVE_QSORT_S)
+       git__qsort_r_glue glue = { cmp, payload };
+       qsort_s(els, nel, elsize, git__qsort_r_glue_cmp, &glue);
+#else
+       git__insertsort_r(els, nel, elsize, NULL, cmp, payload);
 #endif
 }