[PATCH/WIP 2/8] wrapper: implement xfopen()

2015-05-27 Thread Paul Tan
A common usage pattern of fopen() is to check if it succeeded, and die() if it failed: FILE *fp = fopen(path, w); if (!fp) die_errno(_(could not open '%s' for writing), path); Implement a wrapper function xfopen() for the above, so that we can save a few lines of

Re: [PATCH/WIP 2/8] wrapper: implement xfopen()

2015-05-27 Thread Jeff King
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); +