From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id BF81F3858D1E; Sat, 14 Jan 2023 21:59:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF81F3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673733572; bh=3qYkdaWEz7LEL5wqHvXlYVDyqG12lzgyYa4MUTPsiCk=; h=From:To:Subject:Date:From; b=tCcaapPx0NA5xDd2qgrCs/5WmmMcW0Ss3ZqyfrJBnaK+yO+mn+ZjYDjQ4rrO0I2xj 5a0WETDPnuCuvud5IBWmyolUY7S4f/wzU9LH75z5hE4twWqnK8Ly+kn+weE4qrlhkC 6b3WRUjOG9Vu36B5TUnl3dkMZGA+KBGdjtXJtri4= 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-5170] libstdc++: Implement std::chrono::current_zone() for AIX [PR108409] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: c47dcb95666ce0b48f0ff09aa99483fd12df8714 X-Git-Newrev: d80e5a7b30e5d045c808f5235123e366e4e9286c Message-Id: <20230114215932.BF81F3858D1E@sourceware.org> Date: Sat, 14 Jan 2023 21:59:32 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d80e5a7b30e5d045c808f5235123e366e4e9286c commit r13-5170-gd80e5a7b30e5d045c808f5235123e366e4e9286c Author: Jonathan Wakely Date: Sat Jan 14 20:13:32 2023 +0000 libstdc++: Implement std::chrono::current_zone() for AIX [PR108409] libstdc++-v3/ChangeLog: PR libstdc++/108409 * src/c++20/tzdb.cc (current_zone()) [_AIX]: Use TZ environment variable. Diff: --- libstdc++-v3/src/c++20/tzdb.cc | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc index a37859dffdb..eaaea367f4f 100644 --- a/libstdc++-v3/src/c++20/tzdb.cc +++ b/libstdc++-v3/src/c++20/tzdb.cc @@ -34,6 +34,10 @@ #include // mutex #include // filesystem::read_symlink +#ifndef _AIX +# include // getenv +#endif + #ifndef __GTHREADS # define USE_ATOMIC_SHARED_PTR 0 #elif _WIN32 @@ -1625,6 +1629,7 @@ namespace std::chrono { // TODO cache this function's result? +#ifndef _AIX error_code ec; // This should be a symlink to e.g. /usr/share/zoneinfo/Europe/London auto path = filesystem::read_symlink("/etc/localtime", ec); @@ -1655,11 +1660,25 @@ namespace std::chrono if (auto tz = do_locate_zone(this->zones, this->links, name)) return tz; } - - // TODO AIX stores current zone in $TZ in /etc/environment but the value +#else + // AIX stores current zone in $TZ in /etc/environment but the value // is typically a POSIX time zone name, not IANA zone. // https://developer.ibm.com/articles/au-aix-posix/ // https://www.ibm.com/support/pages/managing-time-zone-variable-posix + if (const char* env = std::getenv("TZ")) + { + string_view s(env); + if (s == "GMT0") + s = "Etc/GMT"; + else if (s.size() == 4 && s[3] == '0') + s = "Etc/UTC"; + + // This will fail unless TZ contains an IANA time zone name, + // or one of the special cases above. + if (auto tz = do_locate_zone(this->zones, this->links, s)) + return tz; + } +#endif __throw_runtime_error("tzdb: cannot determine current zone"); }