diff options
author | Heiko Hund | 2011-11-23 19:08:34 +0100 |
---|---|---|
committer | David Sommerseth | 2012-02-04 12:49:03 +0100 |
commit | 6ba68180b89e0290855f70832243fc9b4370e4d2 (patch) | |
tree | 008de7e49567cd78e92d674de025e299b9971316 /win32.c | |
parent | 8fc83a2d6cfa44032f38e13fc2f7dbc096f584d9 (diff) | |
download | openvpn-6ba68180b89e0290855f70832243fc9b4370e4d2.zip openvpn-6ba68180b89e0290855f70832243fc9b4370e4d2.tar.gz |
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 <heiko.hund@sophos.com>
Acked-by: David Sommerseth <davids@redhat.com>
Signed-off-by: David Sommerseth <davids@redhat.com>
Diffstat (limited to 'win32.c')
-rw-r--r-- | win32.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -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); |