summaryrefslogtreecommitdiff
path: root/util/cbfstool/common.h
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2014-03-04 22:01:12 -0600
committerAaron Durbin <adurbin@google.com>2014-03-11 19:46:45 +0100
commit6e8c2790bbc9190cf8b7ff83787b5328a2b8828e (patch)
tree880be6067eecf2d2d39fd5f4ebd9f9f48152fc27 /util/cbfstool/common.h
parent1240d29209c1e1bac556113485a894f6ef4ae0af (diff)
downloadcoreboot-6e8c2790bbc9190cf8b7ff83787b5328a2b8828e.tar.xz
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@chromium.org> Reviewed-on: http://review.coreboot.org/5367 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'util/cbfstool/common.h')
-rw-r--r--util/cbfstool/common.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h
index d0069c3d58..60ffb51816 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);