NordicSemiconductor / zcbor

Low footprint C/C++ CBOR library and Python tool providing code generation from CDDL descriptions.
Apache License 2.0
105 stars 34 forks source link

Implementing strnlen(), should come with a recommendation for POSIX_SOURCE = 200809L #348

Closed jnz86 closed 10 months ago

jnz86 commented 11 months ago

I don't use Zepher. I assume most people here do, and assume that this isn't an issue for many.

With a lot of setups, POSIX_SOURCE is set to zero. Which means that in <string.h>, strnlen() will not be included. Obviously this is an issue if using zcbor from https://github.com/NordicSemiconductor/zcbor/pull/342 on.

I would probably make a note in the readme that you may need either

#define POSIX_C_SOURCE 200809L

Or if using CMake, -D_POSIX_C_SOURCE=200809L

Both of these assuming GCC (I'm using ARM-NONE-EABI v12.3 toolchain).

There are also portable versions of strnlen() like this but that may be more annoying to work in compared to being included in <string.h>

If it were me, I probably would have included that simple portable version as WEAK or optional in case the user didn't define or want POSIX above.

oyvindronningstad commented 10 months ago

Hi, a weak implementation will be added soon.