diff options
author | Guy Harris <guy@alum.mit.edu> | 2018-10-07 10:06:00 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2018-10-07 18:57:54 +0000 |
commit | a679ae6f791ac6b02f342d3b73d6b4aecb9ca6e9 (patch) | |
tree | d2f21c87ea7422fa56ba8cc2ff6f23d18bea36f2 /mergecap.c | |
parent | ce53b4c170e0b0b1c7bb521fe677db1eadc7792b (diff) |
Use wsetargv.obj, and wmain() rather than main(), on Windows.
Doing so for command-line programs means that the argument list doesn't
ever get converted to the local code page; converting to the local code
page can mangle file names that *can't* be converted to the local code
page.
Furthermore, code that uses setargv.obj rather than wsetargv.obj has
issues in some versions of Windows 10; see bug 15151.
That means that converting the argument list to UTF-8 is a bit simpler -
we don't need to call GetCommandLineW() or CommandLineToArgvW(), we just
loop over the UTF-16LE argument strings in argv[].
While we're at it, note in Wireshark's main() why we discard argv on
Windows (Qt does the same "convert-to-the-local-code-page" stuff); that
means we *do* need to call GetCommandLineW() and CommandLineToArgvW() in
main() (i.e., we duplicate what Qt's WinMain() does, but converting to
UTF-8 rather than to the local code page).
Change-Id: I35b57c1b658fb3e9b0c685097afe324e9fe98649
Ping-Bug: 15151
Reviewed-on: https://code.wireshark.org/review/30051
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'mergecap.c')
-rw-r--r-- | mergecap.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/mergecap.c b/mergecap.c index bc55d63bc9..516ab714da 100644 --- a/mergecap.c +++ b/mergecap.c @@ -225,9 +225,8 @@ merge_callback(merge_event event, int num, return FALSE; } - -int -main(int argc, char *argv[]) +static int +real_main(int argc, char *argv[]) { GString *comp_info_str; GString *runtime_info_str; @@ -259,7 +258,6 @@ main(int argc, char *argv[]) cmdarg_err_init(mergecap_cmdarg_err, mergecap_cmdarg_err_cont); #ifdef _WIN32 - arg_list_utf_16to8(argc, argv); create_app_running_mutex(); #endif /* _WIN32 */ @@ -473,6 +471,26 @@ clean_exit: return (status == MERGE_OK) ? 0 : 2; } +#ifdef _WIN32 +int +wmain(int argc, wchar_t *argv[]) +{ + char **argv_utf8; + + /* Convert our arg list from UTF-16LE to UTF-8. */ + argv_utf8 = g_malloc(argc * sizeof *argv_utf8); + for (int i = 0; i < argc; i++) + argv_utf8[i] = g_utf16_to_utf8(argv[i], -1, NULL, NULL, NULL); + return real_main(argc, argv_utf8); +} +#else +int +main(int argc, char *argv[]) +{ + return real_main(argc, argv); +} +#endif + /* * Editor modelines - http://www.wireshark.org/tools/modelines.html * @@ -485,4 +503,3 @@ clean_exit: * vi: set shiftwidth=2 tabstop=8 expandtab: * :indentSize=2:tabSize=8:noTabs=true: */ - |