[coreboot-gerrit] New patch to review for coreboot: eb62fa1 cbfstool: add struct buffer helper routines

Aaron Durbin (adurbin@google.com) gerrit at coreboot.org
Tue Mar 11 18:11:37 CET 2014


Aaron Durbin (adurbin at google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/5367

-gerrit

commit eb62fa1166b272448a3e86676d887daf16e6a734
Author: Aaron Durbin <adurbin at chromium.org>
Date:   Tue Mar 4 22:01:12 2014 -0600

    cbfstool: add struct buffer helper routines
    
    There are some open-coded manipulation of the struct buffer
    innards in the elf parsing code. Add helper functions to avoid
    reaching into the struct itself.
    
    Change-Id: I0d5300afa1a3549f87f588f976184e880d071682
    Signed-off-by: Aaron Durbin <adurbin at chromium.org>
---
 util/cbfstool/common.h | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h
index d0069c3..60ffb51 100644
--- a/util/cbfstool/common.h
+++ b/util/cbfstool/common.h
@@ -48,6 +48,49 @@ struct buffer {
 	size_t size;
 };
 
+static inline void *buffer_get(const struct buffer *b)
+{
+	return b->data;
+}
+
+static inline size_t buffer_size(const struct buffer *b)
+{
+	return b->size;
+}
+
+static inline void buffer_set_size(struct buffer *b, size_t size)
+{
+	b->size = size;
+}
+
+/*
+ * Splice a buffer into another buffer. If size is zero the entire buffer
+ * is spliced while if size is non-zero the buffer is spliced starting at
+ * offset for size bytes. Note that it's up to caller to bounds check.
+ */
+static inline void buffer_splice(struct buffer *dest, const struct buffer *src,
+                                 size_t offset, size_t size)
+{
+	dest->name = src->name;
+	dest->data = src->data;
+	dest->size = src->size;
+	if (size != 0) {
+		dest->data += offset;
+		buffer_set_size(dest, size);
+	}
+}
+
+static inline void buffer_clone(struct buffer *dest, const struct buffer *src)
+{
+	buffer_splice(dest, src, 0, 0);
+}
+
+static inline void buffer_seek(struct buffer *b, size_t size)
+{
+	b->size -= size;
+	b->data += size;
+}
+
 /* Creates an empty memory buffer with given size.
  * Returns 0 on success, otherwise non-zero. */
 int buffer_create(struct buffer *buffer, size_t size, const char *name);



More information about the coreboot-gerrit mailing list