9
static inline int textbuffer_ensure_capacity(struct text_buffer *txtbuf, size_t len)
11
if (txtbuf->pos + len > txtbuf->capacity) {
13
unsigned capacity = MAX(txtbuf->pos + len, txtbuf->capacity + 4096);
14
d = cli_realloc(txtbuf->data, capacity);
17
txtbuf->capacity = capacity;
23
static inline int textbuffer_append_len(struct text_buffer *txtbuf, const char *s, size_t len)
25
if(textbuffer_ensure_capacity(txtbuf, len) == -1)
27
memcpy(&txtbuf->data[txtbuf->pos], s, len);
33
static inline int textbuffer_append(struct text_buffer *txtbuf, const char *s)
35
size_t len = strlen(s);
36
return textbuffer_append_len(txtbuf, s, len);
39
static inline int textbuffer_putc(struct text_buffer *txtbuf, const char c)
41
if(textbuffer_ensure_capacity(txtbuf, 1) == -1)
43
txtbuf->data[txtbuf->pos++] = c;