project_files/frontlib/util/util.c
changeset 7269 5b0aeef8ba2a
parent 7230 240620f46dd7
child 7275 15f722e0b96f
--- a/project_files/frontlib/util/util.c	Tue Jun 19 21:20:08 2012 +0200
+++ b/project_files/frontlib/util/util.c	Thu Jun 21 21:32:12 2012 +0200
@@ -36,6 +36,28 @@
 	return result;
 }
 
+char *flib_join(char **parts, int partCount, const char *delimiter) {
+	size_t totalSize = 1;
+	size_t delimLen = strlen(delimiter);
+	for(int i=0; i<partCount; i++) {
+		totalSize += strlen(parts[i]) + delimLen;
+	}
+
+	char *result = flib_malloc(totalSize);
+	if(result) {
+		size_t outpos = 0;
+		for(int i=0; i<partCount; i++) {
+			if(i>0) {
+				strcpy(result+outpos, delimiter);
+				outpos += delimLen;
+			}
+			strcpy(result+outpos, parts[i]);
+			outpos += strlen(parts[i]);
+		}
+	}
+	return result;
+}
+
 char *flib_strdupnull(const char *str) {
 	if(!str) {
 		return NULL;