X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=abspath.c;h=91ca00f05f7d648fa801a36b78c749f9d691ba43;hb=b3f66fd3e3abeb9183f33f023727e3a53868849d;hp=c91a29cb298a3ad792ff8745f3e8e0eb28d71678;hpb=d249515f297d47df6d79167b988eaa7db0981178;p=git.git diff --git a/abspath.c b/abspath.c index c91a29cb2..91ca00f05 100644 --- a/abspath.c +++ b/abspath.c @@ -108,10 +108,14 @@ const char *make_nonrelative_path(const char *path) if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX) die("Too long path: %.*s", 60, path); } else { + size_t len; + const char *fmt; const char *cwd = get_pwd_cwd(); if (!cwd) die_errno("Cannot determine the current working directory"); - if (snprintf(buf, PATH_MAX, "%s/%s", cwd, path) >= PATH_MAX) + len = strlen(cwd); + fmt = (len > 0 && is_dir_sep(cwd[len-1])) ? "%s%s" : "%s/%s"; + if (snprintf(buf, PATH_MAX, fmt, cwd, path) >= PATH_MAX) die("Too long path: %.*s", 60, path); } return buf;