wrapper.c: add and use fopen_or_warn()
When fopen() returns NULL, it could be because the given path does not exist, but it could also be some other errors and the caller has to check. Add a wrapper so we don't have to repeat the same error check everywhere. 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:

committed by
Junio C Hamano

parent
11dc1fcb3f
commit
e9d983f116
7
attr.c
7
attr.c
@ -720,16 +720,13 @@ void git_attr_set_direction(enum git_attr_direction new_direction,
|
||||
|
||||
static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
|
||||
{
|
||||
FILE *fp = fopen(path, "r");
|
||||
FILE *fp = fopen_or_warn(path, "r");
|
||||
struct attr_stack *res;
|
||||
char buf[2048];
|
||||
int lineno = 0;
|
||||
|
||||
if (!fp) {
|
||||
if (errno != ENOENT && errno != ENOTDIR)
|
||||
warn_on_inaccessible(path);
|
||||
if (!fp)
|
||||
return NULL;
|
||||
}
|
||||
res = xcalloc(1, sizeof(*res));
|
||||
while (fgets(buf, sizeof(buf), fp)) {
|
||||
char *bufp = buf;
|
||||
|
Reference in New Issue
Block a user