diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2022-11-26 14:10:43 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2022-11-26 14:10:43 +0000 |
commit | 010c5f5b3c3db4c07c19e706c9a70c886b614497 (patch) | |
tree | c29d7bd97106e6dc1c160bf21b73dfe1a69d28ec /src | |
parent | 429245749eeb99196d82d140af6522f962fc4601 (diff) | |
download | libparserutils-010c5f5b3c3db4c07c19e706c9a70c886b614497.tar.gz |
(buffer): Add parserutils_buffer_appendv()
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/buffer.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/utils/buffer.c b/src/utils/buffer.c index 5e0f58c..b568948 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; + 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 |