Import bind 9.5.2 vendor sources.
[dragonfly.git] / contrib / bind-9.5.2 / lib / isc / bufferlist.c
blob0e5c1251bf043f18d27bc9bf77d98d82aea8c3ce
1 /*
2 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 Internet Software Consortium.
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.
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.
18 /* $Id: bufferlist.c,v 1.17 2007/06/19 23:47:17 tbox Exp $ */
20 /*! \file */
22 #include <config.h>
24 #include <stddef.h>
26 #include <isc/buffer.h>
27 #include <isc/bufferlist.h>
28 #include <isc/util.h>
30 unsigned int
31 isc_bufferlist_usedcount(isc_bufferlist_t *bl) {
32 isc_buffer_t *buffer;
33 unsigned int length;
35 REQUIRE(bl != NULL);
37 length = 0;
38 buffer = ISC_LIST_HEAD(*bl);
39 while (buffer != NULL) {
40 REQUIRE(ISC_BUFFER_VALID(buffer));
41 length += isc_buffer_usedlength(buffer);
42 buffer = ISC_LIST_NEXT(buffer, link);
45 return (length);
48 unsigned int
49 isc_bufferlist_availablecount(isc_bufferlist_t *bl) {
50 isc_buffer_t *buffer;
51 unsigned int length;
53 REQUIRE(bl != NULL);
55 length = 0;
56 buffer = ISC_LIST_HEAD(*bl);
57 while (buffer != NULL) {
58 REQUIRE(ISC_BUFFER_VALID(buffer));
59 length += isc_buffer_availablelength(buffer);
60 buffer = ISC_LIST_NEXT(buffer, link);
63 return (length);