make the concat stuff a bit more variable and use stdarg.h for this

This commit is contained in:
Patrick Winnertz 2009-01-11 13:03:41 +01:00
parent e2acd70013
commit c3a8fe91c8

View File

@ -2,6 +2,7 @@
#define __MHL_STRING_H
#include <ctype.h>
#include <stdarg.h>
#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)
{