summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/utils.c29
-rw-r--r--common/utils.h1
2 files changed, 30 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;
diff --git a/common/utils.h b/common/utils.h
index 388a793..96e6ba2 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -37,6 +37,7 @@
char *stpcpy(char *s1, const char *s2);
#endif
char *string_concat(const char *str, ...);
+char *string_build_path(const char *elem, ...);
char *generate_uuid();
void buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length);