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