X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD92B3858434
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1679606081;
	bh=RKp/MXaP3EfAcb0p5FUdLucEmnuN5cm7NlVMmcFh3zY=;
	h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe:
	 List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
	 From;
	b=KmZMAz+3KZYgZGj2GzT5kwVKT4XO1WeQtSpx5VZz5vPQcZ3idixR4uA4XXL5zM0vZ
	 2Zk6zQ1PWd+XUDYQyRdu2aJE0A0aARkD41oO80frtemE+IJHP/efrObNCTCeVd9hL/
	 /ZS8Ug+cklj5g83IkOl7YIMUpFVoX884nPOZQCNk=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 874A73858CDB
Date: Thu, 23 Mar 2023 22:14:23 +0100
To: cygwin@cygwin.com
Subject: Re: newlocale: Linux incompatibility
Message-ID: <ZBzBL2jFO7Oltjd1@calimero.vinschen.de>
Mail-Followup-To: cygwin@cygwin.com
References: <bd7ebebc-cf90-d509-ef15-11d702a6126c@cornell.edu>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <bd7ebebc-cf90-d509-ef15-11d702a6126c@cornell.edu>
X-Provags-ID: V03:K1:6XMin+etnZUcvtOvwA5aQI3fXAn8v0O7u6syJg26X4JOrXh/jcT
 cBcDhnayt2H7GRYpd6nTGxk9nm3aOCtYtWQT+rRK2VrT2bVkzROqpp7n/pyZ7BTJoDre1wI
 SWfowJqcX+hCkIkjkCry7c0KR1GSTiHTU527RPKIrjx8zErIbcTzY3yETdicRyGD2KRtL2v
 M75U6Shob9wxwoQjUzrxw==
UI-OutboundReport: notjunk:1;M01:P0:/zx+jbjCMww=;Xguwv3qAi2JvrS8v9vjo+v4MPvd
 1IzBy0L9jCFyIllw1edabOjLLbFV0aI61F0Pqa2mSkhtoSs0RLaNl9F8R54PsyjijWUrejtuu
 HT47TgI0lnTCJPsvKDoRXI7FZ4LHAQT9tVFHfEjDrZ9P3YFNF8BxHtpsunDwYTi+IFqyJLhHR
 x8oS4nsk5n9wocKlsX/qCYVSMXsbpI1DJiuXCEkBW5mxchkjhvEPmJT4GKoWvkdgPf6f/G+sH
 xlIb7AMKFCJQmshzns1PYnpiklMtAo8ZSZc6boAXJc1nUj48klDIAD67toVV6whIQolfxB2Lt
 J7yvu6kE0Li+6OOVCM/HBy3RXr5aHd8Hn2sEsNo8dxKvtL1vhMJhlIdMAdi2HW/Y1emulo5Y/
 YME1SSM3gebFkRvUigHl+Ls+upSVhbS1J0OJyTnDY4Pb0tlwTabmS03eaMeWZKC88LFvqD22N
 2XyJwSiizgRhPU7O4CWyuqt0O+HHrSfGuUFwHNhHklYkZYeaPOx2vWFsc1qSiawYnkIsmgnXr
 KEHrbrcuhpZNPl3oBhRbJlzbGYz0TaqCusRI0m5kjdekKY3jBAxC7YWv26xR/81P6xNDL/4oL
 3DnxvgzXzTvA4N8iUEZxjITHSvq/8grMMCA0npVc5RzxnDflz/Hk5MhE+2SIlJR0AAggrh47l
 7vX6jRQrS06VhLf5cRll0iX8pNdBHmqZOlpcxhsPug==
X-Spam-Status: No, score=-97.6 required=5.0 tests=BAYES_00,
 GOOD_FROM_CORINNA_CYGWIN, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE,
 RCVD_IN_MSPIKE_H2, SPF_FAIL, SPF_HELO_NONE,
 TXREP autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Corinna Vinschen via Cygwin <cygwin@cygwin.com>
Reply-To: cygwin@cygwin.com
Cc: Corinna Vinschen <corinna-cygwin@cygwin.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces+archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>

On Mar 23 15:48, Ken Brown via Cygwin wrote:
> 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.

Actually, it's a Windows 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");
>   else
>     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.

Three bugs in fact.

First, it's a bug in the Emacs testsuite.  The test simply assumes that
there's no en_DE locale on any system, but that's just not true.
Windows support the RFC 5646 locale "en-DE", which is called "English
(Germany)" in the "Region" settings.

You can also check with `locale -av | less' and search for en_DE.

For the reminder of this mail, I assume you're talking about Cygwin 3.5.
I won't fix this for 3.4 anymore, given how much locale handling has
changed for 3.5.

The second bug is that Cygwin blindly trusts the Windows function
ResolveLocaleName().  That function blatantly converts even vaguely
similar locales into something it supports.  E.g., it converts "en-XY"
to "en-US".  I. .e., even if you use "en_XY.utf8" as locale, the above
testcase will wrongly succeed.  So I have to rethink how I resolve POSIX
locales to Windows locales.

And the third bug is that Cygwin fails to set errno if it doesn't
support a locale, but that's a minor inconvenience in comparison.

Thanks for the report, I totally missed the above problem with
ResolveLocaleName.


Corinna

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
