lib: posix: Fix compile error with time.h and older newlib

Some older variants of newlib (like what we have on xtensa or riscv in
SDK 0.9.5) define timespec and itimerspec in sys/types.h.  The timespec
can be handled by a check of __timespec_defined.  However itimerspec
doesn't have anything similar so we have to do it by newlib version
info.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2019-02-23 09:35:55 -06:00 committed by Kumar Gala
commit 29dac2233e

View file

@ -10,15 +10,29 @@
extern "C" {
#endif
struct timespec {
signed int tv_sec;
signed int tv_nsec;
};
#ifndef __timespec_defined
#define __timespec_defined
struct timespec {
signed int tv_sec;
signed int tv_nsec;
};
#endif
/* 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
* sys/types.h w/o any protection. It appears sometime in the 2.3.0 version
* of newlib did itimerspec move out of sys/types.h, however version 2.3.0
* seems to report itself as __NEWLIB_MINOR__ == 2, where as 2.2.0 doesn't
* even define __NEWLIB_MINOR__ or __NEWLIB__
*/
#if !defined(__NEWLIB_H__) || (__NEWLIB__ >= 3) || \
(__NEWLIB__ == 2 && __NEWLIB_MINOR__ >= 2)
struct itimerspec {
struct timespec it_interval; /* Timer interval */
struct timespec it_value; /* Timer expiration */
};
#endif
struct timeval {
signed int tv_sec;