xref: /freebsd/lib/libc/string/wcsncmp.c (revision 9829d36a8683ded23a8c7cbc12dac15ceb045e0a)
19829d36aSTakuya SHIOZAKI /*	$NetBSD$	*/
29829d36aSTakuya SHIOZAKI 
39829d36aSTakuya SHIOZAKI /*
49829d36aSTakuya SHIOZAKI  * Copyright (c) 1989, 1993
59829d36aSTakuya SHIOZAKI  *	The Regents of the University of California.  All rights reserved.
69829d36aSTakuya SHIOZAKI  *
79829d36aSTakuya SHIOZAKI  * Redistribution and use in source and binary forms, with or without
89829d36aSTakuya SHIOZAKI  * modification, are permitted provided that the following conditions
99829d36aSTakuya SHIOZAKI  * are met:
109829d36aSTakuya SHIOZAKI  * 1. Redistributions of source code must retain the above copyright
119829d36aSTakuya SHIOZAKI  *    notice, this list of conditions and the following disclaimer.
129829d36aSTakuya SHIOZAKI  * 2. Redistributions in binary form must reproduce the above copyright
139829d36aSTakuya SHIOZAKI  *    notice, this list of conditions and the following disclaimer in the
149829d36aSTakuya SHIOZAKI  *    documentation and/or other materials provided with the distribution.
159829d36aSTakuya SHIOZAKI  * 3. All advertising materials mentioning features or use of this software
169829d36aSTakuya SHIOZAKI  *    must display the following acknowledgement:
179829d36aSTakuya SHIOZAKI  *	This product includes software developed by the University of
189829d36aSTakuya SHIOZAKI  *	California, Berkeley and its contributors.
199829d36aSTakuya SHIOZAKI  * 4. Neither the name of the University nor the names of its contributors
209829d36aSTakuya SHIOZAKI  *    may be used to endorse or promote products derived from this software
219829d36aSTakuya SHIOZAKI  *    without specific prior written permission.
229829d36aSTakuya SHIOZAKI  *
239829d36aSTakuya SHIOZAKI  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
249829d36aSTakuya SHIOZAKI  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
259829d36aSTakuya SHIOZAKI  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
269829d36aSTakuya SHIOZAKI  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
279829d36aSTakuya SHIOZAKI  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
289829d36aSTakuya SHIOZAKI  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
299829d36aSTakuya SHIOZAKI  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
309829d36aSTakuya SHIOZAKI  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
319829d36aSTakuya SHIOZAKI  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
329829d36aSTakuya SHIOZAKI  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
339829d36aSTakuya SHIOZAKI  * SUCH DAMAGE.
349829d36aSTakuya SHIOZAKI  *
359829d36aSTakuya SHIOZAKI  * $FreeBSD$
369829d36aSTakuya SHIOZAKI  */
379829d36aSTakuya SHIOZAKI 
389829d36aSTakuya SHIOZAKI #include <sys/cdefs.h>
399829d36aSTakuya SHIOZAKI #if defined(LIBC_SCCS) && !defined(lint)
409829d36aSTakuya SHIOZAKI #if 0
419829d36aSTakuya SHIOZAKI static char sccsid[] = "@(#)strncmp.c	8.1 (Berkeley) 6/4/93";
429829d36aSTakuya SHIOZAKI #else
439829d36aSTakuya SHIOZAKI __RCSID("$NetBSD$");
449829d36aSTakuya SHIOZAKI #endif
459829d36aSTakuya SHIOZAKI #endif /* LIBC_SCCS and not lint */
469829d36aSTakuya SHIOZAKI 
479829d36aSTakuya SHIOZAKI #include <assert.h>
489829d36aSTakuya SHIOZAKI #include <wchar.h>
499829d36aSTakuya SHIOZAKI 
509829d36aSTakuya SHIOZAKI int
519829d36aSTakuya SHIOZAKI wcsncmp(s1, s2, n)
529829d36aSTakuya SHIOZAKI 	const wchar_t *s1, *s2;
539829d36aSTakuya SHIOZAKI 	size_t n;
549829d36aSTakuya SHIOZAKI {
559829d36aSTakuya SHIOZAKI 
569829d36aSTakuya SHIOZAKI 	_DIAGASSERT(s1 != NULL);
579829d36aSTakuya SHIOZAKI 	_DIAGASSERT(s2 != NULL);
589829d36aSTakuya SHIOZAKI 
599829d36aSTakuya SHIOZAKI 	if (n == 0)
609829d36aSTakuya SHIOZAKI 		return (0);
619829d36aSTakuya SHIOZAKI 	do {
629829d36aSTakuya SHIOZAKI 		if (*s1 != *s2++) {
639829d36aSTakuya SHIOZAKI 			/* XXX assumes wchar_t = int */
649829d36aSTakuya SHIOZAKI 			return (*(const unsigned int *)s1 -
659829d36aSTakuya SHIOZAKI 			    *(const unsigned int *)--s2);
669829d36aSTakuya SHIOZAKI 		}
679829d36aSTakuya SHIOZAKI 		if (*s1++ == 0)
689829d36aSTakuya SHIOZAKI 			break;
699829d36aSTakuya SHIOZAKI 	} while (--n != 0);
709829d36aSTakuya SHIOZAKI 	return (0);
719829d36aSTakuya SHIOZAKI }
72