wcsncmp.c revision 251069
1234353Sdim/* 2193323Sed * Copyright (c) 1989, 1993 3193323Sed * The Regents of the University of California. All rights reserved. 4193323Sed * 5193323Sed * Redistribution and use in source and binary forms, with or without 6193323Sed * modification, are permitted provided that the following conditions 7193323Sed * are met: 8193323Sed * 1. Redistributions of source code must retain the above copyright 9193323Sed * notice, this list of conditions and the following disclaimer. 10193323Sed * 2. Redistributions in binary form must reproduce the above copyright 11193323Sed * notice, this list of conditions and the following disclaimer in the 12193323Sed * documentation and/or other materials provided with the distribution. 13193323Sed * 3. Neither the name of the University nor the names of its contributors 14193323Sed * may be used to endorse or promote products derived from this software 15193323Sed * without specific prior written permission. 16193323Sed * 17193323Sed * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18193323Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19193323Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20224145Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21224145Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22224145Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23193323Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24193323Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25193323Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26193323Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27239462Sdim * SUCH DAMAGE. 28239462Sdim */ 29193323Sed 30221345Sdim#include <sys/cdefs.h> 31239462Sdim#if 0 32243830Sdim#if defined(LIBC_SCCS) && !defined(lint) 33193323Sedstatic char sccsid[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93"; 34193323Sed__RCSID("$NetBSD: wcsncmp.c,v 1.3 2001/01/05 12:13:13 itojun Exp $"); 35193323Sed#endif /* LIBC_SCCS and not lint */ 36193323Sed#endif 37193323Sed__FBSDID("$FreeBSD: head/lib/libc/string/wcsncmp.c 251069 2013-05-28 20:57:40Z emaste $"); 38193323Sed 39198090Srdivacky#include <wchar.h> 40193323Sed 41193323Sedint 42193323Sedwcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n) 43193323Sed{ 44193323Sed 45249423Sdim if (n == 0) 46249423Sdim return (0); 47239462Sdim do { 48234353Sdim if (*s1 != *s2++) { 49193323Sed /* XXX assumes wchar_t = int */ 50193323Sed return (*(const unsigned int *)s1 - 51193323Sed *(const unsigned int *)--s2); 52234353Sdim } 53234353Sdim if (*s1++ == 0) 54239462Sdim break; 55193323Sed } while (--n != 0); 56193323Sed return (0); 57212904Sdim} 58249423Sdim