9
static inline int textbuffer_ensure_capacity(struct text_buffer *txtbuf, size_t len)
11
if (txtbuf->pos + len > txtbuf->capacity) {
13
txtbuf->capacity = MAX(txtbuf->pos + len, txtbuf->capacity + 4096);
14
d = cli_realloc(txtbuf->data, txtbuf->capacity);
22
static inline int textbuffer_append_len(struct text_buffer *txtbuf, const char *s, size_t len)
24
if(textbuffer_ensure_capacity(txtbuf, len) == -1)
26
memcpy(&txtbuf->data[txtbuf->pos], s, len);
32
static inline int textbuffer_append(struct text_buffer *txtbuf, const char *s)
34
size_t len = strlen(s);
35
return textbuffer_append_len(txtbuf, s, len);
38
static inline int textbuffer_putc(struct text_buffer *txtbuf, const char c)
40
if(textbuffer_ensure_capacity(txtbuf, 1) == -1)
42
txtbuf->data[txtbuf->pos++] = c;