real_path: create real_pathdup
authorBrandon Williams <bmwill@google.com>
Mon, 12 Dec 2016 18:16:54 +0000 (10:16 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 Dec 2016 23:22:32 +0000 (15:22 -0800)
Create real_pathdup which returns a caller owned string of the resolved
realpath based on the provide path.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
abspath.c
cache.h
index 8c6c76b05e397c96811ea213177b1314c74f7c7d..79ee3108678c97e1dade83e4ff4943edf3d3da9e 100644 (file)
--- a/abspath.c
+++ b/abspath.c
@@ -205,6 +205,19 @@ const char *real_path_if_valid(const char *path)
        return strbuf_realpath(&realpath, path, 0);
 }
 
+char *real_pathdup(const char *path)
+{
+       struct strbuf realpath = STRBUF_INIT;
+       char *retval = NULL;
+
+       if (strbuf_realpath(&realpath, path, 0))
+               retval = strbuf_detach(&realpath, NULL);
+
+       strbuf_release(&realpath);
+
+       return retval;
+}
+
 /*
  * Use this to get an absolute path from a relative one. If you want
  * to resolve links, you should use real_path.
diff --git a/cache.h b/cache.h
index 7a81294036965b0df5c6bddd125a85a14e231840..e12a5d9129b9382a7c2155f740672dce9d0a3280 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1068,6 +1068,7 @@ char *strbuf_realpath(struct strbuf *resolved, const char *path,
                      int die_on_error);
 const char *real_path(const char *path);
 const char *real_path_if_valid(const char *path);
+char *real_pathdup(const char *path);
 const char *absolute_path(const char *path);
 const char *remove_leading_path(const char *in, const char *prefix);
 const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);