From cddd2ce1069c4d84179ce606e830db98abc50609 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 Jan 2018 11:15:00 +0100 Subject: [PATCH] path-util: don't add extra "/" when prefix already is suffixed by slash No need to insert duplicate "/" if we can avoid it. This is particularly relevant if the prefix passed in is the root directory. --- src/basic/path-util.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/basic/path-util.c b/src/basic/path-util.c index b877bdc1cbe..f5f506ccf57 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -84,7 +84,10 @@ char *path_make_absolute(const char *p, const char *prefix) { if (path_is_absolute(p) || isempty(prefix)) return strdup(p); - return strjoin(prefix, "/", p); + if (endswith(prefix, "/")) + return strjoin(prefix, p); + else + return strjoin(prefix, "/", p); } int path_make_absolute_cwd(const char *p, char **ret) {