From 9fbe9cfc23711ca800f81df228fa879a850f6a44 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Thu, 30 Sep 2010 22:43:08 +0200 Subject: [PATCH] common/strbuf.c: attach function. --- src/common/strbuf.c | 10 ++++++++++ src/common/strbuf.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/common/strbuf.c b/src/common/strbuf.c index 0d3a1dd..0a64884 100644 --- a/src/common/strbuf.c +++ b/src/common/strbuf.c @@ -72,6 +72,16 @@ void strbuf_free(strbuf_t *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) { strbuf_expand(s, len); diff --git a/src/common/strbuf.h b/src/common/strbuf.h index d92f0e9..d6e191b 100644 --- a/src/common/strbuf.h +++ b/src/common/strbuf.h @@ -33,6 +33,8 @@ char* strbuf_release(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_str(strbuf_t *s, const char *str);