diff --git a/common/str.c b/common/str.c index 295f450804..d2c83fb2da 100644 --- a/common/str.c +++ b/common/str.c @@ -34,6 +34,8 @@ #include /* for strncasecmp() and strcasecmp() */ #endif +#include /* get the va_* routines */ + #include "nut_stdint.h" #include "str.h" @@ -627,3 +629,40 @@ int str_ends_with(const char *s, const char *suff) { return (slen >= sufflen) && (!memcmp(s + slen - sufflen, suff, sufflen)); } + +/* Based on code by "mmdemirbas" posted "Jul 9 '12 at 11:41" to forum page + * http://stackoverflow.com/questions/8465006/how-to-concatenate-2-strings-in-c + * This concatenates the given number of strings into one freshly allocated + * heap object; NOTE that it is up to the caller to free the object afterwards. + */ +char * str_concat(size_t count, ...) +{ + va_list ap; + size_t i, len, null_pos; + char* merged = NULL; + + /* Find required length to store merged string */ + va_start(ap, count); + len = 1; /* room for '\0' in the end */ + for(i=0 ; i