1 /* $NetBSD: region.h,v 1.6 2014/12/10 04:38:00 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2004-2007, 2013 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 #include <isc/lang.h> 29 30 struct isc_region { 31 unsigned char * base; 32 unsigned int length; 33 }; 34 35 struct isc_textregion { 36 char * base; 37 unsigned int length; 38 }; 39 40 /* XXXDCL questionable ... bears discussion. we have been putting off 41 * discussing the region api. 42 */ 43 struct isc_constregion { 44 const void * base; 45 unsigned int length; 46 }; 47 48 struct isc_consttextregion { 49 const char * base; 50 unsigned int length; 51 }; 52 53 /*@{*/ 54 /*! 55 * The region structure is not opaque, and is usually directly manipulated. 56 * Some macros are defined below for convenience. 57 */ 58 59 #define isc_region_consume(r,l) \ 60 do { \ 61 isc_region_t *_r = (r); \ 62 unsigned int _l = (l); \ 63 INSIST(_r->length >= _l); \ 64 _r->base += _l; \ 65 _r->length -= _l; \ 66 } while (/*CONSTCOND*/0) 67 68 #define isc_textregion_consume(r,l) \ 69 do { \ 70 isc_textregion_t *_r = (r); \ 71 unsigned int _l = (l); \ 72 INSIST(_r->length >= _l); \ 73 _r->base += _l; \ 74 _r->length -= _l; \ 75 } while (/*CONSTCOND*/0) 76 77 #define isc_constregion_consume(r,l) \ 78 do { \ 79 isc_constregion_t *_r = (r); \ 80 unsigned int _l = (l); \ 81 INSIST(_r->length >= _l); \ 82 _r->base += _l; \ 83 _r->length -= _l; \ 84 } while (/*CONSTCOND*/0) 85 /*@}*/ 86 87 ISC_LANG_BEGINDECLS 88 89 int 90 isc_region_compare(isc_region_t *r1, isc_region_t *r2); 91 /*%< 92 * Compares the contents of two regions 93 * 94 * Requires: 95 *\li 'r1' is a valid region 96 *\li 'r2' is a valid region 97 * 98 * Returns: 99 *\li < 0 if r1 is lexicographically less than r2 100 *\li = 0 if r1 is lexicographically identical to r2 101 *\li > 0 if r1 is lexicographically greater than r2 102 */ 103 104 ISC_LANG_ENDDECLS 105 106 #endif /* ISC_REGION_H */ 107