summaryrefslogtreecommitdiffstats
path: root/common/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/utils.c')
-rw-r--r--common/utils.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/common/utils.c b/common/utils.c
index 4465490..fb6822f 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -29,6 +29,7 @@
#include <time.h>
#include <sys/time.h>
#include <inttypes.h>
+#include <ctype.h>
#include "utils.h"
@@ -110,6 +111,34 @@ char *string_concat(const char *str, ...)
return result;
}
+char *string_build_path(const char *elem, ...)
+{
+ if (!elem)
+ return NULL;
+ va_list args;
+ int len = strlen(elem)+1;
+ va_start(args, elem);
+ char *arg = va_arg(args, char*);
+ while (arg) {
+ len += strlen(arg)+1;
+ arg = va_arg(args, char*);
+ }
+ va_end(args);
+
+ char* out = (char*)malloc(len);
+ strcpy(out, elem);
+
+ va_start(args, elem);
+ arg = va_arg(args, char*);
+ while (arg) {
+ strcat(out, "/");
+ strcat(out, arg);
+ arg = va_arg(args, char*);
+ }
+ va_end(args);
+ return out;
+}
+
static int get_rand(int min, int max)
{
int retval = (rand() % (max - min)) + min;