summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Contreras <felipe.contreras@gmail.com>2010-06-13 12:40:01 +0300
committerFelipe Contreras <felipe.contreras@gmail.com>2010-06-14 03:33:28 +0300
commitf579d63c0eef97adc5960b27ff13427df59edd28 (patch)
tree7f0f7b38175c583c56d4b4562976f49f74acbd6b
parentfe020b0d457f0253602d9bc82f7a98e2fcfcecdf (diff)
buffer: add _new_use() helper
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
-rw-r--r--pn_buffer.c13
-rw-r--r--pn_buffer.h1
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);