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