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