17a2a491fSJohn Marino /*-
27a2a491fSJohn Marino * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
37a2a491fSJohn Marino * All rights reserved.
47a2a491fSJohn Marino *
57a2a491fSJohn Marino * Redistribution and use in source and binary forms, with or without
67a2a491fSJohn Marino * modification, are permitted provided that the following conditions
77a2a491fSJohn Marino * are met:
87a2a491fSJohn Marino * 1. Redistributions of source code must retain the above copyright
97a2a491fSJohn Marino * notice, this list of conditions and the following disclaimer.
107a2a491fSJohn Marino * 2. Redistributions in binary form must reproduce the above copyright
117a2a491fSJohn Marino * notice, this list of conditions and the following disclaimer in the
127a2a491fSJohn Marino * documentation and/or other materials provided with the distribution.
137a2a491fSJohn Marino *
147a2a491fSJohn Marino * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
157a2a491fSJohn Marino * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
167a2a491fSJohn Marino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
177a2a491fSJohn Marino * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
187a2a491fSJohn Marino * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
197a2a491fSJohn Marino * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
207a2a491fSJohn Marino * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
217a2a491fSJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
227a2a491fSJohn Marino * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
237a2a491fSJohn Marino * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
247a2a491fSJohn Marino * SUCH DAMAGE.
25*0d5acd74SJohn Marino *
26*0d5acd74SJohn Marino * $FreeBSD: head/lib/libc/string/wcsncasecmp.c 189136 2009-02-28 06:00:58Z das $
277a2a491fSJohn Marino */
287a2a491fSJohn Marino
297a2a491fSJohn Marino #include <wchar.h>
307a2a491fSJohn Marino #include <wctype.h>
317a2a491fSJohn Marino
327a2a491fSJohn Marino int
wcsncasecmp(const wchar_t * s1,const wchar_t * s2,size_t n)337a2a491fSJohn Marino wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n)
347a2a491fSJohn Marino {
357a2a491fSJohn Marino wchar_t c1, c2;
367a2a491fSJohn Marino
377a2a491fSJohn Marino if (n == 0)
387a2a491fSJohn Marino return (0);
397a2a491fSJohn Marino for (; *s1; s1++, s2++) {
407a2a491fSJohn Marino c1 = towlower(*s1);
417a2a491fSJohn Marino c2 = towlower(*s2);
427a2a491fSJohn Marino if (c1 != c2)
437a2a491fSJohn Marino return ((int)c1 - c2);
447a2a491fSJohn Marino if (--n == 0)
457a2a491fSJohn Marino return (0);
467a2a491fSJohn Marino }
477a2a491fSJohn Marino return (-*s2);
487a2a491fSJohn Marino }
49