]> granicus.if.org Git - graphviz/commitdiff
no qsort_r() on EL5
authorJohn Ellson <ellson@research.att.com>
Tue, 5 Jan 2016 22:03:47 +0000 (17:03 -0500)
committerJohn Ellson <ellson@research.att.com>
Tue, 5 Jan 2016 22:03:47 +0000 (17:03 -0500)
lib/common/postproc.c

index 17b51aad6d5af024fae39663cb16aba7558c293e..ea301aed72062ade6f6d7275b650d659f31640c1 100644 (file)
@@ -432,6 +432,31 @@ static int cmp_obj(object_t* obj0, object_t* obj1, xlabel_state* state)
 }
 #endif
 
+#if (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8)
+void git__insertsort_r(
+       void *els, size_t nel, size_t elsize, void *swapel,
+       git__sort_r_cmp cmp, void *payload)
+{
+       uint8_t *base = els;
+       uint8_t *end = base + nel * elsize;
+       uint8_t *i, *j;
+       bool freeswap = !swapel;
+
+       if (freeswap)
+               swapel = git__malloc(elsize);
+
+       for (i = base + elsize; i < end; i += elsize)
+               for (j = i; j > base && cmp(j, j - elsize, payload) < 0; j -= elsize) {
+                       memcpy(swapel, j, elsize);
+                       memcpy(j, j - elsize, elsize);
+                       memcpy(j - elsize, swapel, elsize);
+               }
+
+       if (freeswap)
+               git__free(swapel);
+}
+#endif
+
 static void addXLabels(Agraph_t * gp)
 {
     Agnode_t *np;
@@ -627,11 +652,11 @@ static void addXLabels(Agraph_t * gp)
     if (priorities) {
        xlabs.priorities = priorities;
        xlabs.p0 = objs;
-#if defined(WIN32)
+#if defined(WIN32) 
        qsort_s(objs, n_objs, sizeof(object_t), (qsortr_cmpf)cmp_obj, &xlabs);
 #elif (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8)
        // EL5 has glibc 2.5 and no qsort_r
-       git__insertsort_r(objs, n_objs, sizeof(object_t), NULL, (qsortr_cmpf)cmp_obj, &xlabs);
+       qsort_s(objs, n_objs, sizeof(object_t), (qsortr_cmpf)cmp_obj, &xlabs);
 #else
        qsort_r(objs, n_objs, sizeof(object_t), (qsortr_cmpf)cmp_obj, &xlabs);
 #endif