This is the mail archive of the cygwin-developers mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: "C" UTF-8 trouble


2009/10/7 Eric Blake:
> For the problematic apps, are they checking just the environment
> variables, or are they using setlocale(,NULL) and/or setlocale(,"") to
> determine the current/default settings?

Looking into this question, I found that for vim there's actually a
completely different culprit: nl_langinfo(CODESET) returns "US-ASCII"
for the C locale. (It also returns incorrect values for other
charset-less locales.)

Hence I replaced the code in nl_langinfo's CODESET case with just 'ret
= __locale_charset()', and vim's fine!

Unfortunately that's not the case for emacs.


> Anyone using _just_ the
> environment variables is doomed to failure. ÂPOSIX states:
>
> "If the LANG environment variable is not set or is set to the empty
> string, the implementation-defined default locale shall be used."
>
> My preference would be that if the environment variables were not set when
> cygwin1.dll started, then setlocale(,NULL) returns "C.UTF-8" rather than
> "C".

The way I understand it, setlocale(,NULL) only queries the current
setting and has to return "C" (or "POSIX") in the initial state.

But you're right regarding setlocale(,""); that could indeed return
something else if none of the environment variables is set. From
http://www.opengroup.org/onlinepubs/7990989775/xbd/locale.html:

"All implementations define a locale as the default locale, to be
invoked when no environment variables are set, or set to the empty
string. This default locale can be the POSIX locale or any other,
implementation-dependent locale."

I think this a good idea, so I replaced "C" with "C.UTF-8" at the end
of __get_locale_env. Yet emacs still doesn't behave, and digging into
its code I found that it does indeed read the env variables directly.
:(

      ;; Use the first of these three environment variables
      ;; that has a nonempty value.
      (let ((vars '("LC_ALL" "LC_CTYPE" "LANG")))
	(while (and vars
		    (= 0 (length locale))) ; nil or empty string
	  (setq locale (getenv (pop vars) frame)))))

Andy


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]