summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/utils/buffer.c33
-rw-r--r--src/utils/endian.h4
2 files changed, 35 insertions, 2 deletions
diff --git a/src/utils/buffer.c b/src/utils/buffer.c
index 5e0f58c..4b68923 100644
--- a/src/utils/buffer.c
+++ b/src/utils/buffer.c
@@ -6,6 +6,7 @@
*/
#include <string.h>
+#include <stdarg.h>
#include <parserutils/utils/buffer.h>
@@ -131,6 +132,38 @@ parserutils_error parserutils_buffer_append(parserutils_buffer *buffer,
}
/**
+ * Append multiple data blocks to a memory buffer.
+ *
+ * Each data block must be passed as a pair of const uint8_t* and size_t
+ *
+ * \param buffer The buffer to append to
+ * \param count The number of data blocks to append
+ * \param ... The pairs of pointer and size
+ * \return PARSERUTILS_OK on success, appropriate error otherwise.
+*/
+parserutils_error parserutils_buffer_appendv(parserutils_buffer *buffer,
+ size_t count, ...)
+{
+ va_list ap;
+ parserutils_error error = PARSERUTILS_OK;
+ const uint8_t *data;
+ size_t len;
+
+ va_start(ap, count);
+ while (count > 0) {
+ data = va_arg(ap, const uint8_t *);
+ len = va_arg(ap, size_t);
+ error = parserutils_buffer_append(buffer, data, len);
+ if (error != PARSERUTILS_OK)
+ break;
+ count--;
+ }
+ va_end(ap);
+
+ return error;
+}
+
+/**
* Insert data into a memory buffer
*
* \param buffer The buffer to insert into
diff --git a/src/utils/endian.h b/src/utils/endian.h
index 8a4760b..3227c30 100644
--- a/src/utils/endian.h
+++ b/src/utils/endian.h
@@ -10,9 +10,9 @@
static inline bool endian_host_is_le(void)
{
- static uint32_t magic = 0x10000002;
+ const uint16_t test = 1;
- return (((uint8_t *) &magic)[0] == 0x02);
+ return ((const uint8_t *) &test)[0];
}
static inline uint32_t endian_swap(uint32_t val)