From 29dac2233e1da32c2ee0b662835edf4424fd5b21 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Sat, 23 Feb 2019 09:35:55 -0600 Subject: [PATCH] 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 --- include/posix/time.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/include/posix/time.h b/include/posix/time.h index 78b9ea29f6a..a9bcf82a8d3 100644 --- a/include/posix/time.h +++ b/include/posix/time.h @@ -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;