wcsncasecmp.c revision 189136
156160Sru/*-
2146515Sru * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
356160Sru * All rights reserved.
4146515Sru *
5114472Sru * Redistribution and use in source and binary forms, with or without
656160Sru * modification, are permitted provided that the following conditions
756160Sru * are met:
856160Sru * 1. Redistributions of source code must retain the above copyright
956160Sru *    notice, this list of conditions and the following disclaimer.
1056160Sru * 2. Redistributions in binary form must reproduce the above copyright
1156160Sru *    notice, this list of conditions and the following disclaimer in the
1256160Sru *    documentation and/or other materials provided with the distribution.
1356160Sru *
1456160Sru * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1556160Sru * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1656160Sru * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1756160Sru * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1856160Sru * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1956160Sru * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2056160Sru * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2156160Sru * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2256160Sru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2356160Sru * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24146515Sru * SUCH DAMAGE.
25146515Sru */
2656160Sru
2756160Sru#include <sys/cdefs.h>
2856160Sru__FBSDID("$FreeBSD: head/lib/libc/string/wcsncasecmp.c 189136 2009-02-28 06:00:58Z das $");
29146515Sru
3093139Sru#include <wchar.h>
3156160Sru#include <wctype.h>
3256160Sru
3356160Sruint
3493139Sruwcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n)
35100513Sru{
36146515Sru	wchar_t c1, c2;
37146515Sru
38146515Sru	if (n == 0)
39146515Sru		return (0);
40146515Sru	for (; *s1; s1++, s2++) {
41146515Sru		c1 = towlower(*s1);
42146515Sru		c2 = towlower(*s2);
43146515Sru		if (c1 != c2)
44146515Sru			return ((int)c1 - c2);
45146515Sru		if (--n == 0)
46146515Sru			return (0);
4756160Sru	}
4856160Sru	return (-*s2);
4956160Sru}
5056160Sru