[project @ 1997-03-19 14:16:50 by sof]
[ghc-hetmet.git] / ghc / lib / cbits / toClockSec.lc
diff --git a/ghc/lib/cbits/toClockSec.lc b/ghc/lib/cbits/toClockSec.lc
new file mode 100644 (file)
index 0000000..71062e5
--- /dev/null
@@ -0,0 +1,41 @@
+%
+% (c) The GRASP/AQUA Project, Glasgow University, 1995
+%
+\subsection[toClockSec.lc]{toClockSec Runtime Support}
+
+\begin{code}
+
+#include "rtsdefs.h"
+#include "timezone.h"
+#include "stgio.h"
+
+StgAddr 
+toClockSec(I_ year, I_ mon, I_ mday, I_ hour, I_ min, I_ sec, I_ tz, StgByteArray res)
+{
+    struct tm tm;
+    time_t t;
+
+    tm.tm_year = year - 1900;
+    tm.tm_mon = mon;
+    tm.tm_mday = mday;
+    tm.tm_hour = hour;
+    tm.tm_min = min;
+    tm.tm_sec = sec;
+    tm.tm_isdst = -1;
+
+#ifdef HAVE_MKTIME
+    t = mktime(&tm);
+#else
+#ifdef HAVE_TIMELOCAL
+    t = timelocal(&tm);
+#else
+    t = (time_t) -1;
+#endif
+#endif
+    if (t == (time_t) -1)
+       return NULL;
+
+    *(time_t *)res = t;
+    return res;
+}
+\end{code}