mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-23 10:29:58 +01:00
common,w32: Do not assume the ANSI codepage 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:
parent
73b0fdabdb
commit
bef68efd8d
@ -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
|
/* Return a malloced string encoded in the active code page from the
|
||||||
* wide char input string STRING. Caller must free this value.
|
* wide char input string STRING. Caller must free this value.
|
||||||
* Returns NULL and sets ERRNO on failure. Calling this function with
|
* 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 *
|
char *
|
||||||
wchar_to_native (const wchar_t *string)
|
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 *
|
wchar_t *
|
||||||
native_to_wchar (const char *string)
|
native_to_wchar (const char *string)
|
||||||
{
|
{
|
||||||
return cp_to_wchar (string, CP_ACP);
|
return cp_to_wchar (string, get_w32_codepage ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user