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
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);
+
2 matches
Mail list logo