summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2015-09-30 05:49:04 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2015-09-30 05:49:04 -0400
commite683d15247ef7231143b46580f07113ecae43773 (patch)
tree352de5feb6e3429010a5c81a1fcb829b9b71b6db /src/util.c
parent8649dfd8df4f0d840a64c1d6c5fc80b8e94a68d1 (diff)
downloadlibgit2-e683d15247ef7231143b46580f07113ecae43773.tar.gz
qsort_r/qsort_s: detect their support
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/util.c b/src/util.c
index b3929bca2..9e67f4347 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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
}