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).
Details
- Reviewers
amccarth EricWF ldionne - Group Reviewers
Restricted Project - Commits
- rGd4f4e723d0b4: [libcxx] Implement temp_directory_path using GetTempPath on windows
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libcxx/src/filesystem/operations.cpp | ||
---|---|---|
1599 | What do you think of using GetTempPath instead? That is more likely to be writable. |
libcxx/src/filesystem/operations.cpp | ||
---|---|---|
1599 | That's also an option - or we could skip our own code and just use that one. That function does essentially the same, checks a few env vars (two of the ones checked here, plus USERPROFILE). But if none of the env vars are available, GetTempPath also falls back to c:\windows - that's where I got the idea. |
libcxx/src/filesystem/operations.cpp | ||
---|---|---|
1599 | My first choice would be to use GetTempPathW directly, since that will match expectations for Windows programmers and be relatively future proff. My second choice would be to keep the custom iteration through the well-known environment variables but to replace the hardcoded c:\windows with a call to GetWindowsDirectoryW. |
LGTM.
libcxx/src/filesystem/operations.cpp | ||
---|---|---|
1702 | My gut said >= rather than >, but the documentation for this API is a cagey about this boundary condition. I experimented and realized this does work with > because there is no case where it would return exactly the buffer size. |
libcxx/src/filesystem/operations.cpp | ||
---|---|---|
1702 | Yeah, the return value handling there is pretty tricky - GetFinalPathNameByHandleW had the same pattern. |
Rebased, retriggering CI.
For this function, there's not much of a corresponding posix-like function to hide the functionality within.
What do you think of using GetTempPath instead? That is more likely to be writable.