Recently I needed an API for writing a temporary file, so I started to check what API was available on Windows for getting the path to a temporary directory.
Note also that bindings do not have to be part of the standard library for you to be able to use them. They can go in your project’s source and it’ll work just fine.
If there’s a need for a general purpose API for writing temporary files in the standard library, then the linked issues above still apply. Adding bindings for GetTempPath2W would still be discouraged, and instead the goal would be to re-implement the functionality using lower-level ntdll syscalls (I typically use NtTrace to see what a function is doing for this purpose).
Again, though, if you need this function, you can just put this in your project and use it:
The reason GetTempPath2 exists and defaults to returning C:\Windows\SystemTemp is because that directory is ACL’d with the correct permissions to prevent common path redirection issues. For security reasons, only set the SystemTemp environment variable to a directory with permissions that only allow for a SYSTEM process/administrator to access it.
I’m not sure how common path redirection is a security issue.