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 a6aee9b4c8. 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 <paul.sokolovsky@linaro.org>
This commit is contained in:
Paul Sokolovsky 2019-06-05 14:54:37 +03:00 committed by Kumar Gala
parent 3a4553913e
commit 15a9709186

View file

@ -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 <newlib.h>
#ifdef __NEWLIB__
/* Newever Newlib 3.x+ */
#include <sys/_timespec.h>
#else
/* Workaround for older Newlib 2.x, as used by Xtensa. It lacks sys/_timeval.h,
* so mimic it here.
*/
#include <sys/types.h>
#ifndef __timespec_defined
struct timespec {
time_t tv_sec;
long tv_nsec;
};
#endif
#endif
#else
/* Not Newlib */
#include <sys/_timespec.h>
#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