summaryrefslogtreecommitdiff
path: root/src/strings/strncasecmp.c
blob: fc02e73468eef9dc480e4bdead41b3254e43e557 (plain)
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
#include <strings.h>
#include <ctype.h>

int strncasecmp(const char *s1, const char *s2, size_t n)
{
	while (n > 0 && *s1 && *s2) {
		char c1 = tolower(*s1);
		char c2 = tolower(*s2);
		if (c1 != c2) {
			return c1 - c2;
		}
		n--;
	}

	if (n == 0) {
		return 0;
	}

	if (*s1) {
		return -1;
	} else if (*s2) {
		return 1;
	}

	return 0;
}

/*
XOPEN(400)
POSIX(200809)
*/