[project @ 1997-03-19 14:16:50 by sof]
[ghc-hetmet.git] / ghc / lib / cbits / showTime.lc
diff --git a/ghc/lib/cbits/showTime.lc b/ghc/lib/cbits/showTime.lc
new file mode 100644 (file)
index 0000000..08adcd5
--- /dev/null
@@ -0,0 +1,51 @@
+%
+% (c) The GRASP/AQUA Project, Glasgow University, 1995
+%
+\subsection[showTime.lc]{ClockTime.showsPrec Runtime Support}
+
+\begin{code}
+
+#include "rtsdefs.h"
+#include "stgio.h"
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+StgAddr
+showTime(I_ size, StgByteArray d, StgByteArray buf)
+{
+    time_t t;
+    struct tm *tm;
+
+    switch(size) {
+       default:
+            return (StgAddr)strcpy(buf, "ClockTime.show{LibTime}: out of range");
+       case 0:
+           t = 0;
+           break;
+       case -1:
+           t = - (time_t) ((StgInt *)d)[0];
+           if (t > 0) 
+                return
+ (StgAddr)strcpy(buf, "ClockTime.show{LibTime}: out of range");
+           break;
+       case 1:
+           t = (time_t) ((StgInt *)d)[0];
+           if (t < 0) 
+               return (StgAddr) strcpy(buf, "ClockTime.show{LibTime}: out of range");
+           break;
+       }
+    tm = localtime(&t);
+    if (tm != NULL && strftime(buf, 32 /*Magic number*/, "%a %b %d %T %Z %Y", tm) > 0)
+       return (StgAddr)buf;
+    return (StgAddr)strcpy(buf, "ClockTime.show{LibTime}: internal error");
+}
+\end{code}