Index: b/tools/gpgtar-create.c =================================================================== --- b/tools/gpgtar-create.c +++ b/tools/gpgtar-create.c @@ -72,13 +72,13 @@ for (p=hdr->name; *p; p++) if (*p == '/') *p = '\\'; - wfname = utf8_to_wchar (hdr->name); + wfname = native_to_wchar (hdr->name); for (p=hdr->name; *p; p++) if (*p == '\\') *p = '/'; if (!wfname) { - log_error ("error utf8-ing `%s': %s\n", hdr->name, w32_strerror (-1)); + log_error ("error converting `%s': %s\n", hdr->name, w32_strerror (-1)); return gpg_error_from_syserror (); } if (!GetFileAttributesExW (wfname, GetFileExInfoStandard, &fad)) @@ -299,7 +299,7 @@ for (p=fname; *p; p++) if (*p == '/') *p = '\\'; - wfname = utf8_to_wchar (fname); + wfname = native_to_wchar (fname); xfree (fname); if (!wfname) { @@ -322,11 +322,11 @@ do { - char *fname = wchar_to_utf8 (fi.cFileName); + char *fname = wchar_to_native (fi.cFileName); if (!fname) { err = gpg_error_from_syserror (); - log_error ("error utf8-ing filename: %s\n", w32_strerror (-1)); + log_error ("error converting filename: %s\n", w32_strerror (-1)); break; } for (p=fname; *p; p++) Index: b/tools/gpgtar.h =================================================================== --- b/tools/gpgtar.h +++ b/tools/gpgtar.h @@ -113,8 +113,8 @@ int gnupg_mkdir (const char *name, const char *modestr); #ifdef HAVE_W32_SYSTEM -char *wchar_to_utf8 (const wchar_t *string); -wchar_t *utf8_to_wchar (const char *string); +char *wchar_to_native (const wchar_t *string); +wchar_t *native_to_wchar (const char *string); #endif /*-- gpgtar-create.c --*/ Index: b/tools/gpgtar.c =================================================================== --- b/tools/gpgtar.c +++ b/tools/gpgtar.c @@ -465,18 +465,19 @@ #endif } + #ifdef HAVE_W32_SYSTEM -/* Return a malloced string encoded in UTF-8 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_utf8 (const wchar_t *string) +/* Return a malloced string encoded for the codepage CODEPAGE 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. */ +static char * +wchar_to_cp (const wchar_t *string, unsigned int codepage) { int n; 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) { errno = EINVAL; @@ -487,7 +488,7 @@ if (!result) 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) { xfree (result); @@ -497,19 +498,18 @@ return result; } - -/* Return a malloced wide char string from an UTF-8 encoded input +/* Return a malloced wide char string from an CODEPAGE 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 * -utf8_to_wchar (const char *string) +static wchar_t* +cp_to_wchar (const char *string, unsigned int codepage) { int n; size_t nbytes; wchar_t *result; - n = MultiByteToWideChar (CP_UTF8, 0, string, -1, NULL, 0); + n = MultiByteToWideChar (codepage, 0, string, -1, NULL, 0); if (n < 0) { errno = EINVAL; @@ -526,7 +526,7 @@ if (!result) return NULL; - n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n); + n = MultiByteToWideChar (codepage, 0, string, -1, result, n); if (n < 0) { free (result); @@ -535,4 +535,24 @@ } 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*/