From: Tycho Andersen Date: Wed, 14 Sep 2016 14:46:47 +0000 (+0000) Subject: utils: add lxc_deslashify X-Git-Tag: lxc-2.1.0~322^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aeb3682ff631e6afaa9c0b5d8a32654e8ebd2771;p=thirdparty%2Flxc.git utils: add lxc_deslashify Signed-off-by: Tycho Andersen --- diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 27362daa3..9a6ef4b37 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -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; diff --git a/src/lxc/utils.h b/src/lxc/utils.h index 98b4e1374..c2eef507b 100644 --- a/src/lxc/utils.h +++ b/src/lxc/utils.h @@ -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