From: Kalle Wallin Date: Mon, 29 Mar 2004 19:43:12 +0000 (+0000) Subject: Added error handling in the character conversion functions. X-Git-Tag: v0.12_alpha1~619 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=06b750db39674ccb9d15ff58e09bac4187f38a02;p=ncmpc.git Added error handling in the character conversion functions. git-svn-id: https://svn.musicpd.org/ncmpc/trunk@544 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- diff --git a/support.c b/support.c index becd60b..bf60132 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; }