From: Marek Olšák Date: Fri, 8 Nov 2019 00:10:55 +0000 (-0500) Subject: util: add blob_finish_get_buffer X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ad56022b0d96ca6a823623dd93b3f0bf9de17ba8;p=mesa.git util: add blob_finish_get_buffer Reviewed-by: Timothy Arceri --- 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. *