unsetenv() patch for TZ
Craig Howland
howland@LGSInnovations.com
Mon Mar 30 21:38:00 GMT 2015
On 03/30/2015 03:45 PM, Corinna Vinschen wrote:
> On Mar 30 21:30, Corinna Vinschen wrote:
>> On Mar 30 11:38, Craig Howland wrote:
>>> On 06/07/2013 06:23 AM, Corinna Vinschen wrote:
>> Btw., was there some (historical?) reason that _setenv_r called tzset,
>> and not _tzset_r?
>
Patch modified to call _tzset_r() instead of tzset(), to save that 1 level of
overhead. (Pending the general lock question.)
-------------- next part --------------
diff --git a/newlib/libc/stdlib/setenv_r.c b/newlib/libc/stdlib/setenv_r.c
index f9ff2c1..c32c6ac 100644
--- a/newlib/libc/stdlib/setenv_r.c
+++ b/newlib/libc/stdlib/setenv_r.c
@@ -79,9 +79,6 @@ _DEFUN (_setenv_r, (reent_ptr, name, value, rewrite),
{ /* old larger; copy over */
while ((*C++ = *value++) != 0);
ENV_UNLOCK;
- /* if we are changing the TZ environment variable, update timezone info */
- if (strcmp (name, "TZ") == 0)
- tzset ();
return 0;
}
}
@@ -128,10 +125,6 @@ _DEFUN (_setenv_r, (reent_ptr, name, value, rewrite),
ENV_UNLOCK;
- /* if we are setting the TZ environment variable, update timezone info */
- if (strncmp ((*p_environ)[offset], "TZ=", 3) == 0)
- tzset ();
-
return 0;
}
diff --git a/newlib/libc/time/lcltime_r.c b/newlib/libc/time/lcltime_r.c
index 9094e5d..89af2b3 100644
--- a/newlib/libc/time/lcltime_r.c
+++ b/newlib/libc/time/lcltime_r.c
@@ -31,6 +31,7 @@ _DEFUN (localtime_r, (tim_p, res),
year = res->tm_year + YEAR_BASE;
ip = __month_lengths[isleap(year)];
+ _tzset_r(_REENT);
TZ_LOCK;
if (_daylight)
{
diff --git a/newlib/libc/time/mktime.c b/newlib/libc/time/mktime.c
index 5bedf5a..4dd305d 100644
--- a/newlib/libc/time/mktime.c
+++ b/newlib/libc/time/mktime.c
@@ -197,6 +197,8 @@ _DEFUN(mktime, (tim_p),
/* compute total seconds */
tim += (days * _SEC_IN_DAY);
+ _tzset_r(_REENT);
+
TZ_LOCK;
if (_daylight)
diff --git a/newlib/libc/time/strftime.c b/newlib/libc/time/strftime.c
index 7db3383..e980375 100644
--- a/newlib/libc/time/strftime.c
+++ b/newlib/libc/time/strftime.c
@@ -1283,6 +1283,7 @@ recurse:
if (tim_p->tm_isdst >= 0)
{
long offset;
+ _tzset_r(_REENT);
#if defined (__CYGWIN__)
/* Cygwin must check if the application has been built with or
@@ -1313,6 +1314,7 @@ recurse:
size_t size;
const char *tznam;
+ _tzset_r(_REENT);
TZ_LOCK;
#if defined (__CYGWIN__)
/* See above. */
More information about the Newlib
mailing list