[libcxx-commits] [libcxx] d4f4e72 - [libcxx] Implement temp_directory_path using GetTempPath on windows
Martin Storsjö via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Feb 5 12:48:01 PST 2021
Author: Martin Storsjö
Date: 2021-02-05T22:47:33+02:00
New Revision: d4f4e723d0b4f09d72880f1679c02d586bf8abfa
URL: https://github.com/llvm/llvm-project/commit/d4f4e723d0b4f09d72880f1679c02d586bf8abfa
DIFF: https://github.com/llvm/llvm-project/commit/d4f4e723d0b4f09d72880f1679c02d586bf8abfa.diff
LOG: [libcxx] Implement temp_directory_path using GetTempPath on windows
This does roughly the same as the manual implementation, but checks
a slightly different set of environment variables and has a more
appropriate fallback if no environment variables are available
(/tmp isn't a very useful fallback on windows).
Differential Revision: https://reviews.llvm.org/D91175
Added:
Modified:
libcxx/src/filesystem/operations.cpp
Removed:
################################################################################
diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp
index dccec9378531..674f19154e6f 100644
--- a/libcxx/src/filesystem/operations.cpp
+++ b/libcxx/src/filesystem/operations.cpp
@@ -1347,6 +1347,19 @@ file_status __symlink_status(const path& p, error_code* ec) {
path __temp_directory_path(error_code* ec) {
ErrorHandler<path> err("temp_directory_path", ec);
+#if defined(_LIBCPP_WIN32API)
+ wchar_t buf[MAX_PATH];
+ DWORD retval = GetTempPathW(MAX_PATH, buf);
+ if (!retval)
+ return err.report(detail::make_windows_error(GetLastError()));
+ if (retval > MAX_PATH)
+ return err.report(errc::filename_too_long);
+ // GetTempPathW returns a path with a trailing slash, which we
+ // shouldn't include for consistency.
+ if (buf[retval-1] == L'\\')
+ buf[retval-1] = L'\0';
+ path p(buf);
+#else
const char* env_paths[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR"};
const char* ret = nullptr;
@@ -1357,6 +1370,7 @@ path __temp_directory_path(error_code* ec) {
ret = "/tmp";
path p(ret);
+#endif
error_code m_ec;
file_status st = detail::posix_stat(p, &m_ec);
if (!status_known(st))
More information about the libcxx-commits
mailing list