git-tar-tree: no more void pointer arithmetic
[git.git] / path.c
diff --git a/path.c b/path.c
index 334b2bd..194e0b5 100644 (file)
--- a/path.c
+++ b/path.c
@@ -83,14 +83,19 @@ int git_mkstemp(char *path, size_t len, const char *template)
 }
 
 
-char *safe_strncpy(char *dest, const char *src, size_t n)
+size_t safe_strncpy(char *dest, const char *src, size_t size)
 {
-       strncpy(dest, src, n);
-       dest[n - 1] = '\0';
+       size_t ret = strlen(src);
 
-       return dest;
+       if (size) {
+               size_t len = (ret >= size) ? size - 1 : ret;
+               memcpy(dest, src, len);
+               dest[len] = '\0';
+       }
+       return ret;
 }
 
+
 int validate_symref(const char *path)
 {
        struct stat st;
@@ -250,3 +255,26 @@ char *enter_repo(char *path, int strict)
 
        return NULL;
 }
+
+int adjust_shared_perm(const char *path)
+{
+       struct stat st;
+       int mode;
+
+       if (!shared_repository)
+               return 0;
+       if (lstat(path, &st) < 0)
+               return -1;
+       mode = st.st_mode;
+       if (mode & S_IRUSR)
+               mode |= S_IRGRP;
+       if (mode & S_IWUSR)
+               mode |= S_IWGRP;
+       if (mode & S_IXUSR)
+               mode |= S_IXGRP;
+       if (S_ISDIR(mode))
+               mode |= S_ISGID;
+       if (chmod(path, mode) < 0)
+               return -2;
+       return 0;
+}