Changeset View
Changeset View
Standalone View
Standalone View
b/jnlib/w32-gettext.c
Context not available. | |||||
} | } | ||||
/* 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 | string STRING. Caller must free this value. On failure returns | ||||
NULL. The result of calling this function with STRING set to NULL | NULL. The result of calling this function with STRING set to NULL | ||||
is not defined. */ | is not defined. */ | ||||
Context not available. | |||||
{ | { | ||||
int n; | int n; | ||||
char *result; | char *result; | ||||
/* We are a console program thus we need to use the | |||||
n = WideCharToMultiByte (CP_ACP, 0, string, length, NULL, 0, NULL, NULL); | 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) | if (n < 0 || (n+1) <= 0) | ||||
return NULL; | return NULL; | ||||
Context not available. | |||||
if (!result) | if (!result) | ||||
return NULL; | 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) | if (n < 0) | ||||
{ | { | ||||
jnlib_free (result); | jnlib_free (result); | ||||
Context not available. |