Skip to content

Commit 88465e6

Browse files
khorbentimg236
authored andcommitted
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.
1 parent 0ecdc0a commit 88465e6

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

fmemopen.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#include <string.h>
2121
#include <sys/mman.h>
2222

23+
#if defined(__NetBSD__)
24+
# define FPOS_T off_t
25+
#else
26+
# define FPOS_T fpos_t
27+
#endif
28+
2329
struct fmem {
2430
size_t pos;
2531
size_t size;
@@ -53,7 +59,7 @@ static int writefn(void *handler, const char *buf, int size) {
5359
return size;
5460
}
5561

56-
static fpos_t seekfn(void *handler, fpos_t offset, int whence) {
62+
static FPOS_T seekfn(void *handler, FPOS_T offset, int whence) {
5763
size_t pos;
5864
fmem_t *mem = handler;
5965

@@ -83,7 +89,7 @@ static fpos_t seekfn(void *handler, fpos_t offset, int whence) {
8389
}
8490

8591
mem->pos = pos;
86-
return (fpos_t)pos;
92+
return (FPOS_T)pos;
8793
}
8894

8995
static int closefn(void *handler) {

0 commit comments

Comments
 (0)