X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fstrcasecmp.c;h=ebbfe8f0386f61b21fd2d62a06d4fb0c2ba18ca3;hb=533101a268dc5015a140ff4695d8eeb04fbe57b6;hp=cf4ab88dbdf04448b73d8507f1cbe142d15f67e8;hpb=92295bc4b2a378893386efd3cf8cf9bc31024b59;p=gnulib.git
diff --git a/lib/strcasecmp.c b/lib/strcasecmp.c
index cf4ab88db..ebbfe8f03 100644
--- a/lib/strcasecmp.c
+++ b/lib/strcasecmp.c
@@ -1,5 +1,5 @@
-/* strcasecmp.c -- case insensitive string comparator
- Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+/* Case-insensitive string comparison function.
+ Copyright (C) 1998-1999, 2005-2007, 2009-2013 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -12,41 +12,31 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+ along with this program; if not, see . */
-#if HAVE_CONFIG_H
-# include
-#endif
+#include
-#ifdef LENGTH_LIMIT
-# define STRXCASECMP_FUNCTION strncasecmp
-# define STRXCASECMP_DECLARE_N , size_t n
-# define LENGTH_LIMIT_EXPR(Expr) Expr
-#else
-# define STRXCASECMP_FUNCTION strcasecmp
-# define STRXCASECMP_DECLARE_N /* empty */
-# define LENGTH_LIMIT_EXPR(Expr) 0
-#endif
+/* Specification. */
+#include
-#include
#include
+#include
#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
-/* Compare {{no more than N characters of }}strings S1 and S2,
- ignoring case, returning less than, equal to or
- greater than zero if S1 is lexicographically less
- than, equal to or greater than S2. */
+/* Compare strings S1 and S2, ignoring case, returning less than, equal to or
+ greater than zero if S1 is lexicographically less than, equal to or greater
+ than S2.
+ Note: This function does not work with multibyte strings! */
int
-STRXCASECMP_FUNCTION (const char *s1, const char *s2 STRXCASECMP_DECLARE_N)
+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;
+ const unsigned char *p1 = (const unsigned char *) s1;
+ const unsigned char *p2 = (const unsigned char *) s2;
unsigned char c1, c2;
- if (p1 == p2 || LENGTH_LIMIT_EXPR (n == 0))
+ if (p1 == p2)
return 0;
do
@@ -54,13 +44,19 @@ STRXCASECMP_FUNCTION (const char *s1, const char *s2 STRXCASECMP_DECLARE_N)
c1 = TOLOWER (*p1);
c2 = TOLOWER (*p2);
- if (LENGTH_LIMIT_EXPR (--n == 0) || c1 == '\0')
- break;
+ if (c1 == '\0')
+ break;
++p1;
++p2;
}
while (c1 == c2);
- return 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);
}