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