From 0c6ea3a4e2ac3f350dcb58e8f08bb74b030cd624 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Sat, 26 Jul 2014 14:47:31 -0400 Subject: Add utility function to append root to path --- src/shared/path-util.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/shared/path-util.c') diff --git a/src/shared/path-util.c b/src/shared/path-util.c index 6b13f0254e..5bc5012fe8 100644 --- a/src/shared/path-util.c +++ b/src/shared/path-util.c @@ -435,6 +435,22 @@ bool path_equal(const char *a, const char *b) { } } +char* path_join(const char *root, const char *path, const char *rest) { + assert(path); + + if (!isempty(root)) + return strjoin(root, "/", + path[0] == '/' ? path+1 : path, + rest ? "/" : NULL, + rest && rest[0] == '/' ? rest+1 : rest, + NULL); + else + return strjoin(path, + rest ? "/" : NULL, + rest && rest[0] == '/' ? rest+1 : rest, + NULL); +} + int path_is_mount_point(const char *t, bool allow_symlink) { union file_handle_union h = { -- cgit v1.2.3-54-g00ecf