embryo: don't mess with env vars in tzdate if no tz is passed

This commit is contained in:
Mike Blumenkrantz 2016-03-24 17:37:27 -04:00
parent ab4bfcf250
commit 5edd64c849
1 changed files with 9 additions and 6 deletions

View File

@ -107,7 +107,7 @@ _embryo_time_tzdate(Embryo_Program *ep, Embryo_Cell *params)
tzenv = getenv("TZ"); tzenv = getenv("TZ");
if (tzenv) if (tzenv)
strncpy(prevtz, tzenv, sizeof(prevtz) - 1); strncpy(prevtz, tzenv, sizeof(prevtz) - 1);
if (tz) if (tz && tz[0])
{ {
setenv("TZ", tz, 1); setenv("TZ", tz, 1);
tzset(); tzset();
@ -115,11 +115,14 @@ _embryo_time_tzdate(Embryo_Program *ep, Embryo_Cell *params)
gettimeofday(&timev, NULL); gettimeofday(&timev, NULL);
tt = (time_t)(timev.tv_sec); tt = (time_t)(timev.tv_sec);
tm = localtime(&tt); tm = localtime(&tt);
if (prevtz[0]) if (tz && tz[0])
setenv("TZ", prevtz, 1); {
else if (prevtz[0])
unsetenv("TZ"); setenv("TZ", prevtz, 1);
tzset(); else
unsetenv("TZ");
tzset();
}
if (tm) if (tm)
{ {
Embryo_Cell *cptr; Embryo_Cell *cptr;