This copies the approach used in libstdc++ if getttimeofday is available
and clock_gettime is not, then use the former.

libgm2/ChangeLog:

        * libm2iso/wrapclock.cc (GetTimeRealtime): Provide a fallback when
        clock_gettime is not available.

Signed-off-by: Iain Sandoe <[email protected]>
---
 libgm2/libm2iso/wrapclock.cc | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/libgm2/libm2iso/wrapclock.cc b/libgm2/libm2iso/wrapclock.cc
index 540a8b9ae6d..3a770e5f8c5 100644
--- a/libgm2/libm2iso/wrapclock.cc
+++ b/libgm2/libm2iso/wrapclock.cc
@@ -86,7 +86,6 @@ typedef long long int longint_t;
 extern "C" int
 EXPORT(GetTimeRealtime) (struct timespec *ts)
 {
-  timespec tp;
 #if defined(_GLIBCXX_USE_CLOCK_GETTIME_SYSCALL)
   return syscall (SYS_clock_gettime, CLOCK_REALTIME, ts);
 #else
@@ -94,6 +93,18 @@ EXPORT(GetTimeRealtime) (struct timespec *ts)
 #endif
 }
 
+#elif defined(HAVE_STRUCT_TIMESPEC) && defined(HAVE_GETTIMEOFDAY)
+extern "C" int
+EXPORT(GetTimeRealtime) (struct timespec *ts)
+{
+  struct timeval tv;
+  if (gettimeofday (&tv, NULL) != 0)
+    return -1;
+  ts->tv_sec = tv.tv_sec;
+  ts->tv_nsec = ((long) tv.tv_usec) * 1000;
+  return 0;
+}
+
 #else
 
 extern "C" int
-- 
2.50.1 (Apple Git-155)

Reply via email to