From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Implement std::chrono::current_zone() for AIX [PR108409]
Date: Sat, 14 Jan 2023 21:59:53 +0000 [thread overview]
Message-ID: <20230114215953.1299851-1-jwakely@redhat.com> (raw)
Tested x86_64-linux and powerpc-aix. Pushed to trunk.
-- >8 --
libstdc++-v3/ChangeLog:
PR libstdc++/108409
* src/c++20/tzdb.cc (current_zone()) [_AIX]: Use TZ environment
variable.
---
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> // mutex
#include <filesystem> // filesystem::read_symlink
+#ifndef _AIX
+# include <cstdlib> // 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");
}
--
2.39.0
reply other threads:[~2023-01-14 21:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230114215953.1299851-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).