diff options
author | Werner Koch <[email protected]> | 2020-08-21 12:42:08 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2020-08-21 12:42:08 +0000 |
commit | 5305ce17ff7a68ecc88c5ae8c4bec5897df6322f (patch) | |
tree | 19f78643ac69be141c19dbbe874aced99a5500b1 | |
parent | common: Strip trailing CR,LF from w32_strerror. (diff) | |
download | gnupg-5305ce17ff7a68ecc88c5ae8c4bec5897df6322f.tar.gz gnupg-5305ce17ff7a68ecc88c5ae8c4bec5897df6322f.zip |
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 <[email protected]>
-rw-r--r-- | common/utf8conv.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/common/utf8conv.c b/common/utf8conv.c index 01604e176..7804dbfcd 100644 --- a/common/utf8conv.c +++ b/common/utf8conv.c @@ -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 ()); } |