2301
setenv("TERM", "cygwin", 1);
2302
}
2303
2304
+#if !defined(_MSC_VER)
2305
/*
2306
* Disable MSVCRT command line wildcard expansion (__getmainargs called from
2307
* mingw startup code, see init.c in mingw runtime).
2308
*/
2309
int _CRT_glob = 0;
2309
-
2310
-typedef struct {
2311
- int newmode;
2312
-} _startupinfo;
2313
-
2314
-extern int __wgetmainargs(int *argc, wchar_t ***argv, wchar_t ***env, int glob,
2315
- _startupinfo *si);
2310
+#endif
2311
2312
static NORETURN void die_startup(void)
2313
{
2385
GENERIC_WRITE, FILE_FLAG_NO_BUFFERING);
2386
}
2387
2393
-void mingw_startup(void)
2388
+/*
2389
+ * We implement wmain() and compile with -municode, which would
2390
+ * normally ignore main(), but we call the latter from the former
2391
+ * so that we can handle non-ASCII command-line parameters
2392
+ * appropriately.
2393
+ *
2394
+ * To be more compatible with the core git code, we convert
2395
+ * argv into UTF8 and pass them directly to main().
2396
+ */
2397
+int wmain(int argc, const wchar_t **wargv)
2398
{
2395
- int i, maxlen, argc;
2396
- char *buffer;
2397
- wchar_t **wenv, **wargv;
2398
- _startupinfo si;
2399
+ int i, maxlen, exit_status;
2400
+ char *buffer, **save;
2401
+ const char **argv;
2402
2403
trace2_initialize_clock();
2404
2405
maybe_redirect_std_handles();
2406
2404
- /* get wide char arguments and environment */
2405
- si.newmode = 0;
2406
- if (__wgetmainargs(&argc, &wargv, &wenv, _CRT_glob, &si) < 0)
2407
- die_startup();
2408
-
2407
/* determine size of argv and environ conversion buffer */
2408
maxlen = wcslen(wargv[0]);
2409
for (i = 1; i < argc; i++)
2413
maxlen = 3 * maxlen + 1;
2414
buffer = malloc_startup(maxlen);
2415
2418
- /* convert command line arguments and environment to UTF-8 */
2416
+ /*
2417
+ * Create a UTF-8 version of w_argv. Also create a "save" copy
2418
+ * to remember all the string pointers because parse_options()
2419
+ * will remove claimed items from the argv that we pass down.
2420
+ */
2421
+ ALLOC_ARRAY(argv, argc + 1);
2422
+ ALLOC_ARRAY(save, argc + 1);
2423
for (i = 0; i < argc; i++)
2420
- __argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2424
+ argv[i] = save[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
2425
+ argv[i] = save[i] = NULL;
2426
free(buffer);
2427
2428
/* fix Windows specific environment settings */
2441
2442
/* initialize Unicode console */
2443
winansi_init();
2444
+
2445
+ /* invoke the real main() using our utf8 version of argv. */
2446
+ exit_status = main(argc, argv);
2447
+
2448
+ for (i = 0; i < argc; i++)
2449
+ free(save[i]);
2450
+ free(save);
2451
+ free(argv);
2452
+
2453
+ return exit_status;
2454
}
2455
2456
int uname(struct utsname *buf)