diff options
Diffstat (limited to 'compat.h')
-rw-r--r-- | compat.h | 5 |
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__ */ |