[project @ 1998-04-10 11:04:49 by simonm]
[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.1 1998/04/10 10:54:57 simonm Exp $
5  *
6  * toClockSec Runtime Support
7  */
8
9 #include "Rts.h"
10 #include "timezone.h"
11 #include "stgio.h"
12
13 StgAddr 
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 #else
30 #ifdef HAVE_TIMELOCAL
31     t = timelocal(&tm);
32 #else
33     t = (time_t) -1;
34 #endif
35 #endif
36     if (t == (time_t) -1)
37         return NULL;
38
39     *(time_t *)res = t;
40     return res;
41 }