home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fs.zip / octave / kpathsea / strcasecmp.c < prev    next >
C/C++ Source or Header  |  2000-01-15  |  2KB  |  84 lines

  1. /* Copyright (C) 1991, 1992, 1995 Free Software Foundation, Inc.
  2. This file was part of the GNU C Library. Modified by kb@mail.tug.org to
  3. avoid glibc-isms.
  4.  
  5. This file is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. License, or (at your option) any later version.
  9.  
  10. This file is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with this file; see the file COPYING.LIB.  If not, write
  17. to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18. Boston, MA 02111-1307, USA.  */
  19.  
  20. #ifdef HAVE_CONFIG_H
  21. #include <config.h>
  22. #endif
  23.  
  24. #if !defined (__STDC__) || !__STDC__
  25. /* This is a separate conditional since some stdc systems
  26.    reject `defined (const)'.  */
  27. #ifndef const
  28. #define const
  29. #endif
  30. #endif
  31.  
  32. #include <ctype.h>
  33.  
  34. /* Compare S1 and S2, ignoring case, returning less than, equal to or
  35.    greater than zero if S1 is lexiographically less than,
  36.    equal to or greater than S2.  */
  37. int
  38. strcasecmp (s1, s2)
  39.     const char *s1;
  40.     const char *s2;
  41. {
  42.   register const unsigned char *p1 = (const unsigned char *) s1;
  43.   register const unsigned char *p2 = (const unsigned char *) s2;
  44.   unsigned char c1, c2;
  45.  
  46.   if (p1 == p2)
  47.     return 0;
  48.  
  49.   do
  50.     {
  51.       c1 = tolower (*p1++);
  52.       c2 = tolower (*p2++);
  53.       if (c1 == '\0')
  54.     break;
  55.     }
  56.   while (c1 == c2);
  57.  
  58.   return c1 - c2;
  59. }
  60.  
  61. int
  62. strncasecmp (s1, s2, n)
  63.     const char *s1;
  64.     const char *s2;
  65.     unsigned n;
  66. {
  67.   register const unsigned char *p1 = (const unsigned char *) s1;
  68.   register const unsigned char *p2 = (const unsigned char *) s2;
  69.   unsigned char c1, c2;
  70.  
  71.   if (p1 == p2 || n == 0)
  72.     return 0;
  73.  
  74.   do
  75.     {
  76.       c1 = tolower (*p1++);
  77.       c2 = tolower (*p2++);
  78.       if (c1 == '\0' || c1 != c2)
  79.     return c1 - c2;
  80.     } while (--n > 0);
  81.  
  82.   return c1 - c2;
  83. }
  84.