summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/util.c28
1 files changed, 10 insertions, 18 deletions
diff --git a/src/util.c b/src/util.c
index a58b5d1..5fa10c8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -28,35 +28,27 @@
char*
slv2_strjoin(const char* first, ...)
{
- /* FIXME: This is, in fact, as stupid as it looks */
-
size_t len = strlen(first);
- char* result = NULL;
- va_list args;
-
- va_start(args, first);
- while (1) {
- const char* const s = va_arg(args, const char *);
- if (s == NULL)
- break;
- len += strlen(s);
- }
- va_end(args);
+ char* result = malloc(len + 1);
- result = malloc(len + 1);
- if (!result)
- return NULL;
+ memcpy(result, first, len);
- strcpy(result, first);
+ va_list args;
va_start(args, first);
while (1) {
const char* const s = va_arg(args, const char *);
if (s == NULL)
break;
- strcat(result, s);
+
+ const size_t this_len = strlen(s);
+ result = realloc(result, len + this_len + 1);
+ memcpy(result + len, s, this_len);
+ len += this_len;
}
va_end(args);
+ result[len] = '\0';
+
return result;
}