Blame gnulib/tests/c-strcasecmp.c
|
Packit Service |
a2ae7a |
/* c-strcasecmp.c -- case insensitive string comparator in C locale
|
|
Packit Service |
a2ae7a |
Copyright (C) 1998-1999, 2005-2006, 2009-2019 Free Software Foundation, Inc.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
a2ae7a |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
a2ae7a |
the Free Software Foundation; either version 3, or (at your option)
|
|
Packit Service |
a2ae7a |
any later version.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
a2ae7a |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
a2ae7a |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
a2ae7a |
GNU General Public License for more details.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
a2ae7a |
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <config.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Specification. */
|
|
Packit Service |
a2ae7a |
#include "c-strcase.h"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <limits.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include "c-ctype.h"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
int
|
|
Packit Service |
a2ae7a |
c_strcasecmp (const char *s1, const char *s2)
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
register const unsigned char *p1 = (const unsigned char *) s1;
|
|
Packit Service |
a2ae7a |
register const unsigned char *p2 = (const unsigned char *) s2;
|
|
Packit Service |
a2ae7a |
unsigned char c1, c2;
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
if (p1 == p2)
|
|
Packit Service |
a2ae7a |
return 0;
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
do
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
c1 = c_tolower (*p1);
|
|
Packit Service |
a2ae7a |
c2 = c_tolower (*p2);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
if (c1 == '\0')
|
|
Packit Service |
a2ae7a |
break;
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
++p1;
|
|
Packit Service |
a2ae7a |
++p2;
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
while (c1 == c2);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
if (UCHAR_MAX <= INT_MAX)
|
|
Packit Service |
a2ae7a |
return c1 - c2;
|
|
Packit Service |
a2ae7a |
else
|
|
Packit Service |
a2ae7a |
/* On machines where 'char' and 'int' are types of the same size, the
|
|
Packit Service |
a2ae7a |
difference of two 'unsigned char' values - including the sign bit -
|
|
Packit Service |
a2ae7a |
doesn't fit in an 'int'. */
|
|
Packit Service |
a2ae7a |
return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
|
|
Packit Service |
a2ae7a |
}
|