2 * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
4 * $Id: getClockTime.c,v 1.5 1999/09/12 14:33:56 sof Exp $
6 * getClockTime Runtime Support
12 /* It seems morally wrong to skew this in favour of
13 using non-POSIX calls (gettimeofday(), ftime()..),
14 rather than time()....so, let's re-order it all
15 (and hope OS idiosyncracies won't get in the way
16 of using time(), the moral elite's favourite.)
19 #if defined(HAVE_TIME_H)
21 #elif defined(HAVE_GETCLOCK)
22 # ifdef HAVE_SYS_TIMERS_H
24 # include <sys/timers.h>
26 #elif defined(HAVE_GETTIMEOFDAY)
27 # ifdef HAVE_SYS_TIME_H
28 # include <sys/time.h>
34 #include <sys/types.h>
35 #include <sys/timeb.h>
39 getClockTime(StgByteArray sec, StgByteArray nsec)
41 #if defined(_WIN32) && !defined(cygwin32_TARGET_OS)
43 * time() as is implemented by cygwin (in B20.1) is
44 * not right, so stay away (and use time()) instead.
50 ((unsigned int *)sec)[0] = (unsigned int)t.time;
51 ((unsigned int *)nsec)[0] = (unsigned int)t.millitm * 1000;
53 #elif defined(HAVE_TIME_H)
55 if ((t = time(NULL)) == (time_t) -1) {
60 ((unsigned long int *)sec)[0] = t;
61 ((unsigned long int *)nsec)[0] = 0;
63 #elif defined(HAVE_GETCLOCK)
66 if (getclock(TIMEOFDAY, &tp) != 0) {
71 ((unsigned long int *)sec)[0] = tp.tv_sec;
72 ((unsigned long int *)nsec)[0] = tp.tv_nsec;
74 #elif defined(HAVE_GETTIMEOFDAY)
77 if (gettimeofday(&tp, NULL) != 0) {
82 ((unsigned long int *)sec)[0] = tp.tv_sec;
83 ((unsigned long int *)nsec)[0] = tp.tv_usec * 1000;
86 #error "getClockTime: don't know how to get at the clock's time"
91 prim_getClockTime(StgByteArray sec, StgByteArray nsec)
93 #if defined(_WIN32) && !defined(cygwin32_TARGET_OS)
94 /* see getClockTime() comment re: ftime() & cygwin */
99 ((unsigned long int *)sec)[0] = t.time;
100 ((unsigned long int *)nsec)[0] = t.millitm * 1000;
102 #elif defined(HAVE_TIME_H)
104 if ((t = time(NULL)) == (time_t) -1) {
109 ((StgInt64*)sec)[0] = t;
110 ((StgInt64*)nsec)[0] = 0;
112 #elif defined(HAVE_GETCLOCK)
115 if (getclock(TIMEOFDAY, &tp) != 0) {
120 ((StgInt64*)sec)[0] = tp.tv_sec;
121 ((StgInt64*)nsec)[0] = tp.tv_nsec;
123 #elif defined(HAVE_GETTIMEOFDAY)
126 if (gettimeofday(&tp, NULL) != 0) {
131 ((StgInt64*)sec)[0] = tp.tv_sec;
132 ((StgInt64*)nsec)[0] = tp.tv_usec * 1000;
135 #error "getClockTime: don't know how to get at the clock's time"