[project @ 1996-01-11 14:06:51 by partain]
[ghc-hetmet.git] / ghc / runtime / io / toClockSec.lc
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1995
3 %
4 \subsection[toClockSec.lc]{toClockSec Runtime Support}
5
6 \begin{code}
7
8 #include "rtsdefs.h"
9 #include "stgio.h"
10 #include "timezone.h"
11
12 StgAddr 
13 toClockSec(year, mon, mday, hour, min, sec, tz, res)
14 StgInt year;
15 StgInt mon;
16 StgInt mday;
17 StgInt hour;
18 StgInt min;
19 StgInt sec;
20 StgInt tz;
21 StgByteArray res;
22 {
23     struct tm tm;
24     time_t t;
25
26     tm.tm_year = year - 1900;
27     tm.tm_mon = mon;
28     tm.tm_mday = mday;
29     tm.tm_hour = hour;
30     tm.tm_min = min;
31     tm.tm_sec = sec;
32     tm.tm_isdst = -1;
33
34 #ifdef HAVE_MKTIME
35     t = mktime(&tm);
36 #else
37 #ifdef HAVE_TIMELOCAL
38     t = timelocal(&tm);
39 #else
40     t = (time_t) -1;
41 #endif
42 #endif
43     if (t == (time_t) -1)
44         return NULL;
45
46     *(time_t *)res = t;
47     return res;
48 }
49
50 \end{code}