newlocale: Linux incompatibility
Thu Mar 23 20:09:57 GMT 2023
Am 23.03.2023 um 20:48 schrieb Ken Brown via Cygwin:
> I'm reporting this here rather than the newlib list because the
> behavior is compatible with Posix but not Linux, so I think it's a
> Cygwin issue.
> Consider the following test case:
> $ cat locale_test.c
> #include <stdio.h>
> #include <locale.h>
> int main ()
> const char *locale = "en_DE.UTF-8";
> locale_t loc = newlocale (LC_COLLATE_MASK | LC_CTYPE_MASK, locale, 0);
> if (!loc)
> perror ("newlocale");
> printf ("newlocale succeeded on invalid locale %s\n", locale);
> $ gcc -o locale_test locale_test.c
> $ ./locale_test.exe
> newlocale succeeded on invalid locale en_DE.UTF-8
> On Linux, the newlocale call fails with ENOENT, as is documented on
> the man page. Posix doesn't say what should happen on an invalid
> locale, so this is not, strictly speaking, a bug.
So the question is what is an invalid locale. In Linux, locales are only
valid if explicitly listed somewhere.
This strict behaviour may be a problem. A much better approach is to
allow any combination of known language_REGIOIN tags with encoding
indications, to be much more flexible and dynamic.
So if such combinations are considered legal, as in cygwin, this is not
> P.S. I noticed this because of a failing Emacs test. No one else has
> reported this test failure, so it seems that newlocale fails on an
> invalid locale on all platforms supported by Emacs other than Cygwin.
More information about the Cygwin