1*38a75b98Sguenther /* $OpenBSD: wcscasecmp.c,v 1.3 2015/09/12 16:23:14 guenther Exp $ */
242569c7dSespie
342569c7dSespie /*
442569c7dSespie * Copyright (c) 2011 Marc Espie
542569c7dSespie *
642569c7dSespie * Redistribution and use in source and binary forms, with or without
742569c7dSespie * modification, are permitted provided that the following conditions
842569c7dSespie * are met:
942569c7dSespie * 1. Redistributions of source code must retain the above copyright
1042569c7dSespie * notice, this list of conditions and the following disclaimer.
1142569c7dSespie * 2. Redistributions in binary form must reproduce the above copyright
1242569c7dSespie * notice, this list of conditions and the following disclaimer in the
1342569c7dSespie * documentation and/or other materials provided with the distribution.
1442569c7dSespie *
1542569c7dSespie * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
1642569c7dSespie * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1742569c7dSespie * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1842569c7dSespie * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
1942569c7dSespie * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2042569c7dSespie * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2142569c7dSespie * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2242569c7dSespie * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2342569c7dSespie * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2442569c7dSespie * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2542569c7dSespie * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2642569c7dSespie */
2742569c7dSespie
2842569c7dSespie #include <wchar.h>
2942569c7dSespie #include <wctype.h>
3042569c7dSespie #include "locale/runetype.h"
3142569c7dSespie
3242569c7dSespie int
wcscasecmp(const wchar_t * s1,const wchar_t * s2)339e7c890bSnaddy wcscasecmp(const wchar_t *s1, const wchar_t *s2)
3442569c7dSespie {
3542569c7dSespie wchar_t l1, l2;
3642569c7dSespie
3742569c7dSespie while ((l1 = towlower(*s1++)) == (l2 = towlower(*s2++))) {
3842569c7dSespie if (l1 == 0)
3942569c7dSespie return (0);
4042569c7dSespie }
4142569c7dSespie /* XXX assumes wchar_t = int */
4242569c7dSespie return ((rune_t)l1 - (rune_t)l2);
4342569c7dSespie }
44*38a75b98Sguenther DEF_WEAK(wcscasecmp);
4542569c7dSespie
4642569c7dSespie int
wcsncasecmp(const wchar_t * s1,const wchar_t * s2,size_t n)4742569c7dSespie wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n)
4842569c7dSespie {
4942569c7dSespie wchar_t l1, l2;
5042569c7dSespie
5142569c7dSespie if (n == 0)
5242569c7dSespie return (0);
5342569c7dSespie do {
5442569c7dSespie if (((l1 = towlower(*s1++))) != (l2 = towlower(*s2++))) {
5542569c7dSespie /* XXX assumes wchar_t = int */
5642569c7dSespie return ((rune_t)l1 - (rune_t)l2);
5742569c7dSespie }
5842569c7dSespie if (l1 == 0)
5942569c7dSespie break;
6042569c7dSespie } while (--n != 0);
6142569c7dSespie return (0);
6242569c7dSespie }
63*38a75b98Sguenther DEF_WEAK(wcsncasecmp);
64