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 ESMTP id E4A463889C31 for ; Mon, 2 Aug 2021 15:35:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E4A463889C31 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-390-aDPiz-0xOQmlgYS6VH6WkA-1; Mon, 02 Aug 2021 11:35:48 -0400 X-MC-Unique: aDPiz-0xOQmlgYS6VH6WkA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 356D6190A7C0; Mon, 2 Aug 2021 15:35:47 +0000 (UTC) Received: from localhost (unknown [10.33.36.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE3075C1C2; Mon, 2 Aug 2021 15:35:46 +0000 (UTC) Date: Mon, 2 Aug 2021 16:35:45 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix filesystem::temp_directory_path [PR101709] Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="xkA+29eLAUAVSClM" Content-Disposition: inline X-Spam-Status: No, score=-14.2 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Aug 2021 15:36:01 -0000 --xkA+29eLAUAVSClM Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline On 30/07/21 18:13 +0100, Jonathan Wakely wrote: >This adds a configure check for the GNU extension secure_getenv and then >uses it for looking up TMPDIR and similar variables. > >Signed-off-by: Jonathan Wakely > >libstdc++-v3/ChangeLog: > > PR libstdc++/65018 > * configure.ac: Check for secure_getenv. > * config.h.in: Regenerate. > * configure: Regenerate. > * src/filesystem/ops-common.h (get_temp_directory_from_env): New > helper function to obtain path from the environment. > * src/c++17/fs_ops.cc (fs::temp_directory_path): Use new helper. > * src/filesystem/ops.cc (fs::temp_directory_path): Likewise. > * testsuite/27_io/filesystem/operations/temp_directory_path.cc: > Print messages if test cannot be run. > * testsuite/experimental/filesystem/operations/temp_directory_path.cc: > Likewise. Fix incorrect condition. Use "TMP" to work with > Windows as well as POSIX. This refactoring broke the Windows build. Fixed like so. Tested powerpc64le-linux and x86_64-w64-mingw32 (cross-compiled and run under Wine). Committed to trunk. --xkA+29eLAUAVSClM Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit 38fb24ba4d67254cea78731fc8d961903dad9646 Author: Jonathan Wakely Date: Mon Aug 2 15:52:41 2021 libstdc++: Fix filesystem::temp_directory_path [PR101709] Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: PR libstdc++/101709 * src/filesystem/ops-common.h (get_temp_directory_from_env): Add error_code parameter. * src/c++17/fs_ops.cc (fs::temp_directory_path): Pass error_code argument to get_temp_directory_from_env and check it. * src/filesystem/ops.cc (fs::temp_directory_path): Likewise. diff --git a/libstdc++-v3/src/c++17/fs_ops.cc b/libstdc++-v3/src/c++17/fs_ops.cc index db2250e4841..0e2d952673f 100644 --- a/libstdc++-v3/src/c++17/fs_ops.cc +++ b/libstdc++-v3/src/c++17/fs_ops.cc @@ -1604,7 +1604,9 @@ fs::temp_directory_path() fs::path fs::temp_directory_path(error_code& ec) { - path p = fs::get_temp_directory_from_env(); + path p = fs::get_temp_directory_from_env(ec); + if (ec) + return p; auto st = status(p, ec); if (ec) p.clear(); diff --git a/libstdc++-v3/src/filesystem/ops-common.h b/libstdc++-v3/src/filesystem/ops-common.h index b8bbf446883..304e5b263fb 100644 --- a/libstdc++-v3/src/filesystem/ops-common.h +++ b/libstdc++-v3/src/filesystem/ops-common.h @@ -572,7 +572,7 @@ _GLIBCXX_BEGIN_NAMESPACE_FILESYSTEM // Caller must check that the path is an accessible directory. #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS inline wstring - get_temp_directory_from_env() + get_temp_directory_from_env(error_code& ec) { unsigned len = 1024; std::wstring buf; @@ -583,17 +583,18 @@ _GLIBCXX_BEGIN_NAMESPACE_FILESYSTEM } while (len > buf.size()); if (len == 0) - { - ec.assign((int)GetLastError(), std::system_category()); - return p; - } + ec.assign((int)GetLastError(), std::system_category()); + else + ec.clear(); + buf.resize(len); return buf; } #else inline const char* - get_temp_directory_from_env() noexcept + get_temp_directory_from_env(error_code& ec) noexcept { + ec.clear(); for (auto env : { "TMPDIR", "TMP", "TEMP", "TEMPDIR" }) { #if _GLIBCXX_HAVE_SECURE_GETENV diff --git a/libstdc++-v3/src/filesystem/ops.cc b/libstdc++-v3/src/filesystem/ops.cc index 3494cbd19f9..b0a0f15e98f 100644 --- a/libstdc++-v3/src/filesystem/ops.cc +++ b/libstdc++-v3/src/filesystem/ops.cc @@ -1302,7 +1302,9 @@ fs::temp_directory_path() fs::path fs::temp_directory_path(error_code& ec) { - path p = fs::get_temp_directory_from_env(); + path p = fs::get_temp_directory_from_env(ec); + if (ec) + return p; auto st = status(p, ec); if (ec) p.clear(); --xkA+29eLAUAVSClM--