From 37fd7d52102bd6a75ad0a814f9775f70a36fb88c Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Fri, 30 Jan 2026 18:06:56 +0100 Subject: [PATCH] Start from a clean baseline for C11 ext1 and POSIX features Define `_POSIX_C_SOURCE` and `_XOPEN_SOURCE` in a single place that applies everywhere, to make things simple. This may break some platforms that require special handling for POSIX functions and types. Subsequent commits will add platform-specific hacks as needed. Signed-off-by: Gilles Peskine --- library/mbedtls_platform_requirements.h | 14 ++++++++++++++ library/net_sockets.c | 10 ---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/library/mbedtls_platform_requirements.h b/library/mbedtls_platform_requirements.h index c86204e6fa..c4f959191f 100644 --- a/library/mbedtls_platform_requirements.h +++ b/library/mbedtls_platform_requirements.h @@ -15,6 +15,20 @@ #ifndef MBEDTLS_MBEDTLS_PLATFORM_REQUIREMENTS_H #define MBEDTLS_MBEDTLS_PLATFORM_REQUIREMENTS_H +#if !defined(_POSIX_C_SOURCE) +/* For standards-compliant access to + * getaddrinfo(), + * ... */ +#define _POSIX_C_SOURCE 200112L +#endif + +#if !defined(_XOPEN_SOURCE) +/* For standards-compliant access to + * sockaddr_storage, + * ... */ +#define _XOPEN_SOURCE 600 +#endif + /* On Mingw-w64, force the use of a C99-compliant printf() and friends. * This is necessary on older versions of Mingw and/or Windows runtimes * where snprintf does not always zero-terminate the buffer, and does diff --git a/library/net_sockets.c b/library/net_sockets.c index 25f06824cb..404ef761ae 100644 --- a/library/net_sockets.c +++ b/library/net_sockets.c @@ -5,16 +5,6 @@ * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ -/* Enable definition of getaddrinfo() even when compiling with -std=c99. Must - * be set before mbedtls_config.h, which pulls in glibc's features.h indirectly. - * Harmless on other platforms. */ -#ifndef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 200112L -#endif -#ifndef _XOPEN_SOURCE -#define _XOPEN_SOURCE 600 /* sockaddr_storage */ -#endif - #include "ssl_misc.h" #if defined(MBEDTLS_NET_C)