]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/bind9/lib/isc/include/isc/region.h
MFC r363988:
[FreeBSD/stable/9.git] / contrib / bind9 / lib / isc / include / isc / region.h
1 /*
2  * Copyright (C) 2004-2007, 2013  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1998-2002  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or 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.25 2007/06/19 23:47:18 tbox Exp $ */
19
20 #ifndef ISC_REGION_H
21 #define ISC_REGION_H 1
22
23 /*! \file isc/region.h */
24
25 #include <isc/types.h>
26 #include <isc/lang.h>
27
28 struct isc_region {
29         unsigned char * base;
30         unsigned int    length;
31 };
32
33 struct isc_textregion {
34         char *          base;
35         unsigned int    length;
36 };
37
38 /* XXXDCL questionable ... bears discussion.  we have been putting off
39  * discussing the region api.
40  */
41 struct isc_constregion {
42         const void *    base;
43         unsigned int    length;
44 };
45
46 struct isc_consttextregion {
47         const char *    base;
48         unsigned int    length;
49 };
50
51 /*@{*/
52 /*!
53  * The region structure is not opaque, and is usually directly manipulated.
54  * Some macros are defined below for convenience.
55  */
56
57 #define isc_region_consume(r,l) \
58         do { \
59                 isc_region_t *_r = (r); \
60                 unsigned int _l = (l); \
61                 INSIST(_r->length >= _l); \
62                 _r->base += _l; \
63                 _r->length -= _l; \
64         } while (0)
65
66 #define isc_textregion_consume(r,l) \
67         do { \
68                 isc_textregion_t *_r = (r); \
69                 unsigned int _l = (l); \
70                 INSIST(_r->length >= _l); \
71                 _r->base += _l; \
72                 _r->length -= _l; \
73         } while (0)
74
75 #define isc_constregion_consume(r,l) \
76         do { \
77                 isc_constregion_t *_r = (r); \
78                 unsigned int _l = (l); \
79                 INSIST(_r->length >= _l); \
80                 _r->base += _l; \
81                 _r->length -= _l; \
82         } while (0)
83 /*@}*/
84
85 ISC_LANG_BEGINDECLS
86
87 int
88 isc_region_compare(isc_region_t *r1, isc_region_t *r2);
89 /*%<
90  * Compares the contents of two regions
91  *
92  * Requires:
93  *\li   'r1' is a valid region
94  *\li   'r2' is a valid region
95  *
96  * Returns:
97  *\li    < 0 if r1 is lexicographically less than r2
98  *\li    = 0 if r1 is lexicographically identical to r2
99  *\li    > 0 if r1 is lexicographically greater than r2
100  */
101
102 ISC_LANG_ENDDECLS
103
104 #endif /* ISC_REGION_H */