-
Notifications
You must be signed in to change notification settings - Fork 20
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
base: main
Are you sure you want to change the base?
Conversation
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :)
The two behaviors are indistinguishable from the POV of the calling program, so either way of doing it would be fine. |
Sure. I just realized that the function is supposed to use only up to 3 characters of the prefix. |
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]; |
There was a problem hiding this comment.
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")); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
No description provided.