From 1555aefd8aa5f21809473335166d38e88bf4ffcb Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Sat, 5 Mar 2016 14:41:13 +0000
Subject: [PATCH] Check that the required system functions are present at
 configure time

---
 configure.ac |  2 +-
 src/clocks.c | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 6abf5a35bb..719b5e6897 100644
--- a/configure.ac
+++ b/configure.ac
@@ -329,7 +329,7 @@ is defined in <sys/time.h>])],,
 [#if HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif])
-AC_CHECK_FUNCS([gethrtime read_real_time time_base_to_time clock_gettime mach_absolute_time])
+AC_CHECK_FUNCS([gethrtime read_real_time time_base_to_time clock_gettime mach_absolute_time strftime gettimeofday localtime])
 AC_MSG_CHECKING([for _rtc intrinsic])
 rtc_ok=yes
 AC_LINK_IFELSE([AC_LANG_PROGRAM(
diff --git a/src/clocks.c b/src/clocks.c
index 20152c07d1..d572e9d850 100644
--- a/src/clocks.c
+++ b/src/clocks.c
@@ -222,8 +222,17 @@ double clocks_from_ticks(ticks tics) {
  */
 const char *clocks_getunit() { return clocks_units[clocks_units_index]; }
 
+/**
+ * @brief returns a string containing the local date and time
+ *
+ * The date is return in the format [YYYY-MM-DD hh:mm:ss]
+ *
+ * @result the current time.
+ */
 const char *clocks_get_timeofday() {
 
+#if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_LOCALTIME) && \
+    defined(HAVE_STRFTIME)
   struct timeval time;
   struct tm *local_time;
   static char buffer[40];
@@ -235,5 +244,8 @@ const char *clocks_get_timeofday() {
   /* Make it a string */
   strftime(buffer, 40, "[%F %T]", local_time);
 
+#else
+  static char buffer[40] = "[Unknown time]";
+#endif
   return buffer;
 }
-- 
GitLab