]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: chunk: new strncat function
authorBaptiste Assmann <bedis9@gmail.com>
Sat, 26 Mar 2016 13:12:50 +0000 (14:12 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 12 Sep 2016 17:51:59 +0000 (19:51 +0200)
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

index aac5282fb15046b0b1730896740a76220499fe0f..205523c382835bab237e3786309b28ef40a5ea19 100644 (file)
@@ -120,6 +120,19 @@ static inline int chunk_strcat(struct chunk *chk, const char *str)
        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