From patchwork Sat Jan 14 21:59:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 43799 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp463184wrn; Sat, 14 Jan 2023 14:00:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXuIH8Vn4IOJwnL81g/mEOdWxfPGESXCyAuWbe1xHliYp1tL9F4HyN/00+2w6AnvWWmkFBSR X-Received: by 2002:aa7:c98f:0:b0:49d:32d0:126 with SMTP id c15-20020aa7c98f000000b0049d32d00126mr4642366edt.20.1673733659666; Sat, 14 Jan 2023 14:00:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673733659; cv=none; d=google.com; s=arc-20160816; b=Ercv0ARsiWzgcnImt+HQg11QpPLaeZRnBzKlNJq64TOWbpNz79+DE6Xyj0Ab/fiwx4 2Za91Yo/gt2kjUOzHOJIzSmvNiwKe+qK8v9jPPku0xHglfhtMjtVC269w/dsahF0L651 K7zt1kLqYesf+c/ZvsPfCi7fN1g6MF5dF0IWikiJOZppIkMxy8BxFNGATwQEU/ktuc4n kfwf7Z1C0ZPG2B26CqFyuW/EwpJ+A59chdj4VRSN+LVlXcDZ16xO1NBbXDZLej30ks8/ xfDRrlT1sWP1RHbFJjmPNr5USkWZRwhB3V4LrXCMQVhk/hjGdVWPvMrZjvXAzEQ3twT1 Kyow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=2ZsiRf7bEsDNAfQCb6O/vXb7bZoRQ80DkXoYZ++Hwdk=; b=SYFq50fTB5om/APB7QVcwi4GvOcLuSG1ruu0Q6FrV3BCptzbrKwEeeVmxgdRCd7YgB 4DduXuT7NSXo9iq3GD6/10EC+6az6vZrXvfOkR+AjYNFjHeH4HEMt7YUWSWV8dT+m5fD EYPAgu6H8h5KZIQUeDH30fhvzpr9Hn8WjjEIlqbZWQnhBO2XEAnqUaTvVYx3Bkny3qMc 7+lCtCoWAq7g1NJ+a2dDoT9aGncRYHeExMsmeuEb8JDdcjXGD2AJOw/0gqVdSCfEAa5O LDbQJ+IQ54nGBPuAk+LKrSaF3SQpcDM4LxE5VTtw14+iOd3lTe4RlE11iubyYqtxHpYv 7wzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GBNXD5e2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r25-20020aa7d599000000b0048ccd99d3fasi2653376edq.482.2023.01.14.14.00.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 14:00:59 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GBNXD5e2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7BB403858022 for ; Sat, 14 Jan 2023 22:00:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BB403858022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673733643; bh=2ZsiRf7bEsDNAfQCb6O/vXb7bZoRQ80DkXoYZ++Hwdk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=GBNXD5e2lHLwvzgvHoM+QrOyiLsl7A57EtubJOyy2VHAduT4827JVZ/hE9CH13AqY bY5DI00CQtNygZcjK6Cp+2MCqjc7abeIuRF9dNKxu5+fUEuwXjPxWBEIh/XBX0Xs4a ghMr4OMTFyUk2t4DOoNjDGA7Mm4X+swhTR+XXJD0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 77B553858C62 for ; Sat, 14 Jan 2023 21:59:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 77B553858C62 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) 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755036945820812344?= X-GMAIL-MSGID: =?utf-8?q?1755036945820812344?= 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"); }