1*a466cc55SCy Schubert /* 2*a466cc55SCy Schubert * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC") 3*a466cc55SCy Schubert * Copyright (C) 1998-2002 Internet Software Consortium. 4*a466cc55SCy Schubert * 5*a466cc55SCy Schubert * Permission to use, copy, modify, and/or distribute this software for any 6*a466cc55SCy Schubert * purpose with or without fee is hereby granted, provided that the above 7*a466cc55SCy Schubert * copyright notice and this permission notice appear in all copies. 8*a466cc55SCy Schubert * 9*a466cc55SCy Schubert * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10*a466cc55SCy Schubert * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11*a466cc55SCy Schubert * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12*a466cc55SCy Schubert * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13*a466cc55SCy Schubert * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14*a466cc55SCy Schubert * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15*a466cc55SCy Schubert * PERFORMANCE OF THIS SOFTWARE. 16*a466cc55SCy Schubert */ 17*a466cc55SCy Schubert 18*a466cc55SCy Schubert /* $Id: region.h,v 1.25 2007/06/19 23:47:18 tbox Exp $ */ 19*a466cc55SCy Schubert 20*a466cc55SCy Schubert #ifndef ISC_REGION_H 21*a466cc55SCy Schubert #define ISC_REGION_H 1 22*a466cc55SCy Schubert 23*a466cc55SCy Schubert /*! \file isc/region.h */ 24*a466cc55SCy Schubert 25*a466cc55SCy Schubert #include <isc/types.h> 26*a466cc55SCy Schubert 27*a466cc55SCy Schubert struct isc_region { 28*a466cc55SCy Schubert unsigned char * base; 29*a466cc55SCy Schubert unsigned int length; 30*a466cc55SCy Schubert }; 31*a466cc55SCy Schubert 32*a466cc55SCy Schubert struct isc_textregion { 33*a466cc55SCy Schubert char * base; 34*a466cc55SCy Schubert unsigned int length; 35*a466cc55SCy Schubert }; 36*a466cc55SCy Schubert 37*a466cc55SCy Schubert /* XXXDCL questionable ... bears discussion. we have been putting off 38*a466cc55SCy Schubert * discussing the region api. 39*a466cc55SCy Schubert */ 40*a466cc55SCy Schubert struct isc_constregion { 41*a466cc55SCy Schubert const void * base; 42*a466cc55SCy Schubert unsigned int length; 43*a466cc55SCy Schubert }; 44*a466cc55SCy Schubert 45*a466cc55SCy Schubert struct isc_consttextregion { 46*a466cc55SCy Schubert const char * base; 47*a466cc55SCy Schubert unsigned int length; 48*a466cc55SCy Schubert }; 49*a466cc55SCy Schubert 50*a466cc55SCy Schubert /*@{*/ 51*a466cc55SCy Schubert /*! 52*a466cc55SCy Schubert * The region structure is not opaque, and is usually directly manipulated. 53*a466cc55SCy Schubert * Some macros are defined below for convenience. 54*a466cc55SCy Schubert */ 55*a466cc55SCy Schubert 56*a466cc55SCy Schubert #define isc_region_consume(r,l) \ 57*a466cc55SCy Schubert do { \ 58*a466cc55SCy Schubert isc_region_t *_r = (r); \ 59*a466cc55SCy Schubert unsigned int _l = (l); \ 60*a466cc55SCy Schubert INSIST(_r->length >= _l); \ 61*a466cc55SCy Schubert _r->base += _l; \ 62*a466cc55SCy Schubert _r->length -= _l; \ 63*a466cc55SCy Schubert } while (0) 64*a466cc55SCy Schubert 65*a466cc55SCy Schubert #define isc_textregion_consume(r,l) \ 66*a466cc55SCy Schubert do { \ 67*a466cc55SCy Schubert isc_textregion_t *_r = (r); \ 68*a466cc55SCy Schubert unsigned int _l = (l); \ 69*a466cc55SCy Schubert INSIST(_r->length >= _l); \ 70*a466cc55SCy Schubert _r->base += _l; \ 71*a466cc55SCy Schubert _r->length -= _l; \ 72*a466cc55SCy Schubert } while (0) 73*a466cc55SCy Schubert 74*a466cc55SCy Schubert #define isc_constregion_consume(r,l) \ 75*a466cc55SCy Schubert do { \ 76*a466cc55SCy Schubert isc_constregion_t *_r = (r); \ 77*a466cc55SCy Schubert unsigned int _l = (l); \ 78*a466cc55SCy Schubert INSIST(_r->length >= _l); \ 79*a466cc55SCy Schubert _r->base += _l; \ 80*a466cc55SCy Schubert _r->length -= _l; \ 81*a466cc55SCy Schubert } while (0) 82*a466cc55SCy Schubert /*@}*/ 83*a466cc55SCy Schubert 84*a466cc55SCy Schubert int 85*a466cc55SCy Schubert isc_region_compare(isc_region_t *r1, isc_region_t *r2); 86*a466cc55SCy Schubert /*%< 87*a466cc55SCy Schubert * Compares the contents of two regions 88*a466cc55SCy Schubert * 89*a466cc55SCy Schubert * Requires: 90*a466cc55SCy Schubert *\li 'r1' is a valid region 91*a466cc55SCy Schubert *\li 'r2' is a valid region 92*a466cc55SCy Schubert * 93*a466cc55SCy Schubert * Returns: 94*a466cc55SCy Schubert *\li < 0 if r1 is lexicographically less than r2 95*a466cc55SCy Schubert *\li = 0 if r1 is lexicographically identical to r2 96*a466cc55SCy Schubert *\li > 0 if r1 is lexicographically greater than r2 97*a466cc55SCy Schubert */ 98*a466cc55SCy Schubert 99*a466cc55SCy Schubert #endif /* ISC_REGION_H */ 100