common,w32: Do not assume the ANSI code during string conversion.

* common/utf8conv.c (get_w32_codepage): New.
(wchar_to_native): Use instead oc CP_ACP.
(native_to_wchar): Ditto.
--

This should fix quite some issue; we fixed it when using the iconv
based machinery about 14 years ago.  At some point we introduced the
new conversion functions because Windows started to support UTF-8
natively.  The fix comes late but well, it is done.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2020-08-21 14:42:08 +02:00
parent 33fd55ca6f
commit 5305ce17ff
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
1 changed files with 21 additions and 2 deletions

View File

@ -792,6 +792,25 @@ cp_to_wchar (const char *string, unsigned int codepage)
}
/* Get the current codepage as used by wchar_to_native and
* native_to_char. Note that these functions intentionally do not use
* iconv based conversion machinery. */
static unsigned int
get_w32_codepage (void)
{
static unsigned int cp;
if (!cp)
{
#ifndef HAVE_W32CE_SYSTEM
cp = GetConsoleOutputCP ();
if (!cp)
#endif
cp = GetACP ();
}
return cp;
}
/* Return a malloced string encoded in the active code page from the
* wide char input string STRING. Caller must free this value.
* Returns NULL and sets ERRNO on failure. Calling this function with
@ -799,7 +818,7 @@ cp_to_wchar (const char *string, unsigned int codepage)
char *
wchar_to_native (const wchar_t *string)
{
return wchar_to_cp (string, CP_ACP);
return wchar_to_cp (string, get_w32_codepage ());
}
@ -810,7 +829,7 @@ wchar_to_native (const wchar_t *string)
wchar_t *
native_to_wchar (const char *string)
{
return cp_to_wchar (string, CP_ACP);
return cp_to_wchar (string, get_w32_codepage ());
}