wcsncmp.c revision 92986
190075Sobrien/*
290075Sobrien * Copyright (c) 1989, 1993
390075Sobrien *	The Regents of the University of California.  All rights reserved.
490075Sobrien *
5132718Skan * Redistribution and use in source and binary forms, with or without
690075Sobrien * modification, are permitted provided that the following conditions
7132718Skan * are met:
8132718Skan * 1. Redistributions of source code must retain the above copyright
9132718Skan *    notice, this list of conditions and the following disclaimer.
10132718Skan * 2. Redistributions in binary form must reproduce the above copyright
1190075Sobrien *    notice, this list of conditions and the following disclaimer in the
12132718Skan *    documentation and/or other materials provided with the distribution.
13132718Skan * 3. All advertising materials mentioning features or use of this software
14132718Skan *    must display the following acknowledgement:
15132718Skan *	This product includes software developed by the University of
1690075Sobrien *	California, Berkeley and its contributors.
17132718Skan * 4. Neither the name of the University nor the names of its contributors
18132718Skan *    may be used to endorse or promote products derived from this software
19169689Skan *    without specific prior written permission.
20169689Skan *
2190075Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2290075Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2390075Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
35#if 0
36#if defined(LIBC_SCCS) && !defined(lint)
37static char sccsid[] = "@(#)strncmp.c	8.1 (Berkeley) 6/4/93";
38__RCSID("$NetBSD$");
39#endif /* LIBC_SCCS and not lint */
40#endif
41__FBSDID("$FreeBSD: head/lib/libc/string/wcsncmp.c 92986 2002-03-22 21:53:29Z obrien $");
42
43#include <assert.h>
44#include <wchar.h>
45
46int
47wcsncmp(s1, s2, n)
48	const wchar_t *s1, *s2;
49	size_t n;
50{
51
52	if (n == 0)
53		return (0);
54	do {
55		if (*s1 != *s2++) {
56			/* XXX assumes wchar_t = int */
57			return (*(const unsigned int *)s1 -
58			    *(const unsigned int *)--s2);
59		}
60		if (*s1++ == 0)
61			break;
62	} while (--n != 0);
63	return (0);
64}
65