X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=path.c;h=047fdb0a1fe8151f5f275ca5333365df786a8abd;hb=0ded47581aa6097f1a685443d3c2fc0cebaf8c3c;hp=8a0a6741fd664f98f2883348c0a755d60616035b;hpb=2c8f8b19d4f293edd78885880ed1a6166395ffdd;p=git.git diff --git a/path.c b/path.c index 8a0a6741f..047fdb0a1 100644 --- a/path.c +++ b/path.c @@ -139,6 +139,22 @@ int git_mkstemp(char *path, size_t len, const char *template) return mkstemp(path); } +/* git_mkstemps() - create tmp file with suffix honoring TMPDIR variable. */ +int git_mkstemps(char *path, size_t len, const char *template, int suffix_len) +{ + const char *tmp; + size_t n; + + tmp = getenv("TMPDIR"); + if (!tmp) + tmp = "/tmp"; + n = snprintf(path, len, "%s/%s", tmp, template); + if (len <= n) { + errno = ENAMETOOLONG; + return -1; + } + return mkstemps(path, suffix_len); +} int validate_headref(const char *path) {