util: add blob_finish_get_buffer

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
This commit is contained in:
Marek Olšák 2019-11-07 19:10:55 -05:00
parent b1f38aed84
commit ad56022b0d
2 changed files with 14 additions and 0 deletions

View file

@ -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,

View file

@ -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.
*