From c3a8fe91c87a5a1ad54b6946ca390d9c0a37fa06 Mon Sep 17 00:00:00 2001 From: Patrick Winnertz Date: Sun, 11 Jan 2009 13:03:41 +0100 Subject: [PATCH] make the concat stuff a bit more variable and use stdarg.h for this --- mhl/string.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mhl/string.h b/mhl/string.h index 338e169f2..89a65a7c9 100644 --- a/mhl/string.h +++ b/mhl/string.h @@ -2,6 +2,7 @@ #define __MHL_STRING_H #include +#include #include "../mhl/memory.h" #define mhl_str_dup(str) ((str ? strdup(str) : strdup(""))) @@ -45,6 +46,26 @@ static inline void mhl_str_toupper(char* str) *str = toupper(*str); } +static inline char* mhl_str_concat(int n, ...) +{ + va_list ap; + char* buf = NULL; + char* ptr = buf; + + va_start(ap,n); + for (;n;n--) { + char *foo = va_arg(ap, char*); + int bar = strlen(foo); + int length += bar; + mhl_mem_realloc(buf, length); + memcpy(buf,foo,bar); + buf+bar; + } + va_end(ap); + *buf = 0; + return ptr; +} + /* concat 1 string to another and return as mhl_mem_alloc()'ed string */ static inline char* mhl_str_concat_1(const char* base, const char* one) {