字符编码转换函数linux通用
/** * FormatConversion 字符编码格式转换 * @param from_charset 转化前格式 * @param sourcebuf 转化后格式 * @param sourcebuf 源包缓冲区 * @param sourcelen 源包长度 * @param destbuf 目标缓冲区 * @param destlen 目标长度 * @@return 无返回 */ int FormatConversion(char*from_charset,char*to_charset,char *sourcebuf,size_t sourcelen,char *destbuf,size_t destlen) { iconv_t cd; if( (cd = iconv_open(to_charset,from_charset)) ==0 ) { printf("iconv_open error \n"); return -1; } memset(destbuf,0,destlen); char **source = &sourcebuf; char **dest = &destbuf; if(-1 == iconv(cd,source,&sourcelen,dest,&destlen)) { printf("iconv error \n"); iconv_close(cd); return -1; } iconv_close(cd); printf("sourcelen = %d destlen = %d\n",sourcelen,destlen); return 0; }