From: Heiko Hund Date: Wed, 23 Nov 2011 18:08:34 +0000 (+0100) Subject: Windows UTF-8 input/output X-Git-Tag: v2.3-alpha1~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ba68180b89e0290855f70832243fc9b4370e4d2;p=thirdparty%2Fopenvpn.git Windows UTF-8 input/output This patch makes openvpn read unicode from the console and convert the input to UTF-8. And then display UTF-8 output to the console correctly. Signed-off-by: Heiko Hund Acked-by: David Sommerseth Signed-off-by: David Sommerseth --- diff --git a/configure.ac b/configure.ac index 19173e96d..25dcc3722 100644 --- a/configure.ac +++ b/configure.ac @@ -349,6 +349,7 @@ case "$host" in OPENVPN_ADD_LIBS(-lcrypt32) OPENVPN_ADD_LIBS(-liphlpapi) OPENVPN_ADD_LIBS(-lwinmm) + OPENVPN_ADD_LIBS(-lshell32) ;; *-*-dragonfly*) AC_DEFINE(TARGET_DRAGONFLY, 1, [Are we running on DragonFlyBSD?]) diff --git a/openvpn.c b/openvpn.c index b4d6fd2a8..f5f2bce05 100644 --- a/openvpn.c +++ b/openvpn.c @@ -131,6 +131,10 @@ main (int argc, char *argv[]) return 1; #endif +#ifdef TARGET_WIN32 + SetConsoleOutputCP (CP_UTF8); +#endif + CLEAR (c); /* signify first time for components which can diff --git a/win32.c b/win32.c index 416af86d6..2cc8c2a2b 100644 --- a/win32.c +++ b/win32.c @@ -763,6 +763,7 @@ get_console_input_win32 (const char *prompt, const bool echo, char *input, const bool is_console = (GetFileType (in) == FILE_TYPE_CHAR); DWORD flags_save = 0; int status = 0; + WCHAR *winput; if (is_console) { @@ -777,7 +778,18 @@ get_console_input_win32 (const char *prompt, const bool echo, char *input, const is_console = 0; } - status = ReadFile (in, input, capacity, &len, NULL); + if (is_console) + { + winput = malloc (capacity * sizeof (WCHAR)); + if (winput == NULL) + return false; + + status = ReadConsoleW (in, winput, capacity, &len, NULL); + WideCharToMultiByte (CP_UTF8, 0, winput, len, input, capacity, NULL, NULL); + free (winput); + } + else + status = ReadFile (in, input, capacity, &len, NULL); string_null_terminate (input, (int)len, capacity); chomp (input);