mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-03 14:20:27 +00:00
string(TIMESTAMP): Fix unset TZ
The logic added by commit v3.6.0-rc1~338^2 (CMake: Extend TIMESTAMP sub-commands with new unix time format specifier, 2016-02-16) to restore the `TZ` environment variable does not properly handle the case in which the variable was originally not set. Unset the variable in this case. Fixes: #18431
This commit is contained in:
committed by
Brad King
parent
fd02538974
commit
f23760ffac
@@ -96,7 +96,7 @@ time_t cmTimestamp::CreateUtcTimeTFromTm(struct tm& tm) const
|
|||||||
// From Linux timegm() manpage.
|
// From Linux timegm() manpage.
|
||||||
|
|
||||||
std::string tz_old;
|
std::string tz_old;
|
||||||
cmSystemTools::GetEnv("TZ", tz_old);
|
bool const tz_was_set = cmSystemTools::GetEnv("TZ", tz_old);
|
||||||
tz_old = "TZ=" + tz_old;
|
tz_old = "TZ=" + tz_old;
|
||||||
|
|
||||||
// The standard says that "TZ=" or "TZ=[UNRECOGNIZED_TZ]" means UTC.
|
// The standard says that "TZ=" or "TZ=[UNRECOGNIZED_TZ]" means UTC.
|
||||||
@@ -109,7 +109,17 @@ time_t cmTimestamp::CreateUtcTimeTFromTm(struct tm& tm) const
|
|||||||
|
|
||||||
time_t result = mktime(&tm);
|
time_t result = mktime(&tm);
|
||||||
|
|
||||||
|
# ifdef CMAKE_BUILD_WITH_CMAKE
|
||||||
|
if (tz_was_set) {
|
||||||
|
cmSystemTools::PutEnv(tz_old);
|
||||||
|
} else {
|
||||||
|
cmSystemTools::UnsetEnv("TZ");
|
||||||
|
}
|
||||||
|
# else
|
||||||
|
// No UnsetEnv during bootstrap. This is good enough for CMake itself.
|
||||||
cmSystemTools::PutEnv(tz_old);
|
cmSystemTools::PutEnv(tz_old);
|
||||||
|
static_cast<void>(tz_was_set);
|
||||||
|
# endif
|
||||||
|
|
||||||
tzset();
|
tzset();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user