summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-05-01 17:52:38 -0400
committerJune McEnroe <june@causal.agency>2020-05-05 15:29:01 -0400
commite9dffbf429d2aa81c657ce89fc7f4acff328de48 (patch)
tree9c5a25803d06be80187cccf9f2a6e991aa549e31
parentEncode the path as Subject with Q (diff)
downloadnotemap-e9dffbf429d2aa81c657ce89fc7f4acff328de48.tar.gz
notemap-e9dffbf429d2aa81c657ce89fc7f4acff328de48.zip
Update compat.h for split read/write streams
-rw-r--r--compat.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/compat.h b/compat.h
index 6398510..ac7cc3f 100644
--- a/compat.h
+++ b/compat.h
@@ -67,7 +67,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;
 }
@@ -87,7 +87,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__ */