Merge branch 'vendor/MPFR' into gcc441
[dragonfly.git] / contrib / bind-9.3 / lib / isc / bufferlist.c
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2001  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and 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
18 /* $Id: bufferlist.c,v 1.12.206.1 2004/03/06 08:14:28 marka Exp $ */
19
20 #include <config.h>
21
22 #include <stddef.h>
23
24 #include <isc/buffer.h>
25 #include <isc/bufferlist.h>
26 #include <isc/util.h>
27
28 unsigned int
29 isc_bufferlist_usedcount(isc_bufferlist_t *bl) {
30         isc_buffer_t *buffer;
31         unsigned int length;
32
33         REQUIRE(bl != NULL);
34
35         length = 0;
36         buffer = ISC_LIST_HEAD(*bl);
37         while (buffer != NULL) {
38                 REQUIRE(ISC_BUFFER_VALID(buffer));
39                 length += isc_buffer_usedlength(buffer);
40                 buffer = ISC_LIST_NEXT(buffer, link);
41         }
42
43         return (length);
44 }
45
46 unsigned int
47 isc_bufferlist_availablecount(isc_bufferlist_t *bl) {
48         isc_buffer_t *buffer;
49         unsigned int length;
50
51         REQUIRE(bl != NULL);
52
53         length = 0;
54         buffer = ISC_LIST_HEAD(*bl);
55         while (buffer != NULL) {
56                 REQUIRE(ISC_BUFFER_VALID(buffer));
57                 length += isc_buffer_availablelength(buffer);
58                 buffer = ISC_LIST_NEXT(buffer, link);
59         }
60
61         return (length);
62 }