From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 7B9173858D33; Tue, 24 Jan 2023 23:51:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B9173858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674604301; bh=iewR6Oi9XPTi5RIaMDREcExoHV4lr5YrQKsxuBGq//0=; h=From:To:Subject:Date:From; b=jjvRAFrdF+UJN9i8u5vHv4suHcGT00+29iBkZAx9MIQc3wP0Gw7xROqIfJVxb1Exq dG9TpqfaafLltpDW8sgnAkBAlxCfPnMDWahVyVRhrTOjSwjhxn9r7/5EJrVsmLEIxn jnYZACpAnvwOyKBeTbcuV2k7fssGyG4e33U3XM5w= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-5339] libstdc++: Use /etc/sysconfig/clock for std::chrono::current_zone() [PR108530] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 33ed11085837e9492c6ed512931f5b6375c68ee7 X-Git-Newrev: e00d5cafbe1a77772ecc57eec921ff0b7dd41344 Message-Id: <20230124235141.7B9173858D33@sourceware.org> Date: Tue, 24 Jan 2023 23:51:41 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e00d5cafbe1a77772ecc57eec921ff0b7dd41344 commit r13-5339-ge00d5cafbe1a77772ecc57eec921ff0b7dd41344 Author: Jonathan Wakely Date: Tue Jan 24 23:43:24 2023 +0000 libstdc++: Use /etc/sysconfig/clock for std::chrono::current_zone() [PR108530] On some systems /etc/localtime is a tzfile, not a symlink to one. We cannot use it to determine the current time zone in that case. See if /etc/sysconfig/clock sets the variable DEFAULT_TIMEZONE instead. libstdc++-v3/ChangeLog: PR libstdc++/108530 * src/c++20/tzdb.cc (current_zone): Look for DEFAULT_TIMEZONE in /etc/sysconfig/clock. Diff: --- libstdc++-v3/src/c++20/tzdb.cc | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc index 20399b91e47..eb68111e444 100644 --- a/libstdc++-v3/src/c++20/tzdb.cc +++ b/libstdc++-v3/src/c++20/tzdb.cc @@ -62,8 +62,8 @@ #if ! __cpp_constinit # if __has_cpp_attribute(clang::require_constant_initialization) # define constinit [[clang::require_constant_initialization]] -#else // YOLO -# define constinit +# else // YOLO +# define constinit # endif #endif @@ -1663,6 +1663,26 @@ namespace std::chrono if (auto tz = do_locate_zone(this->zones, this->links, name)) return tz; } + + if (ifstream tzf{"/etc/sysconfig/clock"}) + { + string line; + string_view key = "DEFAULT_TIMEZONE="; + while (std::getline(tzf, line)) + if (line.starts_with(key)) + { + string_view name = line; + name.remove_prefix(key.size()); + if (name.size() != 0 && name.front() == '"') + { + name.remove_prefix(1); + if (auto pos = name.find('"'); pos != name.npos) + name = name.substr(0, pos); + } + if (auto tz = do_locate_zone(this->zones, this->links, name)) + return tz; + } + } #else // AIX stores current zone in $TZ in /etc/environment but the value // is typically a POSIX time zone name, not IANA zone.