1 /*
2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3  *
4  * SPDX-License-Identifier: MPL-2.0
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0.  If a copy of the MPL was not distributed with this
8  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
9  *
10  * See the COPYRIGHT file distributed with this work for additional
11  * information regarding copyright ownership.
12  */
13 
14 /*! \file */
15 
16 #include <stddef.h>
17 
18 #include <isc/buffer.h>
19 #include <isc/bufferlist.h>
20 #include <isc/util.h>
21 
22 unsigned int
isc_bufferlist_usedcount(isc_bufferlist_t * bl)23 isc_bufferlist_usedcount(isc_bufferlist_t *bl) {
24 	isc_buffer_t *buffer;
25 	unsigned int length;
26 
27 	REQUIRE(bl != NULL);
28 
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 
37 	return (length);
38 }
39 
40 unsigned int
isc_bufferlist_availablecount(isc_bufferlist_t * bl)41 isc_bufferlist_availablecount(isc_bufferlist_t *bl) {
42 	isc_buffer_t *buffer;
43 	unsigned int length;
44 
45 	REQUIRE(bl != NULL);
46 
47 	length = 0;
48 	buffer = ISC_LIST_HEAD(*bl);
49 	while (buffer != NULL) {
50 		REQUIRE(ISC_BUFFER_VALID(buffer));
51 		length += isc_buffer_availablelength(buffer);
52 		buffer = ISC_LIST_NEXT(buffer, link);
53 	}
54 
55 	return (length);
56 }
57