[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / runtime / io / toClockSec.lc
diff --git a/ghc/runtime/io/toClockSec.lc b/ghc/runtime/io/toClockSec.lc
new file mode 100644 (file)
index 0000000..d00da86
--- /dev/null
@@ -0,0 +1,48 @@
+%
+% (c) The GRASP/AQUA Project, Glasgow University, 1995
+%
+\subsection[toClockSec.lc]{toClockSec Runtime Support}
+
+\begin{code}
+
+#include "rtsdefs.h"
+#include "stgio.h"
+#include "timezone.h"
+
+StgAddr 
+toClockSec(year, mon, mday, hour, min, sec, tz)
+StgInt year;
+StgInt mon;
+StgInt mday;
+StgInt hour;
+StgInt min;
+StgInt sec;
+StgInt tz;
+{
+    struct tm tm;
+    static 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;
+    else
+       return &t;
+}
+
+\end{code}