From: Jeff King Date: Wed, 27 May 2015 21:55:07 GMT Subject: Re: [PATCH/WIP 2/8] wrapper: implement xfopen() Message-ID: <20150527215507.GD23259@peff.net> In-Reply-To: <1432733618-25629-3-git-send-email-pyokagan@gmail.com> On Wed, May 27, 2015 at 09:33:32PM +0800, Paul Tan wrote: > +/** > + * xfopen() is the same as fopen(), but it die()s if the fopen() fails. > + */ > +FILE *xfopen(const char *path, const char *mode) > +{ > + FILE *fp; > + > + assert(path); > + assert(mode); > + fp = fopen(path, mode); > + if (!fp) { > + if (*mode == 'w' || *mode == 'a') > + die_errno(_("could not open '%s' for writing"), path); This misses "r+". I don't think we use that in our code currently, but if we're going to introduce a wrapper like this, I think it makes sense to cover all cases. -Peff