Thread (18 messages) flat view 18 messages, 5 authors, 2016-06-15

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

From: Jeff King <hidden>
Date: 2016-06-15 23:05:01

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help