Skip to content

Commit 15a9709

Browse files
pfalcongalak
authored andcommitted
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 a6aee9b. Zephyr SDK ticket for this issue is zephyrproject-rtos/sdk-ng#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 <[email protected]>
1 parent 3a45539 commit 15a9709

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

include/posix/time.h

+23
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,30 @@
1010
extern "C" {
1111
#endif
1212

13+
#ifdef CONFIG_NEWLIB_LIBC
14+
/* Kludge to support outdated newlib version as used in SDK 0.10 for Xtensa */
15+
#include <newlib.h>
16+
17+
#ifdef __NEWLIB__
18+
/* Newever Newlib 3.x+ */
19+
#include <sys/_timespec.h>
20+
#else
21+
/* Workaround for older Newlib 2.x, as used by Xtensa. It lacks sys/_timeval.h,
22+
* so mimic it here.
23+
*/
24+
#include <sys/types.h>
25+
#ifndef __timespec_defined
26+
struct timespec {
27+
time_t tv_sec;
28+
long tv_nsec;
29+
};
30+
#endif
31+
#endif
32+
33+
#else
34+
/* Not Newlib */
1335
#include <sys/_timespec.h>
36+
#endif /* CONFIG_NEWLIB_LIBC */
1437

1538
/* Older newlib's like 2.{0-2}.0 don't define any newlib version defines, only
1639
* __NEWLIB_H__ so we use that to decide if itimerspec was defined in

0 commit comments

Comments
 (0)