/*
* (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
*
- * $Id: showTime.c,v 1.1 1998/04/10 10:54:53 simonm Exp $
+ * $Id: showTime.c,v 1.8 2000/04/06 17:54:01 rrt Exp $
*
* ClockTime.showsPrec Runtime Support
*/
# endif
#endif
-StgAddr
-showTime(I_ size, StgByteArray d, StgByteArray buf)
+StgInt
+showTime(I_ size, StgByteArray d, I_ maxsize, StgByteArray buf)
{
time_t t;
struct tm *tm;
+ /*
+ * I allege that with the current (9/99) contents of Time.lhs,
+ * size will always be >= 0. -- sof
+ */
switch(size) {
- default:
- return (StgAddr)strcpy(buf, "ClockTime.show{LibTime}: out of range");
case 0:
t = 0;
break;
- case -1:
- t = - (time_t) ((StgInt *)d)[0];
- if (t > 0)
- return
- (StgAddr)strcpy(buf, "ClockTime.show{LibTime}: out of range");
- break;
case 1:
t = (time_t) ((StgInt *)d)[0];
- if (t < 0)
- return (StgAddr) strcpy(buf, "ClockTime.show{LibTime}: out of range");
break;
+ default:
+ return (-1);
}
tm = localtime(&t);
- if (tm != NULL && strftime(buf, 32 /*Magic number*/, "%a %b %d %T %Z %Y", tm) > 0)
- return (StgAddr)buf;
- return (StgAddr)strcpy(buf, "ClockTime.show{LibTime}: internal error");
+#ifdef cygwin32_TARGET_OS
+ /* Same as in timezone.c: tzset() isn't called automatically */
+ tzset();
+#endif
+ if (tm != NULL && strftime(buf, maxsize, "%a %b %d %H:%M:%S %Z %Y", tm) > 0) {
+ return 1;
+ } else {
+ return (-1);
+ }
}