/*
* (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
*/
#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
+}