diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | include/parserutils/utils/buffer.h | 2 | ||||
-rw-r--r-- | src/utils/buffer.c | 33 | ||||
-rw-r--r-- | src/utils/endian.h | 4 |
5 files changed, 39 insertions, 3 deletions
@@ -1,3 +1,4 @@ build-* Makefile.config.override +src/charset/aliases.inc @@ -6,7 +6,7 @@ # Component settings COMPONENT := parserutils -COMPONENT_VERSION := 0.2.4 +COMPONENT_VERSION := 0.2.5 # Default to a static library COMPONENT_TYPE ?= lib-static diff --git a/include/parserutils/utils/buffer.h b/include/parserutils/utils/buffer.h index 5f8f696..5b8b793 100644 --- a/include/parserutils/utils/buffer.h +++ b/include/parserutils/utils/buffer.h @@ -30,6 +30,8 @@ parserutils_error parserutils_buffer_destroy(parserutils_buffer *buffer); parserutils_error parserutils_buffer_append(parserutils_buffer *buffer, const uint8_t *data, size_t len); +parserutils_error parserutils_buffer_appendv(parserutils_buffer *buffer, + size_t count, ...); parserutils_error parserutils_buffer_insert(parserutils_buffer *buffer, size_t offset, const uint8_t *data, size_t len); parserutils_error parserutils_buffer_discard(parserutils_buffer *buffer, 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) |