/contrib/ntp/include/isc/region.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 95 lines · 46 code · 13 blank · 36 comment · 3 complexity · 5cc131c1f1e37896ca7bf5d5d66b77af MD5 · raw file

  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. /* $Id: region.h,v 1.16.12.3 2004/03/08 09:04:53 marka Exp $ */
  18. #ifndef ISC_REGION_H
  19. #define ISC_REGION_H 1
  20. #include <isc/types.h>
  21. struct isc_region {
  22. unsigned char * base;
  23. unsigned int length;
  24. };
  25. struct isc_textregion {
  26. char * base;
  27. unsigned int length;
  28. };
  29. /* XXXDCL questionable ... bears discussion. we have been putting off
  30. * discussing the region api.
  31. */
  32. struct isc_constregion {
  33. const void * base;
  34. unsigned int length;
  35. };
  36. struct isc_consttextregion {
  37. const char * base;
  38. unsigned int length;
  39. };
  40. /*
  41. * The region structure is not opaque, and is usually directly manipulated.
  42. * Some macros are defined below for convenience.
  43. */
  44. #define isc_region_consume(r,l) \
  45. do { \
  46. isc_region_t *_r = (r); \
  47. unsigned int _l = (l); \
  48. INSIST(_r->length >= _l); \
  49. _r->base += _l; \
  50. _r->length -= _l; \
  51. } while (0)
  52. #define isc_textregion_consume(r,l) \
  53. do { \
  54. isc_textregion_t *_r = (r); \
  55. unsigned int _l = (l); \
  56. INSIST(_r->length >= _l); \
  57. _r->base += _l; \
  58. _r->length -= _l; \
  59. } while (0)
  60. #define isc_constregion_consume(r,l) \
  61. do { \
  62. isc_constregion_t *_r = (r); \
  63. unsigned int _l = (l); \
  64. INSIST(_r->length >= _l); \
  65. _r->base += _l; \
  66. _r->length -= _l; \
  67. } while (0)
  68. int
  69. isc_region_compare(isc_region_t *r1, isc_region_t *r2);
  70. /*
  71. * Compares the contents of two regions
  72. *
  73. * Requires:
  74. * 'r1' is a valid region
  75. * 'r2' is a valid region
  76. *
  77. * Returns:
  78. * < 0 if r1 is lexicographically less than r2
  79. * = 0 if r1 is lexicographically identical to r2
  80. * > 0 if r1 is lexicographically greater than r2
  81. */
  82. #endif /* ISC_REGION_H */