summary refs log tree commit diff
path: root/compat.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-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__ */