]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix filesystem::temp_directory_path [PR101709]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 2 Aug 2021 14:52:41 +0000 (15:52 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 2 Aug 2021 15:33:44 +0000 (16:33 +0100)
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
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.

libstdc++-v3/src/c++17/fs_ops.cc
libstdc++-v3/src/filesystem/ops-common.h
libstdc++-v3/src/filesystem/ops.cc

index db2250e4841fd68e923159c7bf9ca7acf9c9e802..0e2d952673fd04ed4edb5adf6d639708ff1e0491 100644 (file)
@@ -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();
index b8bbf446883ccbdfd8c45a58cbd529bcb5b861a2..304e5b263fb77881ff7bc5f415649db9333111ff 100644 (file)
@@ -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
index 3494cbd19f95728c619e01d95f5b2204c1fb0516..b0a0f15e98fd7cc3290d46cb2d2ee5f5981653c4 100644 (file)
@@ -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();