1/*
2** Copyright 2011, Oliver Tappe, zooey@hirschkaefer.de. All rights reserved.
3** Distributed under the terms of the MIT License.
4*/
5
6#include <wctype.h>
7
8#include <wchar_private.h>
9
10
11int
12__wcsncasecmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t count)
13{
14	int cmp = 0;
15
16	while (count-- > 0) {
17		cmp = towlower(*wcs1) - towlower(*wcs2++);
18			/* note: won't overflow, since our wchar_t is guaranteed to never
19			   have the highest bit set */
20
21		if (cmp != 0 || *wcs1++ == L'\0')
22			break;
23	}
24
25	return cmp;
26}
27
28
29B_DEFINE_WEAK_ALIAS(__wcsncasecmp, wcsncasecmp);
30
31
32int
33__wcsncasecmp_l(const wchar_t* wcs1, const wchar_t* wcs2, size_t count, locale_t locale)
34{
35	int cmp = 0;
36
37	while (count-- > 0) {
38		cmp = towlower_l(*wcs1, locale) - towlower_l(*wcs2++, locale);
39			/* note: won't overflow, since our wchar_t is guaranteed to never
40			   have the highest bit set */
41
42		if (cmp != 0 || *wcs1++ == L'\0')
43			break;
44	}
45
46	return cmp;
47}
48
49
50B_DEFINE_WEAK_ALIAS(__wcsncasecmp_l, wcsncasecmp_l);
51