From b8a1b29b90108dda98e6d1a086e9f63f4e7ff673 Mon Sep 17 00:00:00 2001 From: Gary Houston Date: Sun, 14 May 2000 22:15:59 +0000 Subject: [PATCH] 2000-05-14 Gary Houston * stime.c (scm_strftime): if HAVE_TM_ZONE is not defined, hack the TZ environment variable so that the %Z format returns the zone from the input vector instead of the system default. --- libguile/stime.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/libguile/stime.c b/libguile/stime.c index 5f57b40cc..601191d33 100644 --- a/libguile/stime.c +++ b/libguile/stime.c @@ -572,15 +572,45 @@ SCM_DEFINE (scm_strftime, "strftime", 2, 0, 0, len = SCM_ROLENGTH (format); tbuf = SCM_MUST_MALLOC (size); -#ifdef LOCALTIME_CACHE - tzset (); + { +#if !defined (HAVE_TM_ZONE) + /* it seems the only way to tell non-GNU versions of strftime what + zone to use (for the %Z format) is to set TZ in the + environment. interrupts and thread switching must be deferred + until TZ is restored. */ + char **oldenv = NULL; + SCM *velts = SCM_VELTS (stime); + + if (SCM_NFALSEP (velts[10])) + { + /* it's not required that the TZ setting be correct, just that + it has the right name. so try something like TZ=EST. + possibly TZ=EST0 would be better. */ + SCM_DEFER_INTS; + oldenv = setzone (velts[10], SCM_ARG2, FUNC_NAME); + } +#endif + +#ifdef LOCALTIME_CACHE + tzset (); +#endif + + while ((len = strftime (tbuf, size, fmt, &t)) == size) + { + scm_must_free (tbuf); + size *= 2; + tbuf = SCM_MUST_MALLOC (size); + } + +#if !defined (HAVE_TM_ZONE) + if (SCM_NFALSEP (velts[10])) + { + restorezone (velts[10], oldenv, FUNC_NAME); + SCM_ALLOW_INTS; + } #endif - while ((len = strftime (tbuf, size, fmt, &t)) == size) - { - scm_must_free (tbuf); - size *= 2; - tbuf = SCM_MUST_MALLOC (size); } + result = scm_makfromstr (tbuf, len, 0); scm_must_free (tbuf); return result;