cbortojson: don't hardcode OS support for fopencookie()

Instead of saying Linux (a.k.a. glibc) has it and Apple has funopen(),
use the fact that we've just detected them and inform the .c source
which one it was.

Fixes #306

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thiago Macieira
2026-02-05 14:16:39 -08:00
parent 7a3b6ab7bc
commit 0cd8b054a1
2 changed files with 11 additions and 6 deletions
+7 -2
View File
@@ -131,8 +131,13 @@ check_symbol_exists(funopen stdio.h HAVE_OPEN_FUNOPEN)
check_symbol_exists(fopencookie stdio.h HAVE_OPEN_FOPENCOOKIE)
if(NOT HAVE_OPEN_MEMSTREAM)
if (HAVE_OPEN_FUNOPEN AND HAVE_OPEN_FOPENCOOKIE)
message(STATUS "using open_memstream implementation")
if (HAVE_OPEN_FUNOPEN)
message(STATUS "implementing open_memstream using funopen()")
target_compile_definitions(tinycbor PRIVATE HAVE_OPEN_FUNOPEN)
target_sources(tinycbor PRIVATE src/open_memstream.c)
elseif (HAVE_OPEN_FOPENCOOKIE)
message(STATUS "implementing open_memstream using fopencookie()")
target_compile_definitions(tinycbor PRIVATE HAVE_OPEN_FOPENCOOKIE)
target_sources(tinycbor PRIVATE src/open_memstream.c)
else()
target_compile_definitions(tinycbor PRIVATE WITHOUT_OPEN_MEMSTREAM)
+4 -4
View File
@@ -35,10 +35,10 @@
#if defined(__unix__) || defined(__APPLE__)
# include <unistd.h>
#endif
#ifdef __APPLE__
#if defined(HAVE_OPEN_FUNOPEN)
typedef int RetType;
typedef int LenType;
#elif __linux__
#elif defined(HAVE_OPEN_FOPENCOOKIE)
typedef ssize_t RetType;
typedef size_t LenType;
#else
@@ -99,9 +99,9 @@ FILE *open_memstream(char **bufptr, size_t *lenptr)
*bufptr = NULL;
*lenptr = 0;
#ifdef __APPLE__
#if defined(HAVE_OPEN_FUNOPEN)
return funopen(b, NULL, write_to_buffer, NULL, close_buffer);
#elif __linux__
#elif defined(HAVE_OPEN_FOPENCOOKIE)
static const cookie_io_functions_t vtable = {
NULL,
write_to_buffer,