Branch
Hash :
bc2d70ee
Author :
Date :
2025-02-14T15:24:54
newlocale: Work around macOS, NetBSD, Solaris 11 OpenIndiana bug. * m4/newlocale.m4 (gl_FUNC_NEWLOCALE): Test for the "null base" bug. Set REPLACE_NEWLOCALE to 1 if it has the bug. * lib/newlocale.c (newlocale): Add alternative implementation that uses the system's newlocale(). * modules/newlocale (configure.ac): Consider REPLACE_NEWLOCALE. * tests/test-newlocale.c: Include <langinfo.h>. (main): Verify fix for the "null base" bug. * modules/newlocale-tests (configure.ac): Test for nl_langinfo_l. * doc/posix-functions/newlocale.texi: Mention the "null base" bug.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
/* Test of creating a locale object.
Copyright (C) 2025 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* Written by Bruno Haible <bruno@clisp.org>, 2025. */
#include <config.h>
#include <locale.h>
#include "signature.h"
SIGNATURE_CHECK (newlocale, locale_t, (int, const char *, locale_t));
#if HAVE_NL_LANGINFO_L
# include <langinfo.h>
#endif
#include "macros.h"
#if defined _WIN32 && !defined __CYGWIN__
# define ENGLISH "English_United States"
# define FRENCH "French_France"
# define GERMAN "German_Germany"
# define ENCODING ".1252"
# define LOCALE1 ENGLISH ENCODING
# define LOCALE2 FRENCH ENCODING
# define LOCALE3 GERMAN ENCODING
#else
# define LOCALE1 "en_US.UTF-8"
# define LOCALE2 "fr_FR.UTF-8"
# define LOCALE3 "de_DE.UTF-8"
#endif
int
main ()
{
{
locale_t l1 = newlocale (LC_TIME_MASK, LOCALE1, NULL);
locale_t l2 = newlocale (LC_MESSAGES_MASK, LOCALE2, l1);
locale_t l3 = newlocale (LC_TIME_MASK, LOCALE3, l2);
(void) l3;
}
#if HAVE_NL_LANGINFO_L
/* Verify that when the base argument is NULL, "the data for all sections
not requested by category_mask shall be taken from the POSIX locale". */
{
locale_t l1 = newlocale (LC_TIME_MASK, LOCALE1, NULL);
if (l1 != NULL)
{
const char *radixchar1 = nl_langinfo_l (RADIXCHAR, l1);
ASSERT (*radixchar1 == '.');
if (setlocale (LC_ALL, LOCALE2) != NULL)
{
radixchar1 = nl_langinfo_l (RADIXCHAR, l1);
ASSERT (*radixchar1 == '.');
locale_t l1a = newlocale (LC_TIME_MASK, LOCALE1, NULL);
const char *radixchar1a = nl_langinfo_l (RADIXCHAR, l1a);
ASSERT (*radixchar1a == '.');
}
}
}
#endif
return test_exit_status;
}