Skip to content

Commit 9e625f5

Browse files
committed
zephyr: Conditionally include <time.h> for POSIX time functions
Zephyr's POSIX time support has been updated (PR #95226) to provide a new header <zephyr/posix/posix_time.h>. This change ensures that <time.h> can be included safely, even when a libc previously provided its own conflicting version. To maintain compatibility before and after the PR, this patch uses __has_include to prefer <time.h> when <zephyr/posix/posix_time.h> is available, and falls back to <zephyr/posix/time.h> otherwise. This prevents build errors caused by incompatible or incomplete <time.h> implementations in some environments. References: – zephyrproject-rtos/zephyr#95226zephyrproject-rtos/zephyr#96911https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005finclude.html Signed-off-by: Yasushi SHOJI <[email protected]>
1 parent 516ee7e commit 9e625f5

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/arch/zephyr/csp_clock.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#include <csp/csp_types.h>
22
#include <zephyr/kernel.h>
3-
#include <zephyr/posix/time.h>
3+
/* https://github.com/zephyrproject-rtos/zephyr/discussions/96911*/
4+
#if __has_include(<zephyr/posix/posix_time.h>)
5+
#include <time.h>
6+
#else
7+
#include <zephyr/posix/time.h>
8+
#endif
49
#include <zephyr/logging/log.h>
510
LOG_MODULE_DECLARE(libcsp);
611

src/arch/zephyr/csp_zephyr_init.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
2-
31
#include <zephyr/kernel.h>
42
#include <zephyr/init.h>
5-
#include <zephyr/posix/time.h>
3+
/* https://github.com/zephyrproject-rtos/zephyr/discussions/96911*/
4+
#if __has_include(<zephyr/posix/posix_time.h>)
5+
#include <time.h>
6+
#else
7+
#include <zephyr/posix/time.h>
8+
#endif
69
#include <csp/csp_debug.h>
710

811
#include <zephyr/logging/log.h>

0 commit comments

Comments
 (0)