From 61e0111df98f1c98b48902634a0612210419e11f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 30 Jul 2018 21:29:34 +0200 Subject: [PATCH] path-util: port path_join() over to path_join_many() We should probably drop path_join() entirely in the long run (and then rename path_join_many() to it?), but for now let's make one a wrapper for the other. --- src/basic/path-util.c | 14 -------------- src/basic/path-util.h | 6 +++++- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/basic/path-util.c b/src/basic/path-util.c index ba31c858fd5..7d1e0f3f2da 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -481,20 +481,6 @@ bool path_equal_or_files_same(const char *a, const char *b, int flags) { return path_equal(a, b) || files_same(a, b, flags) > 0; } -char* path_join(const char *root, const char *path, const char *rest) { - assert(path); - - if (!isempty(root)) - return strjoin(root, endswith(root, "/") ? "" : "/", - path[0] == '/' ? path+1 : path, - rest ? (endswith(path, "/") ? "" : "/") : NULL, - rest && rest[0] == '/' ? rest+1 : rest); - else - return strjoin(path, - rest ? (endswith(path, "/") ? "" : "/") : NULL, - rest && rest[0] == '/' ? rest+1 : rest); -} - char* path_join_many_internal(const char *first, ...) { char *joined, *q; const char *p; diff --git a/src/basic/path-util.h b/src/basic/path-util.h index 868d64e17d0..8bda450ff3e 100644 --- a/src/basic/path-util.h +++ b/src/basic/path-util.h @@ -49,9 +49,13 @@ char* path_startswith(const char *path, const char *prefix) _pure_; int path_compare(const char *a, const char *b) _pure_; bool path_equal(const char *a, const char *b) _pure_; bool path_equal_or_files_same(const char *a, const char *b, int flags); -char* path_join(const char *root, const char *path, const char *rest); char* path_join_many_internal(const char *first, ...) _sentinel_; #define path_join_many(x, ...) path_join_many_internal(x, __VA_ARGS__, NULL) +static inline char* path_join(const char *root, const char *path, const char *rest) { + assert(path); + + return path_join_many(strempty(root), path, rest); +} char* path_simplify(char *path, bool kill_dots);