X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fstrncasecmp.c;h=0209c39ea00b3e3eaf31f1cbffae8e976399f2db;hb=49bfa9e57a3695690d9becf349cb2260a4e3040e;hp=72ead013be765493939bfbb8398601494c35ad1e;hpb=222b0486b7db1b09293e05512873d633440efcb3;p=gnulib.git diff --git a/lib/strncasecmp.c b/lib/strncasecmp.c index 72ead013b..0209c39ea 100644 --- a/lib/strncasecmp.c +++ b/lib/strncasecmp.c @@ -1,5 +1,5 @@ /* strncasecmp.c -- case insensitive string comparator - Copyright (C) 1998, 1999 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2005 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 @@ -23,6 +23,7 @@ #include "strcase.h" #include +#include #define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) @@ -54,5 +55,11 @@ strncasecmp (const char *s1, const char *s2, size_t n) } 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); }