1872b698pfg/*-
2872b698pfg * SPDX-License-Identifier: BSD-3-Clause
3872b698pfg *
4be22b15rgrimes * Copyright (c) 1989, 1993
5be22b15rgrimes *	The Regents of the University of California.  All rights reserved.
6be22b15rgrimes *
7be22b15rgrimes * Redistribution and use in source and binary forms, with or without
8be22b15rgrimes * modification, are permitted provided that the following conditions
9be22b15rgrimes * are met:
10be22b15rgrimes * 1. Redistributions of source code must retain the above copyright
11be22b15rgrimes *    notice, this list of conditions and the following disclaimer.
12be22b15rgrimes * 2. Redistributions in binary form must reproduce the above copyright
13be22b15rgrimes *    notice, this list of conditions and the following disclaimer in the
14be22b15rgrimes *    documentation and/or other materials provided with the distribution.
15324e4c0emaste * 3. Neither the name of the University nor the names of its contributors
16be22b15rgrimes *    may be used to endorse or promote products derived from this software
17be22b15rgrimes *    without specific prior written permission.
18be22b15rgrimes *
19be22b15rgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20be22b15rgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21be22b15rgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22be22b15rgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23be22b15rgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24be22b15rgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25be22b15rgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26be22b15rgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27be22b15rgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28be22b15rgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29be22b15rgrimes * SUCH DAMAGE.
30be22b15rgrimes */
31be22b15rgrimes
32be22b15rgrimes#if defined(LIBC_SCCS) && !defined(lint)
33be22b15rgrimesstatic char sccsid[] = "@(#)strncmp.c	8.1 (Berkeley) 6/4/93";
34be22b15rgrimes#endif /* LIBC_SCCS and not lint */
35be22b15rgrimes#include <sys/cdefs.h>
36d1bf0c4obrien__FBSDID("$FreeBSD$");
37d1bf0c4obrien
38be22b15rgrimes#include <string.h>
39be22b15rgrimes
40be22b15rgrimesint
41ff17de3dangerstrncmp(const char *s1, const char *s2, size_t n)
42be22b15rgrimes{
43be22b15rgrimes
44bdf8a55eadler	if (n == 0)
45be22b15rgrimes		return (0);
46be22b15rgrimes	do {
47be22b15rgrimes		if (*s1 != *s2++)
48070eb30bde			return (*(const unsigned char *)s1 -
49070eb30bde				*(const unsigned char *)(s2 - 1));
50ff17de3danger		if (*s1++ == '\0')
51be22b15rgrimes			break;
52be22b15rgrimes	} while (--n != 0);
53be22b15rgrimes	return (0);
54be22b15rgrimes}
55