From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id E5DB31F47C for ; Tue, 17 Jan 2023 13:11:18 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=clisp.org header.i=@clisp.org header.a=rsa-sha256 header.s=strato-dkim-0002 header.b=IPGnRYOK; dkim-atps=neutral Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHljw-0008EP-5t; Tue, 17 Jan 2023 08:11:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHljt-0008CF-BP for bug-gnulib@gnu.org; Tue, 17 Jan 2023 08:10:57 -0500 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.160]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHljq-0006eV-RL for bug-gnulib@gnu.org; Tue, 17 Jan 2023 08:10:57 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1673961052; cv=none; d=strato.com; s=strato-dkim-0002; b=c5RiZ1HjzU8155DQxgRaXAGGs/nDrW11nXUJ+uFWEgqtZZLjEDiCWCUNlNmGxXbVhL 0++SANIto8YUu3lmzz0J/LonwsaU49od1gOs7M+U+5K3eqpsGgyHrjA1Kbwnby+yywzg vMpZYBxgHnitxJroC+KEAGC5AnR7JGr3hE7lwQziaV1ig1ZsexjAK0nXPWaVksN+PEbz SaTaNnvMj9k14P+SYGdLWj1qpFAen1ausE2kraavodEN/5hx68qLeTpSCK/jnRyhdJWk RnCBlyCg4KXA9Szd/QrU1PwB3YFrn4x1V5XTDUPqLmeCk2FuaDNpAtffwDbdFGzuBiKW re4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1673961052; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-ID:Date:Subject:To:From:Cc:Date:From: Subject:Sender; bh=txnfr8RDMR/0jb+pNBDWRGNwpdQVe+UAF45ckjfmJKA=; b=DpnC99uPBjG9HHf7usr35qEcaN6r0luRKFJ1UOcKXRyEpj50jtEMdSfPhPuf4JJ98x JLn8C3YkK+EwlRw6+GPs19ka01OJpqVMwgb74Mbhc3aGNFYlGm7Ma+OSC5aFSTksOkkq DHhYurygLTCeybbqqNaTeb+ztD7jNrTuY/UThjbzTtoePhzXSaG2MsBVSIbvwmrIZ2bl OLUeSsRi7y4Lyqij7pqcvSc7c98wAS/ukLWEO7wzq/kiybWo4K471oeNV5gWhpptsCZZ KCvAJsqPLoAxzfM+L2kZYofuRsthW9xnmqWw0npSiKyMDNOa2LHeOk8vZWJM9X5M4orW CHPQ== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1673961052; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:To:From:Cc:Date:From: Subject:Sender; bh=txnfr8RDMR/0jb+pNBDWRGNwpdQVe+UAF45ckjfmJKA=; b=IPGnRYOKJ2asTTo6B5l1TGeiwQTklRQ5O1mogNxTp3G9JJ6pNIaYxSQhrruYpXNCZn u5Q2Kf1PVOQJj1MzbB5GB0JEiM6op4sl7YyKe2wld19SUPpH37aXPTb5mAo7VPF6q49u O9Dw5la36stYuuu5TmVW+jw1qudZi7GgZE+hTPMVhStBnLbZd88tNVtaneJhkN2VaZC+ 8HebL0Nz33qjCPzLjJdc8dPK/QMqUCM2HzZqY0Hv0WNaL8Gx6S48ylF4kPcI0VjLnrDs OBhVEzTWMmG9pJxilnoxDqZPcSD9p4cnFf2wqAQAhY1GqIE2mxScnUvK8cXnGBaY5yYG Xfsg== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zq68+3cfpOejvVUYts2exEnhvWSurYgn7u6IQ==" Received: from nimes.localnet by smtp.strato.de (RZmta 48.6.2 AUTH) with ESMTPSA id I8f358z0HDAqTFj (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 17 Jan 2023 14:10:52 +0100 (CET) From: Bruno Haible To: bug-gnulib@gnu.org Subject: hard_locale on Android Date: Tue, 17 Jan 2023 14:10:51 +0100 Message-ID: <1978752.Cn2yEi2vR9@nimes> In-Reply-To: <1990639.uacIGzncQW@nimes> References: <1990639.uacIGzncQW@nimes> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Received-SPF: none client-ip=81.169.146.160; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Given the strange behaviour of the "C" locale on Android, it is no wonder that I see a test failure: =46AIL: test-hard-locale =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D The initial locale should not be hard! =46AIL test-hard-locale (exit status: 1) This patch adjusts the function hard_locale in a conservative way (i.e. hard_locale(category) returns 1 if the locale has UTF-8 encoding or may behave in an unknown way in the future), and updates the unit test accordingly. I don't expect coreutils malfunctions on Android due to this, but we'll see. 2023-01-17 Bruno Haible hard-locale: Port to Android =E2=89=A5 5.0. * lib/hard-locale.c: Include . (hard_locale): On Android, consider also MB_CUR_MAX, even if the locale's name is "C". * tests/test-hard-locale.c (test_one, main): Assume that on Android, even the "C" locale is hard. diff --git a/lib/hard-locale.c b/lib/hard-locale.c index 0a28552e75..c01fce5344 100644 =2D-- a/lib/hard-locale.c +++ b/lib/hard-locale.c @@ -21,6 +21,7 @@ #include "hard-locale.h" =20 #include +#include #include =20 bool @@ -31,5 +32,16 @@ hard_locale (int category) if (setlocale_null_r (category, locale, sizeof (locale))) return false; =20 =2D return !(strcmp (locale, "C") =3D=3D 0 || strcmp (locale, "POSIX") =3D= =3D 0); + if (!(strcmp (locale, "C") =3D=3D 0 || strcmp (locale, "POSIX") =3D=3D 0= )) + return true; + +#if defined __ANDROID__ + /* On Android 5.0 or newer, it is possible to set a locale that has the = same + name as the "C" locale but in fact uses UTF-8 encoding. Cf. test cas= e 2 in + = =2E */ + if (MB_CUR_MAX > 1) + return true; +#endif + + return false; } diff --git a/tests/test-hard-locale.c b/tests/test-hard-locale.c index eb02f4f6e6..6f94e6c3ac 100644 =2D-- a/tests/test-hard-locale.c +++ b/tests/test-hard-locale.c @@ -38,8 +38,10 @@ test_one (const char *name, int failure_bitmask) /* musl libc has special code for the C.UTF-8 locale; other than tha= t, all locale names are accepted and all locales are trivial. OpenBSD returns the locale name that was set, but we don't know h= ow it =2D behaves under the hood. Likewise for Haiku. */ =2D#if defined MUSL_LIBC || defined __OpenBSD__ || defined __HAIKU__ + behaves under the hood. Likewise for Haiku. + On Android >=3D 5.0, the "C" locale may have UTF-8 encoding, and = we don't + know how it will behave in the future. */ +#if defined MUSL_LIBC || defined __OpenBSD__ || defined __HAIKU__ || defin= ed __ANDROID__ expected =3D true; #else expected =3D !all_trivial; @@ -57,12 +59,14 @@ test_one (const char *name, int failure_bitmask) =20 /* On NetBSD 7.0, some locales such as de_DE.ISO8859-1 and de_DE.UTF= =2D8 have the LC_COLLATE category set to "C". =2D Similarly, on musl libc, with the C.UTF-8 locale. */ + Similarly, on musl libc, with the C.UTF-8 locale. + On Android >=3D 5.0, the "C" locale may have UTF-8 encoding, and = we don't + know how it will behave in the future. */ #if defined __NetBSD__ expected =3D false; #elif defined MUSL_LIBC expected =3D strcmp (name, "C.UTF-8") !=3D 0; =2D#elif (defined __OpenBSD__ && HAVE_DUPLOCALE) || defined __HAIKU__ /* Op= enBSD >=3D 6.2, Haiku */ +#elif (defined __OpenBSD__ && HAVE_DUPLOCALE) || defined __HAIKU__ || defi= ned __ANDROID__ /* OpenBSD >=3D 6.2, Haiku, Android */ expected =3D true; #else expected =3D !all_trivial; @@ -86,12 +90,16 @@ main () { int fail =3D 0; =20 =2D /* The initial locale is the "C" or "POSIX" locale. */ + /* The initial locale is the "C" or "POSIX" locale. + On Android >=3D 5.0, it is equivalent to the "C.UTF-8" locale, cf. + = =2E */ +#if ! defined __ANDROID__ if (hard_locale (LC_CTYPE) || hard_locale (LC_COLLATE)) { fprintf (stderr, "The initial locale should not be hard!\n"); fail |=3D 1; } +#endif =20 all_trivial =3D (setlocale (LC_ALL, "foobar") !=3D NULL); =20