X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=abspath.c;h=3005aedde68b48297aacd2082797b2e2f249b094;hb=v1.7.4.1-296-gb57fb80;hp=91ca00f05f7d648fa801a36b78c749f9d691ba43;hpb=f80b6de4eca9c4c4abfe9407736311de27726e53;p=git.git diff --git a/abspath.c b/abspath.c index 91ca00f05..3005aedde 100644 --- a/abspath.c +++ b/abspath.c @@ -14,7 +14,14 @@ int is_directory(const char *path) /* We allow "recursive" symbolic links. Only within reason, though. */ #define MAXDEPTH 5 -const char *make_absolute_path(const char *path) +/* + * Use this to get the real path, i.e. resolve links. If you want an + * absolute path but don't mind links, use absolute_path. + * + * If path is our buffer, then return path, as it's already what the + * user wants. + */ +const char *real_path(const char *path) { static char bufs[2][PATH_MAX + 1], *buf = bufs[0], *next_buf = bufs[1]; char cwd[1024] = ""; @@ -24,6 +31,10 @@ const char *make_absolute_path(const char *path) char *last_elem = NULL; struct stat st; + /* We've already done it */ + if (path == buf || path == next_buf) + return path; + if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX) die ("Too long path: %.*s", 60, path); @@ -100,7 +111,14 @@ static const char *get_pwd_cwd(void) return cwd; } -const char *make_nonrelative_path(const char *path) +/* + * Use this to get an absolute path from a relative one. If you want + * to resolve links, you should use real_path. + * + * If the path is already absolute, then return path. As the user is + * never meant to free the return value, we're safe. + */ +const char *absolute_path(const char *path) { static char buf[PATH_MAX + 1];