summaryrefslogtreecommitdiffstats
path: root/common/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/utils.c')
-rw-r--r--common/utils.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/common/utils.c b/common/utils.c
index 4a45d95..7f66ec2 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -1,7 +1,10 @@
1/* 1/*
2 * utils.c 2 * utils.c
3 * Miscellaneous utilities for string manipulation 3 * Miscellaneous utilities for string manipulation,
4 * file I/O and plist helper.
4 * 5 *
6 * Copyright (c) 2014-2019 Nikias Bassen, All Rights Reserved.
7 * Copyright (c) 2013-2014 Martin Szulecki, All Rights Reserved.
5 * Copyright (c) 2013 Federico Mena Quintero 8 * Copyright (c) 2013 Federico Mena Quintero
6 * 9 *
7 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
@@ -111,6 +114,50 @@ char *string_concat(const char *str, ...)
111 return result; 114 return result;
112} 115}
113 116
117char *string_append(char* str, ...)
118{
119 size_t len = 0;
120 size_t slen;
121 va_list args;
122 char *s;
123 char *result;
124 char *dest;
125
126 /* Compute final length */
127
128 if (str) {
129 len = strlen(str);
130 }
131 slen = len;
132 len++; /* plus 1 for the null terminator */
133
134 va_start(args, str);
135 s = va_arg(args, char *);
136 while (s) {
137 len += strlen(s);
138 s = va_arg(args, char*);
139 }
140 va_end(args);
141
142 result = realloc(str, len);
143 if (!result)
144 return NULL; /* errno remains set */
145
146 dest = result + slen;
147
148 /* Concat additional strings */
149
150 va_start(args, str);
151 s = va_arg(args, char *);
152 while (s) {
153 dest = stpcpy(dest, s);
154 s = va_arg(args, char *);
155 }
156 va_end(args);
157
158 return result;
159}
160
114char *string_build_path(const char *elem, ...) 161char *string_build_path(const char *elem, ...)
115{ 162{
116 if (!elem) 163 if (!elem)