Import upstream version 1.28
[debian/tar] / gnu / c-strcasecmp.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* c-strcasecmp.c -- case insensitive string comparator in C locale
4    Copyright (C) 1998-1999, 2005-2006, 2009-2014 Free Software Foundation, Inc.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3, or (at your option)
9    any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, see <http://www.gnu.org/licenses/>.  */
18
19 #include <config.h>
20
21 /* Specification.  */
22 #include "c-strcase.h"
23
24 #include <limits.h>
25
26 #include "c-ctype.h"
27
28 int
29 c_strcasecmp (const char *s1, const char *s2)
30 {
31   register const unsigned char *p1 = (const unsigned char *) s1;
32   register const unsigned char *p2 = (const unsigned char *) s2;
33   unsigned char c1, c2;
34
35   if (p1 == p2)
36     return 0;
37
38   do
39     {
40       c1 = c_tolower (*p1);
41       c2 = c_tolower (*p2);
42
43       if (c1 == '\0')
44         break;
45
46       ++p1;
47       ++p2;
48     }
49   while (c1 == c2);
50
51   if (UCHAR_MAX <= INT_MAX)
52     return c1 - c2;
53   else
54     /* On machines where 'char' and 'int' are types of the same size, the
55        difference of two 'unsigned char' values - including the sign bit -
56        doesn't fit in an 'int'.  */
57     return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
58 }