char *git_path(const char *fmt, ...)
{
- const char *git_dir = gitenv(GIT_DIR_ENVIRONMENT) ? : DEFAULT_GIT_DIR_ENVIRONMENT;
+ const char *git_dir = get_git_dir();
va_list args;
unsigned len;
return bad_path;
return cleanup_path(pathname);
}
+
+
+/* git_mkstemp() - create tmp file honoring TMPDIR variable */
+int git_mkstemp(char *path, size_t len, const char *template)
+{
+ char *env, *pch = path;
+
+ if ((env = getenv("TMPDIR")) == NULL) {
+ strcpy(pch, "/tmp/");
+ len -= 5;
+ pch += 5;
+ } else {
+ size_t n = snprintf(pch, len, "%s/", env);
+
+ len -= n;
+ pch += n;
+ }
+
+ safe_strncpy(pch, template, len);
+
+ return mkstemp(path);
+}
+
+
+char *safe_strncpy(char *dest, const char *src, size_t n)
+{
+ strncpy(dest, src, n);
+ dest[n - 1] = '\0';
+
+ return dest;
+}