]> git.mdlowis.com Git - proto/labwc.git/commit
src/common/buf.c: enhance the buffer API
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Sat, 16 Mar 2024 03:39:45 +0000 (04:39 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sat, 16 Mar 2024 15:45:46 +0000 (15:45 +0000)
commitfc9cf5c9316c13640c4a2e97b26acd826cc93be2
treede156db8718fca72543537af3d5b28e64d8e05b2
parentb0c2ac1a6d01a1e954a9eb64c1f6fe2a7c61e840
src/common/buf.c: enhance the buffer API

There is at least one user of the buffer API that reuse a single
buffer by just resetting `buf.len` to `0`. This works as long as
the new user of the buffer actually adds something to the buffer.

However, if we don't add anything but still provide `buf.buf` to
a consumer, the old content will be re-used.

This patch thus adds two new clearing variants to the buffer API:
- `buf_clear()` which doesn't reset the internal allocations
- `buf_reset()` which does free the internal allocations

Additionally, this patch makes `buffer_add_char()` public which
allows adding single characters to an existing buffer. This will
be used in a future PR which implements custom format strings for
the OSD.
include/common/buf.h
src/common/buf.c