aboutsummaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2006-06-03 22:20:43 +0200
committerJelmer Vernooij <jelmer@samba.org>2006-06-03 22:20:43 +0200
commit9779c186bd6d396a6fde61cc215f2438d453ee97 (patch)
treef213d656883f0c9f602b9d78bfe3ee9143744bdf /util.c
parenta15c097fa32028394264cf66ef4fd31f56315eb3 (diff)
parentfb62f81f947c74e274b05e32d2e88e3a4d7e2613 (diff)
[merge] Wilmer
Diffstat (limited to 'util.c')
-rw-r--r--util.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/util.c b/util.c
index db783fe0..dfa0906b 100644
--- a/util.c
+++ b/util.c
@@ -444,3 +444,51 @@ char *ipv6_unwrap( char *src )
return ( src + 7 );
}
#endif
+
+/* Convert from one charset to another.
+
+ from_cs, to_cs: Source and destination charsets
+ src, dst: Source and destination strings
+ size: Size if src. 0 == use strlen(). strlen() is not reliable for UNICODE/UTF16 strings though.
+ maxbuf: Maximum number of bytes to write to dst
+
+ Returns the number of bytes written to maxbuf or -1 on an error.
+*/
+signed int do_iconv( char *from_cs, char *to_cs, char *src, char *dst, size_t size, size_t maxbuf )
+{
+ GIConv cd;
+ size_t res;
+ size_t inbytesleft, outbytesleft;
+ char *inbuf = src;
+ char *outbuf = dst;
+
+ cd = g_iconv_open( to_cs, from_cs );
+ if( cd == (GIConv) -1 )
+ return( -1 );
+
+ inbytesleft = size ? size : strlen( src );
+ outbytesleft = maxbuf - 1;
+ res = g_iconv( cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft );
+ *outbuf = '\0';
+ g_iconv_close( cd );
+
+ if( res == (size_t) -1 )
+ return( -1 );
+ else
+ return( outbuf - dst );
+}
+
+char *set_eval_charset( irc_t *irc, set_t *set, char *value )
+{
+ GIConv cd;
+
+ if ( g_strncasecmp( value, "none", 4 ) == 0 )
+ return( value );
+
+ cd = g_iconv_open( "UTF-8", value );
+ if( cd == (GIConv) -1 )
+ return( NULL );
+
+ g_iconv_close( cd );
+ return( value );
+}