diff mac/dw.m @ 1784:86ace55df07b

Added UTF8/Wide conversion functions on OS/2 and Windows... Updated the readme file and some comment cleanups.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 24 Jul 2012 23:33:50 +0000
parents 9de6d1cc8fb8
children 9a32d4216f24
line wrap: on
line diff
--- a/mac/dw.m	Tue Jul 24 22:52:57 2012 +0000
+++ b/mac/dw.m	Tue Jul 24 23:33:50 2012 +0000
@@ -11035,14 +11035,16 @@
  * Parameters:
  *       utf8string: UTF-8 encoded source string.
  * Returns:
- *       Wide string that needs to be freed with dw_free().
+ *       Wide string that needs to be freed with dw_free()
+ *       or NULL on failure.
  */
 wchar_t * API dw_utf8_to_wchar(char *utf8string)
 {
     size_t buflen = strlen(utf8string) + 1;
-    wchar_t *buffer = malloc(buflen * sizeof(wchar_t));
-    mbstowcs(buffer, utf8string, buflen);
-    return buffer;
+    wchar_t *temp = malloc(buflen * sizeof(wchar_t));
+    if(temp)
+        mbstowcs(temp, utf8string, buflen);
+    return temp;
 }
 
 /*
@@ -11050,12 +11052,14 @@
  * Parameters:
  *       wstring: Wide source string.
  * Returns:
- *       UTF-8 encoded string that needs to be freed with dw_free().
+ *       UTF-8 encoded string that needs to be freed with dw_free()
+ *       or NULL on failure.
  */
 char * API dw_wchar_to_utf8(wchar_t *wstring)
 {
     size_t bufflen = 8 * wcslen(wstring) + 1;
     char *temp = malloc(bufflen);
-    wcstombs(temp, wstring, bufflen);
+    if(temp)
+        wcstombs(temp, wstring, bufflen);
     return temp;
 }