[PATCH v05 70/72] uapi time.h: glibc time.h header file compatibility fixes

From: Mikko Rapeli
Date: Mon Aug 22 2016 - 15:29:00 EST


Fixes these userspace compile errors and warnings when glibc time.h
is included before linux/time.h:

linux/time.h:9:8: error: redefinition of âstruct timespecâ
linux/time.h:15:8: error: redefinition of âstruct timevalâ
linux/time.h:20:8: error: redefinition of âstruct timezoneâ
linux/time.h:30:0: warning: "ITIMER_REAL" redefined
linux/time.h:31:0: warning: "ITIMER_VIRTUAL" redefined
linux/time.h:32:0: warning: "ITIMER_PROF" redefined
linux/time.h:34:8: error: redefinition of âstruct itimerspecâ
linux/time.h:39:8: error: redefinition of âstruct itimervalâ
linux/time.h:67:0: warning: "TIMER_ABSTIME" redefined

Signed-off-by: Mikko Rapeli <mikko.rapeli@xxxxxx>
---
include/uapi/linux/libc-compat.h | 37 +++++++++++++++++++++++++++++++++++++
include/uapi/linux/time.h | 18 ++++++++++++++++--
2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h
index acc2e75..cb25f16 100644
--- a/include/uapi/linux/libc-compat.h
+++ b/include/uapi/linux/libc-compat.h
@@ -230,6 +230,21 @@

#endif /* defined(_NETROSE_ROSE_H) */

+/* Coordinate with glibc time.h */
+#if defined(_TIME_H)
+#define __UAPI_DEF_TIMESPEC 0
+#define __UAPI_DEF_TIMEVAL 0
+#define __UAPI_DEF_ITIMERSPEC 0
+#define __UAPI_DEF_TIMER_ABSTIME 0
+
+#else /* defined(_TIME_H) */
+#define __UAPI_DEF_TIMESPEC 1
+#define __UAPI_DEF_TIMEVAL 1
+#define __UAPI_DEF_ITIMERSPEC 1
+#define __UAPI_DEF_TIMER_ABSTIME 1
+
+#endif /* defined(_TIME_H) */
+
/* Definitions for sys/uio.h */
#if defined(_SYS_UIO_H)
#define __UAPI_DEF_IOVEC 0
@@ -237,6 +252,19 @@
#define __UAPI_DEF_IOVEC 1
#endif /* defined(_SYS_UIO_H) */

+/* Definitions for sys/time.h */
+#if defined(_SYS_TIME_H)
+#define __UAPI_DEF_TIMEZONE 0
+#define __UAPI_DEF_ITIMER_REAL_VIRTUAL_PROF 0
+#define __UAPI_DEF_ITIMERVAL 0
+
+#else /* defined(_SYS_TIME_H) */
+#define __UAPI_DEF_TIMEZONE 1
+#define __UAPI_DEF_ITIMER_REAL_VIRTUAL_PROF 1
+#define __UAPI_DEF_ITIMERVAL 1
+
+#endif /* defined(_SYS_TIME_H) */
+
/* Definitions for xattr.h */
#if defined(_SYS_XATTR_H)
#define __UAPI_DEF_XATTR 0
@@ -313,6 +341,15 @@
#define __UAPI_DEF_ROSE_CAUSE_STRUCT 1
#define __UAPI_DEF_ROSE_FACILITIES_STRUCT 1

+/* Definitions for time.h */
+#define __UAPI_DEF_TIMESPEC 1
+#define __UAPI_DEF_TIMEVAL 1
+#define __UAPI_DEF_TIMEZONE 1
+#define __UAPI_DEF_ITIMER_REAL_VIRTUAL_PROF 1
+#define __UAPI_DEF_ITIMERSPEC 1
+#define __UAPI_DEF_ITIMERVAL 1
+#define __UAPI_DEF_TIMER_ABSTIME 1
+
/* Definitions for uio.h */
#define __UAPI_DEF_IOVEC 1

diff --git a/include/uapi/linux/time.h b/include/uapi/linux/time.h
index e75e1b6..66fb19c 100644
--- a/include/uapi/linux/time.h
+++ b/include/uapi/linux/time.h
@@ -1,45 +1,57 @@
#ifndef _UAPI_LINUX_TIME_H
#define _UAPI_LINUX_TIME_H

+#include <linux/libc-compat.h>
#include <linux/types.h>


#ifndef _STRUCT_TIMESPEC
#define _STRUCT_TIMESPEC
+#if __UAPI_DEF_TIMESPEC
struct timespec {
__kernel_time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
-#endif
+#endif /* __UAPI_DEF_TIMESPEC */
+#endif /* _STRUCT_TIMESPEC */

+#if __UAPI_DEF_TIMEVAL
struct timeval {
__kernel_time_t tv_sec; /* seconds */
__kernel_suseconds_t tv_usec; /* microseconds */
};
+#endif /* __UAPI_DEF_TIMEVAL */

+#if __UAPI_DEF_TIMEZONE
struct timezone {
int tz_minuteswest; /* minutes west of Greenwich */
int tz_dsttime; /* type of dst correction */
};
-
+#endif /* __UAPI_DEF_TIMEZONE */

/*
* Names of the interval timers, and structure
* defining a timer setting:
*/
+#if __UAPI_DEF_ITIMER_REAL_VIRTUAL_PROF
#define ITIMER_REAL 0
#define ITIMER_VIRTUAL 1
#define ITIMER_PROF 2
+#endif /* __UAPI_DEF_ITIMER_REAL_VIRTUAL_PROF */

+#if __UAPI_DEF_ITIMERSPEC
struct itimerspec {
struct timespec it_interval; /* timer period */
struct timespec it_value; /* timer expiration */
};
+#endif /* __UAPI_DEF_ITIMERSPEC */

+#if __UAPI_DEF_ITIMERVAL
struct itimerval {
struct timeval it_interval; /* timer interval */
struct timeval it_value; /* current value */
};
+#endif /* __UAPI_DEF_ITIMERVAL */

/*
* The IDs of the various system clocks (for POSIX.1b interval timers):
@@ -64,6 +76,8 @@ struct itimerval {
/*
* The various flags for setting POSIX.1b interval timers:
*/
+#if __UAPI_DEF_TIMER_ABSTIME
#define TIMER_ABSTIME 0x01
+#endif /* __UAPI_DEF_TIMER_ABSTIME */

#endif /* _UAPI_LINUX_TIME_H */
--
2.8.1