MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_win_utf8_argv

Function cbm_win_utf8_argv

src/main.c:1379–1408  ·  view source on GitHub ↗

On Windows the CRT hands main() an argv encoded in the active ANSI code page, so a * non-ASCII CLI argument (e.g. a repo path like café_日本語_repo) is mangled before the * program ever sees it — the documented `cli index_repository " "` then fails with * "repo_path is required" (#423/#20). Rebuild argv from the wide command line * (GetCommandLineW → CommandLineToArgvW) and convert each elem

Source from the content-addressed store, hash-verified

1377 * the original narrow argv). The returned block lives for the whole process (argv must
1378 * stay valid until exit), so it is intentionally never freed. */
1379static char **cbm_win_utf8_argv(int *out_argc) {
1380 int wargc = 0;
1381 LPWSTR *wargv = CommandLineToArgvW(GetCommandLineW(), &wargc);
1382 if (!wargv) {
1383 return NULL;
1384 }
1385 if (wargc <= 0) {
1386 LocalFree(wargv);
1387 return NULL;
1388 }
1389 char **u8argv = (char **)calloc((size_t)wargc + 1, sizeof(char *));
1390 if (!u8argv) {
1391 LocalFree(wargv);
1392 return NULL;
1393 }
1394 for (int i = 0; i < wargc; i++) {
1395 u8argv[i] = cbm_wide_to_utf8(wargv[i]);
1396 if (!u8argv[i]) {
1397 for (int j = 0; j < i; j++) {
1398 free(u8argv[j]);
1399 }
1400 free(u8argv);
1401 LocalFree(wargv);
1402 return NULL;
1403 }
1404 }
1405 LocalFree(wargv);
1406 *out_argc = wargc;
1407 return u8argv; /* NULL-terminated (calloc'd wargc+1) */
1408}
1409#endif /* _WIN32 */
1410
1411static bool main_resolve_executable(const char *argv0, char out[MAIN_PATH_CAP]) {

Callers 1

mainFunction · 0.85

Calls 1

cbm_wide_to_utf8Function · 0.85

Tested by

no test coverage detected