Properly convert command-line arguments to UTF-8 on Windows.
authorGuy Harris <guy@alum.mit.edu>
Wed, 12 Dec 2018 05:19:09 +0000 (21:19 -0800)
committerGuy Harris <guy@alum.mit.edu>
Wed, 12 Dec 2018 09:31:37 +0000 (09:31 +0000)
Do the same thing we do for most other command-line programs - on
Windows, have wmain() rather than main(), convert the UTF-16 argument
lists to UTF-8, and pass them on to real_main(), otherwise just have
main() call real_main().  That way, they never pass through the local
code page on Windows.

Change-Id: Ib74176dd0586c012eabaa3376c1d7dcba8838978
Reviewed-on: https://code.wireshark.org/review/31014
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
reordercap.c

index 93e2d1bb8d34717435024dcf80124ba37c2e3e45..56d4ae5e333505b56ae1fe8f2f69d9121d95f8bc 100644 (file)
@@ -30,6 +30,7 @@
 #include <wsutil/filesystem.h>
 #include <wsutil/file_util.h>
 #include <wsutil/privileges.h>
+#include <wsutil/unicode-utils.h>
 #include <version_info.h>
 #include <wiretap/wtap_opttypes.h>
 
@@ -160,8 +161,8 @@ failure_message_cont(const char *msg_format, va_list ap)
 /********************************************************************/
 /* Main function.                                                   */
 /********************************************************************/
-int
-main(int argc, char *argv[])
+static int
+real_main(int argc, char *argv[])
 {
     GString *comp_info_str;
     GString *runtime_info_str;
@@ -379,6 +380,23 @@ clean_exit:
     return ret;
 }
 
+#ifdef _WIN32
+int
+wmain(int argc, wchar_t *wc_argv[])
+{
+    char **argv;
+
+    argv = arg_list_utf_16to8(argc, wc_argv);
+    return real_main(argc, argv);
+}
+#else
+int
+main(int argc, char *argv[])
+{
+    return real_main(argc, argv);
+}
+#endif
+
 /*
  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
  *