% % (c) The GRASP/AQUA Project, Glasgow University, 1995 % \subsection[showTime.lc]{ClockTime.showsPrec Runtime Support} \begin{code} #include "rtsdefs.h" #include "stgio.h" #ifdef HAVE_TIME_H #include #endif StgAddr showTime(size, d, buf) StgInt size; StgByteArray d; StgByteArray buf; { time_t t; struct tm *tm; 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; } 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"); } \end{code}