real_path: create real_pathdup
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>
Brandon Williams committed
Dec 12, 2016 at 10:16 UTC
72417640769c91408d15cdbab3160bc494f49c7f
2 files changed
+14
abspath.c
+13
@@ -205,6 +205,19 @@ const char *real_path_if_valid(const char *path)
205
return strbuf_realpath(&realpath, path, 0);
206
}
207
208
+char *real_pathdup(const char *path)
209
+{
210
+ struct strbuf realpath = STRBUF_INIT;
211
+ char *retval = NULL;
212
+
213
+ if (strbuf_realpath(&realpath, path, 0))
214
+ retval = strbuf_detach(&realpath, NULL);
215
+
216
+ strbuf_release(&realpath);
217
+
218
+ return retval;
219
+}
220
+
221
/*
222
* Use this to get an absolute path from a relative one. If you want
223
* to resolve links, you should use real_path.
cache.h
+1
@@ -1068,6 +1068,7 @@ char *strbuf_realpath(struct strbuf *resolved, const char *path,
1068
int die_on_error);
1069
const char *real_path(const char *path);
1070
const char *real_path_if_valid(const char *path);
1071
+char *real_pathdup(const char *path);
1072
const char *absolute_path(const char *path);
1073
const char *remove_leading_path(const char *in, const char *prefix);
1074
const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);