Blame gl/strcasecmp.c

Packit Service 4684c1
/* Case-insensitive string comparison function.
Packit Service 4684c1
   Copyright (C) 1998-1999, 2005-2007, 2009-2020 Free Software Foundation, Inc.
Packit Service 4684c1
Packit Service 4684c1
   This program is free software; you can redistribute it and/or modify
Packit Service 4684c1
   it under the terms of the GNU Lesser General Public License as published by
Packit Service 4684c1
   the Free Software Foundation; either version 2.1, or (at your option)
Packit Service 4684c1
   any later version.
Packit Service 4684c1
Packit Service 4684c1
   This program is distributed in the hope that it will be useful,
Packit Service 4684c1
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 4684c1
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 4684c1
   GNU Lesser General Public License for more details.
Packit Service 4684c1
Packit Service 4684c1
   You should have received a copy of the GNU Lesser General Public License
Packit Service 4684c1
   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
Packit Service 4684c1
Packit Service 4684c1
#include <config.h>
Packit Service 4684c1
Packit Service 4684c1
/* Specification.  */
Packit Service 4684c1
#include <string.h>
Packit Service 4684c1
Packit Service 4684c1
#include <ctype.h>
Packit Service 4684c1
#include <limits.h>
Packit Service 4684c1
Packit Service 4684c1
#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
Packit Service 4684c1
Packit Service 4684c1
/* Compare strings S1 and S2, ignoring case, returning less than, equal to or
Packit Service 4684c1
   greater than zero if S1 is lexicographically less than, equal to or greater
Packit Service 4684c1
   than S2.
Packit Service 4684c1
   Note: This function does not work with multibyte strings!  */
Packit Service 4684c1
Packit Service 4684c1
int
Packit Service 4684c1
strcasecmp (const char *s1, const char *s2)
Packit Service 4684c1
{
Packit Service 4684c1
  const unsigned char *p1 = (const unsigned char *) s1;
Packit Service 4684c1
  const unsigned char *p2 = (const unsigned char *) s2;
Packit Service 4684c1
  unsigned char c1, c2;
Packit Service 4684c1
Packit Service 4684c1
  if (p1 == p2)
Packit Service 4684c1
    return 0;
Packit Service 4684c1
Packit Service 4684c1
  do
Packit Service 4684c1
    {
Packit Service 4684c1
      c1 = TOLOWER (*p1);
Packit Service 4684c1
      c2 = TOLOWER (*p2);
Packit Service 4684c1
Packit Service 4684c1
      if (c1 == '\0')
Packit Service 4684c1
        break;
Packit Service 4684c1
Packit Service 4684c1
      ++p1;
Packit Service 4684c1
      ++p2;
Packit Service 4684c1
    }
Packit Service 4684c1
  while (c1 == c2);
Packit Service 4684c1
Packit Service 4684c1
  if (UCHAR_MAX <= INT_MAX)
Packit Service 4684c1
    return c1 - c2;
Packit Service 4684c1
  else
Packit Service 4684c1
    /* On machines where 'char' and 'int' are types of the same size, the
Packit Service 4684c1
       difference of two 'unsigned char' values - including the sign bit -
Packit Service 4684c1
       doesn't fit in an 'int'.  */
Packit Service 4684c1
    return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
Packit Service 4684c1
}