From ef4cd6a1ab15cb25217fa207baf4d99789a38cc3 Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Wed, 7 Aug 2019 11:23:10 -0500 Subject: [PATCH] lib/libc/minimal: Refined handle duplicate time definitions Follow the approach of newlib to use a file sys/_types.h to specify the underlying type for POSIX/libc types that must be provided in multiple headers. The identifier for this type is in the reserved namespace. Use this type rather than a specific standard type in all headers that need to provide the type under its public name. Remove the inclusion of from headers that should not bring in all symbols present in that header, replacing it with the standard boilerplate to expose the specific symbols that are required. Signed-off-by: Peter A. Bigot --- lib/libc/minimal/include/sys/_timespec.h | 12 +++++++++++- lib/libc/minimal/include/sys/_timeval.h | 12 +++++++++++- lib/libc/minimal/include/sys/_types.h | 18 ++++++++++++++++++ lib/libc/minimal/include/sys/types.h | 5 +++-- lib/libc/minimal/include/time.h | 5 +++-- 5 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 lib/libc/minimal/include/sys/_types.h diff --git a/lib/libc/minimal/include/sys/_timespec.h b/lib/libc/minimal/include/sys/_timespec.h index 5e8364c7726..8d64edd6933 100644 --- a/lib/libc/minimal/include/sys/_timespec.h +++ b/lib/libc/minimal/include/sys/_timespec.h @@ -7,7 +7,17 @@ #ifndef ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS__TIMESPEC_H_ #define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS__TIMESPEC_H_ -#include +#include + +#if !defined(__time_t_defined) +#define __time_t_defined +typedef _TIME_T_ time_t; +#endif + +#if !defined(__suseconds_t_defined) +#define __suseconds_t_defined +typedef _SUSECONDS_T_ suseconds_t; +#endif struct timespec { time_t tv_sec; diff --git a/lib/libc/minimal/include/sys/_timeval.h b/lib/libc/minimal/include/sys/_timeval.h index f3109087c59..f62043491c7 100644 --- a/lib/libc/minimal/include/sys/_timeval.h +++ b/lib/libc/minimal/include/sys/_timeval.h @@ -7,7 +7,17 @@ #ifndef ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS__TIMEVAL_H_ #define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS__TIMEVAL_H_ -#include +#include + +#if !defined(__time_t_defined) +#define __time_t_defined +typedef _TIME_T_ time_t; +#endif + +#if !defined(__suseconds_t_defined) +#define __suseconds_t_defined +typedef _SUSECONDS_T_ suseconds_t; +#endif struct timeval { time_t tv_sec; diff --git a/lib/libc/minimal/include/sys/_types.h b/lib/libc/minimal/include/sys/_types.h new file mode 100644 index 00000000000..a5ed9aff847 --- /dev/null +++ b/lib/libc/minimal/include/sys/_types.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2019 Peter Bigot Consulting, LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* Common header used to define underlying types for typedefs that + * must appear in multiple headers independently. + */ +#ifndef ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_XTYPES_H_ +#define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_XTYPES_H_ + +#include + +typedef int64_t _TIME_T_; +typedef int32_t _SUSECONDS_T_; + +#endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_XTYPES_H_ */ diff --git a/lib/libc/minimal/include/sys/types.h b/lib/libc/minimal/include/sys/types.h index d06d5087818..166f450e019 100644 --- a/lib/libc/minimal/include/sys/types.h +++ b/lib/libc/minimal/include/sys/types.h @@ -9,6 +9,7 @@ #define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS_TYPES_H_ #include +#include typedef unsigned int mode_t; @@ -44,12 +45,12 @@ typedef int off_t; #if !defined(__time_t_defined) #define __time_t_defined -typedef int64_t time_t; +typedef _TIME_T_ time_t; #endif #if !defined(__suseconds_t_defined) #define __suseconds_t_defined -typedef int32_t suseconds_t; +typedef _SUSECONDS_T_ suseconds_t; #endif #if !defined(__mem_word_t_defined) diff --git a/lib/libc/minimal/include/time.h b/lib/libc/minimal/include/time.h index 2a81f9998bf..d23e9296eaf 100644 --- a/lib/libc/minimal/include/time.h +++ b/lib/libc/minimal/include/time.h @@ -9,6 +9,7 @@ #define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_TIME_H_ #include +#include #include /* Minimal time.h to fulfill the requirements of certain libraries @@ -33,12 +34,12 @@ struct tm { #if !defined(__time_t_defined) #define __time_t_defined -typedef int64_t time_t; +typedef _TIME_T_ time_t; #endif #if !defined(__suseconds_t_defined) #define __suseconds_t_defined -typedef int32_t suseconds_t; +typedef _SUSECONDS_T_ suseconds_t; #endif #include