diff --git a/src/libckpool.c b/src/libckpool.c index 9d21c482..f4b7a1f8 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -395,6 +395,33 @@ void align_len(size_t *len) *len += 4 - (*len % 4); } +void realloc_strcat(char **ptr, const char *s) +{ + size_t old, new, len; + char *ofs; + + if (unlikely(!*s)) { + LOGWARNING("Passed empty pointer to realloc_strcat"); + return; + } + new = strlen(s); + if (unlikely(!new)) { + LOGWARNING("Passed empty string to realloc_strcat"); + return; + } + if (!*ptr) + old = 0; + else + old = strlen(*ptr); + len = old + new + 1; + align_len(&len); + *ptr = realloc(*ptr, len); + if (!*ptr) + quit(1, "Failed to realloc ptr of size %d in realloc_strcat", (int)len); + ofs = *ptr + old; + sprintf(ofs, "%s", s); +} + /* Adequate size s==len*2 + 1 must be alloced to use this variant */ void __bin2hex(uchar *s, const uchar *p, size_t len) { diff --git a/src/libckpool.h b/src/libckpool.h index dbdb3bfc..3ad47866 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -140,6 +140,7 @@ void block_socket(int fd); int connect_socket(char *url, char *port); void align_len(size_t *len); +void realloc_strcat(char **ptr, const char *s); void __bin2hex(uchar *s, const uchar *p, size_t len); void *bin2hex(const uchar *p, size_t len); bool hex2bin(uchar *p, const uchar *hexstr, size_t len);