[project @ 1998-11-26 09:17:22 by sof]
[ghc-hetmet.git] / ghc / lib / std / cbits / 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 "timezone.h"
10 #include "stgio.h"
11
12 StgAddr 
13 toClockSec(I_ year, I_ mon, I_ mday, I_ hour, I_ min, I_ sec, I_ isdst, StgByteArray res)
14 {
15     struct tm tm;
16     time_t t;
17
18     tm.tm_year = year - 1900;
19     tm.tm_mon = mon;
20     tm.tm_mday = mday;
21     tm.tm_hour = hour;
22     tm.tm_min = min;
23     tm.tm_sec = sec;
24     tm.tm_isdst = isdst;
25
26 #ifdef HAVE_MKTIME
27     t = mktime(&tm);
28 #else
29 #ifdef HAVE_TIMELOCAL
30     t = timelocal(&tm);
31 #else
32     t = (time_t) -1;
33 #endif
34 #endif
35     if (t == (time_t) -1)
36         return NULL;
37
38     *(time_t *)res = t;
39     return res;
40 }
41 \end{code}