bufferlist.c revision 499b34cea04a46823d003d4c0520c8b03e8513cb
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews/*
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * Copyright (C) 1999-2001 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * copyright notice and this permission notice appear in all copies.
0f467ed4d4a732003941247d26f05596e25f357bAutomatic Updater *
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt */
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt/* $Id: bufferlist.c,v 1.12 2001/01/09 21:55:57 bwelling Exp $ */
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt#include <config.h>
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt#include <stddef.h>
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt#include <isc/buffer.h>
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt#include <isc/bufferlist.h>
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt#include <isc/util.h>
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Huntunsigned int
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Huntisc_bufferlist_usedcount(isc_bufferlist_t *bl) {
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt isc_buffer_t *buffer;
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt unsigned int length;
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt REQUIRE(bl != NULL);
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt
length = 0;
buffer = ISC_LIST_HEAD(*bl);
while (buffer != NULL) {
REQUIRE(ISC_BUFFER_VALID(buffer));
length += isc_buffer_usedlength(buffer);
buffer = ISC_LIST_NEXT(buffer, link);
}
return (length);
}
unsigned int
isc_bufferlist_availablecount(isc_bufferlist_t *bl) {
isc_buffer_t *buffer;
unsigned int length;
REQUIRE(bl != NULL);
length = 0;
buffer = ISC_LIST_HEAD(*bl);
while (buffer != NULL) {
REQUIRE(ISC_BUFFER_VALID(buffer));
length += isc_buffer_availablelength(buffer);
buffer = ISC_LIST_NEXT(buffer, link);
}
return (length);
}