[project @ 1998-11-26 09:17:22 by sof]
[ghc-hetmet.git] / ghc / lib / std / cbits / getClockTime.lc
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1995
3 %
4 \subsection[getClockTime.lc]{getClockTime Runtime Support}
5
6 \begin{code}
7
8 #ifndef _AIX
9 #define NON_POSIX_SOURCE    /* gettimeofday */
10 #endif
11
12 #include "rtsdefs.h"
13 #include "stgio.h"
14
15 #ifdef HAVE_GETCLOCK
16
17 # ifdef HAVE_SYS_TIMERS_H
18 #  define POSIX_4D9 1
19 #  include <sys/timers.h>
20 # endif
21
22 #else
23 # ifdef HAVE_GETTIMEOFDAY
24
25 #  ifdef HAVE_SYS_TIME_H
26 #   include <sys/time.h>
27 #  endif
28
29 # else
30
31 #  ifdef HAVE_TIME_H
32 #   include <time.h>
33 #  endif
34
35 # endif
36 #endif
37
38 StgInt
39 getClockTime(StgByteArray sec, StgByteArray nsec)
40 {
41 #ifdef HAVE_GETCLOCK
42     struct timespec tp;
43
44     if (getclock(TIMEOFDAY, &tp) != 0) {
45         cvtErrno();
46         stdErrno();
47         return -1;
48     }
49     ((unsigned long int *)sec)[0] = tp.tv_sec;
50     ((unsigned long int *)nsec)[0] = tp.tv_nsec;
51     return 0;
52 #else
53 #ifdef HAVE_GETTIMEOFDAY
54     struct timeval tp;
55  
56     if (gettimeofday(&tp, NULL) != 0) {
57         cvtErrno();
58         stdErrno();
59         return -1;
60     }
61     ((unsigned long int *)sec)[0] = tp.tv_sec;
62     ((unsigned long int *)nsec)[0] = tp.tv_usec * 1000;
63     return 0;
64 #else
65     time_t t;
66     if ((t = time(NULL)) == (time_t) -1) {
67         cvtErrno();
68         stdErrno();
69         return -1;
70     }
71     ((unsigned long int *)sec)[0] = t;
72     ((unsigned long int *)nsec)[0] = 0;
73     return 0;
74 #endif
75 #endif
76 }
77 \end{code}