//GB2312转换成UCS-2BE
int GB2312_to_UCS2BE(char **content)
{
static char temp_des[BUFFLEN] = {0};
char *des=temp_des;
size_t srcleft=strlen(*content), desleft=BUFFLEN;
iconv_t cd = iconv_open("UCS-2BE","GB2312");
if(cd == (iconv_t) -1)
{
R5_ERROR((" iconv_open ERR!/n"));
return -1;
}
int ap = iconv(cd, content, &srcleft, &des, &desleft);
if (ap == -1)
{
R5_ERROR((" iconv error -- errno: %d/n", errno));
iconv_close(cd);
return -1;
}
iconv_close(cd);
*content=temp_des;
return BUFFLEN-desleft;
}
iconv -l :查看支持的字符编码标识
eg: UCS-2BE UNICODE-1-1 UNICODEBIG CSUNICODE11
UCS-2LE UNICODELITTLE
ISO-10646-UCS-4 UCS-4 CSUCS4
UCS-4BE
UCS-4LE
UTF-16
UTF-16BE
size_t iconv (iconv t cd, char **inbuf, size t *inbytesleft, **outbuf, size t *outbytesleft);
如果转换发生错误,则iconv()返回-1
入转换成功,则inbytesleft的值为0,outbuf的值是原值+inbytesleft,outbytesleft的值是原值-inbytesleft。
详情:查看libc文档(iconv_open()、iconv()、iconv_close())或man iconv