Changeset View
Changeset View
Standalone View
Standalone View
b/tools/gpgtar.c
Context not available. | |||||
#endif | #endif | ||||
} | } | ||||
#ifdef HAVE_W32_SYSTEM | #ifdef HAVE_W32_SYSTEM | ||||
/* Return a malloced string encoded in UTF-8 from the wide char input | /* Return a malloced string encoded for the codepage CODEPAGE from the wide | ||||
string STRING. Caller must free this value. Returns NULL and sets | char input string STRING. Caller must free this value. Returns NULL | ||||
ERRNO on failure. Calling this function with STRING set to NULL is | and sets ERRNO on failure. Calling this function with STRING set to | ||||
not defined. */ | NULL is not defined. */ | ||||
char * | static char * | ||||
wchar_to_utf8 (const wchar_t *string) | wchar_to_cp (const wchar_t *string, unsigned int codepage) | ||||
{ | { | ||||
int n; | int n; | ||||
char *result; | char *result; | ||||
n = WideCharToMultiByte (CP_UTF8, 0, string, -1, NULL, 0, NULL, NULL); | n = WideCharToMultiByte (codepage, 0, string, -1, NULL, 0, NULL, NULL); | ||||
if (n < 0) | if (n < 0) | ||||
{ | { | ||||
errno = EINVAL; | errno = EINVAL; | ||||
Context not available. | |||||
if (!result) | if (!result) | ||||
return NULL; | return NULL; | ||||
n = WideCharToMultiByte (CP_UTF8, 0, string, -1, result, n, NULL, NULL); | n = WideCharToMultiByte (codepage, 0, string, -1, result, n, NULL, NULL); | ||||
if (n < 0) | if (n < 0) | ||||
{ | { | ||||
xfree (result); | xfree (result); | ||||
Context not available. | |||||
return result; | return result; | ||||
} | } | ||||
/* Return a malloced wide char string from an CODEPAGE encoded input | |||||
/* Return a malloced wide char string from an UTF-8 encoded input | |||||
string STRING. Caller must free this value. Returns NULL and sets | string STRING. Caller must free this value. Returns NULL and sets | ||||
ERRNO on failure. Calling this function with STRING set to NULL is | ERRNO on failure. Calling this function with STRING set to NULL is | ||||
not defined. */ | not defined. */ | ||||
wchar_t * | static wchar_t* | ||||
utf8_to_wchar (const char *string) | cp_to_wchar (const char *string, unsigned int codepage) | ||||
{ | { | ||||
int n; | int n; | ||||
size_t nbytes; | size_t nbytes; | ||||
wchar_t *result; | wchar_t *result; | ||||
n = MultiByteToWideChar (CP_UTF8, 0, string, -1, NULL, 0); | n = MultiByteToWideChar (codepage, 0, string, -1, NULL, 0); | ||||
if (n < 0) | if (n < 0) | ||||
{ | { | ||||
errno = EINVAL; | errno = EINVAL; | ||||
Context not available. | |||||
if (!result) | if (!result) | ||||
return NULL; | return NULL; | ||||
n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n); | n = MultiByteToWideChar (codepage, 0, string, -1, result, n); | ||||
if (n < 0) | if (n < 0) | ||||
{ | { | ||||
free (result); | free (result); | ||||
Context not available. | |||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
/* 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 STRING set to NULL is not defined. */ | |||||
char * | |||||
wchar_to_native (const wchar_t *string) | |||||
{ | |||||
return wchar_to_cp (string, CP_ACP); | |||||
} | |||||
/* Return a malloced wide char string from an UTF-8 encoded input | |||||
string STRING. Caller must free this value. Returns NULL and sets | |||||
ERRNO on failure. Calling this function with STRING set to NULL is | |||||
not defined. */ | |||||
wchar_t * | |||||
native_to_wchar (const char *string) | |||||
{ | |||||
return cp_to_wchar(string, CP_ACP); | |||||
} | |||||
#endif /*HAVE_W32_SYSTEM*/ | #endif /*HAVE_W32_SYSTEM*/ | ||||
Context not available. |