summaryrefslogtreecommitdiff
path: root/lib/libc/string/wcsncasecmp.c
blob: 66a4c7889ae7d8cce2cdfa3f0936f1b79ece50e5 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*	$NetBSD: wcsncasecmp.c,v 1.2 2006/08/26 22:45:52 christos Exp $	*/

/*
 * Copyright (C) 2006 Aleksey Cheusov
 *
 * This material is provided "as is", with absolutely no warranty expressed
 * or implied. Any use is at your own risk.
 *
 * Permission to use or copy this software for any purpose is hereby granted 
 * without fee. Permission to modify the code and to distribute modified
 * code is also granted without any restrictions.
 */

#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint) 
__RCSID("$NetBSD: wcsncasecmp.c,v 1.2 2006/08/26 22:45:52 christos Exp $"); 
#endif /* LIBC_SCCS and not lint */ 

#include "namespace.h"
#include <assert.h>
#include <wchar.h>
#include <wctype.h>

__weak_alias(wcsncasecmp,_wcsncasecmp)

int
wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n)
{
	int lc1  = 0;
	int lc2  = 0;
	int diff = 0;

	_DIAGASSERT(s1);
	_DIAGASSERT(s2);

	while (n--) {
		lc1 = towlower (*s1);
		lc2 = towlower (*s2);

		diff = lc1 - lc2;
		if (diff)
			return diff;

		if (!lc1)
			return 0;

		++s1;
		++s2;
	}

	return 0;
}