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