Re: [PATCH/RFC 07/17] gettext.c: work around us not using setlocale(LC_CTYPE, "")
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Aug 31, 2010, 16:51 UTC
- Message-ID
- <AANLkTi=+oGVx_T_-0T0RTqe+rV4QwQakjXUXKk8tddFL@mail.gmail.com>
- In-Reply-To
- <20100831151800.GG2315@burratino>
On Tue, Aug 31, 2010 at 15:18, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 7 quoted lines
> Ævar Arnfjörð Bjarmason wrote: > >> In 107880a I removed our use of setlocale(LC_CTYPE, "") because of a >> bug in the GNU C Library [1] > > Future readers might benefit from a reminder that it is vsnprintf that > is broken.
I'll work something in about that.
> Aside, not about this patch: glibc printf can be very convenient for > translators, because of format strings like "%4$s". Do other common > platforms like FreeBSD and Mingw have something similar?
I certainly hope so. I was planning on documenting its usage, Johannes?
Show 20 quoted lines
>> --- a/gettext.c
>> +++ b/gettext.c
>> @@ -17,5 +19,9 @@ extern void git_setup_gettext(void) {
>> }
>>
>> (void)setlocale(LC_MESSAGES, "");
>> + (void)setlocale(LC_CTYPE, "");
>> + charset = nl_langinfo(CODESET);
>> + (void)bind_textdomain_codeset("git", charset);
>> + (void)setlocale(LC_CTYPE, "C");
>
> For the curious: we cannot use
>
> setlocale(LC_CTYPE, "");
> charset = nl_langinfo(CODESET);
> setlocale(LC_CTYPE, "C");
> bind_textdomain_codeset("git", charset);
>
> because nl_langinfo returns a pointer to a static buffer that might
> be wiped out by setlocale() iirc.But I'm hopefully sidestepping that issue by passing it to bind_textdomain_codeset() right away.