summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-10-31 10:58:16 +0100
committerJunio C Hamano <gitster@pobox.com>2017-11-01 10:53:19 +0900
commitc8cee96e8a8de2e9c6f12bfac8295f1b9ee29112 (patch)
tree89cdb08974add4b354fe975d2bfe571ca010a846
parent73646bfdcb38114a4d9242a02fc180a9877e01bf (diff)
downloadgit-c8cee96e8a8de2e9c6f12bfac8295f1b9ee29112.tar.gz
sequencer: use O_TRUNC to truncate files
Cut off any previous content of the file to be rewritten by passing the flag O_TRUNC to open(2) instead of calling ftruncate(2) at the end. That's easier and shorter. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--sequencer.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/sequencer.c b/sequencer.c
index 17360eb38a..f93b60f615 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2668,13 +2668,11 @@ leave_check:
static int rewrite_file(const char *path, const char *buf, size_t len)
{
int rc = 0;
- int fd = open(path, O_WRONLY);
+ int fd = open(path, O_WRONLY | O_TRUNC);
if (fd < 0)
return error_errno(_("could not open '%s' for writing"), path);
if (write_in_full(fd, buf, len) < 0)
rc = error_errno(_("could not write to '%s'"), path);
- if (!rc && ftruncate(fd, len) < 0)
- rc = error_errno(_("could not truncate '%s'"), path);
close(fd);
return rc;
}