From: Michael Schroeder Date: Mon, 14 Feb 2011 17:15:46 +0000 (+0100) Subject: - update to freebsd qsort to get rid of advertising clause X-Git-Tag: BASE-SuSE-Code-12_1-Branch~140 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2dbbfcf5a3f2a6f9e01f3a69541649ff944cbcb;p=thirdparty%2Flibsolv.git - update to freebsd qsort to get rid of advertising clause - rename from qsort.c to qsort_r.c, modify to make it match glibc's argument ordering --- diff --git a/src/qsort.c b/src/qsort_r.c similarity index 80% rename from src/qsort.c rename to src/qsort_r.c index f1add73c..ef46d7fa 100644 --- a/src/qsort.c +++ b/src/qsort_r.c @@ -1,3 +1,8 @@ +/* + * qsort taken from FreeBSD, slightly modified to match glibc's + * argument ordering + */ + /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -10,10 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -35,15 +36,12 @@ static char sccsid[] = "@(#)qsort.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include -__FBSDID("$FreeBSD: src/lib/libc/stdlib/qsort.c,v 1.12 2002/09/10 02:04:49 wollman Exp $"); + +/* $FreeBSD: src/lib/libc/stdlib/qsort.c,v 1.13.2.1.8.1 2010/12/21 17:10:29 kensmith Exp $ */ #include -#ifdef I_AM_QSORT_R -typedef int cmp_t(void *, const void *, const void *); -#else -typedef int cmp_t(const void *, const void *); -#endif +typedef int cmp_t(const void *, const void *, void *); static inline char *med3(char *, char *, char *, cmp_t *, void *); static inline void swapfunc(char *, char *, int, int); @@ -87,35 +85,23 @@ swapfunc(a, b, n, swaptype) #define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) -#ifdef I_AM_QSORT_R -#define CMP(t, x, y) (cmp((t), (x), (y))) -#else -#define CMP(t, x, y) (cmp((x), (y))) -#endif +#define CMP(t, x, y) (cmp((x), (y), (t))) static inline char * -med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk -#ifndef I_AM_QSORT_R -__unused -#endif -) +med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk) { return CMP(thunk, a, b) < 0 ? (CMP(thunk, b, c) < 0 ? b : (CMP(thunk, a, c) < 0 ? c : a )) :(CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c )); } -#ifdef I_AM_QSORT_R -void -qsort_r(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp) -#else -#define thunk NULL -void -qsort(void *a, size_t n, size_t es, cmp_t *cmp) -#endif +static void +qsort_r(void *a, size_t n, size_t es, cmp_t *cmp, void *thunk) { char *pa, *pb, *pc, *pd, *pl, *pm, *pn; - int d, r, swaptype, swap_cnt; + size_t d, r; + int cmp_result; + int swaptype, swap_cnt; loop: SWAPINIT(a, es); swap_cnt = 0; @@ -144,16 +130,16 @@ loop: SWAPINIT(a, es); pc = pd = (char *)a + (n - 1) * es; for (;;) { - while (pb <= pc && (r = CMP(thunk, pb, a)) <= 0) { - if (r == 0) { + while (pb <= pc && (cmp_result = CMP(thunk, pb, a)) <= 0) { + if (cmp_result == 0) { swap_cnt = 1; swap(pa, pb); pa += es; } pb += es; } - while (pb <= pc && (r = CMP(thunk, pc, a)) >= 0) { - if (r == 0) { + while (pb <= pc && (cmp_result = CMP(thunk, pc, a)) >= 0) { + if (cmp_result == 0) { swap_cnt = 1; swap(pc, pd); pd -= es; @@ -182,11 +168,7 @@ loop: SWAPINIT(a, es); r = min(pd - pc, pn - pd - es); vecswap(pb, pn - r, r); if ((r = pb - pa) > es) -#ifdef I_AM_QSORT_R - qsort_r(a, r / es, es, thunk, cmp); -#else - qsort(a, r / es, es, cmp); -#endif + qsort_r(a, r / es, es, cmp, thunk); if ((r = pd - pc) > es) { /* Iterate rather than recurse to save stack space */ a = pn - r; diff --git a/src/util.c b/src/util.c index e4b75c04..bfa18e38 100644 --- a/src/util.c +++ b/src/util.c @@ -99,9 +99,7 @@ sat_timems(unsigned int subtract) } #ifdef HAVE_OWN_QSORT -#define __FBSDID(x) -#define I_AM_QSORT_R -#include "qsort.c" +#include "qsort_r.c" #endif /* bsd's qsort_r has different arguments, so we define our