From 7819c125c232a8b59a3b3c1fd9b54c10e3d25723 Mon Sep 17 00:00:00 2001 From: Baptiste Assmann Date: Sat, 26 Mar 2016 14:12:50 +0100 Subject: [PATCH] MINOR: chunk: new strncat function Purpose of this function is to append data to the end of a chunk when we know only the pointer to the beginning of the string and the string length. --- include/common/chunk.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/common/chunk.h b/include/common/chunk.h index aac5282fb1..205523c382 100644 --- a/include/common/chunk.h +++ b/include/common/chunk.h @@ -120,6 +120,19 @@ static inline int chunk_strcat(struct chunk *chk, const char *str) return 1; } +/* appends characters from str after . + * Returns 0 in case of failure. + */ +static inline int chunk_strncat(struct chunk *chk, const char *str, int nb) +{ + if (unlikely(chk->len < 0 || chk->len + nb >= chk->size)) + return 0; + + memcpy(chk->str + chk->len, str, nb); + chk->len += nb; + return 1; +} + /* Adds a trailing zero to the current chunk and returns the pointer to the * following part. The purpose is to be able to use a chunk as a series of * short independant strings with chunk_* functions, which do not need to be -- 2.47.3