Blame missing_d/strncasecmp.c

Packit 575503
/* Copyright (C) 1991,1992,1995,1996,1997,2001,2002, 2004
Packit 575503
   Free Software Foundation, Inc.
Packit 575503
   This file is part of the GNU C Library.
Packit 575503
Packit 575503
   The GNU C Library is free software; you can redistribute it and/or
Packit 575503
   modify it under the terms of the GNU Lesser General Public
Packit 575503
   License as published by the Free Software Foundation; either
Packit 575503
   version 2.1 of the License, or (at your option) any later version.
Packit 575503
Packit 575503
   The GNU C Library is distributed in the hope that it will be useful,
Packit 575503
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 575503
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 575503
   Lesser General Public License for more details.
Packit 575503
Packit 575503
   You should have received a copy of the GNU Lesser General Public
Packit 575503
   License along with the GNU C Library; if not, write to the Free
Packit 575503
   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Packit 575503
   Boston, MA  02110-1301  USA */
Packit 575503
Packit 575503
/*
Packit 575503
 * August 2006. For Gawk: Borrowed from GLIBC to replace BSD licensed version.
Packit 575503
 * DON'T steal this for your own code, just go to the GLIBC sources.
Packit 575503
 * This version hacked unmercifully.
Packit 575503
 */
Packit 575503
Packit 575503
Packit 575503
/* Compare S1 and S2, ignoring case, returning less than, equal to or
Packit 575503
   greater than zero if S1 is lexicographically less than,
Packit 575503
   equal to or greater than S2.  */
Packit 575503
int
Packit 575503
strcasecmp (s1, s2)
Packit 575503
     const char *s1;
Packit 575503
     const char *s2;
Packit 575503
{
Packit 575503
  const unsigned char *p1 = (const unsigned char *) s1;
Packit 575503
  const unsigned char *p2 = (const unsigned char *) s2;
Packit 575503
  int result;
Packit 575503
Packit 575503
  if (p1 == p2)
Packit 575503
    return 0;
Packit 575503
Packit 575503
  while ((result = tolower (*p1) - tolower (*p2++)) == 0)
Packit 575503
    if (*p1++ == '\0')
Packit 575503
      break;
Packit 575503
Packit 575503
  return result;
Packit 575503
}
Packit 575503
Packit 575503
/* Compare at most N characters of two strings without taking care for
Packit 575503
   the case.
Packit 575503
   Copyright (C) 1992, 1996, 1997, 2001, 2004 Free Software Foundation, Inc.
Packit 575503
   This file is part of the GNU C Library.
Packit 575503
Packit 575503
   The GNU C Library is free software; you can redistribute it and/or
Packit 575503
   modify it under the terms of the GNU Lesser General Public
Packit 575503
   License as published by the Free Software Foundation; either
Packit 575503
   version 2.1 of the License, or (at your option) any later version.
Packit 575503
Packit 575503
   The GNU C Library is distributed in the hope that it will be useful,
Packit 575503
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 575503
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 575503
   Lesser General Public License for more details.
Packit 575503
Packit 575503
   You should have received a copy of the GNU Lesser General Public
Packit 575503
   License along with the GNU C Library; if not, write to the Free
Packit 575503
   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
Packit 575503
   MA 02110-1335, USA 
Packit 575503
*/
Packit 575503
Packit 575503
/*
Packit 575503
 * August 2006, for gawk, same comment applies. See strncase.c
Packit 575503
 * in the GLIBC sources.
Packit 575503
 */
Packit 575503
Packit 575503
Packit 575503
/* Compare no more than N characters of S1 and S2,
Packit 575503
   ignoring case, returning less than, equal to or
Packit 575503
   greater than zero if S1 is lexicographically less
Packit 575503
   than, equal to or greater than S2.  */
Packit 575503
int
Packit 575503
strncasecmp (s1, s2, n)
Packit 575503
     const char *s1;
Packit 575503
     const char *s2;
Packit 575503
     size_t n;
Packit 575503
{
Packit 575503
  const unsigned char *p1 = (const unsigned char *) s1;
Packit 575503
  const unsigned char *p2 = (const unsigned char *) s2;
Packit 575503
  int result;
Packit 575503
Packit 575503
  if (p1 == p2 || n == 0)
Packit 575503
    return 0;
Packit 575503
Packit 575503
  while ((result = tolower (*p1) - tolower (*p2++)) == 0)
Packit 575503
    if (*p1++ == '\0' || --n == 0)
Packit 575503
      break;
Packit 575503
Packit 575503
  return result;
Packit 575503
}