Index: b/jnlib/w32-gettext.c =================================================================== --- b/jnlib/w32-gettext.c +++ b/jnlib/w32-gettext.c @@ -1299,7 +1299,7 @@ } -/* Return a malloced string encoded in UTF-8 from the wide char input +/* Return a malloced string encoded for the native codepage from the wide char input string STRING. Caller must free this value. On failure returns NULL. The result of calling this function with STRING set to NULL is not defined. */ @@ -1308,8 +1308,19 @@ { int n; char *result; - - n = WideCharToMultiByte (CP_ACP, 0, string, length, NULL, 0, NULL, NULL); + /* We are a console program thus we need to use the + GetConsoleOutputCP function and not the the GetACP which + would give the codepage for a GUI program. Note this is not + a bulletproof detection because GetConsoleCP might return a + different one for console input. Not sure how to cope with + that. If the console Code page is not known we fall back to + the system code page. This is how utf8conv does resolve this. */ + unsigned int cpno = GetConsoleOutputCP (); + + if (!cpno) + cpno = GetACP (); + + n = WideCharToMultiByte (cpno, 0, string, length, NULL, 0, NULL, NULL); if (n < 0 || (n+1) <= 0) return NULL; @@ -1317,7 +1328,7 @@ if (!result) return NULL; - n = WideCharToMultiByte (CP_ACP, 0, string, length, result, n, NULL, NULL); + n = WideCharToMultiByte (cpno, 0, string, length, result, n, NULL, NULL); if (n < 0) { jnlib_free (result);