1d54cfbdroberto/*
2d54cfbdroberto * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
3d54cfbdroberto * Copyright (C) 1999-2001  Internet Software Consortium.
4d54cfbdroberto *
5d54cfbdroberto * Permission to use, copy, modify, and/or distribute this software for any
6d54cfbdroberto * purpose with or without fee is hereby granted, provided that the above
7d54cfbdroberto * copyright notice and this permission notice appear in all copies.
8d54cfbdroberto *
9d54cfbdroberto * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10d54cfbdroberto * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11d54cfbdroberto * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12d54cfbdroberto * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13d54cfbdroberto * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14d54cfbdroberto * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15d54cfbdroberto * PERFORMANCE OF THIS SOFTWARE.
16d54cfbdroberto */
17d54cfbdroberto
18d54cfbdroberto/* $Id: bufferlist.c,v 1.17 2007/06/19 23:47:17 tbox Exp $ */
19d54cfbdroberto
20d54cfbdroberto/*! \file */
21d54cfbdroberto
22d54cfbdroberto#include <config.h>
23d54cfbdroberto
24d54cfbdroberto#include <stddef.h>
25d54cfbdroberto
26d54cfbdroberto#include <isc/buffer.h>
27d54cfbdroberto#include <isc/bufferlist.h>
28d54cfbdroberto#include <isc/util.h>
29d54cfbdroberto
30d54cfbdrobertounsigned int
31d54cfbdrobertoisc_bufferlist_usedcount(isc_bufferlist_t *bl) {
32d54cfbdroberto	isc_buffer_t *buffer;
33d54cfbdroberto	unsigned int length;
34d54cfbdroberto
35d54cfbdroberto	REQUIRE(bl != NULL);
36d54cfbdroberto
37d54cfbdroberto	length = 0;
38d54cfbdroberto	buffer = ISC_LIST_HEAD(*bl);
39d54cfbdroberto	while (buffer != NULL) {
40d54cfbdroberto		REQUIRE(ISC_BUFFER_VALID(buffer));
41d54cfbdroberto		length += isc_buffer_usedlength(buffer);
42d54cfbdroberto		buffer = ISC_LIST_NEXT(buffer, link);
43d54cfbdroberto	}
44d54cfbdroberto
45d54cfbdroberto	return (length);
46d54cfbdroberto}
47d54cfbdroberto
48d54cfbdrobertounsigned int
49d54cfbdrobertoisc_bufferlist_availablecount(isc_bufferlist_t *bl) {
50d54cfbdroberto	isc_buffer_t *buffer;
51d54cfbdroberto	unsigned int length;
52d54cfbdroberto
53d54cfbdroberto	REQUIRE(bl != NULL);
54d54cfbdroberto
55d54cfbdroberto	length = 0;
56d54cfbdroberto	buffer = ISC_LIST_HEAD(*bl);
57d54cfbdroberto	while (buffer != NULL) {
58d54cfbdroberto		REQUIRE(ISC_BUFFER_VALID(buffer));
59d54cfbdroberto		length += isc_buffer_availablelength(buffer);
60d54cfbdroberto		buffer = ISC_LIST_NEXT(buffer, link);
61d54cfbdroberto	}
62d54cfbdroberto
63d54cfbdroberto	return (length);
64d54cfbdroberto}
65