summary refs log tree commit diff
path: root/compat.h
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-05-01 17:52:38 -0400
committerJune McEnroe <june@causal.agency>2020-05-01 17:52:38 -0400
commit187b2e8acf39cc46a91f6e91e978774cf0f824e4 (patch)
tree5bfbd405d71e38c535c4ea79a23fda76a568b5d0 /compat.h
parentSimplify imbox code and remove text/plain restriction (diff)
downloadimbox-187b2e8acf39cc46a91f6e91e978774cf0f824e4.tar.gz
imbox-187b2e8acf39cc46a91f6e91e978774cf0f824e4.zip
Update compat.h for split read/write streams
Diffstat (limited to 'compat.h')
-rw-r--r--compat.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/compat.h b/compat.h
index 8110e24..77648ac 100644
--- a/compat.h
+++ b/compat.h
@@ -64,7 +64,7 @@ _cookie_write(void *cookie, const char *buf, size_t size) {
 static inline int
 _cookie_close(void *cookie) {
 	struct _funopen *funopen = cookie;
-	int ret = funopen->closefn(funopen->cookie);
+	int ret = (funopen->closefn ? funopen->closefn(funopen->cookie) : 0);
 	free(cookie);
 	return ret;
 }
@@ -84,7 +84,8 @@ funopen(
 	if (!funopen) return NULL;
 	assert(!seekfn);
 	*funopen = (struct _funopen) { (void *)cookie, readfn, writefn, closefn };
-	return fopencookie(funopen, "a+", _cookie_fns);
+	const char *mode = (!readfn ? "w" : !writefn ? "r" : "r+");
+	return fopencookie(funopen, mode, _cookie_fns);
 }
 
 #endif /* __linux__ */