[Proj] Proj may give erroneous results depending on locale

Glynn Clements glynn.clements at virgin.net
Tue Jul 20 22:50:12 EDT 2004


Peter S Galbraith wrote:

> Hi, a Debian user (Radoslaw Grzanka <radekg2 at poczta.onet.pl>) reported
> the following bug when his locale is set to pl_PL :

>         setlocale (LC_ALL, "");                 // SETTING LOCALES!

As the old joke goes:

	Patient: Doctor, when I do this ... it hurts.
	Doctor:  Don't do it, then!

Simple fix: don't call setlocale().

Writing internationalised software is non-trivial. In particular, it's
not a matter of simply calling setlocale() at the beginning of the
program then forgetting about it.

If you want to read/write numbers using printf/scanf etc (or if you
want to use libraries which do so), you have to keep switching locales
between the user's locale (defined by the LC_* and LANG environment
variables) and the C (aka POSIX) locale, as most textual file formats
and communication protocols require that decimal fractions use the
period (aka dot, full-stop) as the decimal separator, regardless of
the user's locale.

And many (most?) libraries require that the current locale is the C
locale. So, if you want to set the LC_NUMERIC category to something
other than the C locale, you have to set it back again before calling
any library functions.

IOW, the bug is in the application code, not in PROJ.

-- 
Glynn Clements <glynn.clements at virgin.net>



More information about the Proj mailing list