110652SHyon.Kim@Sun.COM/*-
210652SHyon.Kim@Sun.COM * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
310652SHyon.Kim@Sun.COM * All rights reserved.
410652SHyon.Kim@Sun.COM *
510652SHyon.Kim@Sun.COM * Redistribution and use in source and binary forms, with or without
610652SHyon.Kim@Sun.COM * modification, are permitted provided that the following conditions
710652SHyon.Kim@Sun.COM * are met:
810652SHyon.Kim@Sun.COM * 1. Redistributions of source code must retain the above copyright
910652SHyon.Kim@Sun.COM *    notice, this list of conditions and the following disclaimer.
1010652SHyon.Kim@Sun.COM * 2. Redistributions in binary form must reproduce the above copyright
1110652SHyon.Kim@Sun.COM *    notice, this list of conditions and the following disclaimer in the
1210652SHyon.Kim@Sun.COM *    documentation and/or other materials provided with the distribution.
1310652SHyon.Kim@Sun.COM *
1410652SHyon.Kim@Sun.COM * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1510652SHyon.Kim@Sun.COM * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1610652SHyon.Kim@Sun.COM * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1710652SHyon.Kim@Sun.COM * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1810652SHyon.Kim@Sun.COM * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1910652SHyon.Kim@Sun.COM * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2010652SHyon.Kim@Sun.COM * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2110652SHyon.Kim@Sun.COM * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2210652SHyon.Kim@Sun.COM * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2310652SHyon.Kim@Sun.COM * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2410652SHyon.Kim@Sun.COM * SUCH DAMAGE.
2510652SHyon.Kim@Sun.COM */
2610652SHyon.Kim@Sun.COM
2710652SHyon.Kim@Sun.COM#include <sys/cdefs.h>
2810652SHyon.Kim@Sun.COM__FBSDID("$FreeBSD$");
2910652SHyon.Kim@Sun.COM
3010652SHyon.Kim@Sun.COM#include <wchar.h>
3110652SHyon.Kim@Sun.COM#include <wctype.h>
3210652SHyon.Kim@Sun.COM
3310652SHyon.Kim@Sun.COMint
3410652SHyon.Kim@Sun.COMwcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n)
3510652SHyon.Kim@Sun.COM{
3610652SHyon.Kim@Sun.COM	wchar_t c1, c2;
3710652SHyon.Kim@Sun.COM
3810652SHyon.Kim@Sun.COM	if (n == 0)
3910652SHyon.Kim@Sun.COM		return (0);
4010652SHyon.Kim@Sun.COM	for (; *s1; s1++, s2++) {
4110652SHyon.Kim@Sun.COM		c1 = towlower(*s1);
4210652SHyon.Kim@Sun.COM		c2 = towlower(*s2);
4310652SHyon.Kim@Sun.COM		if (c1 != c2)
4410652SHyon.Kim@Sun.COM			return ((int)c1 - c2);
4510652SHyon.Kim@Sun.COM		if (--n == 0)
4610652SHyon.Kim@Sun.COM			return (0);
4710652SHyon.Kim@Sun.COM	}
4810652SHyon.Kim@Sun.COM	return (-*s2);
4910652SHyon.Kim@Sun.COM}
5010652SHyon.Kim@Sun.COM