[project @ 1996-01-11 14:06:51 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, buf)
17 StgInt size;
18 StgByteArray d;
19 StgByteArray buf;
20 {
21     time_t t;
22     struct tm *tm;
23
24     switch(size) {
25         default:
26             return (StgAddr)strcpy(buf, "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
34  (StgAddr)strcpy(buf, "ClockTime.show{LibTime}: out of range");
35             break;
36         case 1:
37             t = (time_t) ((StgInt *)d)[0];
38             if (t < 0) 
39                return (StgAddr) strcpy(buf, "ClockTime.show{LibTime}: out of range");
40             break;
41         }
42     tm = localtime(&t);
43     if (tm != NULL && strftime(buf, 32 /*Magic number*/, "%a %b %d %T %Z %Y", tm) > 0)
44        return (StgAddr)buf;
45     return (StgAddr)strcpy(buf, "ClockTime.show{LibTime}: internal error");
46 }
47
48 \end{code}