]> asedeno.scripts.mit.edu Git - git.git/blobdiff - path.c
add_file_to_index: skip rehashing if the cached stat already matches
[git.git] / path.c
diff --git a/path.c b/path.c
index 6395cf23098841c16d993ae7e86b2d8dcff01cd7..dfff41f62668709e80cc54f816394303e8f6cefc 100644 (file)
--- a/path.c
+++ b/path.c
@@ -71,21 +71,17 @@ char *git_path(const char *fmt, ...)
 /* 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;
+       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;
        }
-
-       strlcpy(pch, template, len);
-
        return mkstemp(path);
 }
 
@@ -252,7 +248,7 @@ char *enter_repo(char *path, int strict)
 
        if (access("objects", X_OK) == 0 && access("refs", X_OK) == 0 &&
            validate_headref("HEAD") == 0) {
-               setenv("GIT_DIR", ".", 1);
+               setenv(GIT_DIR_ENVIRONMENT, ".", 1);
                check_repository_format();
                return path;
        }