mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
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.
This commit is contained in:
parent
b0c2ac1a6d
commit
fc9cf5c931
2 changed files with 55 additions and 13 deletions
|
|
@ -45,4 +45,23 @@ void buf_init(struct buf *s);
|
|||
*/
|
||||
void buf_add(struct buf *s, const char *data);
|
||||
|
||||
/**
|
||||
* buf_add_char - add single char to C string buffer
|
||||
* @s: buffer
|
||||
* @data: char to be added
|
||||
*/
|
||||
void buf_add_char(struct buf *s, char data);
|
||||
|
||||
/**
|
||||
* buf_clear - clear the buffer, internal allocations are preserved
|
||||
* @s: buffer
|
||||
*/
|
||||
void buf_clear(struct buf *s);
|
||||
|
||||
/**
|
||||
* buf_reset - reset the buffer, internal allocations are free'd
|
||||
* @s: buffer
|
||||
*/
|
||||
void buf_reset(struct buf *s);
|
||||
|
||||
#endif /* LABWC_BUF_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue