1*9e66e6d7Sabs /* $NetBSD: wcsncmp.c,v 1.9 2012/06/25 22:32:46 abs Exp $ */
2383f218aSitojun
3c5b93796Sitojun /*
4c5b93796Sitojun * Copyright (c) 1989, 1993
5c5b93796Sitojun * The Regents of the University of California. All rights reserved.
6383f218aSitojun *
7383f218aSitojun * Redistribution and use in source and binary forms, with or without
8383f218aSitojun * modification, are permitted provided that the following conditions
9383f218aSitojun * are met:
10383f218aSitojun * 1. Redistributions of source code must retain the above copyright
11383f218aSitojun * notice, this list of conditions and the following disclaimer.
12383f218aSitojun * 2. Redistributions in binary form must reproduce the above copyright
13383f218aSitojun * notice, this list of conditions and the following disclaimer in the
14383f218aSitojun * documentation and/or other materials provided with the distribution.
15eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
16c5b93796Sitojun * may be used to endorse or promote products derived from this software
17c5b93796Sitojun * without specific prior written permission.
18383f218aSitojun *
19c5b93796Sitojun * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20383f218aSitojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21383f218aSitojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22c5b93796Sitojun * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23383f218aSitojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24383f218aSitojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25383f218aSitojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26383f218aSitojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27383f218aSitojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28383f218aSitojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29383f218aSitojun * SUCH DAMAGE.
30383f218aSitojun */
31383f218aSitojun
32383f218aSitojun #include <sys/cdefs.h>
33383f218aSitojun #if defined(LIBC_SCCS) && !defined(lint)
34c5b93796Sitojun #if 0
35c5b93796Sitojun static char sccsid[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93";
36c5b93796Sitojun #else
37*9e66e6d7Sabs __RCSID("$NetBSD: wcsncmp.c,v 1.9 2012/06/25 22:32:46 abs Exp $");
38c5b93796Sitojun #endif
39383f218aSitojun #endif /* LIBC_SCCS and not lint */
40383f218aSitojun
415ba790cbSlukem #include <assert.h>
42383f218aSitojun #include <wchar.h>
432af58f1cStnozaki #include "runetype_local.h"
44383f218aSitojun
45383f218aSitojun int
wcsncmp(const wchar_t * s1,const wchar_t * s2,size_t n)46*9e66e6d7Sabs wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n)
47383f218aSitojun {
48c5b93796Sitojun
495ba790cbSlukem _DIAGASSERT(s1 != NULL);
505ba790cbSlukem _DIAGASSERT(s2 != NULL);
515ba790cbSlukem
52c5b93796Sitojun if (n == 0)
53c5b93796Sitojun return (0);
54c5b93796Sitojun do {
55c5b93796Sitojun if (*s1 != *s2++) {
56c5b93796Sitojun /* XXX assumes wchar_t = int */
576ca22529Stshiozak return (*(const __nbrune_t *)s1 -
586ca22529Stshiozak *(const __nbrune_t *)--s2);
59383f218aSitojun }
60c5b93796Sitojun if (*s1++ == 0)
61c5b93796Sitojun break;
62c5b93796Sitojun } while (--n != 0);
63c5b93796Sitojun return (0);
64383f218aSitojun }
65