Handle GetCurrentDirectory required buffer size return value (#27)

When the output buffer size is too small, GetCurrentDirectory does
nothing and simply returns the larger required size.

https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcurrentdirectory#return-value

Needed to run Code Warrior 4 mwcc.exe with no arguments, displaying usage/help message.

(Still unable to compile/preprocess with CW4 mwcc.exe)
This commit is contained in:
Ryan Burns 2022-12-02 01:46:38 -08:00 committed by GitHub
parent 681137902b
commit 635de4fa93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -932,7 +932,11 @@ namespace kernel32 {
std::filesystem::path cwd = std::filesystem::current_path();
std::string path = files::pathToWindows(cwd);
assert(path.size() < uSize);
// If the buffer is too small, return the required buffer size.
// (Add 1 to include the NUL terminator)
if (path.size() + 1 > uSize) {
return path.size() + 1;
}
strcpy(lpBuffer, path.c_str());
return path.size();