Author: mturk
Date: Sun Aug 16 10:56:51 2009
New Revision: 804661
URL: http://svn.apache.org/viewvc?rev=804661&view=rev
Log:
Add utf8 strdup functions
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=804661&r1=804660&r2=804661&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
(original)
+++
commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
Sun Aug 16 10:56:51 2009
@@ -106,9 +106,10 @@
* Utility functions from wutilc.
*/
wchar_t *res_name_from_filenamew(int, wchar_t *, const wchar_t *);
-int utf8_to_unicode_path(wchar_t *, size_t, const char *);
-int unicode_to_utf8_path(char *, size_t, const wchar_t *);
-
+int utf8_to_unicode_path(wchar_t *, size_t, const char *);
+int unicode_to_utf8_path(char *, size_t, const wchar_t *);
+wchar_t *x_wcsdup_utf8(const char *);
+char *x_strdup_utf8(const wchar_t *);
#ifdef __cplusplus
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c?rev=804661&r1=804660&r2=804661&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c Sun Aug 16
10:56:51 2009
@@ -171,3 +171,64 @@
return 0;
}
+wchar_t *x_wcsdup_utf8(const char *str)
+{
+ int len;
+ wchar_t *res;
+ if (!str)
+ return NULL;
+ if (!(len = MultiByteToWideChar(CP_UTF8,
+ MB_PRECOMPOSED | MB_ERR_INVALID_CHARS,
+ str, -1, NULL, 0, NULL, 0))) {
+ if (GetLastError() != ERROR_INSUFICIENT_BUFFER)
+ errno = EILSEQ;
+ return NULL;
+ }
+ res = malloc(len * sizeof(wchar_t));
+ if (!res)
+ return NULL;
+ if (!MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED | MB_ERR_INVALID_CHARS,
+ str, -1, res, len)) {
+ DWORD saved = GetLastError();
+ free(res);
+ SetLastError(saved);
+ /* Update CRT errno as well */
+ if (saved == ERROR_INSUFICIENT_BUFFER)
+ errno = ENOMEM;
+ else
+ errno = EILSEQ;
+ return NULL;
+ }
+ else {
+ return res;
+ }
+}
+
+char *x_strdup_utf8(const wchar_t *str)
+{
+ int len;
+ char *res;
+
+ if (!(len = WideCharToMultiByte(CP_UTF8, 0, str, -1, NULL, NULL))) {
+ if (GetLastError() != ERROR_INSUFICIENT_BUFFER)
+ errno = EILSEQ;
+ return NULL;
+ }
+ if (!(res = malloc(len)))
+ return NULL;
+ if (!WideCharToMultiByte(CP_UTF8, 0, str, -1, res, len, NULL, NULL)) {
+ DWORD saved = GetLastError();
+ x_free(res);
+ SetLastError(saved);
+ /* Update CRT errno as well */
+ if (saved == ERROR_INSUFICIENT_BUFFER)
+ errno = ENOMEM;
+ else
+ errno = EILSEQ;
+ return NULL;
+ }
+ else {
+ return res;
+ }
+}
+