Subject: Re: userlevel tools and setlocale(3)
To: None <firstname.lastname@example.org>
From: James K. Lowden <email@example.com>
Date: 04/28/2006 20:24:00
Aleksey Cheusov wrote:
> > On Thu, Apr 27, 2006 at 09:53:56PM +0300, Aleksey Cheusov wrote:
> >> What do you think about the following patch for nawk?
> >> With this patch applied, awk will exit with error
> >> if LANG or LC_ variable are set to incorrect value,
> > Incorrect locale settings are softerrors, since it is entire
> > possible that a single part of a locale is not defined. setlocale()
> > is well-behaving in that regard, it falls back to "C", as if nothing
> > had happened.
> With this "softerror" scripts that rely on locale
> work _completely_ incorrect with no chance of signaling
> user about errors.
IMO, your rendering is too strict, and ignoring the return code (and
requiring the script to rely on something external, e.g. locale(1)) is too
lax. Nothing says awk *needs* a locale, but it's dismal to force a script
to work in ignorance when the interpreter is perfectly aware of the locale
The script should have a way -- preferably an awk way -- to discover
whether or not the locale is broken for its purposes. After all, things
like toupper() are affected by the language being represented in by the
What about defining a built-in variable, say, LOCALE to something
meaningful when the locale is OK? Or a die-on-warning option like Perl
and gcc use?