From e9dffbf429d2aa81c657ce89fc7f4acff328de48 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 1 May 2020 17:52:38 -0400 Subject: Update compat.h for split read/write streams --- compat.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'compat.h') 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__ */ -- cgit 1.4.1