From 3dbd4d94bf380f3efa8bba9b203ce7d4c8f47fbb Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 30 Jul 2021 13:56:14 +0100 Subject: libstdc++: Use secure_getenv for filesystem::temp_directory_path() [PR65018] 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. --- .../experimental/filesystem/operations/temp_directory_path.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'libstdc++-v3/testsuite/experimental/filesystem') diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc index 3e0833f..d6d251e 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -59,7 +60,10 @@ test01() clean_env(); if (!fs::exists("/tmp")) + { + puts("/tmp doesn't exist, not testing it for temp_directory_path"); return; // just give up + } std::error_code ec = make_error_code(std::errc::invalid_argument); fs::path p1 = fs::temp_directory_path(ec); @@ -75,8 +79,11 @@ test02() { clean_env(); - if (set_env("TMPDIR", __gnu_test::nonexistent_path().string())) + if (!set_env("TMP", __gnu_test::nonexistent_path().string())) + { + puts("Cannot set environment variables, not testing temp_directory_path"); return; // just give up + } std::error_code ec; fs::path p = fs::temp_directory_path(ec); -- cgit v1.1