wrapper.c: add and use warn_on_fopen_errors()

In many places, Git warns about an inaccessible file after a fopen()
failed. To discern these cases from other cases where we want to warn
about inaccessible files, introduce a new helper specifically to test
whether fopen() failed because the current user lacks the permission to
open file in question.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy
2017-05-03 17:16:49 +07:00
committed by Junio C Hamano
parent 8e178ec4d0
commit 11dc1fcb3f
5 changed files with 20 additions and 4 deletions

View File

@@ -418,6 +418,16 @@ FILE *fopen_for_writing(const char *path)
return ret;
}
int warn_on_fopen_errors(const char *path)
{
if (errno != ENOENT && errno != ENOTDIR) {
warn_on_inaccessible(path);
return -1;
}
return 0;
}
int xmkstemp(char *template)
{
int fd;