From: John Ellson Date: Tue, 5 Jan 2016 22:03:47 +0000 (-0500) Subject: no qsort_r() on EL5 X-Git-Tag: TRAVIS_CI_BUILD_EXPERIMENTAL~75 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d3ae1d42926e621d9eaa1a7a7754871441b42530;p=graphviz no qsort_r() on EL5 --- diff --git a/lib/common/postproc.c b/lib/common/postproc.c index 17b51aad6..ea301aed7 100644 --- a/lib/common/postproc.c +++ b/lib/common/postproc.c @@ -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