diff --git a/src/util/string.c b/src/util/string.c index 0d0cbb9f..f101245f 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -245,79 +245,32 @@ elinks_strlcasecmp(const unsigned char *s1, size_t n1, } } -/* c_strcasecmp - * Taken from GNU coreutils (version 6.9) - * File name: lib/c-strcasecmp.c - * Copyright (C) 1998-1999, 2005-2006 Free Software Foundation, Inc. - * Licensed under the GPL version 2 or any later version. - */ -int c_strcasecmp (const char *s1, const char *s2) +int +c_strcasecmp(const char *s1, const char *s2) { - register const unsigned char *p1 = (const unsigned char *) s1; - register const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; - - if (p1 == p2) - return 0; - - do - { - c1 = c_tolower (*p1); - c2 = c_tolower (*p2); - - if (c1 == '\0') - break; - - ++p1; - ++p2; - } - while (c1 == c2); - - if (UCHAR_MAX <= INT_MAX) - return c1 - c2; - else - /* On machines where 'char' and 'int' are types of the same size, the - difference of two 'unsigned char' values - including the sign bit - - doesn't fit in an 'int'. */ - return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); + for (;; s1++, s2++) { + unsigned char c1 = c_tolower(*(const unsigned char *) s1); + unsigned char c2 = c_tolower(*(const unsigned char *) s2); + + if (c1 != c2) + return (c1 < c2) ? -1: +1; + if (c1 == '\0') + return 0; + } } -/* c_strncasecmp - * Taken from GNU coreutils (version 6.9) - * File name: lib/c-strncasecmp.c - * ^ (note the "n") - * Copyright (C) 1998-1999, 2005-2006 Free Software Foundation, Inc. - * Licensed under the GPL version 2 or any later version. - */ -int c_strncasecmp (const char *s1, const char *s2, size_t n) +int c_strncasecmp(const char *s1, const char *s2, size_t n) { - register const unsigned char *p1 = (const unsigned char *) s1; - register const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; - - if (p1 == p2 || n == 0) - return 0; - - do - { - c1 = c_tolower (*p1); - c2 = c_tolower (*p2); - - if (--n == 0 || c1 == '\0') - break; - - ++p1; - ++p2; - } - while (c1 == c2); - - if (UCHAR_MAX <= INT_MAX) - return c1 - c2; - else - /* On machines where 'char' and 'int' are types of the same size, the - difference of two 'unsigned char' values - including the sign bit - - doesn't fit in an 'int'. */ - return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); + for (; n > 0; n--, s1++, s2++) { + unsigned char c1 = c_tolower(*(const unsigned char *) s1); + unsigned char c2 = c_tolower(*(const unsigned char *) s2); + + if (c1 != c2) + return (c1 < c2) ? -1: +1; + if (c1 == '\0') + return 0; + } + return 0; } /* c_strcasestr - adapted from src/osdep/stub.c */ diff --git a/src/util/string.h b/src/util/string.h index bfce8976..37ea336a 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -107,7 +107,7 @@ int elinks_strlcasecmp(const unsigned char *s1, size_t n1, const int locale_indep); /* strcasecmp and strncasecmp which work as if they are - * in the C locale - both taken from GNU coreutils */ + * in the C locale */ int c_strcasecmp(const char *s1, const char *s2); int c_strncasecmp(const char *s1, const char *s2, size_t n);