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