From a3b0360e4d2c024e4c372ede5821e1b6ffd683e8 Mon Sep 17 00:00:00 2001 From: alaotach Date: Wed, 8 Jul 2026 20:29:31 +0530 Subject: [PATCH] Fix Windows argument encoding by fetching UTF-8 command line --- src/ccextractor.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/ccextractor.c b/src/ccextractor.c index efed81d32..5ffbc5051 100644 --- a/src/ccextractor.c +++ b/src/ccextractor.c @@ -9,6 +9,10 @@ CI verification run: 2025-12-19T08:30 - Testing merged fixes from PRs #1847 and #include #include +#ifdef _WIN32 +#include +#include +#endif volatile int terminate_asap = 0; struct ccx_s_options ccx_options; @@ -432,6 +436,24 @@ int start_ccx() int main(int argc, char *argv[]) { +#ifdef _WIN32 + // On Windows, the standard argv is encoded in the local ANSI code page. + // We need it in UTF-8, so we fetch the Unicode command line and convert it. + int wargc; + wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &wargc); + if (wargv) + { + argv = (char **)malloc(wargc * sizeof(char *)); + argc = wargc; + for (int i = 0; i < wargc; i++) + { + int size = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL); + argv[i] = (char *)malloc(size); + WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], size, NULL, NULL); + } + LocalFree(wargv); + } +#endif setlocale(LC_ALL, ""); // Supports non-English CCs // Use POSIX locale for numbers so we get "." as decimal separator and no // thousands' groupoing instead of what the locale might say