[svn] gpg-error - r150 - in trunk: . src
svn author marcus
cvs at cvs.gnupg.org
Tue Oct 25 21:18:13 CEST 2005
Author: marcus
Date: 2005-10-25 21:18:13 +0200 (Tue, 25 Oct 2005)
New Revision: 150
Modified:
trunk/ChangeLog
trunk/src/w32-gettext.c
Log:
2005-10-25 Marcus Brinkmann <marcus at g10code.de>
* 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.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2005-10-25 18:25:45 UTC (rev 149)
+++ trunk/ChangeLog 2005-10-25 19:18:13 UTC (rev 150)
@@ -1,5 +1,10 @@
2005-10-25 Marcus Brinkmann <marcus at g10code.de>
+ * 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.
Modified: trunk/src/w32-gettext.c
===================================================================
--- trunk/src/w32-gettext.c 2005-10-25 18:25:45 UTC (rev 149)
+++ trunk/src/w32-gettext.c 2005-10-25 19:18:13 UTC (rev 150)
@@ -1410,13 +1410,81 @@
}
+/* 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 @@
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);
More information about the Gnupg-commits
mailing list