Mercurial > hg > th-libs
changeset 445:6d29aaeab290
Add new function th_strbuf_putsn().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 19 Oct 2017 17:37:04 +0300 |
parents | 1920a31927b2 |
children | e0cead622dce |
files | th_datastruct.c th_datastruct.h |
diffstat | 2 files changed, 17 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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);