bash and the current locale implementation

Corinna Vinschen corinna-cygwin@cygwin.com
Thu Oct 1 11:37:00 GMT 2009


On Oct  1 12:22, Andy Koppe wrote:
> 2009/10/1 Corinna Vinschen:
> >> > Consequentially, bash can't just call setlocale (LC_ALL, "").  Instead,
> >> > bash calls the following:
> >> >
> >> >   setlocale (LC_CTYPE, "foo");
> >> >   setlocale (LC_NUMERIC, "foo");
> >> >   setlocale (LC_TIME, "foo");
> >> >   [...]
> >>
> >> I'll see if I can find some way to patch bash.
> >
> >  setenv (locale_var);
> >  if (locale_var == "LANG" || "LC_ALL")
> >    setlocale (LC_ALL, "");
> >  else if (locale_var == "LC_CTYPE")
> >    setlocale (LC_CTYPE, "");
> >
> > would be sufficient.  But I can't say I'm really happy about this.  It
> > sure sounds like a hack, having to change bash.  Unfortunately I can't
> > see any way to change Cygwin as long as the application doesn't change
> > its own environment.
> 
> I'm confused. I thought setlocale() wasn't meant to change Cygwin
> internals aymore, because that would require all apps to call
> setlocale(LC_CTYPE, "")? You'd cited ssh as an example that doesn't do
> that.

No, you misunderstood.  The idea is the the locale environment of the
application determines how Cygwin internally converts multibyte to wide
char and vice versa.

At the start of every application, Cygwin now calls

  setlocale (LC_CTYPE, "");
  setlocale (LC_CTYPE, "C");

The result is that Cygwin internally uses whatever the environment is
set to, while the application uses the default "C" locale per POSIX.

No application *has* to call setlocale (LC_ALL, "") for that to happen.
However, *if* the application calls setlocale (LC_ALL, ""), because it
is locale aware, it will just get the same conversion as the environment
is set to anyway, and Cygwin and the application will use the same
conversion functions.

An application using an explicit locale string like in `setlocale
(LC_ALL, "en.UTF-8") is about to set something explicitely and ignore
the environment settings.  That's what currently happens in bash.

Does that make it clearer?


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat



More information about the Cygwin-developers mailing list