CLEANUP: time: refine the test on _POSIX_TIMERS
The clock_gettime() man page says we must check that _POSIX_TIMERS is
defined to a value greater than zero, not just that it's simply defined
so let's fix this right now.
diff --git a/include/common/compat.h b/include/common/compat.h
index d43b89d..35782de 100644
--- a/include/common/compat.h
+++ b/include/common/compat.h
@@ -99,7 +99,7 @@
#endif
/* systems without such defines do not know clockid_t */
-#if !defined(_POSIX_TIMERS) || (_POSIX_C_SOURCE < 199309L)
+#if !(_POSIX_TIMERS > 0) || (_POSIX_C_SOURCE < 199309L)
#define clockid_t int
#undef CLOCK_REALTIME
#undef CLOCK_MONOTONIC
diff --git a/include/common/time.h b/include/common/time.h
index 9920a77..2633b1c 100644
--- a/include/common/time.h
+++ b/include/common/time.h
@@ -519,7 +519,7 @@
/* returns the system's monotonic time in nanoseconds if supported, otherwise zero */
static inline uint64_t now_mono_time()
{
-#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
+#if (_POSIX_TIMERS > 0) && defined(_POSIX_MONOTONIC_CLOCK)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
@@ -531,7 +531,7 @@
/* returns the current thread's cumulated CPU time in nanoseconds if supported, otherwise zero */
static inline uint64_t now_cpu_time()
{
-#if defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME)
+#if (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
struct timespec ts;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
@@ -543,7 +543,7 @@
/* returns another thread's cumulated CPU time in nanoseconds if supported, otherwise zero */
static inline uint64_t now_cpu_time_thread(const struct thread_info *thr)
{
-#if defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME)
+#if (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
struct timespec ts;
clock_gettime(thr->clock_id, &ts);
return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
diff --git a/src/haproxy.c b/src/haproxy.c
index f85f15f..f5d72e6 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -2511,7 +2511,7 @@
ha_set_tid((unsigned long)data);
-#if defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME)
+#if (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
#ifdef USE_THREAD
pthread_getcpuclockid(pthread_self(), &ti->clock_id);
#else