iconv转码问题
我uncide转换为gbk。
我的红帽测试机可以转换,将unicode能转换为utf-8,gbk。
我用我的红帽静态编译后,放在debian下。
转utf-8的可以,转gbk就遇到问题。转gbk时,连返回码都没有,程序直接从inconv函数跳出了。为什么,求大神解答
附转换代码:
ssize_t convert(const char *tocode, const char *fromcode, char *inbufp, size_t inbytesleft, char *outbufp, size_t outbytesleft)
{
iconv_t ic;
size_t outbytes = outbytesleft;
int ret;
ic = iconv_open (tocode, fromcode);
if (ic == (iconv_t ) - 1)
{
printf ("iconv_open failed: from: %s, to: %s: %s\n", fromcode, tocode, strerror (errno));
return -1;
}
while (inbytesleft > 0)
{
ret = iconv (ic, &inbufp, &inbytesleft, &outbufp, &outbytes); if (ret == -1)
{
printf ("iconv failed: from: %s, to: %s: %s\n", fromcode, tocode, strerror (errno)); return -1;
}
}
ret = iconv_close (ic);
if (ret == -1)
{
printf ("iconv_close failed: from: %s, to: %s: %s\n", fromcode, tocode, strerror (errno));
return -1;
}
return outbytesleft-outbytes;
}