[project @ 1999-09-30 14:25:46 by sof]
[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.5 1999/09/30 14:25:47 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 StgInt
24 showTime(I_ size, StgByteArray d, I_ maxsize, StgByteArray buf)
25 {
26     time_t t;
27     struct tm *tm;
28
29     /*
30      * I allege that with the current (9/99) contents of Time.lhs,
31      * size will always be >= 0.   -- sof
32      */
33     switch(size) {
34         case 0:
35             t = 0;
36             break;
37         case 1:
38             t = (time_t) ((StgInt *)d)[0];
39             break;
40         default:
41             return (-1);
42         }
43     tm = localtime(&t);
44     if (tm != NULL && strftime(buf, maxsize, "%a %b %d %T %Z %Y", tm) > 0) {
45        return 1;
46     } else {
47        return (-1);
48     }
49 }