[libcxx-commits] [PATCH] D91175: [19/N] [libcxx] Implement temp_directory_path using GetTempPath on windows
Martin Storsjö via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Dec 8 01:37:19 PST 2020
mstorsjo updated this revision to Diff 310107.
mstorsjo retitled this revision from "[19/N] [libcxx] Fix the fallback case in temp_directory_path for windows" to "[19/N] [libcxx] Implement temp_directory_path using GetTempPath on windows".
mstorsjo edited the summary of this revision.
mstorsjo added a comment.
Using GetTempPathW instead of the manual code checking environment variables.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D91175/new/
https://reviews.llvm.org/D91175
Files:
libcxx/src/filesystem/operations.cpp
Index: libcxx/src/filesystem/operations.cpp
===================================================================
--- libcxx/src/filesystem/operations.cpp
+++ libcxx/src/filesystem/operations.cpp
@@ -1694,6 +1694,19 @@
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;
@@ -1704,6 +1717,7 @@
ret = "/tmp";
path p(ret);
+#endif
error_code m_ec;
file_status st = detail::posix_stat(p, &m_ec);
if (!status_known(st))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91175.310107.patch
Type: text/x-patch
Size: 1033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201208/f79074dc/attachment.bin>
More information about the libcxx-commits
mailing list