1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-11 22:31:12 +02:00

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.
This commit is contained in:
Gary Houston 2000-05-14 22:15:59 +00:00
parent 1f08acd9ee
commit b8a1b29b90

View file

@ -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;