Browse Source

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>
maint
Brandon Williams 8 years ago committed by Junio C Hamano
parent
commit
7241764076
  1. 13
      abspath.c
  2. 1
      cache.h

13
abspath.c

@ -205,6 +205,19 @@ const char *real_path_if_valid(const char *path) @@ -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.

1
cache.h

@ -1068,6 +1068,7 @@ char *strbuf_realpath(struct strbuf *resolved, const char *path, @@ -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);

Loading…
Cancel
Save