Skip to content

Enable open_memstream for non-linux and apple platforms #306

@vortex314

Description

@vortex314

When trying to include tinycbor on ESP32 I got the below compile errors


Compiling .pio/build/hoverboard/lib24a/tinycbor/open_memstream.o
.pio/libdeps/hoverboard/tinycbor/src/open_memstream.c:45:4: error: #error "Cannot implement open_memstream!"
   45 | #  error "Cannot implement open_memstream!"
      |    ^~~~~
.pio/libdeps/hoverboard/tinycbor/src/open_memstream.c:57:8: error: unknown type name 'RetType'
   57 | static RetType write_to_buffer(void *cookie, const char *data, LenType len)
      |        ^~~~~~~
.pio/libdeps/hoverboard/tinycbor/src/open_memstream.c:57:64: error: unknown type name 'LenType'
   57 | static RetType write_to_buffer(void *cookie, const char *data, LenType len)
      |                                                                ^~~~~~~
.pio/libdeps/hoverboard/tinycbor/src/open_memstream.c: In function 'open_memstream':
.pio/libdeps/hoverboard/tinycbor/src/open_memstream.c:113:1: error: control reaches end of non-void function [-Werror=return-type]
  113 | }
      | ^
.pio/libdeps/hoverboard/tinycbor/src/open_memstream.c: At top level:
.pio/libdeps/hoverboard/tinycbor/src/open_memstream.c:82:12: warning: 'close_buffer' defined but not used [-Wunused-function]
   82 | static int close_buffer(void *cookie)
      |            ^~~~~~~~~~~~
cc1: some warnings being treated as errors
*** [.pio/build/hoverboard/lib24a/tinycbor/open_memstream.o] Error 1

the code limits the platforms , changing the elif linux to a generic else is sufficient to correct this.

Or is there an gcc cpp directive to avoid this ?

#ifdef __APPLE__
typedef int RetType;
typedef int LenType;
#elif __linux__
typedef ssize_t RetType;
typedef size_t LenType;
#else
#  error "Cannot implement open_memstream!"
#endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions