Skip to content

Commit 0cd8b05

Browse files
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>
1 parent 7a3b6ab commit 0cd8b05

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,13 @@ check_symbol_exists(funopen stdio.h HAVE_OPEN_FUNOPEN)
131131
check_symbol_exists(fopencookie stdio.h HAVE_OPEN_FOPENCOOKIE)
132132

133133
if(NOT HAVE_OPEN_MEMSTREAM)
134-
if (HAVE_OPEN_FUNOPEN AND HAVE_OPEN_FOPENCOOKIE)
135-
message(STATUS "using open_memstream implementation")
134+
if (HAVE_OPEN_FUNOPEN)
135+
message(STATUS "implementing open_memstream using funopen()")
136+
target_compile_definitions(tinycbor PRIVATE HAVE_OPEN_FUNOPEN)
137+
target_sources(tinycbor PRIVATE src/open_memstream.c)
138+
elseif (HAVE_OPEN_FOPENCOOKIE)
139+
message(STATUS "implementing open_memstream using fopencookie()")
140+
target_compile_definitions(tinycbor PRIVATE HAVE_OPEN_FOPENCOOKIE)
136141
target_sources(tinycbor PRIVATE src/open_memstream.c)
137142
else()
138143
target_compile_definitions(tinycbor PRIVATE WITHOUT_OPEN_MEMSTREAM)

src/open_memstream.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
#if defined(__unix__) || defined(__APPLE__)
3636
# include <unistd.h>
3737
#endif
38-
#ifdef __APPLE__
38+
#if defined(HAVE_OPEN_FUNOPEN)
3939
typedef int RetType;
4040
typedef int LenType;
41-
#elif __linux__
41+
#elif defined(HAVE_OPEN_FOPENCOOKIE)
4242
typedef ssize_t RetType;
4343
typedef size_t LenType;
4444
#else
@@ -99,9 +99,9 @@ FILE *open_memstream(char **bufptr, size_t *lenptr)
9999
*bufptr = NULL;
100100
*lenptr = 0;
101101

102-
#ifdef __APPLE__
102+
#if defined(HAVE_OPEN_FUNOPEN)
103103
return funopen(b, NULL, write_to_buffer, NULL, close_buffer);
104-
#elif __linux__
104+
#elif defined(HAVE_OPEN_FOPENCOOKIE)
105105
static const cookie_io_functions_t vtable = {
106106
NULL,
107107
write_to_buffer,

0 commit comments

Comments
 (0)