Skip to content

Add GetTempFileNameA #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add GetTempFileNameA #84

wants to merge 3 commits into from

Conversation

dbalatoni13
Copy link

No description provided.

@dbalatoni13
Copy link
Author

This is necessary to run ngccc.exe. I tried to mimic the original behavior of the function, that's why I increment the number instead of generating a new one.

dll/kernel32.cpp Outdated
snprintf(uniqueStr, sizeof(uniqueStr), "%s%X.TMP", lpPrefixString, uUnique);
path = files::pathFromWindows(lpPathName) / uniqueStr;
if (!std::filesystem::exists(path)) {
foundAvailable = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

break + infinite loop is cleaner

Copy link
Author

Choose a reason for hiding this comment

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

That's what I wrote first but it's gonna be the first in the project, so I wasn't sure :)

@simonlindholm
Copy link
Contributor

I tried to mimic the original behavior of the function, that's why I increment the number instead of generating a new one.

The two behaviors are indistinguishable from the POV of the calling program, so either way of doing it would be fine.

@dbalatoni13
Copy link
Author

Sure. I just realized that the function is supposed to use only up to 3 characters of the prefix.

@mkst
Copy link
Contributor

mkst commented Jun 1, 2025

This function name felt familiar... This was my attempt some time ago. I wanted the random name to be deterministic, but I guess that would be super dumb and give the same name every run 🙈 main...pspld

wibo::lastError = ERROR_BUFFER_OVERFLOW;
return 0;
}
char uniqueStr[12];
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm counting 13, but if you round it up to 20 we don't have to think

path = files::pathFromWindows(lpPathName) / uniqueStr;
if (!std::filesystem::exists(path)) {
// create empty file
fclose(fopen(path.c_str(), "a"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we fail and try again with the next uUnique if creating the file fails because it already exists? That would help guard against race conditions, which are a real problem if you're running multiple compilations at once in a parallel build system. Unsure whether this is possible with fopen (there might be some "exclusive" flag?); if not, it should be with open.

std::filesystem::path path;

if (uUnique == 0) {
random_shorts_engine rse;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this isn't seeded I guess it gives the same numbers every time? Not that it's really a problem given the loop

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.

3 participants