From f579d63c0eef97adc5960b27ff13427df59edd28 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sun, 13 Jun 2010 12:40:01 +0300 Subject: buffer: add _new_use() helper Signed-off-by: Felipe Contreras --- pn_buffer.c | 13 ++++++++++--- pn_buffer.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pn_buffer.c b/pn_buffer.c index df67405..97daee4 100644 --- a/pn_buffer.c +++ b/pn_buffer.c @@ -30,19 +30,26 @@ pn_buffer_new_and_alloc(size_t size) } struct pn_buffer * -pn_buffer_new_memdup(const void *data, - size_t size) +pn_buffer_new_use(void *data, + size_t size) { struct pn_buffer *buffer; buffer = g_malloc(sizeof(*buffer)); buffer->size = buffer->len = size; - buffer->data = buffer->alloc_data = g_memdup(data, size); + buffer->data = buffer->alloc_data = data; buffer->offset = 0; return buffer; } +struct pn_buffer * +pn_buffer_new_memdup(const void *data, + size_t size) +{ + return pn_buffer_new_use(g_memdup(data, size), size); +} + void pn_buffer_free(struct pn_buffer *buffer) { diff --git a/pn_buffer.h b/pn_buffer.h index 4dd1962..7f7bdaf 100644 --- a/pn_buffer.h +++ b/pn_buffer.h @@ -14,6 +14,7 @@ struct pn_buffer { struct pn_buffer *pn_buffer_new(void); struct pn_buffer *pn_buffer_new_and_alloc(size_t size); struct pn_buffer *pn_buffer_new_memdup(const void *data, size_t size); +struct pn_buffer *pn_buffer_new_use(void *data, size_t size); void pn_buffer_free(struct pn_buffer *buffer); void pn_buffer_resize(struct pn_buffer *buffer, size_t new_size); char *pn_buffer_to_string(struct pn_buffer *buffer); -- cgit v1.2.3