os: use GetTempPathW for allocTmpDir on Windows#12469
Merged
mitchellh merged 1 commit intoghostty-org:mainfrom Apr 26, 2026
Merged
os: use GetTempPathW for allocTmpDir on Windows#12469mitchellh merged 1 commit intoghostty-org:mainfrom
mitchellh merged 1 commit intoghostty-org:mainfrom
Conversation
`allocTmpDir` previously read `%TMP%` via `getenvW` and returned `null` if the variable wasn't set, requiring each caller to to deal with the nullable. Unfortunately, there isn't a platform-neutral default value that makes sense for those cases (i.e. `/tmp` is POSIX-y). We now use `GetTempPathW` on Windows, which is the official way to get this directory: `TMP` → `TEMP` → `USERPROFILE` → `GetWindowsDirectoryW`. With a real system call behind it, the function no longer needs to be nullable: the only remaining failure modes are OOM (propagated) and the syscall itself failing or returning data we can't decode. In those later cases, we use `C:\Windows\Temp` as a fallback, similar to how we use `/tmp` in the POSIX case. The Windows path always allocates so it still must be paired with `freeTmpDir`, which matches the existing contract.
jcollie
approved these changes
Apr 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
allocTmpDirpreviously read%TMP%viagetenvWand returnednullif the variable wasn't set, requiring each caller to to deal with the nullable. Unfortunately, there isn't a platform-neutral default value that makes sense for those cases (i.e./tmpis POSIX-y).We now use
GetTempPathWon Windows, which is the official way to get this directory:TMP→TEMP→USERPROFILE→GetWindowsDirectoryW.With a real system call behind it, the function no longer needs to be nullable: the only remaining failure modes are OOM (propagated) and the syscall itself failing or returning data we can't decode. In those later cases, we use
C:\Windows\Tempas a fallback, similar to how we use/tmpin the POSIX case.The Windows path always allocates so it still must be paired with
freeTmpDir, which matches the existing contract.AI Disclosure: I verified the Windows path using Claude and Zig's cross-compilation capabilities because I don't have a Windows environment in which to test this. I do fully understand the code based on my prior life as a Windows game developer though.