Archived
1
0
Fork 0

common/strbuf.c: attach function.

This commit is contained in:
Henrik Hautakoski 2010-09-30 22:43:08 +02:00
parent 3abbb2b63e
commit 9fbe9cfc23
2 changed files with 12 additions and 0 deletions

View file

@ -72,6 +72,16 @@ void strbuf_free(strbuf_t *s) {
strbuf_init(s); strbuf_init(s);
} }
void strbuf_attach(strbuf_t *s, void *buf, size_t len, size_t alloc_size) {
strbuf_free(s);
s->buf = buf;
s->len = len;
s->alloc_size = alloc_size;
strbuf_expand(s, 0);
s->buf[s->len] = '\0';
}
void strbuf_append(strbuf_t *s, const void *ptr, size_t len) { void strbuf_append(strbuf_t *s, const void *ptr, size_t len) {
strbuf_expand(s, len); strbuf_expand(s, len);

View file

@ -33,6 +33,8 @@ char* strbuf_release(strbuf_t *s);
void strbuf_free(strbuf_t *s); void strbuf_free(strbuf_t *s);
void strbuf_attach(strbuf_t *s, void *str, size_t len, size_t alloc_size);
void strbuf_append(strbuf_t *s, const void *ptr, size_t len); void strbuf_append(strbuf_t *s, const void *ptr, size_t len);
void strbuf_append_str(strbuf_t *s, const char *str); void strbuf_append_str(strbuf_t *s, const char *str);