Skip to content

Commit feec9bd

Browse files
committed
x: Fix x_fopencookie() for some systems.
Some OSs require _GNU_SOURCE for cookie_io_functions_t, which made the previous approach of just using #define to access that struct unworkable. Instead define our own data types and use a proper wrapper.
1 parent 687bfce commit feec9bd

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/csnip/x.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,7 @@ int asprintf(char** strp, const char* fmt, ...);
7979
int csnip_x_asprintf_imp(char** strp, const char* format, ...);
8080

8181
/** Wrapper for system fopencookie() or funopen(). */
82-
#if defined(CSNIP_CONF__HAVE_FOPENCOOKIE)
83-
typedef cookie_io_functions_t csnip_x_cookie_io_functions_t;
84-
85-
FILE* csnip_x_fopencookie(void* __restrict__ cookie,
86-
const char* __restrict__ mode,
87-
csnip_x_cookie_io_functions_t funcs);
88-
#elif defined(CSNIP_CONF__HAVE_FUNOPEN)
82+
#if defined(CSNIP_CONF__HAVE_FOPENCOOKIE) || defined(CSNIP_CONF__HAVE_FUNOPEN)
8983
typedef csnip_x_ssize_t csnip_x_cookie_read_function_t(
9084
void* cookie,
9185
char* buf,

src/csnip/x/fopencookie.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ FILE* x_fopencookie(void* restrict cookie,
1212
const char* restrict mode,
1313
x_cookie_io_functions_t io_funcs)
1414
{
15-
return fopencookie(cookie, mode, io_funcs);
15+
cookie_io_functions_t io_funcs2 = {
16+
.read = io_funcs.read,
17+
.write = io_funcs.write,
18+
.seek = io_funcs.seek,
19+
.close = io_funcs.close,
20+
};
21+
return fopencookie(cookie, mode, io_funcs2);
1622
}
1723

1824
#elif defined(CSNIP_CONF__HAVE_FUNOPEN)

0 commit comments

Comments
 (0)