X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Ftime.c;h=7b4b167e7a825b0a7cc1703db54bc97b0c662dce;hb=440baf2d4f88579609615c6cbf598c336fb07445;hp=1fe3551b92d75f0670745f9e87c9df28e0344ec5;hpb=a530bbe337109d898d5b4a001fc8f1afa3b5dc39;p=sbcl.git diff --git a/src/runtime/time.c b/src/runtime/time.c index 1fe3551..7b4b167 100644 --- a/src/runtime/time.c +++ b/src/runtime/time.c @@ -13,27 +13,43 @@ * files for more information. */ -/* - * $Header$ - */ - #include #include +#include "sbcl.h" #include "runtime.h" -void get_timezone(time_t when, int *minwest, boolean *dst) +#ifdef LISP_FEATURE_HPUX +struct tm *gmtime_r(const time_t *timer, struct tm *result); +struct tm *localtime_r(const time_t *timer, struct tm *result); +#endif + +void get_timezone(time_t when, int *secwest, boolean *dst) { struct tm ltm, gtm; - int mw; + int sw; +#ifdef LISP_FEATURE_WIN32 + /* No _r versions on Windows, but the API documentation also + * doesn't warn them about being non-reentrant... So here's + * hoping they actually are -- once Windows grows threads + * this better be checked, though. + * + * The Windows versions also don't support times before the + * epoch, so we kludge it. */ + if (when < 0) + when = 0; ltm = *localtime(&when); gtm = *gmtime(&when); +#else + ltm = *localtime_r(&when, <m); + gtm = *gmtime_r(&when, >m); +#endif - mw = ((gtm.tm_hour*60)+gtm.tm_min) - ((ltm.tm_hour*60)+ltm.tm_min); + sw = (((gtm.tm_hour*60)+gtm.tm_min)*60+gtm.tm_sec) - (((ltm.tm_hour*60)+ltm.tm_min)*60+ltm.tm_sec); if ((gtm.tm_wday + 1) % 7 == ltm.tm_wday) - mw -= 24*60; + sw -= 24*3600; else if (gtm.tm_wday == (ltm.tm_wday + 1) % 7) - mw += 24*60; - *minwest = mw; + sw += 24*3600; + *secwest = sw; *dst = ltm.tm_isdst; }