2000-05-14 Gary Houston <ghouston@arglist.com>
authorGary Houston <ghouston@arglist.com>
Sun, 14 May 2000 22:15:59 +0000 (22:15 +0000)
committerGary Houston <ghouston@arglist.com>
Sun, 14 May 2000 22:15:59 +0000 (22:15 +0000)
* 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

index 5f57b40..601191d 100644 (file)
@@ -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;