File: strncasecmp.c

package info (click to toggle)
klibc 1.5.12-2lenny1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 4,856 kB
  • ctags: 6,757
  • sloc: ansic: 44,932; asm: 2,318; perl: 758; makefile: 141; sh: 136; yacc: 105
file content (24 lines) | stat: -rw-r--r-- 501 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * strncasecmp.c
 */

#include <string.h>
#include <ctype.h>

int strncasecmp(const char *s1, const char *s2, size_t n)
{
	const unsigned char *c1 = (const unsigned char *)s1;
	const unsigned char *c2 = (const unsigned char *)s2;
	unsigned char ch;
	int d = 0;

	while (n--) {
		/* toupper() expects an unsigned char (implicitly cast to int)
		   as input, and returns an int, which is exactly what we want. */
		d = toupper(ch = *c1++) - toupper(*c2++);
		if (d || !ch)
			break;
	}

	return d;
}