xref: /freebsd/lib/libc/string/wcsncmp.c (revision 5b31cc94b10d4bb7109c6b27940a0fc76a44a331)
18a16b7a1SPedro F. Giffuni /*-
28a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
38a16b7a1SPedro F. Giffuni  *
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.
153fb3b97cSEd Maste  * 3. Neither the name of the University nor the names of its contributors
169829d36aSTakuya SHIOZAKI  *    may be used to endorse or promote products derived from this software
179829d36aSTakuya SHIOZAKI  *    without specific prior written permission.
189829d36aSTakuya SHIOZAKI  *
199829d36aSTakuya SHIOZAKI  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
209829d36aSTakuya SHIOZAKI  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
219829d36aSTakuya SHIOZAKI  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
229829d36aSTakuya SHIOZAKI  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
239829d36aSTakuya SHIOZAKI  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
249829d36aSTakuya SHIOZAKI  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
259829d36aSTakuya SHIOZAKI  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
269829d36aSTakuya SHIOZAKI  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
279829d36aSTakuya SHIOZAKI  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
289829d36aSTakuya SHIOZAKI  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
299829d36aSTakuya SHIOZAKI  * SUCH DAMAGE.
309829d36aSTakuya SHIOZAKI  */
319829d36aSTakuya SHIOZAKI 
32*5b31cc94SWarner Losh /* $NetBSD: wcsncmp.c,v 1.3 2001/01/05 12:13:13 itojun Exp $ */
33*5b31cc94SWarner Losh 
349829d36aSTakuya SHIOZAKI #include <wchar.h>
359829d36aSTakuya SHIOZAKI 
369829d36aSTakuya SHIOZAKI int
wcsncmp(const wchar_t * s1,const wchar_t * s2,size_t n)37bd604b4bSDaniel Gerzo wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n)
389829d36aSTakuya SHIOZAKI {
399829d36aSTakuya SHIOZAKI 
409829d36aSTakuya SHIOZAKI 	if (n == 0)
419829d36aSTakuya SHIOZAKI 		return (0);
429829d36aSTakuya SHIOZAKI 	do {
439829d36aSTakuya SHIOZAKI 		if (*s1 != *s2++) {
449829d36aSTakuya SHIOZAKI 			/* XXX assumes wchar_t = int */
459829d36aSTakuya SHIOZAKI 			return (*(const unsigned int *)s1 -
469829d36aSTakuya SHIOZAKI 			    *(const unsigned int *)--s2);
479829d36aSTakuya SHIOZAKI 		}
489829d36aSTakuya SHIOZAKI 		if (*s1++ == 0)
499829d36aSTakuya SHIOZAKI 			break;
509829d36aSTakuya SHIOZAKI 	} while (--n != 0);
519829d36aSTakuya SHIOZAKI 	return (0);
529829d36aSTakuya SHIOZAKI }
53