Skip to content

Commit

Permalink
utils: Add lxc_append_paths to join two paths.
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
  • Loading branch information
chris-se authored and hallyn committed Sep 12, 2013
1 parent 4bee03b commit 24b5148
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/lxc/utils.c
Expand Up @@ -658,6 +658,25 @@ char **lxc_normalize_path(const char *path)
return components;
}

char *lxc_append_paths(const char *first, const char *second)
{
size_t len = strlen(first) + strlen(second) + 1;
const char *pattern = "%s%s";
char *result = NULL;

if (second[0] != '/') {
len += 1;
pattern = "%s/%s";
}

result = calloc(1, len);
if (!result)
return NULL;

snprintf(result, len, pattern, first, second);
return result;
}

bool lxc_string_in_list(const char *needle, const char *haystack, char _sep)
{
char *token, *str, *saveptr = NULL;
Expand Down
1 change: 1 addition & 0 deletions src/lxc/utils.h
Expand Up @@ -219,6 +219,7 @@ extern char *lxc_string_join(const char *sep, const char **parts, bool use_as_pr
* foo//bar -> { foo, bar, NULL }
*/
extern char **lxc_normalize_path(const char *path);
extern char *lxc_append_paths(const char *first, const char *second);
/* Note: the following two functions use strtok(), so they will never
* consider an empty element, even if two delimiters are next to
* each other.
Expand Down

0 comments on commit 24b5148

Please sign in to comment.