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

@ -53,9 +53,7 @@ static void hash_object(const char *path, const char *type, const char *vpath,
unsigned flags, int literally)
{
int fd;
fd = open(path, O_RDONLY);
if (fd < 0)
die_errno("Cannot open '%s'", path);
fd = xopen(path, O_RDONLY);
hash_fd(fd, type, vpath, flags, literally);
}