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