aboutsummaryrefslogtreecommitdiffstats
path: root/copy.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-02-26 00:14:22 -0800
committerJunio C Hamano <gitster@pobox.com>2008-02-26 00:14:22 -0800
commit2db511fdbdbe1c8aab80f4bc13f0df037bce8a33 (patch)
tree23350997a56089356ccaeaa923a783378c198bf6 /copy.c
parentgitweb: Better cutting matched string and its context (diff)
parentDocumentation/git-am.txt: Pass -r in the example invocation of rm -f .dotest (diff)
downloadgit-2db511fdbdbe1c8aab80f4bc13f0df037bce8a33.tar.gz
git-2db511fdbdbe1c8aab80f4bc13f0df037bce8a33.zip
Merge branch 'maint'
* maint: Documentation/git-am.txt: Pass -r in the example invocation of rm -f .dotest timezone_names[]: fixed the tz offset for New Zealand. filter-branch documentation: non-zero exit status in command abort the filter rev-parse: fix potential bus error with --parseopt option spec handling Use a single implementation and API for copy_file() Documentation/git-filter-branch: add a new msg-filter example Correct fast-export file mode strings to match fast-import standard
Diffstat (limited to 'copy.c')
-rw-r--r--copy.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/copy.c b/copy.c
index c225d1b0ff..afc4fbf414 100644
--- a/copy.c
+++ b/copy.c
@@ -34,3 +34,24 @@ int copy_fd(int ifd, int ofd)
close(ifd);
return 0;
}
+
+int copy_file(const char *dst, const char *src, int mode)
+{
+ int fdi, fdo, status;
+
+ mode = (mode & 0111) ? 0777 : 0666;
+ if ((fdi = open(src, O_RDONLY)) < 0)
+ return fdi;
+ if ((fdo = open(dst, O_WRONLY | O_CREAT | O_EXCL, mode)) < 0) {
+ close(fdi);
+ return fdo;
+ }
+ status = copy_fd(fdi, fdo);
+ if (close(fdo) != 0)
+ return error("%s: write error: %s", dst, strerror(errno));
+
+ if (!status && adjust_shared_perm(dst))
+ return -1;
+
+ return status;
+}