00001 /* 00002 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC") 00003 * Copyright (C) 1999-2001 Internet Software Consortium. 00004 * 00005 * Permission to use, copy, modify, and/or distribute this software for any 00006 * purpose with or without fee is hereby granted, provided that the above 00007 * copyright notice and this permission notice appear in all copies. 00008 * 00009 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 00010 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 00011 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 00012 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 00013 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 00014 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00015 * PERFORMANCE OF THIS SOFTWARE. 00016 */ 00017 00018 /* $Id: bufferlist.c,v 1.17 2007/06/19 23:47:17 tbox Exp $ */ 00019 00020 /*! \file */ 00021 00022 #include <config.h> 00023 00024 #include <stddef.h> 00025 00026 #include <isc/buffer.h> 00027 #include <isc/bufferlist.h> 00028 #include <isc/util.h> 00029 00030 unsigned int 00031 isc_bufferlist_usedcount(isc_bufferlist_t *bl) { 00032 isc_buffer_t *buffer; 00033 unsigned int length; 00034 00035 REQUIRE(bl != NULL); 00036 00037 length = 0; 00038 buffer = ISC_LIST_HEAD(*bl); 00039 while (buffer != NULL) { 00040 REQUIRE(ISC_BUFFER_VALID(buffer)); 00041 length += isc_buffer_usedlength(buffer); 00042 buffer = ISC_LIST_NEXT(buffer, link); 00043 } 00044 00045 return (length); 00046 } 00047 00048 unsigned int 00049 isc_bufferlist_availablecount(isc_bufferlist_t *bl) { 00050 isc_buffer_t *buffer; 00051 unsigned int length; 00052 00053 REQUIRE(bl != NULL); 00054 00055 length = 0; 00056 buffer = ISC_LIST_HEAD(*bl); 00057 while (buffer != NULL) { 00058 REQUIRE(ISC_BUFFER_VALID(buffer)); 00059 length += isc_buffer_availablelength(buffer); 00060 buffer = ISC_LIST_NEXT(buffer, link); 00061 } 00062 00063 return (length); 00064 }