Skip to content

Commit

Permalink
utils: add lxc_deslashify
Browse files Browse the repository at this point in the history
Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
  • Loading branch information
Tycho Andersen authored and stgraber committed Sep 23, 2016
1 parent 336b642 commit 8c41d0f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lxc/utils.c
Expand Up @@ -716,6 +716,24 @@ char **lxc_normalize_path(const char *path)
return components;
}

bool lxc_deslashify(char *path)
{
char **parts = NULL, *path2;

parts = lxc_normalize_path(path);
if (!parts)
return false;

path2 = lxc_string_join("/", (const char **) parts, *path == '/');
lxc_free_array((void **) parts, free);
if (!path2)
return false;

strncpy(path, path2, strlen(path));
free(path2);
return true;
}

char *lxc_append_paths(const char *first, const char *second)
{
size_t len = strlen(first) + strlen(second) + 1;
Expand Down
2 changes: 2 additions & 0 deletions src/lxc/utils.h
Expand Up @@ -248,6 +248,8 @@ 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);
/* remove multiple slashes from the path, e.g. ///foo//bar -> /foo/bar */
extern bool lxc_deslashify(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
Expand Down

0 comments on commit 8c41d0f

Please sign in to comment.