Skip to content

Commit 7241764

Browse files
bmwillgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a1ae484 commit 7241764

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

abspath.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ const char *real_path_if_valid(const char *path)
205205
return strbuf_realpath(&realpath, path, 0);
206206
}
207207

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+
208221
/*
209222
* Use this to get an absolute path from a relative one. If you want
210223
* to resolve links, you should use real_path.

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,7 @@ char *strbuf_realpath(struct strbuf *resolved, const char *path,
10681068
int die_on_error);
10691069
const char *real_path(const char *path);
10701070
const char *real_path_if_valid(const char *path);
1071+
char *real_pathdup(const char *path);
10711072
const char *absolute_path(const char *path);
10721073
const char *remove_leading_path(const char *in, const char *prefix);
10731074
const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);

0 commit comments

Comments
 (0)