aboutsummaryrefslogtreecommitdiff
path: root/libcxx/src/filesystem/operations.cpp
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2020-10-29 12:10:26 +0200
committerMartin Storsjö <martin@martin.st>2021-02-05 22:47:33 +0200
commitd4f4e723d0b4f09d72880f1679c02d586bf8abfa (patch)
tree666eb160486c67e6bd59c2914ad572e1106b1b05 /libcxx/src/filesystem/operations.cpp
parent4d292d531bea6f7a6021f212e59b3826bc7cd913 (diff)
downloadllvm-d4f4e723d0b4f09d72880f1679c02d586bf8abfa.zip
llvm-d4f4e723d0b4f09d72880f1679c02d586bf8abfa.tar.gz
llvm-d4f4e723d0b4f09d72880f1679c02d586bf8abfa.tar.bz2
[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
Diffstat (limited to 'libcxx/src/filesystem/operations.cpp')
-rw-r--r--libcxx/src/filesystem/operations.cpp14
1 files changed, 14 insertions, 0 deletions
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<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))