From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 3FCC73858D20 for ; Sat, 14 Jan 2023 21:59:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3FCC73858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673733598; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2ZsiRf7bEsDNAfQCb6O/vXb7bZoRQ80DkXoYZ++Hwdk=; b=Wv93+oVsyGLOzWZ4S9XbZmH0u4H7yP6gT2Lvk7moGWwjZVoGu7znIVmkT4huhsoYJQLsEB QZFqKfyBdexAhbMOrFBmN/pkXVZkd+miCwij/7XnglA1myzZv/r/KbK8BMtZ0ycPeQgPpv 4S7E3MTjyeuz8MojChGhoKG0VSSYJmc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-22-w-HBNJD2Oda5ZSngyMceqA-1; Sat, 14 Jan 2023 16:59:54 -0500 X-MC-Unique: w-HBNJD2Oda5ZSngyMceqA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 55A6A101A521; Sat, 14 Jan 2023 21:59:54 +0000 (UTC) Received: from localhost (unknown [10.33.36.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CC6940C2064; Sat, 14 Jan 2023 21:59:54 +0000 (UTC) From: Jonathan Wakely 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 Message-Id: <20230114215953.1299851-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 #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"); } -- 2.39.0