home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / string / strncscmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-21  |  881 b   |  36 lines

  1. /*
  2.  * This file is part of the C library for Linux and is
  3.  * covered by the GNU Library General Public license version 2, or
  4.  * any later version.
  5.  * 
  6.  * Copyright (C) 1992, 1993 Hoongjiu Lu
  7.  *
  8.  */
  9. #include <ansidecl.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12.  
  13.  
  14. /* Compare no more than N characters of S1 and S2, ignoring case,
  15.    returning less than, equal to or greater than zero
  16.    if S1 is lexiographically less than, equal to or
  17.    greater than S2.  */
  18. int
  19. DEFUN(strncasecmp, (s1, s2, n),
  20.     CONST char *s1 AND CONST char *s2 AND size_t n)
  21. {
  22.   register CONST unsigned char *p1 = (CONST unsigned char *) s1;
  23.   register CONST unsigned char *p2 = (CONST unsigned char *) s2;
  24.   register int ret;
  25.   unsigned char c1;
  26.  
  27.   if (p1 == p2)
  28.     return 0;
  29.  
  30.   for (; n--; p1++, p2++) {
  31.    if (ret = (c1 = tolower(*p1)) - tolower(*p2)) return ret;
  32.    if (c1 == '\0') break;
  33.   }
  34.   return (0);
  35. }
  36.