safe.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 /* $Id$ */
00018 
00019 /*! \file */
00020 
00021 #include <config.h>
00022 
00023 #include <isc/safe.h>
00024 #include <isc/util.h>
00025 
00026 #ifdef _MSC_VER
00027 #pragma optimize("", off)
00028 #endif
00029 
00030 isc_boolean_t
00031 isc_safe_memcmp(const void *s1, const void *s2, size_t n) {
00032         isc_uint8_t acc = 0;
00033 
00034         if (n != 0U) {
00035                 const isc_uint8_t *p1 = s1, *p2 = s2;
00036 
00037                 do {
00038                         acc |= *p1++ ^ *p2++;
00039                 } while (--n != 0U);
00040         }
00041         return (ISC_TF(acc == 0));
00042 }

Generated on Tue Apr 28 17:41:05 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha