From d4f4e723d0b4f09d72880f1679c02d586bf8abfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 29 Oct 2020 12:10:26 +0200 Subject: [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 --- libcxx/src/filesystem/operations.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'libcxx/src/filesystem/operations.cpp') diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp index dccec93..674f191 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 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)) -- cgit v1.1