diff options
Diffstat (limited to 'ghc/runtime/io')
| -rw-r--r-- | ghc/runtime/io/env.lc | 10 | ||||
| -rw-r--r-- | ghc/runtime/io/getCPUTime.lc | 9 | ||||
| -rw-r--r-- | ghc/runtime/io/getDirectoryContents.lc | 4 | ||||
| -rw-r--r-- | ghc/runtime/io/ghcReadline.lc | 8 | ||||
| -rw-r--r-- | ghc/runtime/io/showTime.lc | 17 | ||||
| -rw-r--r-- | ghc/runtime/io/toClockSec.lc | 10 | ||||
| -rw-r--r-- | ghc/runtime/io/toLocalTime.lc | 36 | ||||
| -rw-r--r-- | ghc/runtime/io/toUTCTime.lc | 34 |
8 files changed, 91 insertions, 37 deletions
diff --git a/ghc/runtime/io/env.lc b/ghc/runtime/io/env.lc index 2e26595657..7ee20c1ceb 100644 --- a/ghc/runtime/io/env.lc +++ b/ghc/runtime/io/env.lc @@ -21,13 +21,15 @@ should continue to work properly. int dirtyEnv = 0; /* - * For some reason, OSF turns off the prototype for this if we're _POSIX_SOURCE. - * Seems to me that this ought to be an ANSI-ism rather than a POSIX-ism, - * but no matter. + * For some reason, OSF turns off the prototype for this if we're + * _POSIX_SOURCE. Seems to me that this ought to be an ANSI-ism + * rather than a POSIX-ism, but no matter. (JSM(?)) */ char * -strdup(const char *src) +strdup(char *src) /* should be "const char *" but then some + bozo OS (e.g., AIX) will come along and disagree. + The alt is to rename this routine (WDP 96/01) */ { int len = strlen(src) + 1; char *dst; diff --git a/ghc/runtime/io/getCPUTime.lc b/ghc/runtime/io/getCPUTime.lc index 9c8230784a..0a5d1a5c7f 100644 --- a/ghc/runtime/io/getCPUTime.lc +++ b/ghc/runtime/io/getCPUTime.lc @@ -50,10 +50,11 @@ * seconds to overflow 31 bits. */ -StgAddr -getCPUTime(STG_NO_ARGS) +StgByteArray +getCPUTime(cpuStruct) +StgByteArray cpuStruct; { - static StgInt cpu[4]; + StgInt *cpu=(StgInt *)cpuStruct; #if defined(HAVE_GETRUSAGE) && ! irix_TARGET_OS struct rusage t; @@ -84,7 +85,7 @@ getCPUTime(STG_NO_ARGS) return NULL; # endif #endif - return (StgAddr) cpu; + return (StgByteArray) cpuStruct; } \end{code} diff --git a/ghc/runtime/io/getDirectoryContents.lc b/ghc/runtime/io/getDirectoryContents.lc index da54d7d26a..025aae9751 100644 --- a/ghc/runtime/io/getDirectoryContents.lc +++ b/ghc/runtime/io/getDirectoryContents.lc @@ -27,9 +27,7 @@ /* For cleanup of partial answer on error */ static void -freeEntries(entries, count) - char **entries; - int count; +freeEntries(char **entries, int count) { int i; diff --git a/ghc/runtime/io/ghcReadline.lc b/ghc/runtime/io/ghcReadline.lc index 1d2133b8ec..ee8022b516 100644 --- a/ghc/runtime/io/ghcReadline.lc +++ b/ghc/runtime/io/ghcReadline.lc @@ -7,6 +7,8 @@ \begin{code} #include "rtsdefs.h" + +#include "ghcReadline.h" /* to make sure the code here agrees...*/ \end{code} Wrapper around the callback mechanism to allow Haskell side functions @@ -18,8 +20,7 @@ function. Before exiting, the Haskell function will deposit its result in the global variable $rl_return$. \begin{code} - -int current_narg, rl_return, current_kc; +I_ current_narg, rl_return, current_kc; char* rl_prompt_hack; @@ -27,7 +28,8 @@ StgStablePtr haskellRlEntry; StgStablePtr cbackList; -int genericRlCback (int narg,int kc) +I_ +genericRlCback (I_ narg, I_ kc) { current_narg = narg; current_kc = kc; diff --git a/ghc/runtime/io/showTime.lc b/ghc/runtime/io/showTime.lc index 79f66892cb..124dabd6d0 100644 --- a/ghc/runtime/io/showTime.lc +++ b/ghc/runtime/io/showTime.lc @@ -13,35 +13,36 @@ #endif StgAddr -showTime(size, d) +showTime(size, d, buf) StgInt size; StgByteArray d; +StgByteArray buf; { time_t t; struct tm *tm; - static char buf[32]; switch(size) { default: - return (StgAddr) "ClockTime.show{LibTime}: out of range"; + 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) "ClockTime.show{LibTime}: out of range"; + return + (StgAddr)strcpy(buf, "ClockTime.show{LibTime}: out of range"); break; case 1: t = (time_t) ((StgInt *)d)[0]; if (t < 0) - return (StgAddr) "ClockTime.show{LibTime}: out of range"; + return (StgAddr) strcpy(buf, "ClockTime.show{LibTime}: out of range"); break; } tm = localtime(&t); - if (tm != NULL && strftime(buf, sizeof(buf), "%a %b %d %T %Z %Y", tm) > 0) - return (StgAddr) buf; - return (StgAddr) "ClockTime.show{LibTime}: internal error"; + 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} diff --git a/ghc/runtime/io/toClockSec.lc b/ghc/runtime/io/toClockSec.lc index d00da864c7..6ff42473a2 100644 --- a/ghc/runtime/io/toClockSec.lc +++ b/ghc/runtime/io/toClockSec.lc @@ -10,7 +10,7 @@ #include "timezone.h" StgAddr -toClockSec(year, mon, mday, hour, min, sec, tz) +toClockSec(year, mon, mday, hour, min, sec, tz, res) StgInt year; StgInt mon; StgInt mday; @@ -18,9 +18,10 @@ StgInt hour; StgInt min; StgInt sec; StgInt tz; +StgByteArray res; { struct tm tm; - static time_t t; + time_t t; tm.tm_year = year - 1900; tm.tm_mon = mon; @@ -41,8 +42,9 @@ StgInt tz; #endif if (t == (time_t) -1) return NULL; - else - return &t; + + *(time_t *)res = t; + return res; } \end{code} diff --git a/ghc/runtime/io/toLocalTime.lc b/ghc/runtime/io/toLocalTime.lc index 50a5a104c8..b930ae11ca 100644 --- a/ghc/runtime/io/toLocalTime.lc +++ b/ghc/runtime/io/toLocalTime.lc @@ -9,14 +9,14 @@ #include "stgio.h" #include "timezone.h" -StgAddr -toLocalTime(size, d) +StgAddr +toLocalTime(size, d, res) StgInt size; StgByteArray d; +StgByteArray res; { + struct tm *tm,*tmp=(struct tm *)res; time_t t; - struct tm *tm; - static struct tm cache_tm; switch(size) { default: @@ -40,8 +40,32 @@ StgByteArray d; if (tm == NULL) return NULL; - cache_tm = *tm; - return &cache_tm; + /* + localtime() may return a ptr to statically allocated storage, + so to make toLocalTime reentrant, we manually copy + the structure into the (struct tm *) passed in. + */ + tmp->tm_sec = tm->tm_sec; + tmp->tm_min = tm->tm_min; + tmp->tm_hour = tm->tm_hour; + tmp->tm_mday = tm->tm_mday; + tmp->tm_mon = tm->tm_mon; + tmp->tm_year = tm->tm_year; + tmp->tm_wday = tm->tm_wday; + tmp->tm_yday = tm->tm_yday; + tmp->tm_isdst = tm->tm_isdst; + /* + If you don't have tm_zone in (struct tm), but + you get at it via the shared tmzone[], you'll + lose. Same goes for the tm_gmtoff field. + + */ +#if HAVE_TM_ZONE + strcpy(tmp->tm_zone,tm->tm_zone); + tmp->tm_gmtoff = tm->tm_gmtoff; +#endif + + return (StgAddr)res; } \end{code} diff --git a/ghc/runtime/io/toUTCTime.lc b/ghc/runtime/io/toUTCTime.lc index 1442993ea0..e7555595a5 100644 --- a/ghc/runtime/io/toUTCTime.lc +++ b/ghc/runtime/io/toUTCTime.lc @@ -10,13 +10,13 @@ #include "timezone.h" StgAddr -toUTCTime(size, d) +toUTCTime(size, d, res) StgInt size; StgByteArray d; +StgByteArray res; { time_t t; - struct tm *tm; - static struct tm cache_tm; + struct tm *tm,*tmp=(struct tm *)res; switch(size) { default: @@ -40,8 +40,32 @@ StgByteArray d; if (tm == NULL) return NULL; - cache_tm = *tm; - return &cache_tm; + /* + gmtime() may return a ptr to statically allocated storage, + so to make toUTCTime reentrant, we manually copy + the structure into the (struct tm *) passed in. + */ + tmp->tm_sec = tm->tm_sec; + tmp->tm_min = tm->tm_min; + tmp->tm_hour = tm->tm_hour; + tmp->tm_mday = tm->tm_mday; + tmp->tm_mon = tm->tm_mon; + tmp->tm_year = tm->tm_year; + tmp->tm_wday = tm->tm_wday; + tmp->tm_yday = tm->tm_yday; + tmp->tm_isdst = tm->tm_isdst; + /* + If you don't have tm_zone in (struct tm), but + you get at it via the shared tmzone[], you'll + lose. Same goes for the tm_gmtoff field. + + */ +#if HAVE_TM_ZONE + strcpy(tmp->tm_zone,tm->tm_zone); + tmp->tm_gmtoff = tm->tm_gmtoff; +#endif + + return (StgAddr)res; } \end{code} |
