Skip to content

add GetTempFileNameW - #134

Merged
encounter merged 3 commits into
decompals:mainfrom
miried:add-gettempfilenamew
Jul 11, 2026
Merged

add GetTempFileNameW#134
encounter merged 3 commits into
decompals:mainfrom
miried:add-gettempfilenamew

Conversation

@miried

@miried miried commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

needed by LINK.EXE in MSVC 4.2 when linking with a resource file

Comment thread dll/kernel32/fileapi.cpp Outdated
UINT WINAPI GetTempFileNameW(LPCWSTR lpPathName, LPCWSTR lpPrefixString, UINT uUnique, LPWSTR lpTempFileName) {
HOST_CONTEXT_GUARD();
DEBUG_LOG("GetTempFileNameW -> ");
if (!lpPathName || !lpPrefixString || !lpTempFileName) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null lpPrefixString should be treated as empty, not invalid (your added test fails when run with wine)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. the existing GetTempFileNameA was doing the same, but it was untested, so it was not obvious. I changed both also with a test for the A variant. I can't test against Wine on this machine but I'll do as soon as I have access to one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I managed to test with Wine, on an arm mac. test_gettempfilename was already failing on current main branch for me. I added a fix for one fail:

Only the lower 16 bits of the uUnique parameter are used.

see https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettempfilenamea#remarks

Note it's still failing on my test machine because of expected file path having .TMP in upper-case letters, while for me it is lower-case (test file line 27). I will look into this when I have time.

@miried
miried force-pushed the add-gettempfilenamew branch from 54b10c1 to 2c331c0 Compare July 11, 2026 12:52
@encounter

Copy link
Copy Markdown
Member

Thanks!

@encounter
encounter merged commit d7db13a into decompals:main Jul 11, 2026
12 checks passed
freeqaz added a commit to freeqaz/wibo that referenced this pull request Aug 5, 2026
This fork sat at 1.0.1-23 while upstream shipped 1.1.0 and 1.2.0, both of
which are explicitly about the toolchain we run: per-ABI msvcrt embedding,
"improve kernel32 compatibility for MSVC tools" (decompals#124), a module-TLS-init
race fix, and a per-thread FLS / Windows-faithful CRITICAL_SECTION fix whose
commit message names the symptom we have hit ("intermittent MSVC c2.dll
deadlock", decompals#126). 1.0.1 itself was cut because msvc_ppc_16.00.11886.00 -- our
exact compiler -- segfaulted. Staying behind on a fork whose upstream is
working on our workload is how a fork rots.

Target is upstream/main tip (e8f4795), not the 1.2.0 tag, for two reasons:
decompals#134 adds GetTempFileNameW, which is one of the local patches this fork
carried, so taking the tip lets us DELETE ours; and decompals#137 initializes guest
floating-point state explicitly, which is exactly the kind of thing that can
move a compiler's constant folding and is therefore better under test than
deferred.

Seven files conflicted. Resolutions, and which side won:

  CMakeLists.txt          BOTH -- two fixture registrations that landed on the
                          same line (ours test_mspdb, theirs test_env_strings).
  kernel32/minwinbase.h   THEIRS. Upstream added WIN32_FILE_ATTRIBUTE_DATA
                          independently, with both the P and LP aliases. Our
                          copy deleted as redundant.
  kernel32/fileapi.h      BOTH, deduplicated. Kept our GetTempPathW and
                          FindFirstFileExW (upstream has neither); dropped our
                          now-duplicate GetTempFileNameW and GetFileAttributesEx
                          declarations in favour of upstream's.
  kernel32/fileapi.cpp    THEIRS for GetFileAttributesExA/W -- upstream's has the
                          license.dat special case and correct ERROR_PATH_NOT_FOUND
                          mapping, ours had neither. Deleted our duplicate
                          GetTempFileNameW definition; upstream's (decompals#134) accepts a
                          null prefix, as Windows does, and ours rejected it.
  kernel32/memoryapi.cpp  THEIRS for both hunks. Upstream implemented the same two
                          fixes this fork carried -- growing the backing file for a
                          larger mapping, and FILE_MAP_ALL_ACCESS not meaning
                          copy-on-write -- and its versions are strictly better
                          (a protectAllowsFileGrowth guard, a size_t overflow check,
                          and one fileMapAccessFromDesiredAccess helper shared with
                          desiredAccessToProtect). Two more redundant local patches
                          deleted.
  kernel32/winbase.cpp    THEIRS for lstrcpynA (decompals#124 -- Windows-faithful null
                          handling, and it has a fixture, test/test_lstrcpyn.c).
                          Ours deleted. lstrcpyA/W and lstrcpynW stay -- upstream has
                          no such functions -- but lstrcpynW's null/count handling is
                          rewritten as a transcription of upstream's A so the pair
                          cannot drift.
  src/modules.cpp         BOTH: upstream's builtin table (it adds lib_shlwapi) plus
                          our WIBO_HAS_MSPDB entry.
  src/files.cpp           OURS, plus one adoption. pathFromWindows here is a fork
                          rewrite -- WIBO_PATH_MAP, WIBO_DRIVE_x, the WIBO_FS_CACHE
                          exists/dirent/case caches, /showIncludes rewriting -- and
                          all of it is load-bearing for dc3-decomp, so upstream's much
                          simpler version loses. Upstream's stripTrailingDots (decompals#118,
                          the NMAKE "nm12345." convention) is genuinely new and is
                          taken, called one step earlier than upstream calls it so
                          that the WIBO_DRIVE_x branch sees it too.

Four local patches are now gone as redundant: GetTempFileNameW, the file-mapping
growth, the FILE_MAP_ALL_ACCESS fix, and lstrcpynA. Everything else this fork
carries survived: sigsafe.cpp, the mimalloc foreign-free fix, the 8 MiB guest
stack, mspdb, the X360 linker support, wsprintfW, and the files.cpp caches.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants