X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=path.c;h=f788028a63dbd9b34563d2589697f4b5d65b8648;hb=edde7a8b5324d88f07fcb8204da313c19b4988fa;hp=7ef0d1b80d926d832816a587ddff721cb03130b3;hpb=3f81fc82743ccd4fd7157f1f1db41605eb018fb9;p=git.git diff --git a/path.c b/path.c index 7ef0d1b8..f788028a 100644 --- a/path.c +++ b/path.c @@ -41,10 +41,12 @@ char *mkpath(const char *fmt, ...) char *git_path(const char *fmt, ...) { - const char *git_dir = gitenv(GIT_DIR_ENVIRONMENT) ? : DEFAULT_GIT_DIR_ENVIRONMENT; + const char *git_dir; va_list args; unsigned len; + git_dir = getenv(GIT_DIR_ENVIRONMENT); + if (!git_dir) git_dir = DEFAULT_GIT_DIR_ENVIRONMENT; len = strlen(git_dir); if (len > PATH_MAX-100) return bad_path; @@ -68,8 +70,13 @@ int git_mkstemp(char *path, size_t len, const char *template) if ((env = getenv("TMPDIR")) == NULL) { strcpy(pch, "/tmp/"); len -= 5; - } else - len -= snprintf(pch, len, "%s/", env); + pch += 5; + } else { + size_t n = snprintf(pch, len, "%s/", env); + + len -= n; + pch += n; + } safe_strncpy(pch, template, len);