summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2014-10-22 20:48:00 +0200
committerGravatar Martin Szulecki2014-10-22 22:21:06 +0200
commit067c7c682614fbf0b7aeb13fd8b8ba7dc4fd8bf2 (patch)
tree0330ac9d1dee43f6fbefd85c684d1dab3ad4220f /common
parent744ffa6da4839f4118b585f942985b3330ad3a32 (diff)
downloadlibimobiledevice-067c7c682614fbf0b7aeb13fd8b8ba7dc4fd8bf2.tar.gz
libimobiledevice-067c7c682614fbf0b7aeb13fd8b8ba7dc4fd8bf2.tar.bz2
common: Share idevicebackup helper string_build_path() from utils
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);