aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcus Brinkmann <[email protected]>2005-10-25 19:18:13 +0000
committerMarcus Brinkmann <[email protected]>2005-10-25 19:18:13 +0000
commitf568f8b5b99ea3adeee9b85b41d54b9b9804f107 (patch)
tree3f88f3f394158206473128892a755eb95c9aac64
parent2005-10-25 Marcus Brinkmann <[email protected]> (diff)
downloadlibgpg-error-f568f8b5b99ea3adeee9b85b41d54b9b9804f107.tar.gz
libgpg-error-f568f8b5b99ea3adeee9b85b41d54b9b9804f107.zip
2005-10-25 Marcus Brinkmann <[email protected]>
* src/w32-gettext.c (get_string): Remove extra arguments to utf8_to_native_invocation. (utf8_to_wchar, wchar_to_native): New function. (utf8_to_native): Rewritten.
-rw-r--r--ChangeLog5
-rw-r--r--src/w32-gettext.c76
2 files changed, 77 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 77ae9b0..9c5b7a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2005-10-25 Marcus Brinkmann <[email protected]>
+ * src/w32-gettext.c (get_string): Remove extra arguments to
+ utf8_to_native_invocation.
+ (utf8_to_wchar, wchar_to_native): New function.
+ (utf8_to_native): Rewritten.
+
* src/Makefile.am (gpg_error_CPPFLAGS): New variable.
* src/gpg-error.c (i18n_init): Don't return anything.
diff --git a/src/w32-gettext.c b/src/w32-gettext.c
index 1294ed4..07f15db 100644
--- a/src/w32-gettext.c
+++ b/src/w32-gettext.c
@@ -1410,13 +1410,81 @@ load_domain (const char *filename)
}
+/* Return a malloced string encoded in UTF-8 from the wide char input
+ string STRING. Caller must free this value. On failure returns
+ NULL; caller may use GetLastError to get the actual error number.
+ The result of calling this function with STRING set to NULL is not
+ defined. */
char *
-utf8_to_native (const char *string, size_t length, int delim)
+wchar_to_native (const wchar_t *string)
{
- /* FIXME */
- return strdup (string);
+ int n;
+ char *result;
+
+ n = WideCharToMultiByte (CP_ACP, 0, string, -1, NULL, 0, NULL, NULL);
+ if (n < 0)
+ return NULL;
+
+ result = malloc (n+1);
+ if (!result)
+ return NULL;
+
+ n = WideCharToMultiByte (CP_ACP, 0, string, -1, result, n, NULL, NULL);
+ if (n < 0)
+ {
+ free (result);
+ return NULL;
+ }
+ return result;
+}
+
+
+/* Return a malloced wide char string from an UTF-8 encoded input
+ string STRING. Caller must free this value. On failure returns
+ NULL; caller may use GetLastError to get the actual error number.
+ The result of calling this function with STRING set to NULL is not
+ defined. */
+wchar_t *
+utf8_to_wchar (const char *string)
+{
+ int n;
+ wchar_t *result;
+
+ n = MultiByteToWideChar (CP_UTF8, 0, string, -1, NULL, 0);
+ if (n < 0)
+ return NULL;
+
+ result = malloc ((n+1) * sizeof *result);
+ if (!result)
+ return NULL;
+
+ n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n);
+ if (n < 0)
+ {
+ free (result);
+ return NULL;
+ }
+ return result;
}
+
+char *
+utf8_to_native (const char *string)
+{
+ wchar_t *wstring;
+ char *result;
+
+ wstring = utf8_to_wchar (string);
+ if (!wstring)
+ return NULL;
+
+ result = wchar_to_native (wstring);
+ free (wstring);
+
+ return result;
+}
+
+
static const char*
get_string (struct loaded_domain *domain, u32 idx)
{
@@ -1432,7 +1500,7 @@ get_string (struct loaded_domain *domain, u32 idx)
domain->mapped[idx] = 1;
plen = strlen (p);
- buf = utf8_to_native (p, plen, -1);
+ buf = utf8_to_native (p);
buflen = strlen (buf);
if (buflen <= plen)
strcpy (p, buf);