Skip to content

Commit aae851f

Browse files
aescolardkalowsk
authored andcommitted
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 <[email protected]> (cherry picked from commit a785548)
1 parent f7edec7 commit aae851f

File tree

2 files changed

+9
-5
lines changed
  • include/zephyr/bluetooth/services
  • subsys/bluetooth/services

2 files changed

+9
-5
lines changed

include/zephyr/bluetooth/services/cts.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
#include <stdint.h>
19-
#include <zephyr/posix/time.h>
2019

2120
#ifdef __cplusplus
2221
extern "C" {

subsys/bluetooth/services/cts.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@
77
*
88
* SPDX-License-Identifier: Apache-2.0
99
*/
10+
11+
#undef _POSIX_C_SOURCE
12+
#define _POSIX_C_SOURCE 200809L /* To get gmtime_r()'s prototype */
13+
14+
#ifdef CONFIG_BT_CTS_HELPER_API
15+
#include <time.h>
16+
#include <zephyr/sys/timeutil.h>
17+
#endif
18+
1019
#include <stdbool.h>
1120
#include <zephyr/sys/byteorder.h>
12-
#include <zephyr/posix/time.h>
1321

1422
#include <zephyr/bluetooth/conn.h>
1523
#include <zephyr/bluetooth/gatt.h>
@@ -26,9 +34,6 @@ static const struct bt_cts_cb *cts_cb;
2634

2735
#ifdef CONFIG_BT_CTS_HELPER_API
2836

29-
#include <time.h>
30-
#include <zephyr/sys/timeutil.h>
31-
3237
int bt_cts_time_to_unix_ms(const struct bt_cts_time_format *ct_time, int64_t *unix_ms)
3338
{
3439
struct tm date_time;

0 commit comments

Comments
 (0)