From cfd5c1cb6aca654a4441ae4d539b61182661d088 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Tue, 31 Mar 2026 16:20:51 +0200 Subject: [PATCH] fmemopen.c: portability fix around funopen() As noted in main.c, funopen() is used when fmemopen() is not available. Unfortunately, funopen() is not portable and its definition is not stable across Operating Systems (Darwin/macOS uses fpos_t while NetBSD uses off_t). This change fixes the build on NetBSD, where fpos_t is an opaque type and does not support arithmetic. To be fair, even macOS' manual page for funopen() mentions it erroneously assumes that fpos_t is an integral type, and invites to read fseek(3) for a discussion of this issue. Therefore, arguably the default should be off_t instead, but I did not want to possibly break functionality anywhere else. --- fmemopen.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fmemopen.c b/fmemopen.c index db88799..68d0aa0 100644 --- a/fmemopen.c +++ b/fmemopen.c @@ -20,6 +20,12 @@ #include #include +#if defined(__NetBSD__) +# define FPOS_T off_t +#else +# define FPOS_T fpos_t +#endif + struct fmem { size_t pos; size_t size; @@ -53,7 +59,7 @@ static int writefn(void *handler, const char *buf, int size) { return size; } -static fpos_t seekfn(void *handler, fpos_t offset, int whence) { +static FPOS_T seekfn(void *handler, FPOS_T offset, int whence) { size_t pos; fmem_t *mem = handler; @@ -83,7 +89,7 @@ static fpos_t seekfn(void *handler, fpos_t offset, int whence) { } mem->pos = pos; - return (fpos_t)pos; + return (FPOS_T)pos; } static int closefn(void *handler) {