4efab2c09b29e844bc4f26d262874b22781cf52b
[ghc-hetmet.git] / ghc / lib / std / cbits / showTime.c
1 /* 
2  * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
3  *
4  * $Id: showTime.c,v 1.4 1999/09/30 12:42:26 sof Exp $
5  *
6  * ClockTime.showsPrec Runtime Support
7  */
8
9 #include "Rts.h"
10 #include "stgio.h"
11
12 #if TIME_WITH_SYS_TIME
13 # include <sys/time.h>
14 # include <time.h>
15 #else
16 # if HAVE_SYS_TIME_H
17 #  include <sys/time.h>
18 # else
19 #  include <time.h>
20 # endif
21 #endif
22
23 StgAddr
24 showTime(I_ size, StgByteArray d, I_ maxsize, StgByteArray buf)
25 {
26     time_t t;
27     struct tm *tm;
28
29     switch(size) {
30         case 0:
31             t = 0;
32             break;
33         case -1:
34             t = - (time_t) ((StgInt *)d)[0];
35             break;
36         case 1:
37             t = (time_t) ((StgInt *)d)[0];
38             break;
39         default:
40             return (-1);
41         }
42     tm = localtime(&t);
43     if (tm != NULL && strftime(buf, maxsize, "%a %b %d %T %Z %Y", tm) > 0) {
44        return 1;
45     } else {
46        return (-1);
47     }
48 }