Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Feb 2007 01:06:03 -0600
From:      "Jia Zheng (Colin)" <colinzhengj@gmail.com>
To:        freebsd-i18n@freebsd.org
Subject:   wctomb bug?
Message-ID:  <20070212070603.GA4107@zjc.ch4.mdu>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070212070603.GA4107>