Archived
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:
+7
-2
@@ -131,8 +131,13 @@ check_symbol_exists(funopen stdio.h HAVE_OPEN_FUNOPEN)
|
|||||||
check_symbol_exists(fopencookie stdio.h HAVE_OPEN_FOPENCOOKIE)
|
check_symbol_exists(fopencookie stdio.h HAVE_OPEN_FOPENCOOKIE)
|
||||||
|
|
||||||
if(NOT HAVE_OPEN_MEMSTREAM)
|
if(NOT HAVE_OPEN_MEMSTREAM)
|
||||||
if (HAVE_OPEN_FUNOPEN AND HAVE_OPEN_FOPENCOOKIE)
|
if (HAVE_OPEN_FUNOPEN)
|
||||||
message(STATUS "using open_memstream implementation")
|
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)
|
target_sources(tinycbor PRIVATE src/open_memstream.c)
|
||||||
else()
|
else()
|
||||||
target_compile_definitions(tinycbor PRIVATE WITHOUT_OPEN_MEMSTREAM)
|
target_compile_definitions(tinycbor PRIVATE WITHOUT_OPEN_MEMSTREAM)
|
||||||
|
|||||||
@@ -35,10 +35,10 @@
|
|||||||
#if defined(__unix__) || defined(__APPLE__)
|
#if defined(__unix__) || defined(__APPLE__)
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef __APPLE__
|
#if defined(HAVE_OPEN_FUNOPEN)
|
||||||
typedef int RetType;
|
typedef int RetType;
|
||||||
typedef int LenType;
|
typedef int LenType;
|
||||||
#elif __linux__
|
#elif defined(HAVE_OPEN_FOPENCOOKIE)
|
||||||
typedef ssize_t RetType;
|
typedef ssize_t RetType;
|
||||||
typedef size_t LenType;
|
typedef size_t LenType;
|
||||||
#else
|
#else
|
||||||
@@ -99,9 +99,9 @@ FILE *open_memstream(char **bufptr, size_t *lenptr)
|
|||||||
*bufptr = NULL;
|
*bufptr = NULL;
|
||||||
*lenptr = 0;
|
*lenptr = 0;
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#if defined(HAVE_OPEN_FUNOPEN)
|
||||||
return funopen(b, NULL, write_to_buffer, NULL, close_buffer);
|
return funopen(b, NULL, write_to_buffer, NULL, close_buffer);
|
||||||
#elif __linux__
|
#elif defined(HAVE_OPEN_FOPENCOOKIE)
|
||||||
static const cookie_io_functions_t vtable = {
|
static const cookie_io_functions_t vtable = {
|
||||||
NULL,
|
NULL,
|
||||||
write_to_buffer,
|
write_to_buffer,
|
||||||
|
|||||||
Reference in New Issue
Block a user