diff --git a/include/nuttx/mm/iob.h b/include/nuttx/mm/iob.h index 3b70286d67..abdce41431 100644 --- a/include/nuttx/mm/iob.h +++ b/include/nuttx/mm/iob.h @@ -478,6 +478,17 @@ int iob_trycopyin(FAR struct iob_s *iob, FAR const uint8_t *src, int iob_copyout(FAR uint8_t *dest, FAR const struct iob_s *iob, unsigned int len, unsigned int offset); +/**************************************************************************** + * Name: iob_tailroom + * + * Description: + * Return the number of bytes at the tail of the I/O buffer chain which + * can be used to append data without additional allocations. + * + ****************************************************************************/ + +unsigned int iob_tailroom(FAR struct iob_s *iob); + /**************************************************************************** * Name: iob_clone * diff --git a/mm/iob/Make.defs b/mm/iob/Make.defs index e241204b00..4ae751a2c5 100644 --- a/mm/iob/Make.defs +++ b/mm/iob/Make.defs @@ -27,7 +27,7 @@ CSRCS += iob_concat.c iob_copyin.c iob_copyout.c iob_contig.c iob_free.c CSRCS += iob_free_chain.c iob_free_qentry.c iob_free_queue.c CSRCS += iob_initialize.c iob_pack.c iob_peek_queue.c iob_remove_queue.c CSRCS += iob_statistics.c iob_trimhead.c iob_trimhead_queue.c iob_trimtail.c -CSRCS += iob_navail.c iob_free_queue_qentry.c +CSRCS += iob_navail.c iob_free_queue_qentry.c iob_tailroom.c ifeq ($(CONFIG_IOB_NOTIFIER),y) CSRCS += iob_notifier.c diff --git a/mm/iob/iob_tailroom.c b/mm/iob/iob_tailroom.c new file mode 100644 index 0000000000..d0c999156c --- /dev/null +++ b/mm/iob/iob_tailroom.c @@ -0,0 +1,52 @@ +/**************************************************************************** + * mm/iob/iob_tailroom.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include "iob.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: iob_tailroom + * + * Description: + * Return the number of bytes at the tail of the I/O buffer chain which + * can be used to append data without additional allocations. + * + ****************************************************************************/ + +unsigned int iob_tailroom(FAR struct iob_s *iob) +{ + while (iob->io_flink != NULL) + { + iob = iob->io_flink; + } + + return CONFIG_IOB_BUFSIZE - (iob->io_offset + iob->io_len); +}