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