1 /*
2  *  Copyright (C) 1991, 1992  Linus Torvalds
3  */
4 
5 #include <xen/string.h>
6 #include <xen/ctype.h>
7 
8 /**
9  * strncasecmp - Case insensitive, length-limited string comparison
10  * @s1: One string
11  * @s2: The other string
12  * @len: the maximum number of characters to compare
13  */
14 int (strncasecmp)(const char *s1, const char *s2, size_t len)
15 {
16 	/* Yes, Virginia, it had better be unsigned */
17 	unsigned char c1, c2;
18 
19 	c1 = 0;	c2 = 0;
20 	if (len) {
21 		do {
22 			c1 = *s1; c2 = *s2;
23 			s1++; s2++;
24 			if (!c1)
25 				break;
26 			if (!c2)
27 				break;
28 			if (c1 == c2)
29 				continue;
30 			c1 = tolower(c1);
31 			c2 = tolower(c2);
32 			if (c1 != c2)
33 				break;
34 		} while (--len);
35 	}
36 	return (int)c1 - (int)c2;
37 }
38 
39 /*
40  * Local variables:
41  * mode: C
42  * c-file-style: "BSD"
43  * c-basic-offset: 8
44  * tab-width: 8
45  * indent-tabs-mode: t
46  * End:
47  */
48