/contrib/bind9/lib/isc/bufferlist.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 64 lines · 33 code · 13 blank · 18 comment · 6 complexity · 556ddc60c91c7fa963a4339158aca2ee MD5 · raw file

  1. /*
  2. * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (C) 1999-2001 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. /* $Id: bufferlist.c,v 1.17 2007/06/19 23:47:17 tbox Exp $ */
  18. /*! \file */
  19. #include <config.h>
  20. #include <stddef.h>
  21. #include <isc/buffer.h>
  22. #include <isc/bufferlist.h>
  23. #include <isc/util.h>
  24. unsigned int
  25. isc_bufferlist_usedcount(isc_bufferlist_t *bl) {
  26. isc_buffer_t *buffer;
  27. unsigned int length;
  28. REQUIRE(bl != NULL);
  29. length = 0;
  30. buffer = ISC_LIST_HEAD(*bl);
  31. while (buffer != NULL) {
  32. REQUIRE(ISC_BUFFER_VALID(buffer));
  33. length += isc_buffer_usedlength(buffer);
  34. buffer = ISC_LIST_NEXT(buffer, link);
  35. }
  36. return (length);
  37. }
  38. unsigned int
  39. isc_bufferlist_availablecount(isc_bufferlist_t *bl) {
  40. isc_buffer_t *buffer;
  41. unsigned int length;
  42. REQUIRE(bl != NULL);
  43. length = 0;
  44. buffer = ISC_LIST_HEAD(*bl);
  45. while (buffer != NULL) {
  46. REQUIRE(ISC_BUFFER_VALID(buffer));
  47. length += isc_buffer_availablelength(buffer);
  48. buffer = ISC_LIST_NEXT(buffer, link);
  49. }
  50. return (length);
  51. }