summaryrefslogtreecommitdiff
path: root/util/cbfstool/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'util/cbfstool/common.h')
-rw-r--r--util/cbfstool/common.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h
index 0cf6b6e31f..416d0a44d4 100644
--- a/util/cbfstool/common.h
+++ b/util/cbfstool/common.h
@@ -20,8 +20,10 @@
#ifndef __CBFSTOOL_COMMON_H
#define __CBFSTOOL_COMMON_H
+#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
+#include <string.h>
#include <assert.h>
/* Endianess */
@@ -121,6 +123,15 @@ static inline void buffer_seek(struct buffer *b, size_t size)
b->data += size;
}
+/* Returns whether the buffer begins with the specified magic bytes. */
+static inline bool buffer_check_magic(const struct buffer *b, const char *magic,
+ size_t magic_len)
+{
+ assert(magic);
+ return b && b->size >= magic_len &&
+ memcmp(b->data, magic, magic_len) == 0;
+}
+
/* 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);