use xopen() to handle fatal open(2) failures

Add and apply a semantic patch for using xopen() instead of calling
open(2) and die() or die_errno() explicitly.  This makes the error
messages more consistent and shortens the code.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe
2021-08-25 22:16:46 +02:00
committed by Junio C Hamano
parent a7439d0f9d
commit 66e905b7dd
15 changed files with 33 additions and 52 deletions

View File

@ -95,9 +95,7 @@ static int create_file(const char *path)
{
int fd;
path = get_mtime_path(path);
fd = open(path, O_CREAT | O_RDWR, 0644);
if (fd < 0)
die_errno(_("failed to create file %s"), path);
fd = xopen(path, O_CREAT | O_RDWR, 0644);
return fd;
}