From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 53AA2384843C; Mon, 2 Aug 2021 15:34:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 53AA2384843C 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 r12-2663] libstdc++: Fix filesystem::temp_directory_path [PR101709] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 2aaf69133f39f2409baa146e755a6c52eee4452f X-Git-Newrev: 38fb24ba4d67254cea78731fc8d961903dad9646 Message-Id: <20210802153430.53AA2384843C@sourceware.org> Date: Mon, 2 Aug 2021 15:34:30 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Aug 2021 15:34:30 -0000 https://gcc.gnu.org/g:38fb24ba4d67254cea78731fc8d961903dad9646 commit r12-2663-g38fb24ba4d67254cea78731fc8d961903dad9646 Author: Jonathan Wakely Date: Mon Aug 2 15:52:41 2021 +0100 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: --- libstdc++-v3/src/c++17/fs_ops.cc | 4 +++- libstdc++-v3/src/filesystem/ops-common.h | 13 +++++++------ libstdc++-v3/src/filesystem/ops.cc | 4 +++- 3 files changed, 13 insertions(+), 8 deletions(-) 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();