Blame lib/c-strcasecmp.c

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