diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-28 14:05:16 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-28 14:05:16 -0400 |
| commit | dbe89a3b899f70abf2d8c858df00c1aa7d55d7bb (patch) | |
| tree | 34cce2bf382bac5bdba3356666a5f86f448e9545 /src | |
| parent | af286f7e6ff3709f4be8295cf7b4f255e9f896ef (diff) | |
Add conditional compilation for fopencookie vs fwopen
Diffstat (limited to 'src')
| -rw-r--r-- | src/stdlib/print.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/stdlib/print.c b/src/stdlib/print.c index 023af986..fcbc0cb4 100644 --- a/src/stdlib/print.c +++ b/src/stdlib/print.c @@ -51,6 +51,12 @@ int _print_quoted(FILE *f, quoted_t quoted) return printed; } +#if defined(__GLIBC__) && defined(_GNU_SOURCE) + #define HAS_FOPENCOOKIE 1 +#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) + #define HAS_FUNOPEN 1 +#endif + static ssize_t _gc_stream_write(void *cookie, const char *buf, size_t size) { gc_stream_t *stream = (gc_stream_t *)cookie; if (stream->position + size + 1 > *stream->size) @@ -69,8 +75,17 @@ FILE *gc_memory_stream(char **buf, size_t *size) { *stream->buffer = GC_MALLOC_ATOMIC(*stream->size); (*stream->buffer)[0] = '\0'; stream->position = 0; +#ifdef HAS_FOPENCOOKIE + cookie_io_functions_t functions = {.write = _gc_stream_write}; return fopencookie(stream, "w", functions); +#else +#ifdef HAS_FUNOPEN + return fwopen(stream, _gc_stream_write); +#else +#error "This platform does not support fopencookie() or funopen()!" +#endif +#endif } // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 |
