diff options
| author | 2014-10-22 20:48:00 +0200 | |
|---|---|---|
| committer | 2014-10-22 22:21:06 +0200 | |
| commit | 067c7c682614fbf0b7aeb13fd8b8ba7dc4fd8bf2 (patch) | |
| tree | 0330ac9d1dee43f6fbefd85c684d1dab3ad4220f /common/utils.c | |
| parent | 744ffa6da4839f4118b585f942985b3330ad3a32 (diff) | |
| download | libimobiledevice-067c7c682614fbf0b7aeb13fd8b8ba7dc4fd8bf2.tar.gz libimobiledevice-067c7c682614fbf0b7aeb13fd8b8ba7dc4fd8bf2.tar.bz2 | |
common: Share idevicebackup helper string_build_path() from utils
Diffstat (limited to 'common/utils.c')
| -rw-r--r-- | common/utils.c | 29 |
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 @@ | |||
| 29 | #include <time.h> | 29 | #include <time.h> |
| 30 | #include <sys/time.h> | 30 | #include <sys/time.h> |
| 31 | #include <inttypes.h> | 31 | #include <inttypes.h> |
| 32 | #include <ctype.h> | ||
| 32 | 33 | ||
| 33 | #include "utils.h" | 34 | #include "utils.h" |
| 34 | 35 | ||
| @@ -110,6 +111,34 @@ char *string_concat(const char *str, ...) | |||
| 110 | return result; | 111 | return result; |
| 111 | } | 112 | } |
| 112 | 113 | ||
| 114 | char *string_build_path(const char *elem, ...) | ||
| 115 | { | ||
| 116 | if (!elem) | ||
| 117 | return NULL; | ||
| 118 | va_list args; | ||
| 119 | int len = strlen(elem)+1; | ||
| 120 | va_start(args, elem); | ||
| 121 | char *arg = va_arg(args, char*); | ||
| 122 | while (arg) { | ||
| 123 | len += strlen(arg)+1; | ||
| 124 | arg = va_arg(args, char*); | ||
| 125 | } | ||
| 126 | va_end(args); | ||
| 127 | |||
| 128 | char* out = (char*)malloc(len); | ||
| 129 | strcpy(out, elem); | ||
| 130 | |||
| 131 | va_start(args, elem); | ||
| 132 | arg = va_arg(args, char*); | ||
| 133 | while (arg) { | ||
| 134 | strcat(out, "/"); | ||
| 135 | strcat(out, arg); | ||
| 136 | arg = va_arg(args, char*); | ||
| 137 | } | ||
| 138 | va_end(args); | ||
| 139 | return out; | ||
| 140 | } | ||
| 141 | |||
| 113 | static int get_rand(int min, int max) | 142 | static int get_rand(int min, int max) |
| 114 | { | 143 | { |
| 115 | int retval = (rand() % (max - min)) + min; | 144 | int retval = (rand() % (max - min)) + min; |
