1135446Strhodes/* 2193149Sdougb * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC") 3135446Strhodes * Copyright (C) 2002 Internet Software Consortium. 4135446Strhodes * 5193149Sdougb * Permission to use, copy, modify, and/or distribute this software for any 6135446Strhodes * purpose with or without fee is hereby granted, provided that the above 7135446Strhodes * copyright notice and this permission notice appear in all copies. 8135446Strhodes * 9135446Strhodes * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10135446Strhodes * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11135446Strhodes * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12135446Strhodes * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13135446Strhodes * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14135446Strhodes * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15135446Strhodes * PERFORMANCE OF THIS SOFTWARE. 16135446Strhodes */ 17135446Strhodes 18234010Sdougb/* $Id: region.c,v 1.7 2007/06/19 23:47:17 tbox Exp $ */ 19135446Strhodes 20170222Sdougb/*! \file */ 21170222Sdougb 22135446Strhodes#include <config.h> 23135446Strhodes 24135446Strhodes#include <stdlib.h> 25135446Strhodes#include <string.h> 26135446Strhodes 27135446Strhodes#include <isc/region.h> 28135446Strhodes#include <isc/util.h> 29135446Strhodes 30135446Strhodesint 31135446Strhodesisc_region_compare(isc_region_t *r1, isc_region_t *r2) { 32135446Strhodes unsigned int l; 33135446Strhodes int result; 34135446Strhodes 35135446Strhodes REQUIRE(r1 != NULL); 36135446Strhodes REQUIRE(r2 != NULL); 37135446Strhodes 38135446Strhodes l = (r1->length < r2->length) ? r1->length : r2->length; 39135446Strhodes 40135446Strhodes if ((result = memcmp(r1->base, r2->base, l)) != 0) 41135446Strhodes return ((result < 0) ? -1 : 1); 42135446Strhodes else 43135446Strhodes return ((r1->length == r2->length) ? 0 : 44135446Strhodes (r1->length < r2->length) ? -1 : 1); 45135446Strhodes} 46