[project @ 1999-03-17 13:19:19 by simonm]
[ghc-hetmet.git] / ghc / lib / std / cbits / getClockTime.c
index 9f031bf..07e032b 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
  *
- * $Id: getClockTime.c,v 1.1 1998/04/10 10:54:35 simonm Exp $
+ * $Id: getClockTime.c,v 1.3 1998/12/02 13:27:38 simonm Exp $
  *
  * getClockTime Runtime Support
  */
@@ -75,3 +75,43 @@ getClockTime(StgByteArray sec, StgByteArray nsec)
 #endif
 #endif
 }
+
+StgInt
+prim_getClockTime(StgByteArray sec, StgByteArray nsec)
+{
+#ifdef HAVE_GETCLOCK
+    struct timespec tp;
+
+    if (getclock(TIMEOFDAY, &tp) != 0) {
+       cvtErrno();
+       stdErrno();
+       return -1;
+    }
+    ((StgInt64*)sec)[0] = tp.tv_sec;
+    ((StgInt64*)nsec)[0] = tp.tv_nsec;
+    return 0;
+#else
+#ifdef HAVE_GETTIMEOFDAY
+    struct timeval tp;
+    if (gettimeofday(&tp, NULL) != 0) {
+       cvtErrno();
+       stdErrno();
+       return -1;
+    }
+    ((StgInt64*)sec)[0] = tp.tv_sec;
+    ((StgInt64*)nsec)[0] = tp.tv_usec * 1000;
+    return 0;
+#else
+    time_t t;
+    if ((t = time(NULL)) == (time_t) -1) {
+       cvtErrno();
+       stdErrno();
+       return -1;
+    }
+    ((StgInt64*)sec)[0] = t;
+    ((StgInt64*)nsec)[0] = 0;
+    return 0;
+#endif
+#endif
+}