diff common/strhelp.c @ 1158:ffdc8cba139a

(issue36) Add acp_to_wchar based on utf8_to_wchar
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 18 Sep 2014 15:43:48 +0200
parents 698b6a9bd75e
children
line wrap: on
line diff
--- a/common/strhelp.c	Thu Sep 18 15:43:22 2014 +0200
+++ b/common/strhelp.c	Thu Sep 18 15:43:48 2014 +0200
@@ -281,4 +281,29 @@
   result[n] = 0;
   return result;
 }
+
+wchar_t
+*acp_to_wchar (const char *string, size_t len)
+{
+  int n, ilen;
+  wchar_t *result;
+
+  ilen = (int) len;
+  if (ilen < 0)
+    return NULL;
+
+  n = MultiByteToWideChar (CP_ACP, 0, string, ilen, NULL, 0);
+  if (n < 0 || n + 1 < 0)
+    return NULL;
+
+  result = xmalloc ((size_t)(n+1) * sizeof *result);
+  n = MultiByteToWideChar (CP_ACP, 0, string, ilen, result, n);
+  if (n < 0)
+    {
+      xfree (result);
+      return NULL;
+    }
+  result[n] = 0;
+  return result;
+}
 #endif

http://wald.intevation.org/projects/trustbridge/