From 0173d86e6fc09adf76a151e54385f968dc79a79d Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 3 Sep 2019 00:22:51 +0300 Subject: [PATCH] lib: posix, minlibc: struct itimerspec is defined by sys/timespec.h Newlib has it defined in sys/timespec.h, and thus per the established conventions, everything else relies on it being there. Specifically, minimal libc acquires sys/timespec.h with a similar definition, and POSIX headers rely on that header. Still with a workaround for old Newlib version as used by Xtensa (but all infrastructure for that is already there; actually, this patch removes duplicate similar-infra, which apparently didn't work as expected by now, so now we have a single workaround, not 2 different once). To emphasize a point, now there 2 headers: sys/_timespec.h, defining struct timespec, and sys/timespec.h, defining struct itimerspec That's how Newlib has it, and what we faithfully embrace and follow, because otherwise, there will be header conflicts depending on various libc and POSIX subsys options. Signed-off-by: Paul Sokolovsky --- include/posix/time.h | 33 ++++++------------------- lib/libc/minimal/include/sys/timespec.h | 17 +++++++++++++ 2 files changed, 24 insertions(+), 26 deletions(-) create mode 100644 lib/libc/minimal/include/sys/timespec.h diff --git a/include/posix/time.h b/include/posix/time.h index ca1e262f1f..285d4ae44d 100644 --- a/include/posix/time.h +++ b/include/posix/time.h @@ -12,7 +12,7 @@ #ifdef __NEWLIB__ /* Newever Newlib 3.x+ */ -#include +#include #else /* __NEWLIB__ */ /* Workaround for older Newlib 2.x, as used by Xtensa. It lacks sys/_timeval.h, * so mimic it here. @@ -29,6 +29,11 @@ struct timespec { long tv_nsec; }; +struct itimerspec { + struct timespec it_interval; /* Timer interval */ + struct timespec it_value; /* Timer expiration */ +}; + #ifdef __cplusplus } #endif @@ -38,33 +43,9 @@ struct timespec { #else /* CONFIG_NEWLIB_LIBC */ /* Not Newlib */ -#include +#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 - * 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) - -#ifdef __cplusplus -extern "C" { -#endif - -struct itimerspec { - struct timespec it_interval; /* Timer interval */ - struct timespec it_value; /* Timer expiration */ -}; -#ifdef __cplusplus -} -#endif - -#endif - #include #include #include "posix_types.h" diff --git a/lib/libc/minimal/include/sys/timespec.h b/lib/libc/minimal/include/sys/timespec.h new file mode 100644 index 0000000000..20e6fdbb5e --- /dev/null +++ b/lib/libc/minimal/include/sys/timespec.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2019 Linaro Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_TIMESPEC_H_ +#define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_TIMESPEC_H_ + +#include + +struct itimerspec { + struct timespec it_interval; /* Timer interval */ + struct timespec it_value; /* Timer expiration */ +}; + +#endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_TIMESPEC_H_ */