From ad56022b0d96ca6a823623dd93b3f0bf9de17ba8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Thu, 7 Nov 2019 19:10:55 -0500 Subject: [PATCH] util: add blob_finish_get_buffer Reviewed-by: Timothy Arceri --- src/util/blob.c | 11 +++++++++++ src/util/blob.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/util/blob.c b/src/util/blob.c index c89092e1cf3..050df8351f8 100644 --- a/src/util/blob.c +++ b/src/util/blob.c @@ -125,6 +125,17 @@ blob_init_fixed(struct blob *blob, void *data, size_t size) blob->out_of_memory = false; } +void +blob_finish_get_buffer(struct blob *blob, void **buffer, size_t *size) +{ + *buffer = blob->data; + *size = blob->size; + blob->data = NULL; + + /* Trim the buffer. */ + *buffer = realloc(*buffer, *size); +} + bool blob_overwrite_bytes(struct blob *blob, size_t offset, diff --git a/src/util/blob.h b/src/util/blob.h index b56fa4b2fe0..0c275911983 100644 --- a/src/util/blob.h +++ b/src/util/blob.h @@ -117,6 +117,9 @@ blob_finish(struct blob *blob) free(blob->data); } +void +blob_finish_get_buffer(struct blob *blob, void **buffer, size_t *size); + /** * Add some unstructured, fixed-size data to a blob. * -- 2.30.2