1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-07-25 18:19:00 +02:00
Files
coreutils/lib/memcasecmp.c
T

52 lines
1.5 KiB
C
Raw Normal View History

1996-04-25 04:33:03 +00:00
/* Case-insensitive buffer comparator.
2006-07-09 16:59:05 +00:00
Copyright (C) 1996, 1997, 2000, 2003, 2006 Free Software Foundation, Inc.
1996-04-25 04:33:03 +00:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
2005-05-14 07:58:06 +00:00
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
1996-04-25 04:33:03 +00:00
/* Written by Jim Meyering. */
1996-04-25 04:33:03 +00:00
2005-09-22 06:05:39 +00:00
#ifdef HAVE_CONFIG_H
1996-04-10 03:29:05 +00:00
# include <config.h>
#endif
#include "memcasecmp.h"
2006-07-09 16:59:05 +00:00
#include <ctype.h>
#include <limits.h>
1997-10-27 04:59:25 +00:00
/* Like memcmp, but ignore differences in case.
Convert to upper case (not lower) before comparing so that
join -i works with sort -f. */
1996-04-10 03:29:05 +00:00
int
memcasecmp (const void *vs1, const void *vs2, size_t n)
1996-04-10 03:29:05 +00:00
{
2003-08-18 09:44:49 +00:00
size_t i;
char const *s1 = vs1;
char const *s2 = vs2;
1996-04-10 03:29:05 +00:00
for (i = 0; i < n; i++)
{
2003-08-18 09:44:49 +00:00
unsigned char u1 = s1[i];
unsigned char u2 = s2[i];
2006-07-09 16:59:05 +00:00
int U1 = toupper (u1);
int U2 = toupper (u2);
int diff = (UCHAR_MAX <= INT_MAX ? U1 - U2
: U1 < U2 ? -1 : U2 < U1);
2003-08-18 09:44:49 +00:00
if (diff)
return diff;
1996-04-10 03:29:05 +00:00
}
return 0;
}