aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKalle Wallin <kaw@linux.se>2004-03-29 19:43:12 +0000
committerKalle Wallin <kaw@linux.se>2004-03-29 19:43:12 +0000
commit06b750db39674ccb9d15ff58e09bac4187f38a02 (patch)
tree6578996115a25833a6230bd78f9f1dc97bf0013d
parent452dde67513ccaef8bc69321ee5e2e0f12ed29c1 (diff)
downloadmpd-06b750db39674ccb9d15ff58e09bac4187f38a02.tar.gz
mpd-06b750db39674ccb9d15ff58e09bac4187f38a02.tar.xz
mpd-06b750db39674ccb9d15ff58e09bac4187f38a02.zip
Added error handling in the character conversion functions.
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@544 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--support.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/support.c b/support.c
index becd60b31..bf6013277 100644
--- 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;
}