diff options
author | Dan McGee <dan@archlinux.org> | 2007-07-12 21:20:43 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2007-07-12 21:20:43 +0200 |
commit | 20f73d6299c08fa79c2c8edd3d1955e208e701cb (patch) | |
tree | 470b4e84b81009aaaf318c04cee3fa1dcb1e2b53 /lib/libalpm/util.c | |
parent | 653fb8fe036363dfb550785c45adcf26f6fcbfbc (diff) | |
download | pacman-20f73d6299c08fa79c2c8edd3d1955e208e701cb.tar.gz pacman-20f73d6299c08fa79c2c8edd3d1955e208e701cb.tar.xz |
Remove versioncmp.{c,h}, clean up selective #ifdefs
Remove versioncmp.c by moving all functions to locations that make sense.
Move replacement functions (for building without glibc) into util.c where
they belong, and do proper checks for them instead of using __sun__, etc.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/util.c')
-rw-r--r-- | lib/libalpm/util.c | 131 |
1 files changed, 103 insertions, 28 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 20e2017b..5ead8a26 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -49,7 +49,109 @@ #include "package.h" #include "alpm.h" -#ifdef __sun__ +#ifndef HAVE_STRVERSCMP +/* GNU's strverscmp() function, taken from glibc 2.3.2 sources + */ + +/* Compare strings while treating digits characters numerically. + Copyright (C) 1997, 2002 Free Software Foundation, Inc. + Contributed by Jean-François Bignolles <bignolle@ecoledoc.ibp.fr>, 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. +*/ + +/* states: S_N: normal, S_I: comparing integral part, S_F: comparing + fractionnal parts, S_Z: idem but with leading Zeroes only */ +#define S_N 0x0 +#define S_I 0x4 +#define S_F 0x8 +#define S_Z 0xC + +/* result_type: CMP: return diff; LEN: compare using len_diff/diff */ +#define CMP 2 +#define LEN 3 + +/* Compare S1 and S2 as strings holding indices/version numbers, + returning less than, equal to or greater than zero if S1 is less than, + equal to or greater than S2 (for more info, see the texinfo doc). +*/ + +static int strverscmp (s1, s2) + const char *s1; + const char *s2; +{ + const unsigned char *p1 = (const unsigned char *) s1; + const unsigned char *p2 = (const unsigned char *) s2; + unsigned char c1, c2; + int state; + int diff; + + /* Symbol(s) 0 [1-9] others (padding) + Transition (10) 0 (01) d (00) x (11) - */ + static const unsigned int next_state[] = + { + /* state x d 0 - */ + /* S_N */ S_N, S_I, S_Z, S_N, + /* S_I */ S_N, S_I, S_I, S_I, + /* S_F */ S_N, S_F, S_F, S_F, + /* S_Z */ S_N, S_F, S_Z, S_Z + }; + + static const int result_type[] = + { + /* state x/x x/d x/0 x/- d/x d/d d/0 d/- + 0/x 0/d 0/0 0/- -/x -/d -/0 -/- */ + + /* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP, + CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, + /* S_I */ CMP, -1, -1, CMP, +1, LEN, LEN, CMP, + +1, LEN, LEN, CMP, CMP, CMP, CMP, CMP, + /* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP, + CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, + /* S_Z */ CMP, +1, +1, CMP, -1, CMP, CMP, CMP, + -1, CMP, CMP, CMP + }; + + if (p1 == p2) + return 0; + + c1 = *p1++; + c2 = *p2++; + /* Hint: '0' is a digit too. */ + state = S_N | ((c1 == '0') + (isdigit (c1) != 0)); + + while ((diff = c1 - c2) == 0 && c1 != '\0') + { + state = next_state[state]; + c1 = *p1++; + c2 = *p2++; + state |= (c1 == '0') + (isdigit (c1) != 0); + } + + state = result_type[state << 2 | (((c2 == '0') + (isdigit (c2) != 0)))]; + + switch (state) + { + case CMP: + return diff; + + case LEN: + while (isdigit (*p1++)) + if (!isdigit (*p2++)) + return 1; + + return isdigit (*p2) ? -1 : diff; + + default: + return state; + } +} +#endif + +#ifndef HAVE_STRSEP /* This is a replacement for strsep which is not portable (missing on Solaris). * Copyright (c) 2001 by François Gouget <fgouget_at_codeweavers.com> */ char* strsep(char** str, const char* delims) @@ -74,33 +176,6 @@ char* strsep(char** str, const char* delims) *str=NULL; return token; } - -/* Backported from Solaris Express 4/06 - * Copyright (c) 2006 Sun Microsystems, Inc. */ -char *mkdtemp(char *template) -{ - char *t = alloca(strlen(template) + 1); - char *r; - - /* Save template */ - (void) strcpy(t, template); - for (; ; ) { - r = mkstemp(template); - - if (*r == '\0') - return (NULL); - - if (mkdir(template, 0700) == 0) - return (r); - - /* Other errors indicate persistent conditions. */ - if (errno != EEXIST) - return (NULL); - - /* Reset template */ - (void) strcpy(template, t); - } -} #endif /* does the same thing as 'mkdir -p' */ |