1183299Sobrien/*- 2183299Sobrien * Copyright (c) 1990, 1993 3183299Sobrien * The Regents of the University of California. All rights reserved. 4183299Sobrien * 5183299Sobrien * This code is derived from software contributed to Berkeley by 6183299Sobrien * Chris Torek. 7183299Sobrien * 8183299Sobrien * Redistribution and use in source and binary forms, with or without 9183299Sobrien * modification, are permitted provided that the following conditions 10183299Sobrien * are met: 11183299Sobrien * 1. Redistributions of source code must retain the above copyright 12183299Sobrien * notice, this list of conditions and the following disclaimer. 13183299Sobrien * 2. Redistributions in binary form must reproduce the above copyright 14183299Sobrien * notice, this list of conditions and the following disclaimer in the 15183299Sobrien * documentation and/or other materials provided with the distribution. 16183299Sobrien * 4. Neither the name of the University nor the names of its contributors 17183299Sobrien * may be used to endorse or promote products derived from this software 18183299Sobrien * without specific prior written permission. 19183299Sobrien * 20183299Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21183299Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22183299Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23183299Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24183299Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25183299Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26183299Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27183299Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28183299Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29183299Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30183299Sobrien * SUCH DAMAGE. 31183299Sobrien */ 32183299Sobrien 33183299Sobrien#include <sys/cdefs.h> 34183299Sobrien__FBSDID("$FreeBSD$"); 35183299Sobrien 36183299Sobrien#include <sys/libkern.h> 37183299Sobrien 38183299Sobrien/* 39183299Sobrien * Compare memory regions. 40183299Sobrien */ 41183299Sobrienint 42183299Sobrienmemcmp(const void *s1, const void *s2, size_t n) 43183299Sobrien{ 44183299Sobrien if (n != 0) { 45183299Sobrien const unsigned char *p1 = s1, *p2 = s2; 46183299Sobrien 47183299Sobrien do { 48183299Sobrien if (*p1++ != *p2++) 49183299Sobrien return (*--p1 - *--p2); 50183299Sobrien } while (--n != 0); 51183299Sobrien } 52183299Sobrien return (0); 53183299Sobrien} 54