linux字符编码转换
/*
from_charset //要转换的编码
to_charset //转换为某某编码
inbuf //要转换的字符串
inlen //要转换的长度
outbuf //输出缓存
outlen //输出长度
*/
static int code_convert(char *from_charset,char *to_charset,char *inbuf,size_t inlen,char *outbuf,size_t outlen)
{
iconv_t cd;
char **pin = &inbuf;
char **pout = &outbuf;
cd = iconv_open(to_charset,from_charset);
if (cd==0)
return -1;
memset(outbuf,0,outlen);
if (iconv(cd,pin,&inlen,pout,&outlen)==-1)
{
fprintf(stderr,"iconv error:%s\n",strerror(errno));
return -2;
}
iconv_close(cd);
return 0;
}