File: strncscmp.c

package info (click to toggle)
libc-sparc 5.3.12-3
  • links: PTS
  • area: main
  • in suites: potato, slink
  • size: 17,608 kB
  • ctags: 44,718
  • sloc: ansic: 163,548; asm: 5,080; makefile: 3,340; lex: 521; sh: 439; yacc: 401; awk: 28
file content (35 lines) | stat: -rw-r--r-- 881 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * This file is part of the C library for Linux and is
 * covered by the GNU Library General Public license version 2, or
 * any later version.
 * 
 * Copyright (C) 1992, 1993 Hoongjiu Lu
 *
 */
#include <ansidecl.h>
#include <string.h>
#include <ctype.h>


/* Compare no more than N characters of S1 and S2, ignoring case,
   returning less than, equal to or greater than zero
   if S1 is lexiographically less than, equal to or
   greater than S2.  */
int
DEFUN(strncasecmp, (s1, s2, n),
	CONST char *s1 AND CONST char *s2 AND size_t n)
{
  register CONST unsigned char *p1 = (CONST unsigned char *) s1;
  register CONST unsigned char *p2 = (CONST unsigned char *) s2;
  register int ret;
  unsigned char c1;

  if (p1 == p2)
    return 0;

  for (; n--; p1++, p2++) {
   if (ret = (c1 = tolower(*p1)) - tolower(*p2)) return ret;
   if (c1 == '\0') break;
  }
  return (0);
}