summaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/util.c b/src/util.c
index 99564eb..4f08e20 100644
--- a/src/util.c
+++ b/src/util.c
@@ -42,36 +42,37 @@ strappend(char** dst, const char* suffix)
char*
strjoin(const char* first, ...)
{
- va_list args_list;
- va_start(args_list, first);
-
- char* result = vstrjoin(first, args_list);
-
- va_end(args_list);
-
- return result;
-}
-
-
-char*
-vstrjoin(const char* first, va_list args_list)
-{
- // FIXME: this is horribly, awfully, disgracefully slow.
- // so I'm lazy.
-
- const char* arg = NULL;
- char* result = strdup(first);
+ 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);
+
+ result = malloc(len + 1);
+ if (!result)
+ return NULL;
- while ((arg = va_arg(args_list, const char*)) != NULL)
- strappend(&result, arg);
-
- //va_end(args_list);
+ strcpy(result, first);
+ va_start(args, first);
+ while (1) {
+ const char* const s = va_arg(args, const char *);
+ if (s == NULL)
+ break;
+ strcat(result, s);
+ }
+ va_end(args);
return result;
}
-
/** Convert a URL to a local filesystem path (ie by chopping off the
* leading "file://".
*