[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / runtime / io / showTime.lc
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1995
3 %
4 \subsection[showTime.lc]{ClockTime.showsPrec Runtime Support}
5
6 \begin{code}
7
8 #include "rtsdefs.h"
9 #include "stgio.h"
10
11 #ifdef HAVE_TIME_H
12 #include <time.h>
13 #endif
14
15 StgAddr
16 showTime(size, d)
17 StgInt size;
18 StgByteArray d;
19 {
20     time_t t;
21     struct tm *tm;
22     static char buf[32];
23
24     switch(size) {
25         default:
26             return (StgAddr) "ClockTime.show{LibTime}: out of range";
27         case 0:
28             t = 0;
29             break;
30         case -1:
31             t = - (time_t) ((StgInt *)d)[0];
32             if (t > 0) 
33                 return (StgAddr) "ClockTime.show{LibTime}: out of range";
34             break;
35         case 1:
36             t = (time_t) ((StgInt *)d)[0];
37             if (t < 0) 
38                 return (StgAddr) "ClockTime.show{LibTime}: out of range";
39             break;
40         }
41     tm = localtime(&t);
42     if (tm != NULL && strftime(buf, sizeof(buf), "%a %b %d %T %Z %Y", tm) > 0)
43             return (StgAddr) buf;
44     return (StgAddr) "ClockTime.show{LibTime}: internal error";
45 }
46
47 \end{code}