Add, forgotten in last commit.
[gnulib.git] / lib / strcasecmp.c
index 71f2eca..c1bac0a 100644 (file)
@@ -25,6 +25,7 @@
 #include "strcase.h"
 
 #include <ctype.h>
+#include <limits.h>
 
 #if HAVE_MBRTOWC
 # include "mbuiter.h"
@@ -93,6 +94,12 @@ strcasecmp (const char *s1, const char *s2)
        }
       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);
     }
 }