Files
AnyPS5/core/libs/tests/GuestProcessArguments.cpp
T
Doston Abdullayev 5cb7de6ba9 fix(libkernel): return every command-line argument as UTF-8 from getargv on Windows
On Windows, getargc and getargv reported only the executable path, read
with GetModuleFileNameA in the ANSI code page, and dropped every other
argument. Linux returns the whole command line from /proc/self/cmdline,
and the relinker's Windows entry stub already passes the guest entry all
arguments converted to UTF-8.

Parse GetCommandLineW with CommandLineToArgvW and convert each argument
to UTF-8 with WC_ERR_INVALID_CHARS, as the entry stub does, so getargv
matches the entry's argv and the Linux behaviour. The Linux path is
unchanged.
2026-10-10 21:20:29 +13:00

30 lines
1.2 KiB
C++

#include "prx/libc/include/general/VabiMacros.hpp"
#include <cstdio>
#include <cstdlib>
#include <cstring>
extern "C" int APS5_VABI getargc_nid_postfix(void);
extern "C" const char** APS5_VABI getargv_nid_postfix(void);
static void Require(bool condition, const char* message) {
if (!condition) {
std::fprintf(stderr, "%s\n", message);
std::abort();
}
}
int main() {
const char* const expected[] = {"plain", "two words", "ü日"};
constexpr int expectedCount = 1 + static_cast<int>(sizeof(expected) / sizeof(expected[0]));
const int count = getargc_nid_postfix();
const char** values = getargv_nid_postfix();
Require(count == expectedCount, "getargc does not count every command-line argument");
Require(values != nullptr && values[0] != nullptr && values[0][0] != '\0', "getargv has no program name");
for (int index = 1; index < expectedCount; ++index) {
Require(values[index] != nullptr && std::strcmp(values[index], expected[index - 1]) == 0,
"getargv does not return a command-line argument as UTF-8");
}
Require(values[count] == nullptr, "getargv is not terminated by a null pointer");
return 0;
}