src: fix gb2312 -> utf8 iconv conversion issue

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2017-11-07 19:24:06 +01:00
parent 1c27ead3af
commit 25aeff66ba

View File

@ -323,7 +323,16 @@ int utf8_encode(char *inbuf, int inbuflen, char *outbuf, int outbuflen, char *en
memset(outbuf, 0, outbuflen);
cd = iconv_open("utf-8", encoding);
// Iconv sometimes produces an invalid utf8 sequence for gb2312.
// The fix is to use cp936, instead of gb2312 encoding.
//
// If there will be more similar exceptions, then we have to use
// a more efficient lookup method
if(strcasecmp(encoding, "gb2312") == 0)
cd = iconv_open("utf-8", "cp936");
else
cd = iconv_open("utf-8", encoding);
if(cd != (iconv_t)-1){
inbytesleft = inbuflen;
@ -339,4 +348,3 @@ int utf8_encode(char *inbuf, int inbuflen, char *outbuf, int outbuflen, char *en
return ret;
}