summaryrefslogtreecommitdiffstats
path: root/Source/cmTimestamp.cxx
diff options
context:
space:
mode:
authorJose Luis Blanco-Claraco <jlblanco@ual.es>2018-10-08 21:59:44 (GMT)
committerBrad King <brad.king@kitware.com>2018-10-09 11:26:40 (GMT)
commitf23760ffac85f4cee6206c654265df9b3a46bf90 (patch)
tree3b2bf09d504326898c55887cb289195f934b02d5 /Source/cmTimestamp.cxx
parentfd02538974dd952a8639d371c2c0067d30d5469a (diff)
downloadCMake-f23760ffac85f4cee6206c654265df9b3a46bf90.zip
CMake-f23760ffac85f4cee6206c654265df9b3a46bf90.tar.gz
CMake-f23760ffac85f4cee6206c654265df9b3a46bf90.tar.bz2
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
Diffstat (limited to 'Source/cmTimestamp.cxx')
-rw-r--r--Source/cmTimestamp.cxx12
1 files changed, 11 insertions, 1 deletions
diff --git a/Source/cmTimestamp.cxx b/Source/cmTimestamp.cxx
index 14cf6e9..da5d21e 100644
--- a/Source/cmTimestamp.cxx
+++ b/Source/cmTimestamp.cxx
@@ -96,7 +96,7 @@ time_t cmTimestamp::CreateUtcTimeTFromTm(struct tm& tm) const
// From Linux timegm() manpage.
std::string tz_old;
- cmSystemTools::GetEnv("TZ", tz_old);
+ bool const tz_was_set = cmSystemTools::GetEnv("TZ", tz_old);
tz_old = "TZ=" + tz_old;
// 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);
+# 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);
+ static_cast<void>(tz_was_set);
+# endif
tzset();