diff options
author | Gary Houston <ghouston@arglist.com> | 2000-05-14 22:15:59 +0000 |
---|---|---|
committer | Gary Houston <ghouston@arglist.com> | 2000-05-14 22:15:59 +0000 |
commit | b8a1b29b90108dda98e6d1a086e9f63f4e7ff673 (patch) | |
tree | a3ff27b520ed83ba0b118cafcd77a774eac24427 | |
parent | 1f08acd9eef40805840d17e61ecfc4b4658f8fe1 (diff) | |
download | guile-b8a1b29b90108dda98e6d1a086e9f63f4e7ff673.tar.gz |
2000-05-14 Gary Houston <ghouston@arglist.com>
* 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.
-rw-r--r-- | libguile/stime.c | 42 |
1 files changed, 36 insertions, 6 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); + { +#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 (); + 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; |