]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
utils: Add lxc_append_paths to join two paths.
authorChristian Seiler <christian@iwakd.de>
Wed, 11 Sep 2013 23:44:41 +0000 (01:44 +0200)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 12 Sep 2013 16:45:33 +0000 (11:45 -0500)
Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/utils.c
src/lxc/utils.h

index 2e665858f9639ebed064c49eb40a02f2db60ea31..78b234d98313ae316e55c9bab6131e87445ef044 100644 (file)
@@ -658,6 +658,25 @@ char **lxc_normalize_path(const char *path)
        return components;
 }
 
+char *lxc_append_paths(const char *first, const char *second)
+{
+       size_t len = strlen(first) + strlen(second) + 1;
+       const char *pattern = "%s%s";
+       char *result = NULL;
+
+       if (second[0] != '/') {
+               len += 1;
+               pattern = "%s/%s";
+       }
+
+       result = calloc(1, len);
+       if (!result)
+               return NULL;
+
+       snprintf(result, len, pattern, first, second);
+       return result;
+}
+
 bool lxc_string_in_list(const char *needle, const char *haystack, char _sep)
 {
        char *token, *str, *saveptr = NULL;
index 9776d188ce16e9a78499b93f5ba910edbac3a4e2..ba7cfb3efcc0adb69b30b1739390157564956e2b 100644 (file)
@@ -219,6 +219,7 @@ 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);
+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
  *       each other.