Skip to content

Commit c8cee96

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 73646bf commit c8cee96

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

sequencer.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,13 +2668,11 @@ int check_todo_list(void)
26682668
static int rewrite_file(const char *path, const char *buf, size_t len)
26692669
{
26702670
int rc = 0;
2671-
int fd = open(path, O_WRONLY);
2671+
int fd = open(path, O_WRONLY | O_TRUNC);
26722672
if (fd < 0)
26732673
return error_errno(_("could not open '%s' for writing"), path);
26742674
if (write_in_full(fd, buf, len) < 0)
26752675
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);
26782676
close(fd);
26792677
return rc;
26802678
}

0 commit comments

Comments
 (0)