Buffer
A dynamically growing buffer storing arbitrary data.
Note
Used for Register, not Text content.
Functions
-
void
buffer_init
(Buffer*)
Initalize a Buffer object.
-
void
buffer_release
(Buffer*)
Release all resources, reinitialize buffer.
-
void
buffer_clear
(Buffer*)
Set buffer length to zero, keep allocated memory.
-
bool
buffer_reserve
(Buffer*, size_t size)
Reserve space to store at least size
bytes.
-
bool
buffer_grow
(Buffer*, size_t len)
Reserve space for at least len
more bytes.
-
bool
buffer_terminate
(Buffer*)
If buffer is non-empty, make sure it is NUL
terminated.
-
bool
buffer_put
(Buffer*, const void *data, size_t len)
Set buffer content, growing the buffer as needed.
-
bool
buffer_put0
(Buffer*, const char *data)
Set buffer content to NUL
terminated data.
-
bool
buffer_remove
(Buffer*, size_t pos, size_t len)
Remove len
bytes starting at pos
.
-
bool
buffer_insert
(Buffer*, size_t pos, const void *data, size_t len)
Insert len
bytes of data
at pos
.
-
bool
buffer_insert0
(Buffer*, size_t pos, const char *data)
Insert NUL-terminated data at pos.
-
bool
buffer_append
(Buffer*, const void *data, size_t len)
Append further content to the end.
-
bool
buffer_append0
(Buffer*, const char *data)
Append NUl-terminated data.
-
bool
buffer_prepend
(Buffer*, const void *data, size_t len)
Insert len
bytes of data
at the begin.
-
bool
buffer_prepend0
(Buffer*, const char *data)
Insert NUL-terminated data at the begin.
-
bool buffer_printf (Buffer *, const char *fmt,...) __attribute__((format(printf
Set formatted buffer content, ensures NUL termination on success.
-
bool bool buffer_appendf (Buffer *, const char *fmt,...) __attribute__((format(printf
Append formatted buffer content, ensures NUL termination on success.
-
bool bool size_t buffer_length0 (Buffer *)
Return length of a buffer without trailing NUL byte.
-
size_t
buffer_length
(Buffer*)
Return length of a buffer including possible NUL byte.
-
size_t
buffer_capacity
(Buffer*)
Return current maximal capacity in bytes of this buffer.
-
const char *
buffer_content0
(Buffer*)
Get pointer to buffer data.
Guaranteed to return a NUL terminated string even if buffer is empty.
-
const char *
buffer_content
(Buffer*)
Get pointer to buffer data.
Warning
Might be NULL, if empty. Might not be NUL terminated.
-
char *
buffer_move
(Buffer*)
Borrow underlying buffer data.
Warning
The caller is responsible to free(3)
it.
-
struct
Buffer
- #include <buffer.h>
A dynamically growing buffer storing arbitrary data.
Public Members
-
char *
data
Data pointer, NULL
if empty.
-
size_t
len
Current length of data.
-
size_t
size
Maximal capacity of the buffer.