From 15b526b4cef7b9aea49e2aa831be130610ab1e6e Mon Sep 17 00:00:00 2001 From: Divyansh Sharma Date: Mon, 23 Feb 2026 03:03:06 +0530 Subject: [PATCH 1/2] Fix Issue 22614 - [Windows] tmpnam() in runPreprocessor generates root-drive paths, fails with permission denied for non-admin users --- compiler/src/dmd/link.d | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/src/dmd/link.d b/compiler/src/dmd/link.d index b3ad7cc3dabd..350bcd286246 100644 --- a/compiler/src/dmd/link.d +++ b/compiler/src/dmd/link.d @@ -958,9 +958,11 @@ public int runPreprocessor(Loc loc, const(char)[] cpp, const(char)[] filename, c version (Windows) { // generate unique temporary file name for preprocessed output - const(char)* tmpname = tmpnam(null); - assert(tmpname); - const(char)[] ifilename = tmpname[0 .. strlen(tmpname) + 1]; + char[MAX_PATH] tempDir = void; + char[MAX_PATH] tempFile = void; + GetTempPathA(MAX_PATH, tempDir.ptr); + GetTempFileNameA(tempDir.ptr, "dmd", 0, tempFile.ptr); + const(char)[] ifilename = tempFile[0 .. strlen(tempFile.ptr) + 1]; ifilename = xarraydup(ifilename); const(char)[] output = ifilename; From e2e60c342cfec81e184388eb59a421889d1b7846 Mon Sep 17 00:00:00 2001 From: Divyansh Sharma Date: Mon, 2 Mar 2026 10:46:53 +0530 Subject: [PATCH 2/2] Fix temporary file creation in runPreprocessor to handle errors on Windows --- compiler/src/dmd/link.d | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/src/dmd/link.d b/compiler/src/dmd/link.d index 350bcd286246..1429efd1d1b8 100644 --- a/compiler/src/dmd/link.d +++ b/compiler/src/dmd/link.d @@ -960,8 +960,10 @@ public int runPreprocessor(Loc loc, const(char)[] cpp, const(char)[] filename, c // generate unique temporary file name for preprocessed output char[MAX_PATH] tempDir = void; char[MAX_PATH] tempFile = void; - GetTempPathA(MAX_PATH, tempDir.ptr); - GetTempFileNameA(tempDir.ptr, "dmd", 0, tempFile.ptr); + if (GetTempPathA(MAX_PATH, tempDir.ptr) == 0) + return STATUS_FAILED; + if (GetTempFileNameA(tempDir.ptr, "dmd", 0, tempFile.ptr) == 0) + return STATUS_FAILED; const(char)[] ifilename = tempFile[0 .. strlen(tempFile.ptr) + 1]; ifilename = xarraydup(ifilename); const(char)[] output = ifilename;