From 15a9709186f59bdc8c5925bd906416ed0a60b2eb Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 5 Jun 2019 14:54:37 +0300 Subject: [PATCH] posix: time.h: Add workaround for outdated newlib used by Xtensa Unfortunately, Zephyr SDK 0.10.0 ships with outdated Newlib 2.0.0 (from 2015 or earlier) which lacks sys/_timespec.h header, requiring ugly workaround of defining struct timespec inline (the whole idea was to standardize on sys/_timespec.h header for different libc's). This is similar to earlier workaround for struct timeval definition introduced in a6aee9b4c85642053d. Zephyr SDK ticket for this issue is https://github.com/zephyrproject-rtos/sdk-ng/issues/64, and it will ve possible to remove both workarounds when Xtensa toolchain will be upgraded to newlib version consistent with other architectures. Signed-off-by: Paul Sokolovsky --- include/posix/time.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/posix/time.h b/include/posix/time.h index 169bd73d7d8..72b3b8b386b 100644 --- a/include/posix/time.h +++ b/include/posix/time.h @@ -10,7 +10,30 @@ extern "C" { #endif +#ifdef CONFIG_NEWLIB_LIBC +/* Kludge to support outdated newlib version as used in SDK 0.10 for Xtensa */ +#include + +#ifdef __NEWLIB__ +/* Newever Newlib 3.x+ */ #include +#else +/* Workaround for older Newlib 2.x, as used by Xtensa. It lacks sys/_timeval.h, + * so mimic it here. + */ +#include +#ifndef __timespec_defined +struct timespec { + time_t tv_sec; + long tv_nsec; +}; +#endif +#endif + +#else +/* Not Newlib */ +#include +#endif /* CONFIG_NEWLIB_LIBC */ /* Older newlib's like 2.{0-2}.0 don't define any newlib version defines, only * __NEWLIB_H__ so we use that to decide if itimerspec was defined in