X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=path.c;h=6e3df1849965be6a88fac89c007f9b5fe960f825;hb=4df0d7af6be27fe5b0ffef438ef0169607253f66;hp=4945f2abc50be08aa5e0cc2f9be562c74c47b9d7;hpb=1b9a9467f8b9a8da2fe58d10ae16779492aa7737;p=git.git diff --git a/path.c b/path.c index 4945f2abc..6e3df1849 100644 --- a/path.c +++ b/path.c @@ -314,7 +314,7 @@ const char *make_nonrelative_path(const char *path) { static char buf[PATH_MAX + 1]; - if (path[0] == '/') { + if (is_absolute_path(path)) { if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX) die ("Too long path: %.*s", 60, path); } else { @@ -330,6 +330,23 @@ const char *make_nonrelative_path(const char *path) /* We allow "recursive" symbolic links. Only within reason, though. */ #define MAXDEPTH 5 +const char *make_relative_path(const char *abs, const char *base) +{ + static char buf[PATH_MAX + 1]; + int baselen; + if (!base) + return abs; + baselen = strlen(base); + if (prefixcmp(abs, base)) + return abs; + if (abs[baselen] == '/') + baselen++; + else if (base[baselen - 1] != '/') + return abs; + strcpy(buf, abs + baselen); + return buf; +} + const char *make_absolute_path(const char *path) { static char bufs[2][PATH_MAX + 1], *buf = bufs[0], *next_buf = bufs[1];