* configure.in: check whether localtime caches TZ. copied from

Emacs 20.5.
	* acconfig.h: add LOCALTIME_CACHE.

	* These changes should make it unnecessary to call tzset from
	Scheme after modifying the TZ environment variable, even if the
	system date facilities cache the value.
	* stime.c (setzone, scm_localtime): added comments.
	(tzset): don't define a noop tzset macro if HAVE_TZSET not defined.
	(setzone): don't call tzset.
	(restorezone): call tzset only if HAVE_TZSET is defined.
	(scm_tzset): don't define if HAVE_TZSET not defined.  Change the
	doc string to indicate that this procedure isn't likely to do
	anything useful.
	(scm_localtime, scm_strftime, scm_mktime): call tzset if
	LOCALTIME_CACHE is defined.
This commit is contained in:
Gary Houston 2000-01-09 20:50:03 +00:00
commit 38c1d3c4d5
6 changed files with 100 additions and 12 deletions

View file

@ -1,3 +1,9 @@
2000-01-09 Gary Houston <ghouston@arglist.com>
* configure.in: check whether localtime caches TZ. copied from
Emacs 20.5.
* acconfig.h: add LOCALTIME_CACHE.
Tue Dec 14 09:12:22 1999 Greg J. Badros <gjb@cs.washington.edu>
* configure.in: Make it be guile-snarf.awk, since we'll be

4
NEWS
View file

@ -142,6 +142,10 @@ need minor modification: an error will be thrown with key
now possible to use `defined?' to check whether the facility is
available.
** Procedures which depend on the timezone should now give the correct
result on systems which cache the TZ environment variable, even if TZ
is changed without calling tzset.
* Changes to the networking interfaces:
** New functions: htons, ntohs, htonl, ntohl: for converting short and

View file

@ -110,6 +110,9 @@
/* Define if dlsym automatically supplies a leading underscore. */
#undef DLSYM_ADDS_USCORE
/* Define if localtime caches the TZ setting. */
#undef LOCALTIME_CACHE
/* Define if the operating system can restart system calls. */
#undef HAVE_RESTARTS

View file

@ -248,6 +248,53 @@ AC_CHECK_FUNCS(sethostent gethostent endhostent dnl
dnl </GNU-WIN32 hacks>
AC_MSG_CHECKING(whether localtime caches TZ)
AC_CACHE_VAL(guile_cv_localtime_cache,
[if test x$ac_cv_func_tzset = xyes; then
AC_TRY_RUN([#include <time.h>
#if STDC_HEADERS
# include <stdlib.h>
#endif
extern char **environ;
unset_TZ ()
{
char **from, **to;
for (to = from = environ; (*to = *from); from++)
if (! (to[0][0] == 'T' && to[0][1] == 'Z' && to[0][2] == '='))
to++;
}
char TZ_GMT0[] = "TZ=GMT0";
char TZ_PST8[] = "TZ=PST8";
main()
{
time_t now = time ((time_t *) 0);
int hour_GMT0, hour_unset;
if (putenv (TZ_GMT0) != 0)
exit (1);
hour_GMT0 = localtime (&now)->tm_hour;
unset_TZ ();
hour_unset = localtime (&now)->tm_hour;
if (putenv (TZ_PST8) != 0)
exit (1);
if (localtime (&now)->tm_hour == hour_GMT0)
exit (1);
unset_TZ ();
if (localtime (&now)->tm_hour != hour_unset)
exit (1);
exit (0);
}], guile_cv_localtime_cache=no, guile_cv_localtime_cache=yes,
[# If we have tzset, assume the worst when cross-compiling.
guile_cv_localtime_cache=yes])
else
# If we lack tzset, report that localtime does not cache TZ,
# since we can't invalidate the cache if we don't have tzset.
guile_cv_localtime_cache=no
fi])dnl
AC_MSG_RESULT($guile_cv_localtime_cache)
if test $guile_cv_localtime_cache = yes; then
AC_DEFINE(LOCALTIME_CACHE)
fi
dnl Test whether system calls are restartable by default on the
dnl current system. If they are not, we put a loop around every system
dnl call to check for EINTR (see SCM_SYSCALL) and do not attempt to

View file

@ -1,3 +1,18 @@
2000-01-09 Gary Houston <ghouston@arglist.com>
* These changes should make it unnecessary to call tzset from
Scheme after modifying the TZ environment variable, even if the
system date facilities cache the value.
* stime.c (setzone, scm_localtime): added comments.
(tzset): don't define a noop tzset macro if HAVE_TZSET not defined.
(setzone): don't call tzset.
(restorezone): call tzset only if HAVE_TZSET is defined.
(scm_tzset): don't define if HAVE_TZSET not defined. Change the
doc string to indicate that this procedure isn't likely to do
anything useful.
(scm_localtime, scm_strftime, scm_mktime): call tzset if
LOCALTIME_CACHE is defined.
2000-01-09 Mikael Djurfeldt <mdj@thalamus.nada.kth.se>
* posix.c (scm_sync): Return SCM_UNSPECIFIED.

View file

@ -205,12 +205,6 @@ terminated child processes.
#undef FUNC_NAME
#endif /* HAVE_TIMES */
#ifndef HAVE_TZSET
/* GNU-WIN32's cygwin.dll doesn't have this. */
#define tzset()
#endif
static long scm_my_base = 0;
SCM_DEFINE (scm_get_internal_run_time, "get-internal-run-time", 0, 0, 0,
@ -298,6 +292,10 @@ filltime (struct tm *bd_time, int zoff, char *zname)
static char tzvar[3] = "TZ";
extern char ** environ;
/* if zone is set, create a temporary environment with only a TZ
string. other threads or interrupt handlers shouldn't be allowed
to run until the corresponding restorezone is called. hence the use
of a static variable for tmpenv is no big deal. */
static char **
setzone (SCM zone, int pos, const char *subr)
{
@ -308,7 +306,6 @@ setzone (SCM zone, int pos, const char *subr)
static char *tmpenv[2];
char *buf;
/* if zone was supplied, set the environment temporarily. */
SCM_ASSERT (SCM_ROSTRINGP (zone), zone, pos, subr);
SCM_COERCE_SUBSTR (zone);
buf = scm_must_malloc (SCM_LENGTH (zone) + sizeof (tzvar) + 1,
@ -318,7 +315,6 @@ setzone (SCM zone, int pos, const char *subr)
tmpenv[0] = buf;
tmpenv[1] = 0;
environ = tmpenv;
tzset();
}
return oldenv;
}
@ -330,7 +326,10 @@ restorezone (SCM zone, char **oldenv, const char *subr)
{
scm_must_free (environ[0]);
environ = oldenv;
#ifdef HAVE_TZSET
/* for the possible benefit of user code linked with libguile. */
tzset();
#endif
}
}
@ -353,8 +352,14 @@ used.")
int err;
itime = SCM_NUM2LONG (1,time);
/* deferring interupts is essential since a) setzone may install a temporary
environment b) localtime uses a static buffer. */
SCM_DEFER_INTS;
oldenv = setzone (zone, SCM_ARG2, FUNC_NAME);
#ifdef LOCALTIME_CACHE
tzset ();
#endif
ltptr = localtime (&itime);
err = errno;
if (ltptr)
@ -487,6 +492,9 @@ as @var{bd-time} but with normalized values.")
SCM_DEFER_INTS;
oldenv = setzone (zone, SCM_ARG2, FUNC_NAME);
#ifdef LOCALTIME_CACHE
tzset ();
#endif
itime = mktime (&lt);
err = errno;
@ -539,18 +547,20 @@ as @var{bd-time} but with normalized values.")
}
#undef FUNC_NAME
#ifdef HAVE_TZSET
SCM_DEFINE (scm_tzset, "tzset", 0, 0, 0,
(void),
"Initialize the timezone from the TZ environment variable or the system
default. Usually this is done automatically by other procedures which
use the time zone, but this procedure may need to be used if TZ
is changed.")
"Initialize the timezone from the TZ environment variable
or the system default. It's not usually necessary to call this procedure
since it's done automatically by other procedures that depend on the
timezone.")
#define FUNC_NAME s_scm_tzset
{
tzset();
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
#endif /* HAVE_TZSET */
SCM_DEFINE (scm_strftime, "strftime", 2, 0, 0,
(SCM format, SCM stime),
@ -579,6 +589,9 @@ is the formatted string.
len = SCM_ROLENGTH (format);
tbuf = SCM_MUST_MALLOC (size);
#ifdef LOCALTIME_CACHE
tzset ();
#endif
while ((len = strftime (tbuf, size, fmt, &t)) == size)
{
scm_must_free (tbuf);