Back to index

tetex-bin  3.0
strcasecmp.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991, 1992, 1995 Free Software Foundation, Inc.
00002 This file was part of the GNU C Library. Modified by kb@mail.tug.org to
00003 avoid glibc-isms.
00004 
00005 This file is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Library General Public License as
00007 published by the Free Software Foundation; either version 2 of the
00008 License, or (at your option) any later version.
00009 
00010 This file is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Library General Public License for more details.
00014 
00015 You should have received a copy of the GNU Library General Public
00016 License along with this file; see the file COPYING.LIB.  If not, write
00017 to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018 Boston, MA 02111-1307, USA.  */
00019 
00020 #ifdef HAVE_CONFIG_H
00021 #include <config.h>
00022 #endif
00023 
00024 #if !defined (__STDC__) || !__STDC__
00025 /* This is a separate conditional since some stdc systems
00026    reject `defined (const)'.  */
00027 #ifndef const
00028 #define const
00029 #endif
00030 #endif
00031 
00032 #include <ctype.h>
00033 
00034 /* Compare S1 and S2, ignoring case, returning less than, equal to or
00035    greater than zero if S1 is lexiographically less than,
00036    equal to or greater than S2.  */
00037 int
00038 strcasecmp (s1, s2)
00039     const char *s1;
00040     const char *s2;
00041 {
00042   register const unsigned char *p1 = (const unsigned char *) s1;
00043   register const unsigned char *p2 = (const unsigned char *) s2;
00044   unsigned char c1, c2;
00045 
00046   if (p1 == p2)
00047     return 0;
00048 
00049   do
00050     {
00051       c1 = tolower (*p1++);
00052       c2 = tolower (*p2++);
00053       if (c1 == '\0')
00054        break;
00055     }
00056   while (c1 == c2);
00057 
00058   return c1 - c2;
00059 }
00060 
00061 int
00062 strncasecmp (s1, s2, n)
00063     const char *s1;
00064     const char *s2;
00065     unsigned n;
00066 {
00067   register const unsigned char *p1 = (const unsigned char *) s1;
00068   register const unsigned char *p2 = (const unsigned char *) s2;
00069   unsigned char c1, c2;
00070 
00071   if (p1 == p2 || n == 0)
00072     return 0;
00073 
00074   do
00075     {
00076       c1 = tolower (*p1++);
00077       c2 = tolower (*p2++);
00078       if (c1 == '\0' || c1 != c2)
00079        return c1 - c2;
00080     } while (--n > 0);
00081 
00082   return c1 - c2;
00083 }