1262445Serwin/*
2262445Serwin * Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
3262445Serwin *
4262445Serwin * Permission to use, copy, modify, and/or distribute this software for any
5262445Serwin * purpose with or without fee is hereby granted, provided that the above
6262445Serwin * copyright notice and this permission notice appear in all copies.
7262445Serwin *
8262445Serwin * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9262445Serwin * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10262445Serwin * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11262445Serwin * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12262445Serwin * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13262445Serwin * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14262445Serwin * PERFORMANCE OF THIS SOFTWARE.
15262445Serwin */
16262445Serwin
17262445Serwin/* $Id$ */
18262445Serwin
19262445Serwin/*! \file */
20262445Serwin
21262445Serwin#include <config.h>
22262445Serwin
23262445Serwin#include <isc/safe.h>
24262445Serwin#include <isc/util.h>
25262445Serwin
26262445Serwin#ifdef _MSC_VER
27262445Serwin#pragma optimize("", off)
28262445Serwin#endif
29262445Serwin
30262445Serwinisc_boolean_t
31262445Serwinisc_safe_memcmp(const void *s1, const void *s2, size_t n) {
32262445Serwin	isc_uint8_t acc = 0;
33262445Serwin
34262445Serwin	if (n != 0U) {
35262445Serwin		const isc_uint8_t *p1 = s1, *p2 = s2;
36262445Serwin
37262445Serwin		do {
38262445Serwin			acc |= *p1++ ^ *p2++;
39262445Serwin		} while (--n != 0U);
40262445Serwin	}
41262445Serwin	return (ISC_TF(acc == 0));
42262445Serwin}
43