public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r11-9921] libstdc++: Fix filesystem::temp_directory_path [PR101709]
Date: Thu, 21 Apr 2022 13:53:12 +0000 (GMT)	[thread overview]
Message-ID: <20220421135312.443313857343@sourceware.org> (raw)

https://gcc.gnu.org/g:df783ecbaaea340297df8a3bd6666068ce131a33

commit r11-9921-gdf783ecbaaea340297df8a3bd6666068ce131a33
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Aug 2 15:52:41 2021 +0100

    libstdc++: Fix filesystem::temp_directory_path [PR101709]
    
    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.
    
    (cherry picked from commit 38fb24ba4d67254cea78731fc8d961903dad9646)

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 3d437cd0634..2eac9977785 100644
--- a/libstdc++-v3/src/c++17/fs_ops.cc
+++ b/libstdc++-v3/src/c++17/fs_ops.cc
@@ -1597,7 +1597,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 714514bc116..a76a2e6198d 100644
--- a/libstdc++-v3/src/filesystem/ops-common.h
+++ b/libstdc++-v3/src/filesystem/ops-common.h
@@ -571,7 +571,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;
@@ -582,17 +582,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 f4ebf789078..1ee22967a4f 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();


                 reply	other threads:[~2022-04-21 13:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220421135312.443313857343@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).