# HG changeset patch # User Matti Hamalainen # Date 1508423824 -10800 # Node ID 6d29aaeab2909137d23454217404fd764485cf99 # Parent 1920a31927b2398bdcbf3886974fb168617c9aa3 Add new function th_strbuf_putsn(). diff -r 1920a31927b2 -r 6d29aaeab290 th_datastruct.c --- a/th_datastruct.c Thu Oct 19 17:18:29 2017 +0300 +++ b/th_datastruct.c Thu Oct 19 17:37:04 2017 +0300 @@ -568,6 +568,22 @@ } +BOOL th_strbuf_putsn(char **buf, size_t *bufsize, size_t *len, const char *str, const size_t slen) +{ + if (str == NULL) + return FALSE; + + if (!th_strbuf_grow(buf, bufsize, len, slen + 1)) + return FALSE; + + memcpy(*buf + *len, str, slen); + (*len) += slen; + *(buf + *len + slen) = 0; + + return TRUE; +} + + BOOL th_strbuf_puts(char **buf, size_t *bufsize, size_t *len, const char *str) { size_t slen; diff -r 1920a31927b2 -r 6d29aaeab290 th_datastruct.h --- a/th_datastruct.h Thu Oct 19 17:18:29 2017 +0300 +++ b/th_datastruct.h Thu Oct 19 17:37:04 2017 +0300 @@ -82,6 +82,7 @@ */ BOOL th_strbuf_grow(char **buf, size_t *bufsize, size_t *len, const size_t grow); BOOL th_strbuf_putch(char **buf, size_t *bufsize, size_t *len, const char ch); +BOOL th_strbuf_putsn(char **buf, size_t *bufsize, size_t *len, const char *str, const size_t slen); BOOL th_strbuf_puts(char **buf, size_t *bufsize, size_t *len, const char *str);