1 /*
2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
7  *
8  * See the COPYRIGHT file distributed with this work for additional
9  * information regarding copyright ownership.
10  */
11 
12 #ifndef ISC_REGION_H
13 #define ISC_REGION_H 1
14 
15 /*! \file isc/region.h */
16 
17 #include <isc/lang.h>
18 #include <isc/types.h>
19 
20 struct isc_region {
21 	unsigned char *base;
22 	unsigned int   length;
23 };
24 
25 struct isc_textregion {
26 	char *	     base;
27 	unsigned int length;
28 };
29 
30 /* XXXDCL questionable ... bears discussion.  we have been putting off
31  * discussing the region api.
32  */
33 struct isc_constregion {
34 	const void * base;
35 	unsigned int length;
36 };
37 
38 struct isc_consttextregion {
39 	const char * base;
40 	unsigned int length;
41 };
42 
43 /*@{*/
44 /*!
45  * The region structure is not opaque, and is usually directly manipulated.
46  * Some macros are defined below for convenience.
47  */
48 
49 #define isc_region_consume(r, l)          \
50 	do {                              \
51 		isc_region_t *_r = (r);   \
52 		unsigned int  _l = (l);   \
53 		INSIST(_r->length >= _l); \
54 		_r->base += _l;           \
55 		_r->length -= _l;         \
56 	} while (0)
57 
58 #define isc_textregion_consume(r, l)        \
59 	do {                                \
60 		isc_textregion_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_constregion_consume(r, l)        \
68 	do {                                 \
69 		isc_constregion_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 
77 ISC_LANG_BEGINDECLS
78 
79 int
80 isc_region_compare(isc_region_t *r1, isc_region_t *r2);
81 /*%<
82  * Compares the contents of two regions
83  *
84  * Requires:
85  *\li	'r1' is a valid region
86  *\li	'r2' is a valid region
87  *
88  * Returns:
89  *\li	 < 0 if r1 is lexicographically less than r2
90  *\li	 = 0 if r1 is lexicographically identical to r2
91  *\li	 > 0 if r1 is lexicographically greater than r2
92  */
93 
94 ISC_LANG_ENDDECLS
95 
96 #endif /* ISC_REGION_H */
97