From e9d983f116c7de43f40a49aae60ebfe107f153ec Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Wed, 3 May 2017 17:16:50 +0700 Subject: wrapper.c: add and use fopen_or_warn() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- wrapper.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'wrapper.c') diff --git a/wrapper.c b/wrapper.c index 20c25e7e65..6e513c904a 100644 --- a/wrapper.c +++ b/wrapper.c @@ -428,6 +428,17 @@ int warn_on_fopen_errors(const char *path) return 0; } +FILE *fopen_or_warn(const char *path, const char *mode) +{ + FILE *fp = fopen(path, mode); + + if (fp) + return fp; + + warn_on_fopen_errors(path); + return NULL; +} + int xmkstemp(char *template) { int fd; -- cgit v1.3