diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2017-02-05 17:21:52 +0000 |
---|---|---|
committer | Saleem Abdulrasool <compnerd@compnerd.org> | 2017-02-05 17:21:52 +0000 |
commit | 2f7ceb120eb0ece24c671b27680025ffe75eae9d (patch) | |
tree | d7372a12260e7cd1feb27705b647b7b6855c23de /libcxx/src/experimental/filesystem | |
parent | 49c21222a0d6086ea1d3021bfbc0b119e0c07454 (diff) | |
download | bcm5719-llvm-2f7ceb120eb0ece24c671b27680025ffe75eae9d.tar.gz bcm5719-llvm-2f7ceb120eb0ece24c671b27680025ffe75eae9d.zip |
filesystem: fix n4100 conformance for `temp_directory_path`
N4100 states that an error shall be reported if
`!exists(p) || !is_directory(p)`. We were missing the first half of the
conditional. Invert the error and normal code paths to make the code
easier to follow.
llvm-svn: 294127
Diffstat (limited to 'libcxx/src/experimental/filesystem')
-rw-r--r-- | libcxx/src/experimental/filesystem/operations.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/libcxx/src/experimental/filesystem/operations.cpp b/libcxx/src/experimental/filesystem/operations.cpp index 6c7e4cf2488..4ca7727d06c 100644 --- a/libcxx/src/experimental/filesystem/operations.cpp +++ b/libcxx/src/experimental/filesystem/operations.cpp @@ -886,23 +886,28 @@ path __system_complete(const path& p, std::error_code *ec) { return absolute(p, current_path()); } -path __temp_directory_path(std::error_code *ec) { - const char* env_paths[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR"}; - const char* ret = nullptr; - for (auto & ep : env_paths) { - if ((ret = std::getenv(ep))) - break; - } - path p(ret ? ret : "/tmp"); - std::error_code m_ec; - if (is_directory(p, m_ec)) { - if (ec) ec->clear(); - return p; - } +path __temp_directory_path(std::error_code* ec) { + const char* env_paths[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR"}; + const char* ret = nullptr; + + for (auto& ep : env_paths) + if ((ret = std::getenv(ep))) + break; + if (ret == nullptr) + ret = "/tmp"; + + path p(ret); + std::error_code m_ec; + if (!exists(p, m_ec) || !is_directory(p, m_ec)) { if (!m_ec || m_ec == make_error_code(errc::no_such_file_or_directory)) - m_ec = make_error_code(errc::not_a_directory); + m_ec = make_error_code(errc::not_a_directory); set_or_throw(m_ec, ec, "temp_directory_path"); return {}; + } + + if (ec) + ec->clear(); + return p; } // An absolute path is composed according to the table in [fs.op.absolute]. |