summaryrefslogtreecommitdiff
path: root/lib/libc/strings/strcasecmp.c
blob: be8fb7195afc461fbf12ba3ae4c83d5b7949a036 (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
#include <ctype.h>  // for tolower
#include <locale.h> // for locale_t
#include <sys/cdefs.h>

int strcasecmp(const char *s1, const char *s2)
{
	unsigned char c1, c2;

	while (*s1 && *s2) {
		c1 = (unsigned char)tolower((unsigned char)*s1);
		c2 = (unsigned char)tolower((unsigned char)*s2);
		if (c1 != c2)
			return c1 - c2;
		s1++;
		s2++;
	}

	return (unsigned char)tolower((unsigned char)*s1) - (unsigned char)tolower((unsigned char)*s2);
}

__weak int strcasecmp_l(const char *s1, const char *s2, locale_t __unused locale)
{
	return strcasecmp(s1, s2);
}