region.c revision 1.1
1/* $NetBSD: region.c,v 1.1 2018/08/12 12:08:23 christos Exp $ */ 2 3/* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * This Source Code Form is subject to the terms of the Mozilla Public 7 * License, v. 2.0. If a copy of the MPL was not distributed with this 8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 * 10 * See the COPYRIGHT file distributed with this work for additional 11 * information regarding copyright ownership. 12 */ 13 14 15/*! \file */ 16 17#include <config.h> 18 19#include <stdlib.h> 20#include <string.h> 21 22#include <isc/region.h> 23#include <isc/util.h> 24 25int 26isc_region_compare(isc_region_t *r1, isc_region_t *r2) { 27 unsigned int l; 28 int result; 29 30 REQUIRE(r1 != NULL); 31 REQUIRE(r2 != NULL); 32 33 l = (r1->length < r2->length) ? r1->length : r2->length; 34 35 if ((result = memcmp(r1->base, r2->base, l)) != 0) 36 return ((result < 0) ? -1 : 1); 37 else 38 return ((r1->length == r2->length) ? 0 : 39 (r1->length < r2->length) ? -1 : 1); 40} 41