From 7ac6f0842a9dcd363f0a6ec0a2ae7ab14c3b2edc 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 a04454726..2be77126c 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -85,7 +85,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); } #endif // 0 -- 2.30.2