]> asedeno.scripts.mit.edu Git - git.git/blobdiff - abspath.c
Merge branch 'jn/shortlog' into maint
[git.git] / abspath.c
index 4bee0ba1ec6fcf49e88b874f0a415f4220117c0a..c91a29cb298a3ad792ff8745f3e8e0eb28d71678 100644 (file)
--- a/abspath.c
+++ b/abspath.c
@@ -18,7 +18,7 @@ const char *make_absolute_path(const char *path)
 {
        static char bufs[2][PATH_MAX + 1], *buf = bufs[0], *next_buf = bufs[1];
        char cwd[1024] = "";
-       int buf_index = 1, len;
+       int buf_index = 1;
 
        int depth = MAXDEPTH;
        char *last_elem = NULL;
@@ -50,18 +50,19 @@ const char *make_absolute_path(const char *path)
                        die_errno ("Could not get current working directory");
 
                if (last_elem) {
-                       int len = strlen(buf);
+                       size_t len = strlen(buf);
                        if (len + strlen(last_elem) + 2 > PATH_MAX)
                                die ("Too long path name: '%s/%s'",
                                                buf, last_elem);
-                       buf[len] = '/';
-                       strcpy(buf + len + 1, last_elem);
+                       if (len && buf[len-1] != '/')
+                               buf[len++] = '/';
+                       strcpy(buf + len, last_elem);
                        free(last_elem);
                        last_elem = NULL;
                }
 
                if (!lstat(buf, &st) && S_ISLNK(st.st_mode)) {
-                       len = readlink(buf, next_buf, PATH_MAX);
+                       ssize_t len = readlink(buf, next_buf, PATH_MAX);
                        if (len < 0)
                                die_errno ("Invalid symlink '%s'", buf);
                        if (PATH_MAX <= len)