Re: Silly bug or am I just stupid?




Dimitromanolakis Apostolos <apdim@grecian.net> writes:

> Hi everybody,
> 
> There is something very strange in both the 1.0 and 1.1 source trees.
> More specifically the call to set the locale looks like:
> 
> current_locale = g_strdup (setlocale (LC_CTYPE, NULL));
> 
> This has the unfortunate effect that current_locale always has the value
> "C" even if you have set your LANG enviroment variable. This occured to me
> since I use locales and noticed that my locale extra keyboard bindings
> didn't work with any gtk+ application. I believe that more
> politically correct is:
> 
> current_locale = g_strdup (setlocale (LC_CTYPE, ""));
> 
> as is documented on the manual page (the man page does not define 
> behaviour for NULL second argument). At least this patch solved my 
> problem. I don't know if it is related to glibc in any way. Also I have
> noticed the same mistake in at least two other programs (one of them is
> nxterm).

setlocale (xxx, NULL) is different from setlocale (xxx, ""). 

setlocale (xxx, NULL) queries the current locale, while the
latter sets the locale according to the LANG enviroment
vairable.

I believe is is the POSIX behavior - it definitely works
for glibc. It's possible that some C libraries don't support
this, though - if you have an example of such I'd be
interested in hearing about it.

For a GTK+ application to actually use other locales than "C", it
needs to call gtk_set_locale() explicitely. (This is not
done automatically to avoid suprises with scanf, etc.)

The GIMP does this, I believe GNOME applications will do it
as well.

Regards,
                                        Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]