wctomb bug?

Jia Zheng (Colin) colinzhengj at gmail.com
Mon Feb 12 07:30:41 UTC 2007


Hi all,

Pardon me if this is not the right place to write.

My program uses UTF-8 internally, and I wrote the below routine to
convert a UTF-8 char using current encoding.

 24 int utf8tomb (pchar_t pcmb, const pchar_t pc)
 25 {
 26     wchar_t wc;
 27     setlocale (LC_CTYPE, "en_US.UTF-8");
 28     mbtowc (&wc, pc, MB_LEN_MAX);
 29     setlocale (LC_CTYPE, "zh_CN.GB2312");
 30     return wctomb (pcmb, wc);
 31 }

Problem: wctomb works incorrectly with zh_CN.GB2312 (in fact, any
encoding other than UTF-8 and C). When trying to convert a Chinese charactor, pcmb[0] 
always contains the decimal 17, and pcmb[1] is NULL.

Howver this routine works fine in Ubuntu. That is, pcmb points to a
string with length 2, not including the null terminator.

Besides, mbtowc works correctly. Since setlocale() was successful, I
believe the problem is with wctomb...


-zhengjia


More information about the freebsd-i18n mailing list