From 9911e4add4ae4a6a3b6a5590828d5addb3eb84ab Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Wed, 27 May 2020 22:41:19 -0700 Subject: [PATCH 1/2] Check if feature macro is defined before define it Zephyr's native posix port define _POSIX_C_SOURCE with a higher value during the build, so when mbedTLS defines it with a different value breaks the build. As Zephyr is already defining a higher value is guaranteed that mbedTLS required features will be available. So, just define it in case it was not defined before. [taken from Zephyr mbedtls module: https://github.com/zephyrproject-rtos/mbedtls/commit/76dcd6eecae4c1b556a52b1b9ef66e75fc538bc5] Signed-off-by: Flavio Ceolin Signed-off-by: David Brown --- library/net_sockets.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/net_sockets.c b/library/net_sockets.c index 671115f15f..3874783750 100644 --- a/library/net_sockets.c +++ b/library/net_sockets.c @@ -47,11 +47,15 @@ /* Enable definition of getaddrinfo() even when compiling with -std=c99. Must * be set before config.h, which pulls in glibc's features.h indirectly. * Harmless on other platforms. */ +#ifndef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200112L +#endif #if defined(__NetBSD__) +#ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE 600 /* sockaddr_storage */ #endif +#endif #if !defined(MBEDTLS_CONFIG_FILE) #include "mbedtls/config.h" From 6e57cb9d5d9069634a3a92ac651b88e8b30eb9dc Mon Sep 17 00:00:00 2001 From: David Brown Date: Tue, 11 May 2021 12:44:40 -0600 Subject: [PATCH 2/2] Add changelog for posix definition Signed-off-by: David Brown --- ChangeLog.d/posix-define.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 ChangeLog.d/posix-define.txt diff --git a/ChangeLog.d/posix-define.txt b/ChangeLog.d/posix-define.txt new file mode 100644 index 0000000000..98cf2d0122 --- /dev/null +++ b/ChangeLog.d/posix-define.txt @@ -0,0 +1,6 @@ +Bugfix + * In library/net_sockets.c, _POSIX_C_SOURCE and _XOPEN_SOURCE are + defined to specific values. If the code is used in a context + where these are already defined, this can result in a compilation + error. Instead, assume that if they are defined, the values will + be adequate to build Mbed TLS.