summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2019-11-07 19:10:55 -0500
committerMarek Olšák <[email protected]>2019-11-08 15:30:28 -0500
commitad56022b0d96ca6a823623dd93b3f0bf9de17ba8 (patch)
tree9f0e878c40453df28b42aa86ce51480c53c279b8 /src
parentb1f38aed848107be6c2019a0617ff2bf450711e7 (diff)
util: add blob_finish_get_buffer
Reviewed-by: Timothy Arceri <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/util/blob.c11
-rw-r--r--src/util/blob.h3
2 files changed, 14 insertions, 0 deletions
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.
*