Skip to content

os: use GetTempPathW for allocTmpDir on Windows#12469

Merged
mitchellh merged 1 commit intoghostty-org:mainfrom
jparise:alloc-tmpdir-win32
Apr 26, 2026
Merged

os: use GetTempPathW for allocTmpDir on Windows#12469
mitchellh merged 1 commit intoghostty-org:mainfrom
jparise:alloc-tmpdir-win32

Conversation

@jparise
Copy link
Copy Markdown
Contributor

@jparise jparise commented Apr 26, 2026

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: TMPTEMPUSERPROFILEGetWindowsDirectoryW.

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.


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.

`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.
@jparise jparise requested a review from a team as a code owner April 26, 2026 01:48
@mitchellh mitchellh merged commit c74f6d5 into ghostty-org:main Apr 26, 2026
91 checks passed
@github-actions github-actions Bot added this to the 1.3.2 milestone Apr 26, 2026
@jparise jparise deleted the alloc-tmpdir-win32 branch April 26, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants