diff options
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; |
