Code

Added error handling in the character conversion functions.
authorKalle Wallin <kaw@linux.se>
Mon, 29 Mar 2004 19:43:12 +0000 (19:43 +0000)
committerKalle Wallin <kaw@linux.se>
Mon, 29 Mar 2004 19:43:12 +0000 (19:43 +0000)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@544 09075e82-0dd4-0310-85a5-a0d7c8717e4f

support.c

index becd60b3156718208515ef354f336bc6717f5f71..bf60132775aebd3829ba87f7c5fa002f621c6c74 100644 (file)
--- a/support.c
+++ b/support.c
@@ -130,24 +130,54 @@ charset_close(void)
 char *
 utf8_to_locale(char *utf8str)
 {
-  char *str;
+  gchar *str;
+  gsize rb, wb;
+  GError *error;
 
   if( noconvert )
     return g_strdup(utf8str);
-  if( (str=g_locale_from_utf8(utf8str, -1, NULL, NULL, NULL)) == NULL )
-    return g_strdup(utf8str);
+
+  rb = 0; /* bytes read */
+  wb = 0; /* bytes written */
+  error = NULL;
+  str=g_locale_from_utf8(utf8str, 
+                        g_utf8_strlen(utf8str,-1), 
+                        &wb, &rb,
+                        &error);
+  if( error )
+    {
+      g_printerr("utf8_to_locale(): %s\n", error->message);
+      g_error_free(error);
+      return g_strdup(utf8str);
+    }
+  
   return str;
 }
 
 char *
 locale_to_utf8(char *localestr)
 {
-  char *str;
+  gchar *str;
+  gsize rb, wb;
+  GError *error;
 
   if( noconvert )
     return g_strdup(localestr);
-  if( (str=g_locale_to_utf8(localestr, -1, NULL, NULL, NULL)) == NULL )
-    return g_strdup(localestr);
+
+  rb = 0; /* bytes read */
+  wb = 0; /* bytes written */
+  error = NULL;
+  str=g_locale_to_utf8(localestr, 
+                      -1, 
+                      &wb, &rb,
+                      &error);
+  if( error )
+    {
+      g_printerr("locale_to_utf8: %s\n", error->message);
+      g_error_free(error);
+      return g_strdup(localestr);
+    }
+
   return str;
 }