summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-06-03 22:30:45 +0000
committerDavid Robillard <d@drobilla.net>2009-06-03 22:30:45 +0000
commit8d24600968fe0dc2306e3f92e598ffc0d9d4d6af (patch)
tree4abf40d24a35f12b18b55d2dfc34ae18aa9690a6 /src
parentc68a20ee1fca5d6c076d0f754653f48f508279d0 (diff)
downloadlilv-8d24600968fe0dc2306e3f92e598ffc0d9d4d6af.tar.gz
lilv-8d24600968fe0dc2306e3f92e598ffc0d9d4d6af.tar.bz2
lilv-8d24600968fe0dc2306e3f92e598ffc0d9d4d6af.zip
Single-pass slv2_strjoin.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2088 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-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;
}