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

Function cbm_win_utf8_argv

src/main.c:1132–1161  ·  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

1130 * the original narrow argv). The returned block lives for the whole process (argv must
1131 * stay valid until exit), so it is intentionally never freed. */
1132static char **cbm_win_utf8_argv(int *out_argc) {
1133 int wargc = 0;
1134 LPWSTR *wargv = CommandLineToArgvW(GetCommandLineW(), &wargc);
1135 if (!wargv) {
1136 return NULL;
1137 }
1138 if (wargc <= 0) {
1139 LocalFree(wargv);
1140 return NULL;
1141 }
1142 char **u8argv = (char **)calloc((size_t)wargc + 1, sizeof(char *));
1143 if (!u8argv) {
1144 LocalFree(wargv);
1145 return NULL;
1146 }
1147 for (int i = 0; i < wargc; i++) {
1148 u8argv[i] = cbm_wide_to_utf8(wargv[i]);
1149 if (!u8argv[i]) {
1150 for (int j = 0; j < i; j++) {
1151 free(u8argv[j]);
1152 }
1153 free(u8argv);
1154 LocalFree(wargv);
1155 return NULL;
1156 }
1157 }
1158 LocalFree(wargv);
1159 *out_argc = wargc;
1160 return u8argv; /* NULL-terminated (calloc'd wargc+1) */
1161}
1162#endif /* _WIN32 */
1163
1164static 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