diff -r 2e8edba252a0 -r 4ac889e14211 src/cx/buffer.h --- a/src/cx/buffer.h Sun Apr 13 12:30:18 2025 +0200 +++ b/src/cx/buffer.h Sun Apr 13 13:02:54 2025 +0200 @@ -478,6 +478,7 @@ * @param capacity the minimum required capacity for this buffer * @retval zero the capacity was already sufficient or successfully increased * @retval non-zero on allocation failure + * @see cxBufferShrink() */ cx_attr_nonnull cx_attr_export @@ -487,6 +488,29 @@ ); /** + * Shrinks the capacity of the buffer to fit its current size. + * + * If @p reserve is larger than zero, the buffer is shrunk to its size plus + * the number of reserved bytes. + * + * If the current capacity is not larger than the size plus the reserved bytes, + * nothing happens. + * + * If the #CX_BUFFER_COPY_ON_WRITE or #CX_BUFFER_COPY_ON_EXTEND flag is set, + * this function does nothing. + * + * @param buffer the buffer + * @param reserve the number of bytes that shall remain reserved + * @see cxBufferMinimumCapacity() + */ +cx_attr_nonnull +cx_attr_export +void cxBufferShrink( + CxBuffer *buffer, + size_t reserve +); + +/** * Writes data to a CxBuffer. * * If automatic flushing is not enabled, the data is simply written into the