From 24e82e453370e4105d73fcdf14cfb2f8922ddb9a Mon Sep 17 00:00:00 2001 From: Mark Menzynski Date: Tue, 10 Dec 2019 11:28:11 +0100 Subject: [PATCH] util/blob: Add overwrite function for uint8 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Overwrite function for this type was missing and I needed it for my project. Reviewed-by: Marek Olšák Reviewed-by: Karol Herbst Signed-off-by: Mark Menzynski Part-of: --- src/util/blob.c | 9 +++++++++ src/util/blob.h | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/util/blob.c b/src/util/blob.c index e4000334e0a..f830eb48076 100644 --- a/src/util/blob.c +++ b/src/util/blob.c @@ -214,6 +214,15 @@ BLOB_WRITE_TYPE(blob_write_intptr, intptr_t) #define ASSERT_ALIGNED(_offset, _align) \ assert(ALIGN((_offset), (_align)) == (_offset)) +bool +blob_overwrite_uint8 (struct blob *blob, + size_t offset, + uint8_t value) +{ + ASSERT_ALIGNED(offset, sizeof(value)); + return blob_overwrite_bytes(blob, offset, &value, sizeof(value)); +} + bool blob_overwrite_uint32 (struct blob *blob, size_t offset, diff --git a/src/util/blob.h b/src/util/blob.h index 9113331254a..e1e156eb43f 100644 --- a/src/util/blob.h +++ b/src/util/blob.h @@ -183,6 +183,21 @@ blob_overwrite_bytes(struct blob *blob, bool blob_write_uint8(struct blob *blob, uint8_t value); +/** + * Overwrite a uint8_t previously written to the blob. + * + * Writes a uint8_t value to an existing portion of the blob at an offset of + * \offset. This data range must have previously been written to the blob by + * one of the blob_write_* calls. + * + * \return True unless the requested position or position+to_write lie outside + * the current blob's size. + */ +bool +blob_overwrite_uint8(struct blob *blob, + size_t offset, + uint8_t value); + /** * Add a uint16_t to a blob. * -- 2.30.2