From 38203b7e324c82ffe5def891f6148cfc849cbc03 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 14 Nov 2024 19:47:42 +0100 Subject: [PATCH] bluetooth: CTS: Fix includes to avoid build error with some libCs Remove unnecessary include in header and source file. gmtime_r() is an extension to the C library, and therefore one needs to explicitly ask for its prototype to have it exposed. This is done by defining _POSIX_C_SOURCE so let's do so. These two changes fix build errors with some libCs. Tested with pico, newlib, minimal and the host glibc. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit a785548df6353dafe362579af6859d3d02458dbb) --- include/zephyr/bluetooth/services/cts.h | 1 - subsys/bluetooth/services/cts.c | 13 +++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/zephyr/bluetooth/services/cts.h b/include/zephyr/bluetooth/services/cts.h index 46fb7808cc4ee..5b1c780f68615 100644 --- a/include/zephyr/bluetooth/services/cts.h +++ b/include/zephyr/bluetooth/services/cts.h @@ -16,7 +16,6 @@ */ #include -#include #ifdef __cplusplus extern "C" { diff --git a/subsys/bluetooth/services/cts.c b/subsys/bluetooth/services/cts.c index ce72f7728e019..d5744bc5a2480 100644 --- a/subsys/bluetooth/services/cts.c +++ b/subsys/bluetooth/services/cts.c @@ -7,9 +7,17 @@ * * SPDX-License-Identifier: Apache-2.0 */ + +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L /* To get gmtime_r()'s prototype */ + +#ifdef CONFIG_BT_CTS_HELPER_API +#include +#include +#endif + #include #include -#include #include #include @@ -26,9 +34,6 @@ static const struct bt_cts_cb *cts_cb; #ifdef CONFIG_BT_CTS_HELPER_API -#include -#include - int bt_cts_time_to_unix_ms(const struct bt_cts_time_format *ct_time, int64_t *unix_ms) { struct tm date_time;