b461fba01b245b6f42d9d067fb6a84e36915dcc2
[ghc-hetmet.git] / ghc / lib / std / cbits / toClockSec.c
1 /* 
2  * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
3  *
4  * $Id: toClockSec.c,v 1.5 1999/11/26 16:25:56 simonmar Exp $
5  *
6  * toClockSec Runtime Support
7  */
8
9 #include "Rts.h"
10 #include "stgio.h"
11 #include "timezone.h"
12
13 StgInt
14 toClockSec(I_ year, I_ mon, I_ mday, I_ hour, I_ min, I_ sec, I_ isdst, StgByteArray res)
15 {
16     struct tm tm;
17     time_t t;
18
19     tm.tm_year = year - 1900;
20     tm.tm_mon = mon;
21     tm.tm_mday = mday;
22     tm.tm_hour = hour;
23     tm.tm_min = min;
24     tm.tm_sec = sec;
25     tm.tm_isdst = isdst;
26
27 #ifdef HAVE_MKTIME
28     t = mktime(&tm);
29 #elif defined(HAVE_TIMELOCAL)
30     t = timelocal(&tm);
31 #else
32     t = (time_t) -1;
33 #endif
34     if (t == (time_t) -1)
35         return 0;
36
37     *(time_t *)res = t;
38     return 1;
39 }