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>

René Scharfe committed Oct 31, 2017 at 10:58 UTC c8cee96e8a8de2e9c6f12bfac8295f1b9ee29112
1 file changed +1 -3
sequencer.c
+1 -3
@@ -2668,13 +2668,11 @@ leave_check:
2668 static int rewrite_file(const char *path, const char *buf, size_t len)
2669 {
2670 int rc = 0;
2671 - int fd = open(path, O_WRONLY);
2671 + int fd = open(path, O_WRONLY | O_TRUNC);
2672 if (fd < 0)
2673 return error_errno(_("could not open '%s' for writing"), path);
2674 if (write_in_full(fd, buf, len) < 0)
2675 rc = error_errno(_("could not write to '%s'"), path);
2676 - if (!rc && ftruncate(fd, len) < 0)
2677 - rc = error_errno(_("could not truncate '%s'"), path);
2676 close(fd);
2677 return rc;
2678 }