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.
diff --git a/include/common/chunk.h b/include/common/chunk.h
index aac5282..205523c 100644
--- a/include/common/chunk.h
+++ b/include/common/chunk.h
@@ -120,6 +120,19 @@
return 1;
}
+/* appends <nb> characters from str after <chk>.
+ * 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